edit.vue 14 KB

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