edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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-card :bordered="false" class="waitDispatch-cont" v-if="salesBillSn">
  17. <!-- 查询配件列表 -->
  18. <queryPart
  19. ref="partQuery"
  20. :salesBillSn="salesBillSn"
  21. :detailData="detailData"
  22. :newLoading="isInster"
  23. @oneDispatch="oneDispatch"
  24. @cancelProduct="cancelProduct"
  25. @addProduct="insterProduct"></queryPart>
  26. </a-card>
  27. <a-card :bordered="false" class="waitDispatch-cont">
  28. <div slot="title">
  29. <div class="p-title">
  30. 待下推产品
  31. </div>
  32. </div>
  33. <div style="margin: 0 0 10px 0;">
  34. <a-button
  35. type="primary"
  36. @click="delSalerDetailAll"
  37. :loading="delLoading"
  38. id="waitDispatch-del-all">批量移除</a-button>
  39. </div>
  40. <!-- 总计 -->
  41. <a-alert type="info" v-if="totalData">
  42. <div slot="message" class="total-bar">
  43. <div>
  44. 本次下推款数:<strong>¥{{ totalData&&totalData.totalCategory || 0 }}</strong>;
  45. 本次下推数量:<strong>{{ totalData&&totalData.totalQty || 0 }}</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:1000, 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. <editable-cell
  73. size="small"
  74. :text="record.qty"
  75. :max="999999"
  76. :min="1"
  77. :precision="0"
  78. @change="onCellChange(record.id, 'qty', $event)" />
  79. </template>
  80. <!-- 操作 -->
  81. <template slot="action" slot-scope="text, record">
  82. <a-button
  83. size="small"
  84. type="primary"
  85. :loading="delLoading"
  86. class="button-error"
  87. @click="handleDel(record)"
  88. >移除</a-button>
  89. </template>
  90. </s-table>
  91. </a-card>
  92. <a-affix :offset-bottom="0">
  93. <div
  94. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  95. <a-button
  96. size="large"
  97. style="width: 150px;"
  98. type="primary"
  99. class="button-primary"
  100. @click="handleSubmit()"
  101. :loading="loading"
  102. id="productInfoList-handleSubmit">下推</a-button>
  103. </div>
  104. </a-affix>
  105. </div>
  106. </template>
  107. <script>
  108. import { STable, VSelect } from '@/components'
  109. import queryPart from './queryPart.vue'
  110. import { salesDetailBySn } from '@/api/sales'
  111. import { salesDetailDispatchByOneKey, insertBatchOfWaitDispatch, salesDetailUpdateCancelQty } from '@/api/salesDetail'
  112. import EditableCell from '@/views/common/editInput.js'
  113. import { deleteBatch, pushDown, queryCount, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  114. export default {
  115. name: 'SalesDetail',
  116. components: { STable, VSelect, queryPart, EditableCell },
  117. data () {
  118. return {
  119. salesBillSn: null, // 销售单sn
  120. disabled: false, // 查询、重置按钮是否可操作
  121. isInster: false, // 是否正在添加产品
  122. delLoading: false, // 是否正在移除产品
  123. loading: false, // 是否下推中
  124. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  125. dataSource: [],
  126. productForm: {
  127. dispatchBillSn: ''
  128. },
  129. selectedRowKeys: [], // Check here to configure the default column
  130. selectedRows: [],
  131. // 表头
  132. columns: [
  133. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  134. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: 300, align: 'center' },
  135. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', width: 300, customRender: function (text) { return text || '--' } },
  136. { title: '剩余待下推', dataIndex: 'surplusQty', width: 150, align: 'center' },
  137. { title: '本次下推数', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  138. { title: '单位', dataIndex: 'productEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  139. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, align: 'center', fixed: 'right' }
  140. ],
  141. // 加载数据方法 必须为 Promise 对象
  142. loadData: parameter => {
  143. this.disabled = true
  144. this.productForm.dispatchBillSn = this.$route.params.dispatchBillSn
  145. // 查询统计
  146. this.getTotalData(Object.assign(parameter, this.productForm))
  147. return waitDispatchDetailAllList(Object.assign(parameter, this.productForm)).then(res => {
  148. const data = res.data
  149. const no = 0
  150. for (var i = 0; i < data.length; i++) {
  151. data[i].no = no + i + 1
  152. }
  153. this.disabled = false
  154. this.dataSource = data
  155. return data
  156. })
  157. },
  158. totalData: null
  159. }
  160. },
  161. methods: {
  162. onChange (selectedRowKeys, selectedRows) {
  163. this.selectedRowKeys = selectedRowKeys
  164. },
  165. onSelectChange (record, selected, selectedRows, nativeEvent) {
  166. const _this = this
  167. if (selected) { // 选择
  168. this.selectedRows.push(record)
  169. } else { // 取消
  170. this.selectedRows.map((item, index) => {
  171. if (item.id == record.id) {
  172. _this.selectedRows.splice(index, 1)
  173. }
  174. })
  175. }
  176. },
  177. // 本页全选/取消全选
  178. onSelectAllChange (selected, selectedRows, changeRows) {
  179. const _this = this
  180. if (selected) { // 选择
  181. this.selectedRows = [...this.selectedRows, ...changeRows]
  182. } else { // 取消
  183. this.selectedRows.map((item, index) => {
  184. this.selectedRows.map((subItem, ind) => {
  185. if (item.id == subItem.id) {
  186. _this.selectedRows.splice(index, 1)
  187. }
  188. })
  189. })
  190. }
  191. },
  192. // 统计查询
  193. getTotalData (params) {
  194. queryCount(params).then(res => {
  195. this.totalData = res.data || null
  196. })
  197. },
  198. // 修改数量
  199. onCellChange (id, key, value) {
  200. console.log(id, key, value)
  201. const dataSource = [...this.dataSource]
  202. const row = dataSource.find(item => item.id === id)
  203. if (row) {
  204. row[key] = Number(value)
  205. this.dataSource = dataSource
  206. }
  207. if (key == 'qty') {
  208. updateQty({
  209. dispatchBillDetailSn: row.dispatchBillDetailSn,
  210. qty: row.qty,
  211. salesBillSn: this.salesBillSn
  212. }).then(res => {
  213. this.resetSearchForm(true)
  214. if (res.status == 200) {
  215. this.$refs.partQuery.resetCurForm()
  216. this.$message.success(res.message)
  217. }
  218. })
  219. }
  220. },
  221. // 重置
  222. resetSearchForm (flag) {
  223. this.$refs.table.refresh(!!flag)
  224. this.getOrderDetail()
  225. },
  226. // 重置列表
  227. resetForm () {
  228. this.$refs.table.refresh()
  229. },
  230. // 返回
  231. handleBack () {
  232. this.$router.push({ name: 'salesQueryList' })
  233. },
  234. // 批量删除
  235. delSalerDetailAll () {
  236. const _this = this
  237. if (_this.selectedRowKeys.length < 1) {
  238. _this.$message.warning('请在选择待下推产品!')
  239. return
  240. }
  241. const obj = []
  242. _this.selectedRows.map(item => {
  243. obj.push(item.dispatchBillDetailSn)
  244. })
  245. this.$confirm({
  246. title: '提示',
  247. content: '确认要批量删除吗?',
  248. centered: true,
  249. closable: true,
  250. onOk () {
  251. _this.deleteFun(obj, 1)
  252. }
  253. })
  254. },
  255. // 删除产品
  256. handleDel (row) {
  257. const _this = this
  258. this.$confirm({
  259. title: '提示',
  260. content: '确认要删除吗?',
  261. centered: true,
  262. closable: true,
  263. onOk () {
  264. _this.deleteFun(row, 0)
  265. }
  266. })
  267. },
  268. // 移除操作
  269. deleteFun (row, type) {
  270. const _this = this
  271. _this.delLoading = true
  272. deleteBatch(type == 0 ? [row.dispatchBillDetailSn] : row).then(res => {
  273. if (res.status == 200) {
  274. _this.resetSearchForm(true)
  275. _this.$message.success(res.message)
  276. }
  277. _this.delLoading = false
  278. })
  279. },
  280. // 添加产品
  281. insterProduct (list) {
  282. console.log(list)
  283. // 防止多次添加产品
  284. if (this.isInster) { return }
  285. const _this = this
  286. _this.saveNewProduct(list)
  287. },
  288. // 保存添加的产品到下推列表
  289. saveNewProduct (list) {
  290. this.$message.loading('正在添加产品...', 1)
  291. this.isInster = true
  292. insertBatchOfWaitDispatch(list).then(res => {
  293. if (res.status == 200) {
  294. this.resetSearchForm()
  295. this.$refs.partQuery.resetCurForm()
  296. this.$message.success('添加成功', 2.5)
  297. }
  298. this.isInster = false
  299. })
  300. },
  301. // 批量取消产品
  302. cancelProduct (list) {
  303. // 防止多次添加产品
  304. this.$message.loading('正在批量取消产品...', 1)
  305. this.isInster = true
  306. salesDetailUpdateCancelQty(list).then(res => {
  307. if (res.status == 200) {
  308. this.resetSearchForm()
  309. this.$refs.partQuery.resetCurForm()
  310. this.$message.success(res.message, 2.5)
  311. }
  312. this.isInster = false
  313. })
  314. },
  315. // 一键下推
  316. oneDispatch () {
  317. this.isInster = true
  318. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  319. if (res.status == 200) {
  320. this.resetSearchForm()
  321. this.$refs.partQuery.resetCurForm()
  322. }
  323. this.isInster = false
  324. })
  325. },
  326. // 销售单详情
  327. getOrderDetail () {
  328. salesDetailBySn({ salesBillSn: this.$route.params.salesBillSn }).then(res => {
  329. console.log('getOrderDetail')
  330. if (res.status == 200) {
  331. this.detailData = res.data
  332. console.log(this.detailData)
  333. }
  334. })
  335. },
  336. // 提交下推
  337. handleSubmit () {
  338. this.delLoading = true
  339. this.isInster = true
  340. this.loading = true
  341. pushDown({ dispatchBillSn: this.$route.params.dispatchBillSn }).then(res => {
  342. if (res.status == 200) {
  343. this.handleBack()
  344. this.$message.success(res.message)
  345. }
  346. this.delLoading = false
  347. this.isInster = false
  348. this.loading = false
  349. })
  350. }
  351. },
  352. mounted () {
  353. this.getOrderDetail()
  354. },
  355. beforeRouteEnter (to, from, next) {
  356. next(vm => {
  357. console.log('beforeRouteEnter')
  358. vm.salesBillSn = vm.$route.params.salesBillSn
  359. })
  360. }
  361. }
  362. </script>
  363. <style lang="less">
  364. .waitDispatch-wrap{
  365. .waitDispatch-cont{
  366. margin-top: 15px;
  367. }
  368. .sTable{
  369. margin-top: 15px;
  370. }
  371. .p-title{
  372. font-weight: bold;
  373. }
  374. .p-notes{
  375. span{
  376. color: #FF9900;
  377. }
  378. }
  379. .total-bar{
  380. display: flex;
  381. align-items: center;
  382. justify-content: space-between;
  383. > div{
  384. &:last-child{
  385. display: flex;
  386. align-items: center;
  387. justify-content: space-between;
  388. > div{
  389. padding: 0 10px;
  390. }
  391. }
  392. }
  393. }
  394. .redBg-row{
  395. background-color: #f5cdc8;
  396. }
  397. }
  398. </style>