edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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 :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 :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. @click="delSalerDetailAll"
  38. :loading="delLoading"
  39. id="waitDispatch-del-all">批量移除</a-button>
  40. </div>
  41. <!-- 总计 -->
  42. <a-alert type="info">
  43. <div slot="message" class="total-bar">
  44. <div>
  45. 本次下推款数:<strong>¥{{ totalData&&(totalData.totalCategory || totalData.totalCategory==0) ? totalData.totalCategory : '--' }}</strong>;
  46. 本次下推数量:<strong>{{ totalData&&(totalData.totalQty || totalData.totalQty==0) ? totalData.totalQty : '--' }}</strong>;
  47. </div>
  48. <div>
  49. </div>
  50. </div>
  51. </a-alert>
  52. <!-- 已选配件列表 -->
  53. <s-table
  54. class="sTable"
  55. ref="table"
  56. size="small"
  57. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onChange, onSelect: onSelectChange, onSelectAll: onSelectAllChange }"
  58. :rowKey="(record) => record.id"
  59. :columns="columns"
  60. :data="loadData"
  61. :showPagination="false"
  62. :scroll="{ x:1150, y: 300 }"
  63. bordered>
  64. <!-- 产品编码 -->
  65. <template slot="productCode" slot-scope="text, record">
  66. <a-badge count="促" v-if="record.promotionFlag == 1">
  67. <div style="padding-right: 15px;">{{ text }}</div>
  68. </a-badge>
  69. <span v-else>{{ text }}</span>
  70. </template>
  71. <!-- 本次下推数 -->
  72. <template slot="salesNums" slot-scope="text, record">
  73. <editable-cell
  74. size="small"
  75. :text="record.qty"
  76. :max="999999"
  77. :min="1"
  78. :precision="0"
  79. @change="onCellChange(record.id, 'qty', $event)" />
  80. </template>
  81. <!-- 操作 -->
  82. <template slot="action" slot-scope="text, record">
  83. <a-button
  84. size="small"
  85. type="primary"
  86. :loading="delLoading"
  87. class="button-error"
  88. @click="handleDel(record)"
  89. >移除</a-button>
  90. </template>
  91. </s-table>
  92. </a-card>
  93. <a-affix :offset-bottom="0">
  94. <div
  95. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  96. <a-button
  97. size="large"
  98. style="width: 150px;"
  99. type="primary"
  100. class="button-primary"
  101. v-if="dataSource.length>0"
  102. @click="handleSubmit()"
  103. :loading="loading"
  104. id="productInfoList-handleSubmit">下推</a-button>
  105. </div>
  106. </a-affix>
  107. </a-spin>
  108. </div>
  109. </template>
  110. <script>
  111. import { STable, VSelect } from '@/components'
  112. import queryPart from './queryPart.vue'
  113. import { salesDetailBySn } from '@/api/sales'
  114. import { salesDetailDispatchByOneKey, insertBatchOfWaitDispatch, salesDetailUpdateCancelQty } from '@/api/salesDetail'
  115. import EditableCell from '@/views/common/editInput.js'
  116. import { deleteBatch, pushDown, dispatchDetail, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  117. export default {
  118. name: 'SalesDetail',
  119. components: { STable, VSelect, queryPart, EditableCell },
  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: 80, align: 'center' },
  138. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: 220, align: 'center' },
  139. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  140. { title: '剩余待下推', dataIndex: 'surplusQty', width: 150, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  141. { title: '本次下推数', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  142. { title: '单位', dataIndex: 'productEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  143. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, 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. }
  157. this.disabled = false
  158. this.dataSource = data
  159. return data
  160. })
  161. },
  162. totalData: null
  163. }
  164. },
  165. methods: {
  166. onChange (selectedRowKeys, selectedRows) {
  167. this.selectedRowKeys = selectedRowKeys
  168. },
  169. onSelectChange (record, selected, selectedRows, nativeEvent) {
  170. const _this = this
  171. if (selected) { // 选择
  172. this.selectedRows.push(record)
  173. } else { // 取消
  174. this.selectedRows.map((item, index) => {
  175. if (item.id == record.id) {
  176. _this.selectedRows.splice(index, 1)
  177. }
  178. })
  179. }
  180. },
  181. // 本页全选/取消全选
  182. onSelectAllChange (selected, selectedRows, changeRows) {
  183. const _this = this
  184. if (selected) { // 选择
  185. this.selectedRows = [...this.selectedRows, ...changeRows]
  186. } else { // 取消
  187. this.selectedRows.map((item, index) => {
  188. this.selectedRows.map((subItem, ind) => {
  189. if (item.id == subItem.id) {
  190. _this.selectedRows.splice(index, 1)
  191. }
  192. })
  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. // 修改数量
  207. onCellChange (id, key, value) {
  208. console.log(id, key, value)
  209. const dataSource = [...this.dataSource]
  210. const row = dataSource.find(item => item.id === id)
  211. if (row) {
  212. row[key] = Number(value)
  213. this.dataSource = dataSource
  214. }
  215. if (key == 'qty') {
  216. this.spinning = true
  217. updateQty({
  218. dispatchBillDetailSn: row.dispatchBillDetailSn,
  219. qty: row.qty,
  220. salesBillSn: this.salesBillSn
  221. }).then(res => {
  222. this.resetSearchForm(true)
  223. if (res.status == 200) {
  224. this.$refs.partQuery.resetCurForm()
  225. this.$message.success(res.message)
  226. this.spinning = false
  227. } else {
  228. this.spinning = false
  229. }
  230. })
  231. }
  232. },
  233. // 重置
  234. resetSearchForm (flag) {
  235. this.$refs.table.refresh(!!flag)
  236. this.getOrderDetail()
  237. },
  238. // 重置列表
  239. resetForm () {
  240. this.$refs.table.refresh()
  241. },
  242. // 返回
  243. handleBack () {
  244. this.$router.push({ name: 'salesQueryList' })
  245. },
  246. // 批量删除
  247. delSalerDetailAll () {
  248. const _this = this
  249. if (_this.selectedRowKeys.length < 1) {
  250. _this.$message.warning('请在选择待下推产品!')
  251. return
  252. }
  253. const obj = []
  254. _this.selectedRows.map(item => {
  255. if (_this.selectedRowKeys.indexOf(item.id) != -1) {
  256. obj.push(item.dispatchBillDetailSn)
  257. }
  258. })
  259. this.$confirm({
  260. title: '提示',
  261. content: '确认要批量删除吗?',
  262. centered: true,
  263. closable: true,
  264. onOk () {
  265. _this.deleteFun(obj, 1)
  266. }
  267. })
  268. },
  269. // 删除产品
  270. handleDel (row) {
  271. const _this = this
  272. this.$confirm({
  273. title: '提示',
  274. content: '确认要删除吗?',
  275. centered: true,
  276. closable: true,
  277. onOk () {
  278. _this.deleteFun(row, 0)
  279. }
  280. })
  281. },
  282. // 移除操作
  283. deleteFun (row, type) {
  284. const _this = this
  285. _this.delLoading = true
  286. _this.spinning = true
  287. deleteBatch(type == 0 ? [row.dispatchBillDetailSn] : row).then(res => {
  288. if (res.status == 200) {
  289. _this.resetSearchForm(true)
  290. _this.$refs.partQuery.resetCurForm()
  291. if (type == 1) { // 批量操作
  292. _this.selectedRowKeys = []
  293. _this.selectedRows = []
  294. } else if (type == 0) { // 单条
  295. const ind = _this.selectedRowKeys.findIndex(item => item == row.id)
  296. _this.selectedRowKeys.splice(ind, 1)
  297. }
  298. _this.$message.success(res.message)
  299. _this.spinning = false
  300. } else {
  301. _this.spinning = false
  302. }
  303. _this.delLoading = false
  304. })
  305. },
  306. // 添加产品
  307. insterProduct (list) {
  308. console.log(list)
  309. // 防止多次添加产品
  310. if (this.isInster) { return }
  311. this.saveNewProduct(list)
  312. },
  313. // 保存添加的产品到下推列表
  314. saveNewProduct (list) {
  315. this.$message.loading('正在添加产品...', 1)
  316. this.isInster = true
  317. this.spinning = true
  318. insertBatchOfWaitDispatch(list).then(res => {
  319. if (res.status == 200) {
  320. this.resetSearchForm()
  321. this.$refs.partQuery.resetCurForm()
  322. this.$message.success('添加成功', 2.5)
  323. this.spinning = false
  324. } else {
  325. this.spinning = false
  326. }
  327. this.isInster = false
  328. })
  329. },
  330. // 批量取消产品
  331. cancelProduct (list) {
  332. // 防止多次添加产品
  333. this.$message.loading('正在批量取消产品...', 1)
  334. this.isInster = true
  335. this.spinning = true
  336. salesDetailUpdateCancelQty(list).then(res => {
  337. if (res.status == 200) {
  338. this.resetSearchForm()
  339. this.$refs.partQuery.resetCurForm()
  340. this.$message.success(res.message, 2.5)
  341. this.spinning = false
  342. } else {
  343. this.spinning = false
  344. }
  345. this.isInster = false
  346. })
  347. },
  348. // 一键下推
  349. oneDispatch () {
  350. this.isInster = true
  351. this.spinning = true
  352. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  353. if (res.status == 200) {
  354. this.resetSearchForm()
  355. this.$refs.partQuery.resetCurForm()
  356. this.spinning = false
  357. } else {
  358. this.spinning = false
  359. }
  360. this.isInster = false
  361. })
  362. },
  363. // 销售单详情
  364. getOrderDetail () {
  365. salesDetailBySn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  366. console.log('getOrderDetail')
  367. if (res.status == 200) {
  368. this.detailData = res.data
  369. console.log(this.detailData)
  370. }
  371. })
  372. },
  373. // 提交下推
  374. handleSubmit () {
  375. this.delLoading = true
  376. this.isInster = true
  377. this.loading = true
  378. this.spinning = true
  379. pushDown({ dispatchBillSn: this.$route.params.dispatchBillSn }).then(res => {
  380. if (res.status == 200) {
  381. this.handleBack()
  382. this.$message.success(res.message)
  383. }
  384. this.delLoading = false
  385. this.isInster = false
  386. this.loading = false
  387. this.spinning = false
  388. })
  389. }
  390. },
  391. mounted () {
  392. this.getOrderDetail()
  393. },
  394. beforeRouteEnter (to, from, next) {
  395. next(vm => {
  396. console.log('beforeRouteEnter')
  397. vm.salesBillSn = vm.$route.params.salesBillSn
  398. })
  399. }
  400. }
  401. </script>
  402. <style lang="less">
  403. .waitDispatch-wrap{
  404. .waitDispatch-cont{
  405. margin-top: 15px;
  406. }
  407. .sTable{
  408. margin-top: 15px;
  409. }
  410. .p-title{
  411. font-weight: bold;
  412. }
  413. .p-notes{
  414. span{
  415. color: #FF9900;
  416. }
  417. }
  418. .total-bar{
  419. display: flex;
  420. align-items: center;
  421. justify-content: space-between;
  422. > div{
  423. &:last-child{
  424. display: flex;
  425. align-items: center;
  426. justify-content: space-between;
  427. > div{
  428. padding: 0 10px;
  429. }
  430. }
  431. }
  432. }
  433. .redBg-row{
  434. background-color: #f5cdc8;
  435. }
  436. }
  437. </style>