edit.vue 21 KB

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