edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. }).then(res => {
  203. if (res.status == 200) {
  204. _this.$refs.partQuery.resetCurForm()
  205. _this.$message.success(res.message)
  206. _this.spinning = false
  207. _this.resetSearchForm()
  208. } else {
  209. _this.spinning = false
  210. }
  211. })
  212. } else {
  213. record.qty = record.qtyBackups
  214. }
  215. },
  216. // 重置
  217. resetSearchForm () {
  218. this.getTotalData()
  219. this.getOrderDetail()
  220. },
  221. // 返回
  222. handleBack () {
  223. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  224. },
  225. // 批量删除
  226. delSalerDetailAll () {
  227. const _this = this
  228. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  229. _this.$message.warning('请在选择待下推产品!')
  230. return
  231. }
  232. const obj = []
  233. _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
  234. if (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.indexOf(item.id) != -1) {
  235. obj.push(item.dispatchBillDetailSn)
  236. }
  237. })
  238. this.$confirm({
  239. title: '提示',
  240. content: '确认要批量删除吗?',
  241. centered: true,
  242. closable: true,
  243. onOk () {
  244. _this.deleteFun(obj, 1)
  245. }
  246. })
  247. },
  248. // 删除产品
  249. handleDel (row) {
  250. const _this = this
  251. this.$confirm({
  252. title: '提示',
  253. content: '确认要删除吗?',
  254. centered: true,
  255. closable: true,
  256. onOk () {
  257. _this.deleteFun(row, 0)
  258. }
  259. })
  260. },
  261. // 移除操作
  262. deleteFun (row, type) {
  263. const _this = this
  264. _this.delLoading = true
  265. _this.spinning = true
  266. deleteBatch(type == 0 ? [row.dispatchBillDetailSn] : row).then(res => {
  267. if (res.status == 200) {
  268. _this.resetSearchForm()
  269. _this.$refs.partQuery.resetCurForm()
  270. if (type == 1) { // 批量操作
  271. _this.$refs.table.clearSelected() // 清空表格选中项
  272. } else if (type == 0) { // 单条
  273. const ind = _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.findIndex(item => item == row.id)
  274. _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.splice(ind, 1)
  275. }
  276. _this.$message.success(res.message)
  277. _this.spinning = false
  278. } else {
  279. _this.spinning = false
  280. }
  281. _this.delLoading = false
  282. })
  283. },
  284. // 添加产品
  285. insterProduct (list) {
  286. // 防止多次添加产品
  287. if (this.isInster) { return }
  288. this.saveNewProduct(list)
  289. },
  290. // 保存添加的产品到下推列表
  291. saveNewProduct (list) {
  292. this.$message.loading('正在添加产品...', 1)
  293. this.isInster = true
  294. this.spinning = true
  295. insertBatchOfWaitDispatch({
  296. salesBillDetailSnList: list,
  297. salesBillSn: this.salesBillSn
  298. }).then(res => {
  299. if (res.status == 200) {
  300. this.resetSearchForm()
  301. this.$refs.partQuery.resetCurForm()
  302. this.$message.success('添加成功', 2.5)
  303. this.spinning = false
  304. } else {
  305. this.spinning = false
  306. }
  307. this.isInster = false
  308. })
  309. },
  310. // 批量取消产品
  311. cancelProduct (list) {
  312. // 防止多次添加产品
  313. this.$message.loading('正在批量取消产品...', 1)
  314. this.isInster = true
  315. this.spinning = true
  316. salesDetailUpdateCancelQty(list).then(res => {
  317. if (res.status == 200) {
  318. this.resetSearchForm()
  319. this.$refs.partQuery.resetCurForm()
  320. this.$message.success(res.message, 2.5)
  321. this.spinning = false
  322. } else {
  323. this.spinning = false
  324. }
  325. this.isInster = false
  326. })
  327. },
  328. // 一键下推
  329. oneDispatch () {
  330. this.isInster = true
  331. this.spinning = true
  332. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  333. if (res.status == 200) {
  334. this.resetSearchForm()
  335. this.$refs.partQuery.resetCurForm()
  336. this.spinning = false
  337. } else {
  338. this.spinning = false
  339. }
  340. this.isInster = false
  341. })
  342. },
  343. // 销售单详情
  344. getOrderDetail () {
  345. salesDetailBySn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  346. if (res.status == 200) {
  347. this.detailData = res.data
  348. this.$refs.partQuery.pageInit(this.$route.params.salesBillSn, this.detailData)
  349. }
  350. })
  351. },
  352. // 提交下推
  353. handleDispatch () {
  354. if (this.dataSource.length) {
  355. this.showDsModal = true
  356. this.detailData.dispatchBillCount = this.totalData.dispatchBillCount
  357. this.detailData.receiverName = this.totalData.receiverName ? this.totalData.receiverName : ''
  358. this.detailData.receiverSn = this.totalData.receiverSn ? this.totalData.receiverSn : ''
  359. this.$refs.dsModal.setDetail(this.detailData)
  360. } else {
  361. this.$message.warning('请选择待下推产品')
  362. }
  363. },
  364. handleSubmit (data) {
  365. this.delLoading = true
  366. this.isInster = true
  367. this.loading = true
  368. this.spinning = true
  369. const params = Object.assign({ dispatchBillSn: this.productForm.dispatchBillSn }, data)
  370. pushDown(params).then(res => {
  371. if (res.status == 200) {
  372. this.handleBack()
  373. this.$message.success(res.message)
  374. }
  375. this.delLoading = false
  376. this.isInster = false
  377. this.loading = false
  378. this.spinning = false
  379. })
  380. },
  381. pageInit () {
  382. this.rowSelectionInfo = null
  383. // this.$refs.table.clearTable()
  384. this.$refs.partQuery.clearTable()
  385. this.salesBillSn = this.$route.params.salesBillSn
  386. this.getOrderDetail()
  387. this.getTotalData()
  388. }
  389. },
  390. mounted () {
  391. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  392. this.pageInit()
  393. }
  394. },
  395. activated () {
  396. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  397. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  398. this.pageInit()
  399. }
  400. },
  401. beforeRouteEnter (to, from, next) {
  402. next(vm => {})
  403. }
  404. }
  405. </script>
  406. <style lang="less">
  407. .waitDispatch-wrap{
  408. position: relative;
  409. height: 100%;
  410. padding-bottom: 51px;
  411. box-sizing: border-box;
  412. >.ant-spin-nested-loading{
  413. overflow-y: scroll;
  414. height: 100%;
  415. }
  416. .waitDispatch-cont{
  417. margin-top: 10px;
  418. }
  419. .p-title{
  420. font-size: 16px;
  421. font-weight: bold;
  422. }
  423. .p-notes{
  424. span{
  425. color: #FF9900;
  426. }
  427. }
  428. .total-bar{
  429. display: flex;
  430. align-items: center;
  431. justify-content: space-between;
  432. > div{
  433. &:last-child{
  434. display: flex;
  435. align-items: center;
  436. justify-content: space-between;
  437. > div{
  438. padding: 0 10px;
  439. }
  440. }
  441. }
  442. }
  443. .redBg-row{
  444. background-color: #f5cdc8;
  445. }
  446. }
  447. </style>