edit.vue 14 KB

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