edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <div class="waitDispatch-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="waitDispatch-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. </a-page-header>
  11. <a-card size="small" :bordered="false" class="waitDispatch-cont">
  12. <!-- 查询配件列表 -->
  13. <queryPart
  14. ref="partQuery"
  15. :newLoading="isInster"
  16. @oneDispatch="oneDispatch"
  17. @cancelProduct="cancelProduct"
  18. @addProduct="insterProduct"></queryPart>
  19. </a-card>
  20. <a-card size="small" :bordered="false" class="waitDispatch-cont">
  21. <div slot="title">
  22. <div class="p-title">
  23. 待下推产品
  24. </div>
  25. </div>
  26. <div style="margin: 0 0 10px 0;">
  27. <a-button
  28. type="danger"
  29. @click="delSalerDetailAll"
  30. :loading="delLoading"
  31. id="waitDispatch-del-all">批量移除</a-button>
  32. </div>
  33. <!-- 总计 -->
  34. <a-alert type="info" style="margin-bottom: 10px;">
  35. <div slot="message" class="total-bar">
  36. <div>
  37. 本次下推款数:<strong>{{ totalData&&(totalData.totalCategory || totalData.totalCategory==0) ? totalData.totalCategory : '--' }}</strong>;
  38. 本次下推数量:<strong>{{ totalData&&(totalData.totalQty || totalData.totalQty==0) ? totalData.totalQty : '--' }}</strong>;
  39. </div>
  40. <div>
  41. </div>
  42. </div>
  43. </a-alert>
  44. <!-- 已选配件列表 -->
  45. <s-table
  46. class="sTable"
  47. ref="table"
  48. size="small"
  49. :rowKey="(record) => record.id"
  50. :row-selection="{ columnWidth: 40 }"
  51. @rowSelection="rowSelectionFun"
  52. :columns="columns"
  53. :data="loadData"
  54. :showPagination="false"
  55. :scroll="{ y: 300 }"
  56. :defaultLoadData="false"
  57. bordered>
  58. <!-- 产品编码 -->
  59. <template slot="productCode" slot-scope="text, record">
  60. <a-badge count="促" v-if="record.promotionFlag == 1">
  61. <div style="padding-right: 15px;">{{ text }}</div>
  62. </a-badge>
  63. <span v-else>{{ text }}</span>
  64. </template>
  65. <!-- 本次下推数 -->
  66. <template slot="salesNums" slot-scope="text, record">
  67. <a-input-number
  68. id="salesReturn-qty"
  69. size="small"
  70. v-model="record.qty"
  71. :precision="0"
  72. :min="1"
  73. :max="record.surplusQty"
  74. placeholder="请输入"
  75. @blur="e => onCellBlur(e.target.value, record)"
  76. style="width: 100%;" />
  77. </template>
  78. <!-- 操作 -->
  79. <template slot="action" slot-scope="text, record">
  80. <a-button
  81. size="small"
  82. type="link"
  83. :loading="delLoading"
  84. class="button-error"
  85. @click="handleDel(record)"
  86. >移除</a-button>
  87. </template>
  88. </s-table>
  89. </a-card>
  90. </a-spin>
  91. <div class="affix-cont">
  92. <a-button
  93. size="large"
  94. style="padding: 0 60px;"
  95. :disabled="spinning"
  96. type="primary"
  97. class="button-primary"
  98. @click="handleDispatch()"
  99. :loading="loading"
  100. id="productInfoList-handleSubmit">下推</a-button>
  101. </div>
  102. <!-- 下推 -->
  103. <dsModal ref="dsModal" :openModal="showDsModal" @close="showDsModal=false" @ok="handleSubmit" />
  104. </div>
  105. </template>
  106. <script>
  107. import { commonMixin } from '@/utils/mixin'
  108. import { STable, VSelect } from '@/components'
  109. import queryPart from './queryPart.vue'
  110. import dsModal from './dsModal.vue'
  111. import { salesDetailBySn } from '@/api/sales'
  112. import { salesDetailDispatchByOneKey, insertBatchOfWaitDispatch, salesDetailUpdateCancelQty } from '@/api/salesDetail'
  113. import { deleteBatch, pushDown, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  114. import { findBySalesBillSn } from '@/api/dispatch'
  115. import { keys } from 'core-js/fn/array'
  116. export default {
  117. name: 'WaitDispatch',
  118. mixins: [commonMixin],
  119. components: { STable, VSelect, queryPart, dsModal },
  120. data () {
  121. return {
  122. showDsModal: false,
  123. spinning: false,
  124. salesBillSn: null, // 销售单sn
  125. disabled: false, // 查询、重置按钮是否可操作
  126. isInster: false, // 是否正在添加产品
  127. delLoading: false, // 是否正在移除产品
  128. loading: false, // 是否下推中
  129. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  130. dataSource: [],
  131. productForm: {
  132. dispatchBillSn: ''
  133. },
  134. // 表头
  135. columns: [
  136. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  137. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '26%', align: 'center' },
  138. { title: '产品名称', dataIndex: 'productEntity.name', width: '29%', align: 'center', customRender: function (text) { return text || '--' } },
  139. { title: '出库仓库', dataIndex: 'dispatchBill.warehouseName', width: '8%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  140. { title: '待下推数量', dataIndex: 'surplusQty', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  141. { title: '本次下推数', scopedSlots: { customRender: 'salesNums' }, width: '11%', align: 'center' },
  142. { title: '单位', dataIndex: 'productEntity.unit', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  143. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  144. ],
  145. // 加载数据方法 必须为 Promise 对象
  146. loadData: parameter => {
  147. this.disabled = true
  148. // 查询统计
  149. return waitDispatchDetailAllList(Object.assign(parameter, this.productForm)).then(res => {
  150. let data
  151. if (res.status == 200) {
  152. data = res.data
  153. const no = 0
  154. for (var i = 0; i < data.length; i++) {
  155. data[i].no = no + i + 1
  156. data[i].qtyBackups = data[i].qty
  157. }
  158. this.disabled = false
  159. this.dataSource = data
  160. }
  161. return data
  162. })
  163. },
  164. totalData: null,
  165. rowSelectionInfo: null
  166. }
  167. },
  168. methods: {
  169. // 表格选中项
  170. rowSelectionFun (obj) {
  171. this.rowSelectionInfo = obj || null
  172. },
  173. // 统计查询
  174. getTotalData () {
  175. findBySalesBillSn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  176. if (res.status == 200) {
  177. this.totalData = res.data || null
  178. if (res.data && Object.keys(res.data).length > 0) {
  179. this.productForm.dispatchBillSn = res.data.dispatchBillSn
  180. const _this = this
  181. this.$nextTick(() => {
  182. _this.$refs.table.refresh()
  183. })
  184. } else {
  185. this.dataSource = []
  186. this.$refs.table.clearTable()
  187. }
  188. } else {
  189. this.totalData = null
  190. }
  191. })
  192. },
  193. // 已选产品 blur
  194. onCellBlur (val, record) {
  195. const _this = this
  196. if (val && val != record.qtyBackups) {
  197. _this.spinning = true
  198. updateQty({
  199. dispatchBillDetailSn: record.dispatchBillDetailSn,
  200. qty: record.qty,
  201. salesBillSn: _this.salesBillSn,
  202. dispatchBillSn: _this.productForm.dispatchBillSn
  203. }).then(res => {
  204. if (res.status == 200) {
  205. _this.$refs.partQuery.resetCurForm()
  206. _this.$message.success(res.message)
  207. _this.spinning = false
  208. _this.resetSearchForm()
  209. } else {
  210. _this.spinning = false
  211. }
  212. })
  213. } else {
  214. record.qty = record.qtyBackups
  215. }
  216. },
  217. // 重置
  218. resetSearchForm () {
  219. this.getTotalData()
  220. this.getOrderDetail()
  221. },
  222. // 返回
  223. handleBack () {
  224. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  225. },
  226. // 批量删除
  227. delSalerDetailAll () {
  228. const _this = this
  229. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  230. _this.$message.warning('请在选择待下推产品!')
  231. return
  232. }
  233. const obj = []
  234. _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
  235. if (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.indexOf(item.id) != -1) {
  236. obj.push(item.dispatchBillDetailSn)
  237. }
  238. })
  239. this.$confirm({
  240. title: '提示',
  241. content: '确认要批量删除吗?',
  242. centered: true,
  243. closable: true,
  244. onOk () {
  245. _this.deleteFun(obj, 1)
  246. }
  247. })
  248. },
  249. // 删除产品
  250. handleDel (row) {
  251. const _this = this
  252. this.$confirm({
  253. title: '提示',
  254. content: '确认要删除吗?',
  255. centered: true,
  256. closable: true,
  257. onOk () {
  258. _this.deleteFun(row, 0)
  259. }
  260. })
  261. },
  262. // 移除操作
  263. deleteFun (row, type) {
  264. const _this = this
  265. _this.delLoading = true
  266. _this.spinning = true
  267. deleteBatch({
  268. dispatchBillSn: this.productForm.dispatchBillSn,
  269. dispatchBillDetailList : type == 0 ? [row.dispatchBillDetailSn] : row
  270. }).then(res => {
  271. if (res.status == 200) {
  272. _this.resetSearchForm()
  273. _this.$refs.partQuery.resetCurForm()
  274. if (type == 1) { // 批量操作
  275. _this.$refs.table.clearSelected() // 清空表格选中项
  276. } else if (type == 0) { // 单条
  277. const ind = _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.findIndex(item => item == row.id)
  278. _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.splice(ind, 1)
  279. }
  280. _this.$message.success(res.message)
  281. _this.spinning = false
  282. } else {
  283. _this.spinning = false
  284. }
  285. _this.delLoading = false
  286. })
  287. },
  288. // 添加产品
  289. insterProduct (list) {
  290. // 防止多次添加产品
  291. if (this.isInster) { return }
  292. this.saveNewProduct(list)
  293. },
  294. // 保存添加的产品到下推列表
  295. saveNewProduct (list) {
  296. this.$message.loading('正在添加产品...', 1)
  297. this.isInster = true
  298. this.spinning = true
  299. insertBatchOfWaitDispatch({
  300. salesBillDetailSnList: list,
  301. salesBillSn: this.salesBillSn
  302. }).then(res => {
  303. if (res.status == 200) {
  304. this.resetSearchForm()
  305. this.$refs.partQuery.resetCurForm()
  306. this.$message.success('添加成功', 2.5)
  307. this.spinning = false
  308. } else {
  309. this.spinning = false
  310. }
  311. this.isInster = false
  312. })
  313. },
  314. // 批量取消产品
  315. cancelProduct (list) {
  316. // 防止多次添加产品
  317. this.$message.loading('正在批量取消产品...', 1)
  318. this.isInster = true
  319. this.spinning = true
  320. salesDetailUpdateCancelQty(list).then(res => {
  321. if (res.status == 200) {
  322. this.resetSearchForm()
  323. this.$refs.partQuery.resetCurForm()
  324. this.$message.success(res.message, 2.5)
  325. this.spinning = false
  326. } else {
  327. this.spinning = false
  328. }
  329. this.isInster = false
  330. })
  331. },
  332. // 一键下推
  333. oneDispatch () {
  334. this.isInster = true
  335. this.spinning = true
  336. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  337. if (res.status == 200) {
  338. this.resetSearchForm()
  339. this.$refs.partQuery.resetCurForm()
  340. this.spinning = false
  341. } else {
  342. this.spinning = false
  343. }
  344. this.isInster = false
  345. })
  346. },
  347. // 销售单详情
  348. getOrderDetail () {
  349. salesDetailBySn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  350. if (res.status == 200) {
  351. this.detailData = res.data
  352. this.$refs.partQuery.pageInit(this.$route.params.salesBillSn, this.detailData)
  353. }
  354. })
  355. },
  356. // 提交下推
  357. handleDispatch () {
  358. if (this.dataSource.length) {
  359. this.showDsModal = true
  360. this.detailData.dispatchBillCount = this.totalData.dispatchBillCount
  361. this.detailData.receiverName = this.totalData.receiverName ? this.totalData.receiverName : ''
  362. this.detailData.receiverSn = this.totalData.receiverSn ? this.totalData.receiverSn : ''
  363. this.$refs.dsModal.setDetail(this.detailData)
  364. } else {
  365. this.$message.warning('请选择待下推产品')
  366. }
  367. },
  368. handleSubmit (data) {
  369. this.delLoading = true
  370. this.isInster = true
  371. this.loading = true
  372. this.spinning = true
  373. const params = Object.assign({ dispatchBillSn: this.productForm.dispatchBillSn }, data)
  374. pushDown(params).then(res => {
  375. if (res.status == 200) {
  376. this.handleBack()
  377. this.$message.success(res.message)
  378. }
  379. this.delLoading = false
  380. this.isInster = false
  381. this.loading = false
  382. this.spinning = false
  383. })
  384. },
  385. pageInit () {
  386. this.rowSelectionInfo = null
  387. // this.$refs.table.clearTable()
  388. this.$refs.partQuery.clearTable()
  389. this.salesBillSn = this.$route.params.salesBillSn
  390. this.getOrderDetail()
  391. this.getTotalData()
  392. }
  393. },
  394. mounted () {
  395. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  396. this.pageInit()
  397. }
  398. },
  399. activated () {
  400. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  401. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  402. this.pageInit()
  403. }
  404. },
  405. beforeRouteEnter (to, from, next) {
  406. next(vm => {})
  407. }
  408. }
  409. </script>
  410. <style lang="less">
  411. .waitDispatch-wrap{
  412. position: relative;
  413. height: 100%;
  414. padding-bottom: 51px;
  415. box-sizing: border-box;
  416. >.ant-spin-nested-loading{
  417. overflow-y: scroll;
  418. height: 100%;
  419. }
  420. .waitDispatch-cont{
  421. margin-top: 10px;
  422. }
  423. .p-title{
  424. font-size: 16px;
  425. font-weight: bold;
  426. }
  427. .p-notes{
  428. span{
  429. color: #FF9900;
  430. }
  431. }
  432. .total-bar{
  433. display: flex;
  434. align-items: center;
  435. justify-content: space-between;
  436. > div{
  437. &:last-child{
  438. display: flex;
  439. align-items: center;
  440. justify-content: space-between;
  441. > div{
  442. padding: 0 10px;
  443. }
  444. }
  445. }
  446. }
  447. .redBg-row{
  448. background-color: #f5cdc8;
  449. }
  450. }
  451. </style>