edit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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;margin-top: 5px;">
  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. },
  191. // 表头
  192. columns: [
  193. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  194. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', scopedSlots: { customRender: 'productCode' }, align: 'center', sorter: true },
  195. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  196. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  197. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  198. { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  199. { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  200. { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: '7%', align: 'center' },
  201. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '7%', align: 'center' },
  202. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  203. { title: '售价小计', dataIndex: 'totalAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  204. { title: '折后小计', dataIndex: 'discountedAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  205. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  206. ],
  207. // 加载数据方法 必须为 Promise 对象
  208. loadData: parameter => {
  209. this.disabled = true
  210. this.productForm.salesBillSn = this.$route.params.sn
  211. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  212. const data = res.data
  213. const no = (data.pageNo - 1) * data.pageSize
  214. for (var i = 0; i < data.list.length; i++) {
  215. data.list[i].no = no + i + 1
  216. data.list[i].qtyBackups = data.list[i].qty
  217. data.list[i].priceBackups = data.list[i].price
  218. }
  219. this.disabled = false
  220. this.dataSource = data.list || []
  221. return data
  222. })
  223. },
  224. printerType: 'NEEDLE', // 打印机类型
  225. isCosts: false
  226. }
  227. },
  228. methods: {
  229. // 打印预览/快捷打印
  230. handlePrint (type, printerType) {
  231. const _this = this
  232. _this.spinning = true
  233. let url = salesDetailPrint
  234. const params = { sn: this.outBizSn || this.$route.params.sn }
  235. if (type == 'export') { // 导出
  236. url = salesDetailExport
  237. }
  238. // 打印或导出
  239. hdPrint(printerType, type, url, params, '销售单', function () {
  240. _this.spinning = false
  241. })
  242. },
  243. // 已选产品 销售数量 blur
  244. qtyBlur (val, record) {
  245. const _this = this
  246. this.dataSource = record || []
  247. if (val && val != record.qtyBackups) {
  248. this.spinning = true
  249. // 校验库存
  250. stockByProductSn({ productSn: record.productSn }).then(res => {
  251. if (res.status == 200) {
  252. if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
  253. _this.changeQty(record)
  254. } else {
  255. this.$confirm({
  256. title: '提示',
  257. content: '库存不足,确认添加为急件吗?',
  258. centered: true,
  259. closable: true,
  260. onOk () {
  261. _this.changeQty(record)
  262. },
  263. onCancel () {
  264. record.qty = record.qtyBackups
  265. _this.spinning = false
  266. }
  267. })
  268. }
  269. } else {
  270. this.spinning = false
  271. record.qty = record.qtyBackups
  272. }
  273. })
  274. } else {
  275. record.qty = record.qtyBackups
  276. }
  277. },
  278. changeQty (record) {
  279. salesDetailUpdateQty({
  280. id: record.id,
  281. qty: record.qty
  282. }).then(res => {
  283. this.resetSearchForm(false)
  284. if (res.status == 200) {
  285. this.$message.info(res.message)
  286. }
  287. this.spinning = false
  288. })
  289. },
  290. // 已选产品 售价 blur
  291. priceBlur (val, record) {
  292. this.dataSource = record || []
  293. // 光标移出,值发生改变再调用编辑接口
  294. if (val && val != record.priceBackups) {
  295. this.spinning = true
  296. salesDetailUpdatePrice({
  297. salesBillSn: record.salesBillSn,
  298. productSn: record.productSn,
  299. price: record.price
  300. }).then(res => {
  301. this.resetSearchForm(false)
  302. if (res.status == 200) {
  303. this.$message.info(res.message)
  304. this.spinning = false
  305. } else {
  306. this.spinning = false
  307. }
  308. })
  309. } else {
  310. record.price = record.priceBackups
  311. }
  312. },
  313. isCost (val) {
  314. this.isCosts = val
  315. },
  316. // 更新产品列表
  317. updateData (priceType) {
  318. // 价格类型变更
  319. if (priceType != this.$route.params.priceType) {
  320. this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  321. } else {
  322. this.getOrderDetail(true)
  323. }
  324. },
  325. // 重置
  326. resetSearchForm (flag) {
  327. if (flag) { this.$refs.partQuery.onlyList = true }
  328. this.$refs.table.refresh(!!flag)
  329. this.getOrderDetail(false)
  330. },
  331. // 重置列表
  332. resetForm () {
  333. this.productForm = {
  334. productName: '',
  335. productCode: ''
  336. }
  337. this.$refs.table.refresh()
  338. },
  339. // 返回
  340. handleBack () {
  341. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  342. },
  343. // 打折
  344. salesDiscount () {
  345. if (this.detailData.discountAmount < 0) {
  346. return
  347. }
  348. this.spinning = true
  349. salesWriteDiscount({
  350. discountAmount: this.detailData.discountAmount,
  351. salesBillSn: this.detailData.salesBillSn,
  352. id: this.detailData.id
  353. }).then(res => {
  354. if (res.status == 200) {
  355. this.resetSearchForm(true)
  356. this.spinning = false
  357. } else {
  358. this.spinning = false
  359. }
  360. })
  361. },
  362. // 删除销售单
  363. delSalerOrder () {
  364. const _this = this
  365. this.$confirm({
  366. title: '提示',
  367. content: '确认删除该销售单吗?',
  368. centered: true,
  369. closable: true,
  370. onOk () {
  371. _this.spinning = true
  372. salesDel({ id: _this.orderId }).then(res => {
  373. if (res.status == 200) {
  374. _this.$message.success(res.message)
  375. _this.handleBack()
  376. }
  377. _this.spinning = false
  378. })
  379. }
  380. })
  381. },
  382. // 删除已选产品
  383. delSalerDetailAll () {
  384. const _this = this
  385. this.$confirm({
  386. title: '提示',
  387. content: '确认要整单删除吗?',
  388. centered: true,
  389. closable: true,
  390. onOk () {
  391. _this.delLoading = true
  392. _this.spinning = true
  393. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  394. if (res.status == 200) {
  395. _this.resetSearchForm(true)
  396. _this.productForm = {
  397. productName: '',
  398. productCode: ''
  399. }
  400. }
  401. _this.$message.info(res.message)
  402. _this.delLoading = false
  403. _this.spinning = false
  404. })
  405. }
  406. })
  407. },
  408. // 删除产品
  409. handleDel (row) {
  410. const _this = this
  411. this.$confirm({
  412. title: '提示',
  413. content: '确认要删除吗?',
  414. centered: true,
  415. closable: true,
  416. onOk () {
  417. _this.delLoading = true
  418. _this.spinning = true
  419. salesDetailDel({ id: row.id }).then(res => {
  420. if (res.status == 200) {
  421. _this.resetSearchForm(false)
  422. }
  423. _this.$message.info(res.message)
  424. _this.delLoading = false
  425. _this.spinning = false
  426. })
  427. }
  428. })
  429. },
  430. // 添加产品
  431. insterProduct (row) {
  432. // 防止多次添加产品
  433. if (this.isInster) { return }
  434. const _this = this
  435. // 判断是否已添加此产品
  436. if (this.dataSource && this.dataSource.length > 0) {
  437. const hasRow = this.dataSource.find(item => item.productSn == row.productSn)
  438. if (hasRow) {
  439. // this.$message.info('该产品已在当前销售单中存在!')
  440. this.productForm = {
  441. productName: '',
  442. productCode: hasRow.dealerProductEntity && hasRow.dealerProductEntity.code || ''
  443. }
  444. this.$refs.table.refresh(true)
  445. return
  446. } else {
  447. this.productForm = {
  448. productName: '',
  449. productCode: ''
  450. }
  451. }
  452. }
  453. // 库存不足时
  454. if (row.currentQty < row.salesNums) {
  455. this.$confirm({
  456. title: '提示',
  457. content: '库存不足,确认添加为急件吗?',
  458. centered: true,
  459. closable: true,
  460. onOk () {
  461. _this.saveNewProduct(row)
  462. }
  463. })
  464. } else if (row.putCost > row.salePrice) {
  465. // 销售价低于成本价
  466. this.$confirm({
  467. title: '提示',
  468. content: '售价低于成本价,确认要添加吗?',
  469. centered: true,
  470. closable: true,
  471. onOk () {
  472. _this.saveNewProduct(row)
  473. }
  474. })
  475. } else {
  476. this.saveNewProduct(row)
  477. }
  478. },
  479. // 保存添加的产品到销售列表
  480. saveNewProduct (row) {
  481. this.$message.loading('正在添加产品...', 1)
  482. this.isInster = true
  483. // this.spinning = true
  484. salesDetailInsert({
  485. buyerSn: this.detailData.buyerSn,
  486. productSn: row.productSn,
  487. cost: row.putCost,
  488. // productCode: row.productCode,
  489. // productOrigCode: row.productOrigCode,
  490. price: row.salePrice,
  491. qty: row.salesNums,
  492. salesBillSn: this.detailData.salesBillSn,
  493. salesBillNo: this.detailData.salesBillNo,
  494. warehouseSn: row.warehouseSn,
  495. warehouseLocationSn: row.warehouseLocationSn,
  496. stockSn: row.stockSn
  497. }).then(res => {
  498. if (res.status == 200) {
  499. // this.resetSearchForm(true) // 不刷新库存
  500. this.$refs.table.refresh(true)
  501. this.getOrderDetail(false)
  502. }
  503. this.isInster = false
  504. // this.spinning = false
  505. })
  506. },
  507. // 销售单详情
  508. getOrderDetail (flag) {
  509. salesDetail({ id: this.$route.params.id }).then(res => {
  510. if (res.status == 200) {
  511. this.detailData = res.data
  512. if (flag) {
  513. const vm = this
  514. const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.salesBillSource && vm.detailData.salesBillSource == 'PURCHASE') ? '' : vm.detailData.buyerSn
  515. const priceType = vm.$route.params.priceType
  516. vm.$refs.partQuery.pageInit(buyerSn, priceType)
  517. }
  518. }
  519. })
  520. },
  521. // 提交销售单
  522. handleSubmit () {
  523. this.spinning = true
  524. salesWriteSubmit({ id: this.orderId }).then(res => {
  525. if (res.status == 200) {
  526. this.handleBack()
  527. this.$message.success(res.message)
  528. this.spinning = false
  529. } else {
  530. this.spinning = false
  531. }
  532. })
  533. },
  534. pageInit () {
  535. const vm = this
  536. vm.orderId = vm.$route.params.id
  537. vm.salesBillSn = vm.$route.params.sn
  538. vm.getOrderDetail(true)
  539. vm.$refs.table.refresh(true)
  540. }
  541. },
  542. mounted () {
  543. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  544. this.pageInit()
  545. }
  546. },
  547. activated () {
  548. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  549. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  550. this.pageInit()
  551. }
  552. },
  553. beforeRouteEnter (to, from, next) {
  554. next(vm => {})
  555. }
  556. }
  557. </script>
  558. <style lang="less">
  559. .salesEdit-wrap{
  560. position: relative;
  561. height: 100%;
  562. box-sizing: border-box;
  563. >.ant-spin-nested-loading{
  564. overflow-y: scroll;
  565. height: 100%;
  566. }
  567. .salesEdit-cont{
  568. margin-top: 10px;
  569. }
  570. .total-bar{
  571. display: flex;
  572. align-items: center;
  573. justify-content: space-between;
  574. > div{
  575. &:last-child{
  576. display: flex;
  577. align-items: center;
  578. justify-content: space-between;
  579. > div{
  580. padding: 0 10px;
  581. }
  582. }
  583. }
  584. }
  585. .redBg-row{
  586. background-color: #f5cdc8;
  587. }
  588. }
  589. </style>