edit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <div class="salesEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <a style="margin: 0 15px;color: #666;font-size: 18px;font-weight: 600;">单号:{{ detailData&&detailData.salesBillNo || '--' }}</a>
  9. <span style="margin: 0 10px;color: #666;">客户名称:{{ detailData&&detailData.buyerName || '--' }}</span>
  10. </template>
  11. <!-- 操作区,位于 title 行的行尾 -->
  12. <template slot="extra" v-if="$hasPermissions('B_salesPrint')">
  13. <Print :disabled="dataSource.length==0" @handlePrint="handlePrint"></Print>
  14. </template>
  15. </a-page-header>
  16. <a-card size="small" :bordered="false" class="salesEdit-cont">
  17. <!-- 查询配件列表 -->
  18. <queryPart
  19. ref="partQuery"
  20. :newLoading="isInster"
  21. @add="insterProduct"
  22. @isCost="isCost"></queryPart>
  23. </a-card>
  24. <a-card size="small" :bordered="false" class="salesEdit-cont">
  25. <!-- 总计 -->
  26. <a-alert v-if="detailData" style="margin-bottom: 10px;" type="info">
  27. <div slot="message" class="total-bar">
  28. <div>
  29. 总售价:<strong>{{ detailData&&(detailData.totalAmount || detailData.totalAmount==0) ? '¥'+detailData.totalAmount : '--' }}</strong>;
  30. 总款数:<strong>{{ detailData&&(detailData.totalCategory || detailData.totalCategory==0) ? detailData.totalCategory : '--' }}</strong>;
  31. 总数量:<strong>{{ detailData&&(detailData.totalQty || detailData.totalQty==0) ? detailData.totalQty : '--' }}</strong>;
  32. 赠品总数量:<strong>{{ detailData&&(detailData.giftQty || detailData.giftQty==0) ? detailData.giftQty : '--' }}</strong>;
  33. <span v-if="isCosts">
  34. 总成本价:<strong>{{ detailData&&(detailData.totalCost || detailData.totalCost==0) ? detailData.totalCost : '--' }}</strong>;
  35. 毛利:<strong>{{ detailData&&(detailData.grossProfit || detailData.grossProfit==0) ? detailData.grossProfit : '--' }}</strong>;
  36. </span>
  37. </div>
  38. <div>
  39. <div>
  40. 折扣金额:
  41. <a-input-number
  42. id="discount"
  43. size="small"
  44. v-model="detailData.discountAmount"
  45. :min="0"
  46. :precision="2"
  47. :max="999999"/>
  48. <a-button size="small" type="primary" class="button-primary" @click="salesDiscount">打折</a-button>
  49. </div>
  50. <div>
  51. 折扣:<strong>{{ detailData&&(detailData.discountRate || detailData.discountRate==0) ? detailData.discountRate+'%' : '--' }}</strong>;
  52. 折后总售价:<strong>{{ detailData&&(detailData.discountedAmount || detailData.discountedAmount==0) ? '¥'+detailData.discountedAmount : '--' }}</strong>;
  53. </div>
  54. </div>
  55. </div>
  56. </a-alert>
  57. <!-- 搜索条件 -->
  58. <div class="table-page-search-wrapper">
  59. <a-row :gutter="15">
  60. <a-col :span="18">
  61. <a-form-model :model="productForm" ref="ruleForm" layout="inline" @keyup.enter.native="$refs.table.refresh(true)" >
  62. <a-row :gutter="15">
  63. <a-col :md="8" :sm="24">
  64. <a-form-model-item label="产品编码">
  65. <a-input v-model="productForm.productCode" allowClear placeholder="输入产品编码" />
  66. </a-form-model-item>
  67. </a-col>
  68. <a-col :md="8" :sm="24">
  69. <a-form-model-item label="产品名称">
  70. <a-input v-model="productForm.productName" allowClear placeholder="输入产品名称" />
  71. </a-form-model-item>
  72. </a-col>
  73. <a-col :md="8" :sm="24">
  74. <a-form-model-item style="margin-bottom: 10px;">
  75. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  76. <a-button style="margin-left: 5px" @click="resetForm" id="salesEdit-reset">重置</a-button>
  77. </a-form-model-item>
  78. </a-col>
  79. </a-row>
  80. </a-form-model>
  81. </a-col>
  82. <a-col :span="6">
  83. <div style="float:right;overflow: hidden;">
  84. <a-button
  85. type="primary"
  86. @click="delSalerOrder"
  87. :loading="delLoading"
  88. style="margin-right: 10px"
  89. id="salesEdit-del-all">整单删除</a-button>
  90. <a-button
  91. style="padding: 0 25px;"
  92. type="primary"
  93. :disabled="spinning"
  94. class="button-primary"
  95. @click="handleSubmit()"
  96. id="productInfoList-handleSubmit">提交</a-button>
  97. </div>
  98. </a-col>
  99. </a-row>
  100. </div>
  101. <!-- 已选配件列表 -->
  102. <s-table
  103. class="sTable"
  104. ref="table"
  105. size="small"
  106. :rowKey="(record) => record.id"
  107. :columns="columns"
  108. :data="loadData"
  109. :defaultLoadData="false"
  110. :pageSize="5"
  111. :rowClassName="(record, index) => record.cost > record.price ? 'redBg-row':''"
  112. bordered>
  113. <!-- 产品编码 -->
  114. <template slot="productCode" slot-scope="text, record">
  115. <a-badge count="急" v-if="record.oosFlag == 1">
  116. <div style="padding-right: 15px;">{{ text }}</div>
  117. </a-badge>
  118. <span v-else>{{ text }}</span>
  119. </template>
  120. <!-- 售价 -->
  121. <template slot="price" slot-scope="text, record">
  122. <a-input-number
  123. id="salesEdit-price"
  124. size="small"
  125. v-model="record.price"
  126. :precision="2"
  127. :min="0"
  128. :max="999999"
  129. placeholder="请输入"
  130. @blur="e => priceBlur(e.target.value, record)"
  131. style="width: 100%;" />
  132. </template>
  133. <!-- 销售数量 -->
  134. <template slot="salesNums" slot-scope="text, record">
  135. <a-input-number
  136. id="salesEdit-salesNums"
  137. size="small"
  138. v-model="record.qty"
  139. :precision="0"
  140. :min="1"
  141. :max="999999"
  142. placeholder="请输入"
  143. @blur="e => qtyBlur(e.target.value, record)"
  144. style="width: 100%;" />
  145. </template>
  146. <!-- 操作 -->
  147. <template slot="action" slot-scope="text, record">
  148. <a-button
  149. size="small"
  150. type="link"
  151. :loading="delLoading"
  152. class="button-error"
  153. @click="handleDel(record)"
  154. id="productInfoList-Del">删除</a-button>
  155. </template>
  156. </s-table>
  157. </a-card>
  158. </a-spin>
  159. <!-- <div class="affix-cont"></div> -->
  160. <!-- 选择客户弹框 -->
  161. <choose-custom-modal ref="custModal" :show="openModal" @updateData="updateData" @cancel="openModal=false" />
  162. </div>
  163. </template>
  164. <script>
  165. import { STable, VSelect } from '@/components'
  166. import queryPart from './queryPart.vue'
  167. import chooseCustomModal from './chooseCustomModal.vue'
  168. import { stockByProductSn } from '@/api/stock'
  169. import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint, salesDetailExport, salesDel } from '@/api/sales'
  170. import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
  171. import Print from '@/views/common/print.vue'
  172. import { hdPrint } from '@/libs/JGPrint'
  173. export default {
  174. name: 'SalesDetail',
  175. components: { STable, VSelect, queryPart, chooseCustomModal, Print },
  176. data () {
  177. return {
  178. spinning: false,
  179. orderId: null, // 销售单id
  180. salesBillSn: null, // 销售单sn
  181. disabled: false, // 查询、重置按钮是否可操作
  182. isInster: false, // 是否正在添加产品
  183. openModal: false, // 客户弹框
  184. delLoading: false,
  185. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  186. dataSource: [],
  187. productForm: {
  188. productName: '',
  189. productCode: '',
  190. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  191. },
  192. // 表头
  193. columns: [
  194. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  195. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', scopedSlots: { customRender: 'productCode' }, align: 'center' },
  196. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  197. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  198. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  199. { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  200. { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  201. { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: '7%', align: 'center' },
  202. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '7%', align: 'center' },
  203. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  204. { title: '售价小计', dataIndex: 'totalAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  205. { title: '折后小计', dataIndex: 'discountedAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  206. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  207. ],
  208. // 加载数据方法 必须为 Promise 对象
  209. loadData: parameter => {
  210. this.disabled = true
  211. this.productForm.salesBillSn = this.$route.params.sn
  212. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  213. let data
  214. if (res.status == 200) {
  215. data = res.data
  216. const no = (data.pageNo - 1) * data.pageSize
  217. for (var i = 0; i < data.list.length; i++) {
  218. data.list[i].no = no + i + 1
  219. data.list[i].qtyBackups = data.list[i].qty
  220. data.list[i].priceBackups = data.list[i].price
  221. }
  222. this.disabled = false
  223. this.dataSource = data.list || []
  224. }
  225. return data
  226. })
  227. },
  228. printerType: 'NEEDLE', // 打印机类型
  229. isCosts: false
  230. }
  231. },
  232. methods: {
  233. // 打印预览/快捷打印
  234. handlePrint (type, printerType) {
  235. const _this = this
  236. _this.spinning = true
  237. let url = salesDetailPrint
  238. const params = { sn: this.outBizSn || this.$route.params.sn }
  239. if (type == 'export') { // 导出
  240. url = salesDetailExport
  241. }
  242. // 打印或导出
  243. hdPrint(printerType, type, url, params, '销售单', function () {
  244. _this.spinning = false
  245. })
  246. },
  247. // 已选产品 销售数量 blur
  248. qtyBlur (val, record) {
  249. const _this = this
  250. this.dataSource = record || []
  251. if (val && val != record.qtyBackups) {
  252. this.spinning = true
  253. // 校验库存
  254. stockByProductSn({ productSn: record.productSn }).then(res => {
  255. if (res.status == 200) {
  256. if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
  257. _this.changeQty(record)
  258. } else {
  259. this.$confirm({
  260. title: '提示',
  261. content: '库存不足,确认添加为急件吗?',
  262. centered: true,
  263. closable: true,
  264. onOk () {
  265. _this.changeQty(record)
  266. },
  267. onCancel () {
  268. record.qty = record.qtyBackups
  269. _this.spinning = false
  270. }
  271. })
  272. }
  273. } else {
  274. this.spinning = false
  275. record.qty = record.qtyBackups
  276. }
  277. })
  278. } else {
  279. record.qty = record.qtyBackups
  280. }
  281. },
  282. changeQty (record) {
  283. salesDetailUpdateQty({
  284. id: record.id,
  285. qty: record.qty
  286. }).then(res => {
  287. this.resetSearchForm(false)
  288. if (res.status == 200) {
  289. this.$message.info(res.message)
  290. }
  291. this.spinning = false
  292. })
  293. },
  294. // 已选产品 售价 blur
  295. priceBlur (val, record) {
  296. this.dataSource = record || []
  297. // 光标移出,值发生改变再调用编辑接口
  298. if (val && val != record.priceBackups) {
  299. this.spinning = true
  300. salesDetailUpdatePrice({
  301. salesBillSn: record.salesBillSn,
  302. productSn: record.productSn,
  303. price: record.price
  304. }).then(res => {
  305. this.resetSearchForm(false)
  306. if (res.status == 200) {
  307. this.$message.info(res.message)
  308. this.spinning = false
  309. } else {
  310. this.spinning = false
  311. }
  312. })
  313. } else {
  314. record.price = record.priceBackups
  315. }
  316. },
  317. isCost (val) {
  318. this.isCosts = val
  319. },
  320. // 更新产品列表
  321. updateData (priceType) {
  322. // 价格类型变更
  323. if (priceType != this.$route.params.priceType) {
  324. this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  325. } else {
  326. this.getOrderDetail(true)
  327. }
  328. },
  329. // 重置
  330. resetSearchForm (flag) {
  331. if (flag) { this.$refs.partQuery.onlyList = true }
  332. this.$refs.table.refresh(!!flag)
  333. this.getOrderDetail(false)
  334. },
  335. // 重置列表
  336. resetForm () {
  337. this.productForm = {
  338. productName: '',
  339. productCode: '',
  340. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  341. }
  342. this.$refs.table.refresh()
  343. },
  344. // 返回
  345. handleBack () {
  346. this.$router.push({ path: '/salesManagement/salesQuery/list' })
  347. },
  348. // 打折
  349. salesDiscount () {
  350. if (this.detailData.discountAmount < 0) {
  351. return
  352. }
  353. this.spinning = true
  354. salesWriteDiscount({
  355. discountAmount: this.detailData.discountAmount,
  356. salesBillSn: this.detailData.salesBillSn,
  357. id: this.detailData.id
  358. }).then(res => {
  359. if (res.status == 200) {
  360. this.resetSearchForm(true)
  361. this.spinning = false
  362. } else {
  363. this.spinning = false
  364. }
  365. })
  366. },
  367. // 删除销售单
  368. delSalerOrder () {
  369. const _this = this
  370. this.$confirm({
  371. title: '提示',
  372. content: '确认删除该销售单吗?',
  373. centered: true,
  374. closable: true,
  375. onOk () {
  376. _this.spinning = true
  377. salesDel({ id: _this.orderId }).then(res => {
  378. if (res.status == 200) {
  379. _this.$message.success(res.message)
  380. _this.handleBack()
  381. }
  382. _this.spinning = false
  383. })
  384. }
  385. })
  386. },
  387. // 删除已选产品
  388. delSalerDetailAll () {
  389. const _this = this
  390. this.$confirm({
  391. title: '提示',
  392. content: '确认要整单删除吗?',
  393. centered: true,
  394. closable: true,
  395. onOk () {
  396. _this.delLoading = true
  397. _this.spinning = true
  398. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  399. if (res.status == 200) {
  400. _this.resetSearchForm(true)
  401. _this.productForm = {
  402. productName: '',
  403. productCode: '',
  404. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  405. }
  406. }
  407. _this.$message.info(res.message)
  408. _this.delLoading = false
  409. _this.spinning = false
  410. })
  411. }
  412. })
  413. },
  414. // 删除产品
  415. handleDel (row) {
  416. const _this = this
  417. this.$confirm({
  418. title: '提示',
  419. content: '确认要删除吗?',
  420. centered: true,
  421. closable: true,
  422. onOk () {
  423. _this.delLoading = true
  424. _this.spinning = true
  425. salesDetailDel({ id: row.id }).then(res => {
  426. if (res.status == 200) {
  427. _this.resetSearchForm(false)
  428. }
  429. _this.$message.info(res.message)
  430. _this.delLoading = false
  431. _this.spinning = false
  432. })
  433. }
  434. })
  435. },
  436. // 添加产品
  437. insterProduct (row) {
  438. // 防止多次添加产品
  439. if (this.isInster) { return }
  440. const _this = this
  441. // 判断是否已添加此产品
  442. if (this.dataSource && this.dataSource.length > 0) {
  443. const hasRow = this.dataSource.find(item => item.productSn == row.productSn)
  444. if (hasRow) {
  445. // this.$message.info('该产品已在当前销售单中存在!')
  446. this.productForm = {
  447. productName: '',
  448. productCode: hasRow.dealerProductEntity && hasRow.dealerProductEntity.code || '',
  449. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  450. }
  451. this.$refs.table.refresh(true)
  452. return
  453. } else {
  454. this.productForm = {
  455. productName: '',
  456. productCode: '',
  457. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  458. }
  459. }
  460. }
  461. // 库存不足时
  462. if (row.currentQty < row.salesNums) {
  463. _this.$confirm({
  464. title: '提示',
  465. content: '库存不足,确认添加为急件吗?',
  466. centered: true,
  467. closable: true,
  468. onOk () {
  469. _this.isPutCostDyPrice(row)
  470. }
  471. })
  472. } else {
  473. _this.isPutCostDyPrice(row)
  474. }
  475. },
  476. // 判断售价低于成本价
  477. isPutCostDyPrice (row) {
  478. const _this = this
  479. if (row.putCost > row.price) {
  480. // 销售价低于成本价
  481. _this.$confirm({
  482. title: '提示',
  483. content: '售价低于成本价,确认要添加吗?',
  484. centered: true,
  485. closable: true,
  486. onOk () {
  487. _this.saveNewProduct(row)
  488. }
  489. })
  490. } else {
  491. _this.saveNewProduct(row)
  492. }
  493. },
  494. // 保存添加的产品到销售列表
  495. saveNewProduct (row) {
  496. this.$message.loading('正在添加产品...', 1)
  497. this.isInster = true
  498. // this.spinning = true
  499. salesDetailInsert({
  500. buyerSn: this.detailData.buyerSn,
  501. productSn: row.productSn,
  502. cost: row.putCost,
  503. // productCode: row.productCode,
  504. // productOrigCode: row.productOrigCode,
  505. price: row.price,
  506. qty: row.salesNums,
  507. salesBillSn: this.detailData.salesBillSn,
  508. salesBillNo: this.detailData.salesBillNo,
  509. warehouseSn: row.warehouseSn,
  510. warehouseLocationSn: row.warehouseLocationSn,
  511. stockSn: row.stockSn
  512. }).then(res => {
  513. if (res.status == 200) {
  514. // this.resetSearchForm(true) // 不刷新库存
  515. this.$refs.table.refresh(true)
  516. this.getOrderDetail(false)
  517. }
  518. this.isInster = false
  519. // this.spinning = false
  520. })
  521. },
  522. // 销售单详情
  523. getOrderDetail (flag) {
  524. salesDetail({ id: this.$route.params.id }).then(res => {
  525. if (res.status == 200) {
  526. this.detailData = res.data
  527. if (flag) {
  528. const vm = this
  529. const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.salesBillSource && vm.detailData.salesBillSource == 'PURCHASE') ? '' : vm.detailData.buyerSn
  530. const priceType = vm.$route.params.priceType
  531. vm.$refs.partQuery.pageInit(buyerSn, priceType)
  532. }
  533. }
  534. })
  535. },
  536. // 提交销售单
  537. handleSubmit () {
  538. this.spinning = true
  539. salesWriteSubmit({ id: this.orderId }).then(res => {
  540. if (res.status == 200) {
  541. this.handleBack()
  542. this.$message.success(res.message)
  543. this.spinning = false
  544. } else {
  545. this.spinning = false
  546. }
  547. })
  548. },
  549. pageInit () {
  550. const vm = this
  551. vm.orderId = vm.$route.params.id
  552. vm.salesBillSn = vm.$route.params.sn
  553. vm.getOrderDetail(true)
  554. vm.$refs.table.refresh(true)
  555. }
  556. },
  557. mounted () {
  558. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  559. this.pageInit()
  560. }
  561. },
  562. activated () {
  563. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  564. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  565. this.pageInit()
  566. }
  567. },
  568. beforeRouteEnter (to, from, next) {
  569. next(vm => {})
  570. }
  571. }
  572. </script>
  573. <style lang="less">
  574. .salesEdit-wrap{
  575. position: relative;
  576. height: 100%;
  577. box-sizing: border-box;
  578. >.ant-spin-nested-loading{
  579. overflow-y: scroll;
  580. height: 100%;
  581. }
  582. .salesEdit-cont{
  583. margin-top: 10px;
  584. }
  585. .total-bar{
  586. display: flex;
  587. align-items: center;
  588. justify-content: space-between;
  589. > div{
  590. &:last-child{
  591. display: flex;
  592. align-items: center;
  593. justify-content: space-between;
  594. > div{
  595. padding: 0 10px;
  596. }
  597. }
  598. }
  599. }
  600. .redBg-row{
  601. background-color: #f5cdc8;
  602. }
  603. }
  604. </style>