edit.vue 14 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. <!-- <a-button id="waitDispatch-edit-btn" size="small" @click="handleEdit" style="margin-left:10px" key="0">编辑</a-button> -->
  10. </template>
  11. <!-- 操作区,位于 title 行的行尾 -->
  12. <!-- <template slot="extra">
  13. <a-button key="2" id="waitDispatch-preview-btn">打印预览</a-button>
  14. <a-button key="1" type="primary" id="waitDispatch-print-btn">快速打印</a-button>
  15. </template> -->
  16. </a-page-header>
  17. <a-card size="small" :bordered="false" class="waitDispatch-cont" v-if="salesBillSn">
  18. <!-- 查询配件列表 -->
  19. <queryPart
  20. ref="partQuery"
  21. :salesBillSn="salesBillSn"
  22. :detailData="detailData"
  23. :newLoading="isInster"
  24. @oneDispatch="oneDispatch"
  25. @cancelProduct="cancelProduct"
  26. @addProduct="insterProduct"></queryPart>
  27. </a-card>
  28. <a-card size="small" :bordered="false" class="waitDispatch-cont">
  29. <div slot="title">
  30. <div class="p-title">
  31. 待下推产品
  32. </div>
  33. </div>
  34. <div style="margin: 0 0 10px 0;">
  35. <a-button
  36. type="primary"
  37. class="button-error"
  38. @click="delSalerDetailAll"
  39. :loading="delLoading"
  40. id="waitDispatch-del-all">批量移除</a-button>
  41. </div>
  42. <!-- 总计 -->
  43. <a-alert type="info" style="margin-bottom: 10px;">
  44. <div slot="message" class="total-bar">
  45. <div>
  46. 本次下推款数:<strong>¥{{ totalData&&(totalData.totalCategory || totalData.totalCategory==0) ? totalData.totalCategory : '--' }}</strong>;
  47. 本次下推数量:<strong>{{ totalData&&(totalData.totalQty || totalData.totalQty==0) ? totalData.totalQty : '--' }}</strong>;
  48. </div>
  49. <div>
  50. </div>
  51. </div>
  52. </a-alert>
  53. <!-- 已选配件列表 -->
  54. <s-table
  55. class="sTable"
  56. ref="table"
  57. size="small"
  58. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onChange, onSelect: onSelectChange, onSelectAll: onSelectAllChange }"
  59. :rowKey="(record) => record.id"
  60. :columns="columns"
  61. :data="loadData"
  62. :showPagination="false"
  63. :scroll="{ x:650, y: 300 }"
  64. bordered>
  65. <!-- 产品编码 -->
  66. <template slot="productCode" slot-scope="text, record">
  67. <a-badge count="促" v-if="record.promotionFlag == 1">
  68. <div style="padding-right: 15px;">{{ text }}</div>
  69. </a-badge>
  70. <span v-else>{{ text }}</span>
  71. </template>
  72. <!-- 本次下推数 -->
  73. <template slot="salesNums" slot-scope="text, record">
  74. <a-input-number
  75. id="salesReturn-qty"
  76. size="small"
  77. v-model="record.qty"
  78. :precision="0"
  79. :min="1"
  80. :max="999999"
  81. placeholder="请输入"
  82. @blur="e => onCellBlur(e.target.value, record)"
  83. style="width: 100%;" />
  84. </template>
  85. <!-- 操作 -->
  86. <template slot="action" slot-scope="text, record">
  87. <a-button
  88. size="small"
  89. type="primary"
  90. :loading="delLoading"
  91. class="button-error"
  92. @click="handleDel(record)"
  93. >移除</a-button>
  94. </template>
  95. </s-table>
  96. </a-card>
  97. </a-spin>
  98. <div class="affix-cont">
  99. <a-button
  100. size="large"
  101. style="padding: 0 60px;"
  102. :disabled="spinning"
  103. type="primary"
  104. class="button-primary"
  105. @click="handleSubmit()"
  106. :loading="loading"
  107. id="productInfoList-handleSubmit">下推</a-button>
  108. </div>
  109. </div>
  110. </template>
  111. <script>
  112. import { STable, VSelect } from '@/components'
  113. import queryPart from './queryPart.vue'
  114. import { salesDetailBySn } from '@/api/sales'
  115. import { salesDetailDispatchByOneKey, insertBatchOfWaitDispatch, salesDetailUpdateCancelQty } from '@/api/salesDetail'
  116. import { deleteBatch, pushDown, dispatchDetail, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  117. export default {
  118. name: 'SalesDetail',
  119. components: { STable, VSelect, queryPart },
  120. data () {
  121. return {
  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. selectedRowKeys: [], // Check here to configure the default column
  134. selectedRows: [],
  135. // 表头
  136. columns: [
  137. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  138. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: 120, align: 'center' },
  139. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '剩余待下推', dataIndex: 'surplusQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  141. { title: '本次下推数', scopedSlots: { customRender: 'salesNums' }, width: 100, align: 'center' },
  142. { title: '单位', dataIndex: 'productEntity.unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  143. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  144. ],
  145. // 加载数据方法 必须为 Promise 对象
  146. loadData: parameter => {
  147. this.disabled = true
  148. this.productForm.dispatchBillSn = this.$route.params.dispatchBillSn
  149. // 查询统计
  150. this.getTotalData()
  151. return waitDispatchDetailAllList(Object.assign(parameter, this.productForm)).then(res => {
  152. const 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. return data
  161. })
  162. },
  163. totalData: null
  164. }
  165. },
  166. methods: {
  167. onChange (selectedRowKeys, selectedRows) {
  168. this.selectedRowKeys = selectedRowKeys
  169. },
  170. onSelectChange (record, selected, selectedRows, nativeEvent) {
  171. if (selected) { // 选择
  172. this.selectedRows.push(record)
  173. } else { // 取消
  174. this.selectedRows = selectedRows
  175. }
  176. },
  177. // 本页全选/取消全选
  178. onSelectAllChange (selected, selectedRows, changeRows) {
  179. const _this = this
  180. if (selected) { // 选择
  181. this.selectedRows = [...this.selectedRows, ...changeRows]
  182. } else { // 取消
  183. const arrId = []
  184. this.selectedRows.map((item, index) => {
  185. this.selectedRows.map((subItem, ind) => {
  186. if (item.id == subItem.id) {
  187. arrId.push(index)
  188. }
  189. })
  190. })
  191. arrId.map((item, index) => {
  192. _this.selectedRows = _this.selectedRows.slice(item, item + 1)
  193. })
  194. }
  195. },
  196. // 统计查询
  197. getTotalData () {
  198. dispatchDetail({ dispatchBillSn: this.$route.params.dispatchBillSn }).then(res => {
  199. if (res.status == 200) {
  200. this.totalData = res.data || null
  201. } else {
  202. this.totalData = null
  203. }
  204. })
  205. },
  206. // 已选产品 blur
  207. onCellBlur (val, record) {
  208. const _this = this
  209. _this.dataSource = record
  210. if (val && val != record.qtyBackups) {
  211. _this.spinning = true
  212. updateQty({
  213. dispatchBillDetailSn: record.dispatchBillDetailSn,
  214. qty: record.qty,
  215. salesBillSn: _this.salesBillSn
  216. }).then(res => {
  217. _this.resetSearchForm(true)
  218. if (res.status == 200) {
  219. _this.$refs.partQuery.resetCurForm()
  220. _this.$message.success(res.message)
  221. _this.spinning = false
  222. } else {
  223. _this.spinning = false
  224. }
  225. })
  226. } else {
  227. record.qty = record.qtyBackups
  228. }
  229. },
  230. // 重置
  231. resetSearchForm (flag) {
  232. this.$refs.table.refresh(!!flag)
  233. this.getOrderDetail()
  234. },
  235. // 重置列表
  236. resetForm () {
  237. this.$refs.table.refresh()
  238. },
  239. // 返回
  240. handleBack () {
  241. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  242. },
  243. // 批量删除
  244. delSalerDetailAll () {
  245. const _this = this
  246. if (_this.selectedRowKeys.length < 1) {
  247. _this.$message.warning('请在选择待下推产品!')
  248. return
  249. }
  250. const obj = []
  251. _this.selectedRows.map(item => {
  252. if (_this.selectedRowKeys.indexOf(item.id) != -1) {
  253. obj.push(item.dispatchBillDetailSn)
  254. }
  255. })
  256. this.$confirm({
  257. title: '提示',
  258. content: '确认要批量删除吗?',
  259. centered: true,
  260. closable: true,
  261. onOk () {
  262. _this.deleteFun(obj, 1)
  263. }
  264. })
  265. },
  266. // 删除产品
  267. handleDel (row) {
  268. const _this = this
  269. this.$confirm({
  270. title: '提示',
  271. content: '确认要删除吗?',
  272. centered: true,
  273. closable: true,
  274. onOk () {
  275. _this.deleteFun(row, 0)
  276. }
  277. })
  278. },
  279. // 移除操作
  280. deleteFun (row, type) {
  281. const _this = this
  282. _this.delLoading = true
  283. _this.spinning = true
  284. deleteBatch(type == 0 ? [row.dispatchBillDetailSn] : row).then(res => {
  285. if (res.status == 200) {
  286. _this.resetSearchForm(true)
  287. _this.$refs.partQuery.resetCurForm()
  288. if (type == 1) { // 批量操作
  289. _this.selectedRowKeys = []
  290. _this.selectedRows = []
  291. } else if (type == 0) { // 单条
  292. const ind = _this.selectedRowKeys.findIndex(item => item == row.id)
  293. _this.selectedRowKeys.splice(ind, 1)
  294. }
  295. _this.$message.success(res.message)
  296. _this.spinning = false
  297. } else {
  298. _this.spinning = false
  299. }
  300. _this.delLoading = false
  301. })
  302. },
  303. // 添加产品
  304. insterProduct (list) {
  305. console.log(list)
  306. // 防止多次添加产品
  307. if (this.isInster) { return }
  308. this.saveNewProduct(list)
  309. },
  310. // 保存添加的产品到下推列表
  311. saveNewProduct (list) {
  312. this.$message.loading('正在添加产品...', 1)
  313. this.isInster = true
  314. this.spinning = true
  315. insertBatchOfWaitDispatch(list).then(res => {
  316. if (res.status == 200) {
  317. this.resetSearchForm()
  318. this.$refs.partQuery.resetCurForm()
  319. this.$message.success('添加成功', 2.5)
  320. this.spinning = false
  321. } else {
  322. this.spinning = false
  323. }
  324. this.isInster = false
  325. })
  326. },
  327. // 批量取消产品
  328. cancelProduct (list) {
  329. // 防止多次添加产品
  330. this.$message.loading('正在批量取消产品...', 1)
  331. this.isInster = true
  332. this.spinning = true
  333. salesDetailUpdateCancelQty(list).then(res => {
  334. if (res.status == 200) {
  335. this.resetSearchForm()
  336. this.$refs.partQuery.resetCurForm()
  337. this.$message.success(res.message, 2.5)
  338. this.spinning = false
  339. } else {
  340. this.spinning = false
  341. }
  342. this.isInster = false
  343. })
  344. },
  345. // 一键下推
  346. oneDispatch () {
  347. this.isInster = true
  348. this.spinning = true
  349. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  350. if (res.status == 200) {
  351. this.resetSearchForm()
  352. this.$refs.partQuery.resetCurForm()
  353. this.spinning = false
  354. } else {
  355. this.spinning = false
  356. }
  357. this.isInster = false
  358. })
  359. },
  360. // 销售单详情
  361. getOrderDetail () {
  362. salesDetailBySn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  363. console.log('getOrderDetail')
  364. if (res.status == 200) {
  365. this.detailData = res.data
  366. console.log(this.detailData)
  367. }
  368. })
  369. },
  370. // 提交下推
  371. handleSubmit () {
  372. this.delLoading = true
  373. this.isInster = true
  374. this.loading = true
  375. this.spinning = true
  376. pushDown({ dispatchBillSn: this.$route.params.dispatchBillSn }).then(res => {
  377. if (res.status == 200) {
  378. this.handleBack()
  379. this.$message.success(res.message)
  380. }
  381. this.delLoading = false
  382. this.isInster = false
  383. this.loading = false
  384. this.spinning = false
  385. })
  386. },
  387. pageInit () {
  388. this.getOrderDetail()
  389. this.$refs.partQuery.resetSearchForm()
  390. this.$refs.table.refresh(true)
  391. }
  392. },
  393. mounted () {
  394. this.getOrderDetail()
  395. },
  396. beforeRouteEnter (to, from, next) {
  397. next(vm => {
  398. vm.salesBillSn = vm.$route.params.salesBillSn
  399. if (!vm.disabled) {
  400. vm.pageInit()
  401. }
  402. })
  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>