edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <div class="salesEdit-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. <span style="margin: 0 15px;color: #666;">客户名称:{{ detailData&&detailData.buyerName }}</span>
  8. </template>
  9. <!-- 操作区,位于 title 行的行尾 -->
  10. <template slot="extra">
  11. <a-radio-group key="3" v-model="printerType">
  12. <a-radio value="INK">针式</a-radio>
  13. <a-radio value="NEEDLE">喷墨</a-radio>
  14. </a-radio-group>
  15. <a-button key="2" id="salesEdit-preview-btn" :disabled="dataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
  16. <a-button key="1" type="primary" id="salesEdit-print-btn" :disabled="dataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
  17. </template>
  18. </a-page-header>
  19. <a-card size="small" :bordered="false" class="salesEdit-cont">
  20. <!-- 查询配件列表 -->
  21. <queryPart ref="partQuery" :buyerSn="detailData&&detailData.buyerSn" :priceType="$route.params.priceType" :newLoading="isInster" @add="insterProduct"></queryPart>
  22. </a-card>
  23. <a-card size="small" :bordered="false" class="salesEdit-cont">
  24. <!-- 总计 -->
  25. <a-alert style="margin-bottom: 15px;" type="info">
  26. <div slot="message" class="total-bar">
  27. <div>
  28. 总售价:<strong>¥{{ detailData&&detailData.totalAmount || 0 }}</strong>;
  29. 总款数:<strong>{{ detailData&&detailData.totalCategory || 0 }}</strong>;
  30. 总数量:<strong>{{ detailData&&detailData.totalQty || 0 }}</strong>;
  31. 赠品总数量:<strong>{{ detailData&&detailData.giftQty || 0 }}</strong>;
  32. </div>
  33. <div>
  34. <div>
  35. 折扣金额:
  36. <a-input-number id="discount" v-model="detailData.discountAmount" :min="0" :precision="2" :max="999999"/>
  37. <a-button type="primary" @click="salesDiscount" class="button-info">打折</a-button>
  38. </div>
  39. <div>
  40. 折扣:<strong>{{ detailData&&detailData.discountRate || 0 }}%</strong>;
  41. 折后总售价:<strong>¥{{ detailData&&detailData.discountedAmount || 0 }}</strong>;
  42. </div>
  43. </div>
  44. </div>
  45. </a-alert>
  46. <!-- 查询条件 -->
  47. <a-row :gutter="15">
  48. <a-col :span="18">
  49. <a-form-model layout="inline" :model="productForm">
  50. <a-form-model-item label="产品编码">
  51. <a-input v-model="productForm.productCode" allowClear placeholder="输入产品编码" />
  52. </a-form-model-item>
  53. <a-form-model-item label="产品名称">
  54. <a-input v-model="productForm.productName" allowClear placeholder="输入产品名称" />
  55. </a-form-model-item>
  56. <a-form-model-item>
  57. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  58. <a-button style="margin: 0 0 18px 8px" @click="resetForm" id="salesEdit-reset">重置</a-button>
  59. </a-form-model-item>
  60. </a-form-model>
  61. </a-col>
  62. <a-col :span="6">
  63. <div style="float:right;overflow: hidden;">
  64. <!-- <a-button size="small" id="salesEdit-dru">导入明细</a-button> -->
  65. <a-button
  66. size="small"
  67. type="primary"
  68. @click="delSalerDetailAll"
  69. :loading="delLoading"
  70. style="margin-left: 10px"
  71. id="salesEdit-del-all">整单删除</a-button>
  72. </div>
  73. </a-col>
  74. </a-row>
  75. <!-- 已选配件列表 -->
  76. <s-table
  77. class="sTable"
  78. ref="table"
  79. size="small"
  80. :rowKey="(record) => record.id"
  81. :columns="columns"
  82. :data="loadData"
  83. :scroll="{ x: 1940, y: 300 }"
  84. :rowClassName="(record, index) => record.cost > record.price ? 'redBg-row':''"
  85. bordered>
  86. <!-- 产品编码 -->
  87. <template slot="productCode" slot-scope="text, record">
  88. <a-badge count="急" v-if="record.oosFlag == 1">
  89. <div style="padding-right: 15px;">{{ text }}</div>
  90. </a-badge>
  91. <span v-else>{{ text }}</span>
  92. </template>
  93. <!-- 售价 -->
  94. <template slot="price" slot-scope="text, record">
  95. <editable-cell
  96. size="small"
  97. :text="text"
  98. id="salesEdit-price"
  99. :max="999999"
  100. :min="0"
  101. :precision="2"
  102. punit="¥"
  103. @change="onCellChange(record.id, 'price', $event)" />
  104. </template>
  105. <!-- 销售数量 -->
  106. <template slot="salesNums" slot-scope="text, record">
  107. <editable-cell
  108. size="small"
  109. :text="record.qty"
  110. id="salesEdit-salesNums"
  111. :max="999999"
  112. :min="1"
  113. :precision="0"
  114. @change="onCellChange(record.id, 'qty', $event)" />
  115. </template>
  116. <!-- 操作 -->
  117. <template slot="action" slot-scope="text, record">
  118. <a-button
  119. size="small"
  120. type="primary"
  121. :loading="delLoading"
  122. class="button-error"
  123. @click="handleDel(record)"
  124. id="productInfoList-Del">删除</a-button>
  125. </template>
  126. </s-table>
  127. </a-card>
  128. <a-affix :offset-bottom="0">
  129. <div
  130. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  131. <a-button
  132. size="large"
  133. style="width: 150px;"
  134. type="primary"
  135. class="button-primary"
  136. @click="handleSubmit()"
  137. id="productInfoList-handleSubmit">提交</a-button>
  138. </div>
  139. </a-affix>
  140. <!-- 选择客户弹框 -->
  141. <choose-custom-modal ref="custModal" :show="openModal" @updateData="updateData" @cancel="openModal=false" />
  142. <!-- 打印 -->
  143. <div id="print"></div>
  144. </div>
  145. </template>
  146. <script>
  147. import { STable, VSelect } from '@/components'
  148. import queryPart from './queryPart.vue'
  149. import chooseCustomModal from './chooseCustomModal.vue'
  150. import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint } from '@/api/sales'
  151. import EditableCell from '@/views/common/editInput.js'
  152. import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
  153. export default {
  154. name: 'SalesDetail',
  155. components: { STable, VSelect, queryPart, chooseCustomModal, EditableCell },
  156. data () {
  157. return {
  158. orderId: null, // 销售单id
  159. salesBillSn: null, // 销售单sn
  160. disabled: false, // 查询、重置按钮是否可操作
  161. isInster: false, // 是否正在添加产品
  162. openModal: false, // 客户弹框
  163. delLoading: false,
  164. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  165. dataSource: [],
  166. productForm: {
  167. productName: '',
  168. productCode: ''
  169. },
  170. // 表头
  171. columns: [
  172. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  173. { title: '产品编码', dataIndex: 'dealerProductEntity.code', scopedSlots: { customRender: 'productCode' }, width: 220, align: 'center', sorter: true },
  174. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  175. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  176. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: 200, align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  177. { title: '仓库', dataIndex: 'warehouseEntity.name', width: 150, align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  178. { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: 150, align: 'center', customRender: function (text) { return text || '--' } },
  179. { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: 150, align: 'center' },
  180. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  181. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  182. { title: '售价小计', dataIndex: 'totalAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  183. { title: '折后小计', dataIndex: 'discountedAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  184. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  185. ],
  186. // 加载数据方法 必须为 Promise 对象
  187. loadData: parameter => {
  188. this.disabled = true
  189. this.productForm.salesBillSn = this.$route.params.sn
  190. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  191. const data = res.data
  192. const no = (data.pageNo - 1) * data.pageSize
  193. for (var i = 0; i < data.list.length; i++) {
  194. data.list[i].no = no + i + 1
  195. }
  196. this.disabled = false
  197. this.dataSource = data.list
  198. return data
  199. })
  200. },
  201. printerType: 'INK' // 打印机类型
  202. }
  203. },
  204. methods: {
  205. onCellChange (id, key, value) {
  206. console.log(id, key, value)
  207. const dataSource = [...this.dataSource]
  208. const row = dataSource.find(item => item.id === id)
  209. if (row) {
  210. row[key] = Number(value)
  211. this.dataSource = dataSource
  212. }
  213. // 修改价格
  214. if (key == 'price') {
  215. salesDetailUpdatePrice({
  216. salesBillSn: row.salesBillSn,
  217. productSn: row.productSn,
  218. price: row.price
  219. }).then(res => {
  220. this.resetSearchForm(true)
  221. this.$message.info(res.message)
  222. })
  223. }
  224. if (key == 'qty') {
  225. salesDetailUpdateQty({
  226. id: row.id,
  227. qty: row.qty
  228. }).then(res => {
  229. this.resetSearchForm(true)
  230. if (res.status == 200) {
  231. this.$refs.partQuery.resetCurForm()
  232. }
  233. this.$message.info(res.message)
  234. })
  235. }
  236. },
  237. // 打印预览/快捷打印
  238. handlePrint (type) {
  239. const _this = this
  240. salesDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
  241. if (res.type == 'application/json') {
  242. var reader = new FileReader()
  243. reader.addEventListener('loadend', function () {
  244. const obj = JSON.parse(reader.result)
  245. _this.$notification.error({
  246. message: '提示',
  247. description: obj.message
  248. })
  249. })
  250. reader.readAsText(res)
  251. } else {
  252. this.print(res, type)
  253. }
  254. })
  255. },
  256. print (data, type) {
  257. if (!data) {
  258. return
  259. }
  260. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  261. document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
  262. if (type == 'preview') { // 预览
  263. window.open(url)
  264. } else if (type == 'print') { // 打印
  265. window.frames['printf'].focus()
  266. window.frames['printf'].print()
  267. }
  268. },
  269. // 编辑客户信息
  270. handleEdit () {
  271. this.openModal = true
  272. setTimeout(() => {
  273. this.$refs.custModal.editCust(this.detailData)
  274. }, 500)
  275. },
  276. // 更新产品列表
  277. updateData (priceType) {
  278. // 价格类型变更
  279. if (priceType != this.$route.params.priceType) {
  280. this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  281. } else {
  282. this.getOrderDetail()
  283. }
  284. },
  285. // 重置
  286. resetSearchForm (flag) {
  287. this.$refs.table.refresh(!!flag)
  288. this.getOrderDetail()
  289. },
  290. // 重置列表
  291. resetForm () {
  292. this.productForm = {
  293. productName: '',
  294. productCode: ''
  295. }
  296. this.$refs.table.refresh()
  297. },
  298. // 返回
  299. handleBack () {
  300. this.$router.push({ name: 'salesQueryList' })
  301. },
  302. // 打折
  303. salesDiscount () {
  304. if (this.detailData.discountAmount < 0) {
  305. return
  306. }
  307. console.log(this.detailData)
  308. salesWriteDiscount({
  309. discountAmount: this.detailData.discountAmount,
  310. salesBillSn: this.detailData.salesBillSn,
  311. id: this.detailData.id
  312. }).then(res => {
  313. if (res.status == 200) {
  314. this.resetSearchForm()
  315. }
  316. })
  317. },
  318. // 整单删除
  319. delSalerDetailAll () {
  320. const _this = this
  321. this.$confirm({
  322. title: '提示',
  323. content: '确认要整单删除吗?',
  324. centered: true,
  325. closable: true,
  326. onOk () {
  327. _this.delLoading = true
  328. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  329. if (res.status == 200) {
  330. _this.resetSearchForm()
  331. }
  332. _this.$message.info(res.message)
  333. _this.delLoading = false
  334. })
  335. }
  336. })
  337. },
  338. // 删除产品
  339. handleDel (row) {
  340. const _this = this
  341. this.$confirm({
  342. title: '提示',
  343. content: '确认要删除吗?',
  344. centered: true,
  345. closable: true,
  346. onOk () {
  347. _this.delLoading = true
  348. salesDetailDel({ id: row.id }).then(res => {
  349. if (res.status == 200) {
  350. _this.resetSearchForm(true)
  351. }
  352. _this.$message.info(res.message)
  353. _this.delLoading = false
  354. })
  355. }
  356. })
  357. },
  358. // 添加产品
  359. insterProduct (row) {
  360. console.log(row)
  361. // 防止多次添加产品
  362. if (this.isInster) { return }
  363. const _this = this
  364. // 判断是否已添加此产品
  365. const hasRow = this.dataSource.find(item => item.productSn == row.productSn && item.warehouseSn == row.warehouseSn && item.warehouseLocationSn == row.warehouseLocationSn)
  366. if (hasRow) {
  367. this.$message.info('该产品已在当前销售单中存在!')
  368. return
  369. }
  370. // 库存不足时
  371. if (row.currentQty < row.salesNums) {
  372. this.$confirm({
  373. title: '提示',
  374. content: '库存不足,确认添加为急件吗?',
  375. centered: true,
  376. closable: true,
  377. onOk () {
  378. _this.saveNewProduct(row)
  379. }
  380. })
  381. } else if (row.putCost > row.salePrice) {
  382. // 销售价低于成本价
  383. this.$confirm({
  384. title: '提示',
  385. content: '售价低于成本价,确认要添加吗?',
  386. centered: true,
  387. closable: true,
  388. onOk () {
  389. _this.saveNewProduct(row)
  390. }
  391. })
  392. } else {
  393. this.saveNewProduct(row)
  394. }
  395. },
  396. // 保存添加的产品到销售列表
  397. saveNewProduct (row) {
  398. this.$message.loading('正在添加产品...', 1)
  399. this.isInster = true
  400. salesDetailInsert({
  401. buyerSn: this.detailData.buyerSn,
  402. productSn: row.productSn,
  403. cost: row.putCost,
  404. // productCode: row.productCode,
  405. // productOrigCode: row.productOrigCode,
  406. price: row.salePrice,
  407. qty: row.salesNums,
  408. salesBillSn: this.detailData.salesBillSn,
  409. salesBillNo: this.detailData.salesBillNo,
  410. warehouseSn: row.warehouseSn,
  411. warehouseLocationSn: row.warehouseLocationSn,
  412. stockSn: row.stockSn
  413. }).then(res => {
  414. if (res.status == 200) {
  415. this.resetSearchForm()
  416. this.$refs.partQuery.resetCurForm()
  417. this.$message.success('产品添加成功', 2.5)
  418. }
  419. this.isInster = false
  420. })
  421. },
  422. // 销售单详情
  423. getOrderDetail () {
  424. salesDetail({ id: this.$route.params.id }).then(res => {
  425. console.log('getOrderDetail')
  426. if (res.status == 200) {
  427. this.detailData = res.data
  428. console.log(this.detailData)
  429. }
  430. })
  431. },
  432. // 提交销售单
  433. handleSubmit () {
  434. salesWriteSubmit({ id: this.orderId }).then(res => {
  435. if (res.status == 200) {
  436. this.handleBack()
  437. this.$message.success(res.message)
  438. }
  439. })
  440. }
  441. },
  442. mounted () {
  443. this.getOrderDetail()
  444. this.orderId = this.$route.params.id
  445. this.salesBillSn = this.$route.params.sn
  446. },
  447. beforeRouteEnter (to, from, next) {
  448. next(vm => {
  449. console.log('beforeRouteEnter')
  450. })
  451. }
  452. }
  453. </script>
  454. <style lang="less">
  455. .salesEdit-wrap{
  456. .salesEdit-cont{
  457. margin-top: 15px;
  458. }
  459. .total-bar{
  460. display: flex;
  461. align-items: center;
  462. justify-content: space-between;
  463. > div{
  464. &:last-child{
  465. display: flex;
  466. align-items: center;
  467. justify-content: space-between;
  468. > div{
  469. padding: 0 10px;
  470. }
  471. }
  472. }
  473. }
  474. .redBg-row{
  475. background-color: #f5cdc8;
  476. }
  477. }
  478. </style>