edit.vue 21 KB

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