edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class="waitDispatch-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="waitDispatch-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. <span style="margin: 0 15px;color: #666;">客户名称:{{ detailData&&detailData.buyerName || '--' }}</span>
  8. <!-- <a-button id="waitDispatch-edit-btn" size="small" @click="handleEdit" style="margin-left:10px" key="0">编辑</a-button> -->
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <!-- <template slot="extra">
  12. <a-button key="2" id="waitDispatch-preview-btn">打印预览</a-button>
  13. <a-button key="1" type="primary" id="waitDispatch-print-btn">快速打印</a-button>
  14. </template> -->
  15. </a-page-header>
  16. <a-spin :spinning="spinning" tip="Loading...">
  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. <a-affix v-if="dataSource.length>0" :offset-bottom="0">
  99. <div
  100. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  101. <a-button
  102. size="large"
  103. style="width: 150px;"
  104. type="primary"
  105. class="button-primary"
  106. @click="handleSubmit()"
  107. :loading="loading"
  108. id="productInfoList-handleSubmit">下推</a-button>
  109. </div>
  110. </a-affix>
  111. </div>
  112. </template>
  113. <script>
  114. import { STable, VSelect } from '@/components'
  115. import queryPart from './queryPart.vue'
  116. import { salesDetailBySn } from '@/api/sales'
  117. import { salesDetailDispatchByOneKey, insertBatchOfWaitDispatch, salesDetailUpdateCancelQty } from '@/api/salesDetail'
  118. import { deleteBatch, pushDown, dispatchDetail, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  119. export default {
  120. name: 'SalesDetail',
  121. components: { STable, VSelect, queryPart },
  122. data () {
  123. return {
  124. spinning: false,
  125. salesBillSn: null, // 销售单sn
  126. disabled: false, // 查询、重置按钮是否可操作
  127. isInster: false, // 是否正在添加产品
  128. delLoading: false, // 是否正在移除产品
  129. loading: false, // 是否下推中
  130. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  131. dataSource: [],
  132. productForm: {
  133. dispatchBillSn: ''
  134. },
  135. selectedRowKeys: [], // Check here to configure the default column
  136. selectedRows: [],
  137. // 表头
  138. columns: [
  139. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  140. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: 120, align: 'center' },
  141. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' } },
  142. { title: '剩余待下推', dataIndex: 'surplusQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  143. { title: '本次下推数', scopedSlots: { customRender: 'salesNums' }, width: 100, align: 'center' },
  144. { title: '单位', dataIndex: 'productEntity.unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  145. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  146. ],
  147. // 加载数据方法 必须为 Promise 对象
  148. loadData: parameter => {
  149. this.disabled = true
  150. this.productForm.dispatchBillSn = this.$route.params.dispatchBillSn
  151. // 查询统计
  152. this.getTotalData()
  153. return waitDispatchDetailAllList(Object.assign(parameter, this.productForm)).then(res => {
  154. const data = res.data
  155. const no = 0
  156. for (var i = 0; i < data.length; i++) {
  157. data[i].no = no + i + 1
  158. data[i].qtyBackups = data[i].qty
  159. }
  160. this.disabled = false
  161. this.dataSource = data
  162. return data
  163. })
  164. },
  165. totalData: null
  166. }
  167. },
  168. methods: {
  169. onChange (selectedRowKeys, selectedRows) {
  170. this.selectedRowKeys = selectedRowKeys
  171. },
  172. onSelectChange (record, selected, selectedRows, nativeEvent) {
  173. const _this = this
  174. if (selected) { // 选择
  175. this.selectedRows.push(record)
  176. } else { // 取消
  177. const arrId = []
  178. this.selectedRows.map((item, index) => {
  179. if (item.id == record.id) {
  180. arrId.push(index)
  181. }
  182. })
  183. arrId.map((item, index) => {
  184. _this.selectedRows = _this.selectedRows.slice(item, item + 1)
  185. })
  186. }
  187. },
  188. // 本页全选/取消全选
  189. onSelectAllChange (selected, selectedRows, changeRows) {
  190. const _this = this
  191. if (selected) { // 选择
  192. this.selectedRows = [...this.selectedRows, ...changeRows]
  193. } else { // 取消
  194. const arrId = []
  195. this.selectedRows.map((item, index) => {
  196. this.selectedRows.map((subItem, ind) => {
  197. if (item.id == subItem.id) {
  198. arrId.push(index)
  199. }
  200. })
  201. })
  202. arrId.map((item, index) => {
  203. _this.selectedRows = _this.selectedRows.slice(item, item + 1)
  204. })
  205. }
  206. },
  207. // 统计查询
  208. getTotalData () {
  209. dispatchDetail({ dispatchBillSn: this.$route.params.dispatchBillSn }).then(res => {
  210. if (res.status == 200) {
  211. this.totalData = res.data || null
  212. } else {
  213. this.totalData = null
  214. }
  215. })
  216. },
  217. // 已选产品 blur
  218. onCellBlur (val, record) {
  219. const _this = this
  220. _this.dataSource = record
  221. if (val && val != record.qtyBackups) {
  222. _this.spinning = true
  223. updateQty({
  224. dispatchBillDetailSn: record.dispatchBillDetailSn,
  225. qty: record.qty,
  226. salesBillSn: _this.salesBillSn
  227. }).then(res => {
  228. _this.resetSearchForm(true)
  229. if (res.status == 200) {
  230. _this.$refs.partQuery.resetCurForm()
  231. _this.$message.success(res.message)
  232. _this.spinning = false
  233. } else {
  234. _this.spinning = false
  235. }
  236. })
  237. } else {
  238. record.qty = record.qtyBackups
  239. }
  240. },
  241. // 重置
  242. resetSearchForm (flag) {
  243. this.$refs.table.refresh(!!flag)
  244. this.getOrderDetail()
  245. },
  246. // 重置列表
  247. resetForm () {
  248. this.$refs.table.refresh()
  249. },
  250. // 返回
  251. handleBack () {
  252. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  253. },
  254. // 批量删除
  255. delSalerDetailAll () {
  256. const _this = this
  257. if (_this.selectedRowKeys.length < 1) {
  258. _this.$message.warning('请在选择待下推产品!')
  259. return
  260. }
  261. const obj = []
  262. _this.selectedRows.map(item => {
  263. if (_this.selectedRowKeys.indexOf(item.id) != -1) {
  264. obj.push(item.dispatchBillDetailSn)
  265. }
  266. })
  267. this.$confirm({
  268. title: '提示',
  269. content: '确认要批量删除吗?',
  270. centered: true,
  271. closable: true,
  272. onOk () {
  273. _this.deleteFun(obj, 1)
  274. }
  275. })
  276. },
  277. // 删除产品
  278. handleDel (row) {
  279. const _this = this
  280. this.$confirm({
  281. title: '提示',
  282. content: '确认要删除吗?',
  283. centered: true,
  284. closable: true,
  285. onOk () {
  286. _this.deleteFun(row, 0)
  287. }
  288. })
  289. },
  290. // 移除操作
  291. deleteFun (row, type) {
  292. const _this = this
  293. _this.delLoading = true
  294. _this.spinning = true
  295. deleteBatch(type == 0 ? [row.dispatchBillDetailSn] : row).then(res => {
  296. if (res.status == 200) {
  297. _this.resetSearchForm(true)
  298. _this.$refs.partQuery.resetCurForm()
  299. if (type == 1) { // 批量操作
  300. _this.selectedRowKeys = []
  301. _this.selectedRows = []
  302. } else if (type == 0) { // 单条
  303. const ind = _this.selectedRowKeys.findIndex(item => item == row.id)
  304. _this.selectedRowKeys.splice(ind, 1)
  305. }
  306. _this.$message.success(res.message)
  307. _this.spinning = false
  308. } else {
  309. _this.spinning = false
  310. }
  311. _this.delLoading = false
  312. })
  313. },
  314. // 添加产品
  315. insterProduct (list) {
  316. console.log(list)
  317. // 防止多次添加产品
  318. if (this.isInster) { return }
  319. this.saveNewProduct(list)
  320. },
  321. // 保存添加的产品到下推列表
  322. saveNewProduct (list) {
  323. this.$message.loading('正在添加产品...', 1)
  324. this.isInster = true
  325. this.spinning = true
  326. insertBatchOfWaitDispatch(list).then(res => {
  327. if (res.status == 200) {
  328. this.resetSearchForm()
  329. this.$refs.partQuery.resetCurForm()
  330. this.$message.success('添加成功', 2.5)
  331. this.spinning = false
  332. } else {
  333. this.spinning = false
  334. }
  335. this.isInster = false
  336. })
  337. },
  338. // 批量取消产品
  339. cancelProduct (list) {
  340. // 防止多次添加产品
  341. this.$message.loading('正在批量取消产品...', 1)
  342. this.isInster = true
  343. this.spinning = true
  344. salesDetailUpdateCancelQty(list).then(res => {
  345. if (res.status == 200) {
  346. this.resetSearchForm()
  347. this.$refs.partQuery.resetCurForm()
  348. this.$message.success(res.message, 2.5)
  349. this.spinning = false
  350. } else {
  351. this.spinning = false
  352. }
  353. this.isInster = false
  354. })
  355. },
  356. // 一键下推
  357. oneDispatch () {
  358. this.isInster = true
  359. this.spinning = true
  360. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  361. if (res.status == 200) {
  362. this.resetSearchForm()
  363. this.$refs.partQuery.resetCurForm()
  364. this.spinning = false
  365. } else {
  366. this.spinning = false
  367. }
  368. this.isInster = false
  369. })
  370. },
  371. // 销售单详情
  372. getOrderDetail () {
  373. salesDetailBySn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  374. console.log('getOrderDetail')
  375. if (res.status == 200) {
  376. this.detailData = res.data
  377. console.log(this.detailData)
  378. }
  379. })
  380. },
  381. // 提交下推
  382. handleSubmit () {
  383. this.delLoading = true
  384. this.isInster = true
  385. this.loading = true
  386. this.spinning = true
  387. pushDown({ dispatchBillSn: this.$route.params.dispatchBillSn }).then(res => {
  388. if (res.status == 200) {
  389. this.handleBack()
  390. this.$message.success(res.message)
  391. }
  392. this.delLoading = false
  393. this.isInster = false
  394. this.loading = false
  395. this.spinning = false
  396. })
  397. }
  398. },
  399. mounted () {
  400. this.getOrderDetail()
  401. },
  402. beforeRouteEnter (to, from, next) {
  403. next(vm => {
  404. console.log('beforeRouteEnter')
  405. vm.salesBillSn = vm.$route.params.salesBillSn
  406. })
  407. }
  408. }
  409. </script>
  410. <style lang="less">
  411. .waitDispatch-wrap{
  412. .waitDispatch-cont{
  413. margin-top: 10px;
  414. }
  415. .p-title{
  416. font-size: 16px;
  417. font-weight: bold;
  418. }
  419. .p-notes{
  420. span{
  421. color: #FF9900;
  422. }
  423. }
  424. .total-bar{
  425. display: flex;
  426. align-items: center;
  427. justify-content: space-between;
  428. > div{
  429. &:last-child{
  430. display: flex;
  431. align-items: center;
  432. justify-content: space-between;
  433. > div{
  434. padding: 0 10px;
  435. }
  436. }
  437. }
  438. }
  439. .redBg-row{
  440. background-color: #f5cdc8;
  441. }
  442. }
  443. </style>