salesReturnGrabEdit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <div>
  3. <a-affix :target="() => this.$refs.container">
  4. <a-page-header
  5. :ghost="false"
  6. @back="handleBack"
  7. :backIcon="false"
  8. >
  9. <template slot="subTitle">
  10. <a id="back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  11. <span style="margin: 0 15px;color: #666;">客户名称:{{ ordeDetail&&ordeDetail.buyerName }}</span>
  12. <!-- <a-button size="small" @click="handleEditCustom" style="margin-left:50px" key="0">
  13. 编辑
  14. </a-button> -->
  15. </template>
  16. <template slot="extra">
  17. <a-button key="2">
  18. 打印预览
  19. </a-button>
  20. <a-button key="1" type="primary">
  21. 快速打印
  22. </a-button>
  23. </template>
  24. </a-page-header>
  25. </a-affix>
  26. <a-card size="small" :bordered="false" class="pages-wrap">
  27. <!-- 查询配件列表 -->
  28. <queryPart :buyerSn="$route.params.buyerSn" grabFlag="1" :newLoading="isInster" @add="saveProduct"></queryPart>
  29. </a-card>
  30. <a-card size="small" :bordered="false" class="pages-wrap">
  31. <!-- alert -->
  32. <a-alert style="margin-bottom: 15px;" type="info">
  33. <div slot="message" class="total-bar">
  34. <div>
  35. <span>退货总金额:{{ countData&&countData.totalAmount }}元;</span>
  36. <span>总款数:{{ countData&&countData.totalCategory }};</span>
  37. <span>总数量:{{ countData&&countData.totalQty }};</span>
  38. <span>废品总数量:{{ countData&&countData.totalCelQty }};</span>
  39. </div>
  40. <div>
  41. <div>
  42. 折扣金额:
  43. <a-input-number id="discount" v-model="ordeDetail.discountAmount" :min="0" :precision="2" :max="999999"/>
  44. <a-button type="primary" @click="salesReturnDiscount" class="button-info">打折</a-button>
  45. </div>
  46. <div>
  47. 折扣:<strong>{{ ordeDetail&&ordeDetail.discountRate || 0 }}%</strong>;
  48. 折后总售价:<strong>¥{{ ordeDetail&&ordeDetail.discountedAmount || 0 }}</strong>;
  49. </div>
  50. </div>
  51. </div>
  52. </a-alert>
  53. <!-- 查询条件 -->
  54. <a-row :gutter="15">
  55. <a-col :span="18">
  56. <a-form-model layout="inline" :model="productForm">
  57. <a-form-model-item label="产品编码">
  58. <a-input v-model="productForm.productCode" placeholder="输入产品编码" />
  59. </a-form-model-item>
  60. <a-form-model-item label="产品名称">
  61. <a-input v-model="productForm.productName" placeholder="输入产品名称" />
  62. </a-form-model-item>
  63. <a-form-model-item>
  64. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesReturn-refresh">查询</a-button>
  65. <a-button style="margin: 0 0 18px 8px" @click="resetForm" id="salesReturn-reset">重置</a-button>
  66. </a-form-model-item>
  67. </a-form-model>
  68. </a-col>
  69. <a-col :span="6">
  70. <div style="float:right;overflow: hidden;">
  71. <a-button id="salesReturn-dru">导入明细</a-button>
  72. <a-button
  73. size="small"
  74. type="primary"
  75. @click="salesReturnDelAll"
  76. :loading="delLoading"
  77. style="margin-left: 10px"
  78. id="salesReturn-del-all">整单删除</a-button>
  79. </div>
  80. </a-col>
  81. </a-row>
  82. <!-- 已选配件列表 -->
  83. <s-table
  84. class="sTable"
  85. ref="table"
  86. size="default"
  87. :rowKey="(record) => record.id"
  88. :columns="columns"
  89. :data="loadData"
  90. :scroll="{ x: 1500, y: 300 }"
  91. bordered>
  92. <!-- 本次退货数量 -->
  93. <template slot="qty" slot-scope="text, record">
  94. <editable-cell
  95. size="small"
  96. :text="record.qty"
  97. :max="999999"
  98. :min="0"
  99. :precision="0"
  100. @change="onCellChange(record.id, 'qty', $event)" />
  101. </template>
  102. <!-- 废品数量 -->
  103. <template slot="celQty" slot-scope="text, record">
  104. <editable-cell
  105. size="small"
  106. :text="record.celQty"
  107. :max="999999"
  108. :min="0"
  109. :precision="0"
  110. @change="onCellChange(record.id, 'celQty', $event)" />
  111. </template>
  112. <!-- 退货金额小计 -->
  113. <template slot="returnAmount" slot-scope="text, record">
  114. ¥{{ (record.price * record.qty).toFixed(2) }}
  115. </template>
  116. <!-- 仓库仓位 -->
  117. <template slot="warehouse" slot-scope="text, record, index">
  118. <a-cascader
  119. @change="e => changeWarehouseCascade(e, record, index)"
  120. v-model="record.warehouseCascade"
  121. expand-trigger="hover"
  122. :options="warehouseCascadeData"
  123. :allowClear="false"
  124. :fieldNames="{ label: 'name', value: 'sn', children: 'warehouseLocationList' }"
  125. id="bulkWarehousingOrderEdit-warehouseCascade"
  126. placeholder="请选择仓库仓位"
  127. style="width: 100%;" />
  128. </template>
  129. <!-- 操作 -->
  130. <template slot="action" slot-scope="text, record">
  131. <a-button
  132. size="small"
  133. type="primary"
  134. :loading="delLoading"
  135. class="button-error"
  136. @click="handleDel(record)"
  137. id="salesReturn-Del">删除</a-button>
  138. </template>
  139. </s-table>
  140. </a-card>
  141. <a-affix :offset-bottom="0">
  142. <div
  143. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  144. <a-button
  145. size="large"
  146. style="width: 150px;"
  147. type="primary"
  148. class="button-primary"
  149. @click="handleSubmit()"
  150. id="salesReturn-handleSubmit">提交</a-button>
  151. </div>
  152. </a-affix>
  153. <!-- 选择客户弹框 -->
  154. <choose-custom-modal :show="openModal" @ok="chooseCustomOk" @cancel="openModal=false"></choose-custom-modal>
  155. </div>
  156. </template>
  157. <script>
  158. import { STable, VSelect } from '@/components'
  159. import queryPart from './queryPart.vue'
  160. import EditableCell from '@/views/common/editInput.js'
  161. import chooseCustomModal from './chooseCustomModal.vue'
  162. import { warehouseCascadeList } from '@/api/warehouse'
  163. import { salesReturnDetail, salesReturnQueryCount, salesReturnDetailList, salesReturnDiscount, salesReturnDelAll, salesReturnDetailDel, salesReturnSaveProduct, salesReturnSubmit } from '@/api/salesReturn'
  164. export default {
  165. name: 'SalesDetail',
  166. components: {
  167. STable,
  168. VSelect,
  169. queryPart,
  170. EditableCell,
  171. chooseCustomModal
  172. },
  173. data () {
  174. return {
  175. orderId: null,
  176. orderSn: null,
  177. buyerSn: null,
  178. disabled: false,
  179. openModal: false,
  180. isInster: false, // 是否正在添加产品
  181. ordeDetail: { discountAmount: 0 },
  182. delLoading: false,
  183. warehouseCascadeData: [], // 仓库仓位
  184. // 已选产品
  185. dataSource: [],
  186. productForm: {
  187. productCode: '',
  188. productName: ''
  189. },
  190. countData: null,
  191. // 表头
  192. columns: [
  193. {
  194. title: '序号',
  195. dataIndex: 'no',
  196. align: 'center',
  197. width: 100
  198. },
  199. {
  200. title: '产品编码',
  201. dataIndex: 'dealerProductEntity.code',
  202. align: 'center',
  203. width: 160
  204. },
  205. {
  206. title: '产品名称',
  207. dataIndex: 'dealerProductEntity.name',
  208. align: 'center',
  209. width: 200
  210. },
  211. {
  212. title: '原厂编码',
  213. dataIndex: 'dealerProductEntity.origCode',
  214. align: 'center',
  215. width: 160,
  216. customRender: function (text) { return text || '--' }
  217. },
  218. {
  219. title: '销售单号',
  220. dataIndex: 'salesBillNo',
  221. align: 'center',
  222. width: 200
  223. },
  224. {
  225. title: '售价',
  226. dataIndex: 'price',
  227. align: 'center',
  228. width: 150,
  229. scopedSlots: { customRender: 'price' }
  230. },
  231. {
  232. title: '单位',
  233. dataIndex: 'dealerProductEntity.unit',
  234. align: 'center',
  235. width: 100
  236. },
  237. {
  238. title: '销售数量',
  239. dataIndex: 'salesQty',
  240. align: 'center',
  241. width: 100
  242. },
  243. {
  244. title: '本次退货数量',
  245. dataIndex: 'qty',
  246. align: 'center',
  247. width: 150,
  248. scopedSlots: { customRender: 'qty' }
  249. },
  250. {
  251. title: '废品数量',
  252. dataIndex: 'celQty',
  253. align: 'center',
  254. width: 150,
  255. scopedSlots: { customRender: 'celQty' }
  256. },
  257. { title: '仓库仓位', scopedSlots: { customRender: 'warehouse' }, width: 200, align: 'center' },
  258. {
  259. title: '退货金额小计',
  260. align: 'center',
  261. scopedSlots: { customRender: 'returnAmount' },
  262. width: 100
  263. },
  264. {
  265. title: '折后金额小计',
  266. dataIndex: 'discountedAmount',
  267. align: 'center',
  268. width: 100
  269. },
  270. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  271. ],
  272. chooseLoadData: [],
  273. // 加载数据方法 必须为 Promise 对象
  274. loadData: parameter => {
  275. this.disabled = true
  276. // 查询总计
  277. this.productForm.salesReturnBillSn = this.$route.params.sn
  278. this.getQueryCount(Object.assign(parameter, this.productForm))
  279. return salesReturnDetailList(Object.assign(parameter, this.productForm)).then(res => {
  280. const data = res.data
  281. const no = (data.pageNo - 1) * data.pageSize
  282. for (var i = 0; i < data.list.length; i++) {
  283. data.list[i].no = no + i + 1
  284. const warehouseSn = data.list[i].warehouseSn || undefined
  285. const warehouseLocationSn = data.list[i].warehouseLocationSn || undefined
  286. if (warehouseSn || warehouseLocationSn) {
  287. data.list[i].warehouseSnBackups = warehouseSn
  288. data.list[i].warehouseLocationSnBackups = warehouseLocationSn
  289. data.list[i].warehouseCascade = [warehouseSn, warehouseLocationSn]
  290. } else {
  291. data.list[i].warehouseCascade = undefined
  292. }
  293. }
  294. this.disabled = false
  295. this.chooseLoadData = data.list
  296. return data
  297. })
  298. }
  299. }
  300. },
  301. methods: {
  302. // 返回
  303. handleBack () {
  304. this.$router.push({ name: 'salesReturnList' })
  305. },
  306. // 选择客户成功
  307. chooseCustomOk (data) {
  308. },
  309. handleEditCustom () {
  310. this.openModal = true
  311. },
  312. onCellChange (id, key, value) {
  313. const chooseLoadData = [...this.chooseLoadData]
  314. const row = chooseLoadData.find(item => item.id === id)
  315. if (row) {
  316. row[key] = Number(value)
  317. console.log(row.celQty, row.qty)
  318. if (row.celQty > row.qty) {
  319. this.$message.info('废品数量不可大于本次退货数量')
  320. } else {
  321. this.saveProduct(row, 'edit')
  322. }
  323. }
  324. },
  325. // 仓库仓位 级联 列表
  326. getWarehouseCascade () {
  327. warehouseCascadeList({}).then(res => {
  328. if (res.status == 200) {
  329. res.data.map(item => {
  330. item.sn = item.warehouseSn
  331. if (item.warehouseLocationList) {
  332. item.warehouseLocationList.map(subItem => {
  333. subItem.sn = subItem.warehouseLocationSn
  334. })
  335. }
  336. })
  337. this.warehouseCascadeData = res.data
  338. } else {
  339. this.warehouseCascadeData = []
  340. }
  341. })
  342. },
  343. // 修改仓库仓位
  344. changeWarehouseCascade (val, opt, ind) {
  345. console.log(val, opt, ind)
  346. let loadData = this.chooseLoadData[ind]
  347. if (val.length < 2) {
  348. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  349. const warehouseSnBackups = loadData.warehouseSnBackups || undefined
  350. const warehouseLocationSnBackups = loadData.warehouseLocationSnBackups || undefined
  351. loadData.warehouseSn = warehouseSnBackups
  352. loadData.warehouseLocationSn = warehouseLocationSnBackups
  353. if (warehouseSnBackups || warehouseLocationSnBackups) {
  354. loadData.warehouseCascade = [warehouseSnBackups, warehouseLocationSnBackups]
  355. } else {
  356. loadData.warehouseCascade = undefined
  357. }
  358. } else {
  359. loadData.warehouseSn = val[0] ? val[0] : ''
  360. loadData.warehouseLocationSn = val[1] ? val[1] : ''
  361. loadData.warehouseSnBackups = val[0] ? val[0] : ''
  362. loadData.warehouseLocationSnBackups = val[1] ? val[1] : ''
  363. loadData = this.chooseLoadData[ind]
  364. console.log(loadData)
  365. this.saveProduct(loadData, 'edit')
  366. }
  367. },
  368. // 重置列表
  369. resetForm () {
  370. this.productForm = {
  371. productName: '',
  372. productCode: ''
  373. }
  374. this.$refs.table.refresh(true)
  375. },
  376. // 明细统计
  377. getQueryCount (params) {
  378. salesReturnQueryCount(params).then(res => {
  379. this.countData = res.data || null
  380. })
  381. },
  382. // 获取单据详细
  383. getOrderDetail () {
  384. salesReturnDetail({ sn: this.orderSn }).then(res => {
  385. this.ordeDetail = res.data || null
  386. })
  387. },
  388. // 打折
  389. salesReturnDiscount () {
  390. if (this.ordeDetail.discountAmount <= 0) {
  391. return
  392. }
  393. salesReturnDiscount({
  394. discountAmount: this.ordeDetail.discountAmount,
  395. salesReturnSn: this.ordeDetail.salesReturnSn,
  396. id: this.ordeDetail.id
  397. }).then(res => {
  398. if (res.status == 200) {
  399. this.resetSearchForm()
  400. }
  401. })
  402. },
  403. // 整单删除
  404. salesReturnDelAll () {
  405. const _this = this
  406. this.$confirm({
  407. title: '提示',
  408. content: '确认要整单删除吗?',
  409. centered: true,
  410. closable: true,
  411. onOk () {
  412. _this.delLoading = true
  413. salesReturnDelAll({ sn: _this.ordeDetail.salesReturnSn }).then(res => {
  414. if (res.status == 200) {
  415. _this.resetSearchForm()
  416. }
  417. _this.$message.info(res.message)
  418. _this.delLoading = false
  419. })
  420. }
  421. })
  422. },
  423. // 删除产品
  424. handleDel (row) {
  425. const _this = this
  426. this.$confirm({
  427. title: '提示',
  428. content: '确认要删除吗?',
  429. centered: true,
  430. closable: true,
  431. onOk () {
  432. _this.delLoading = true
  433. salesReturnDetailDel({ id: row.id }).then(res => {
  434. if (res.status == 200) {
  435. _this.resetSearchForm(true)
  436. }
  437. _this.$message.info(res.message)
  438. _this.delLoading = false
  439. })
  440. }
  441. })
  442. },
  443. // 重置
  444. resetSearchForm (flag) {
  445. this.$refs.table.refresh(!!flag)
  446. this.getOrderDetail()
  447. },
  448. // 添加或修改产品
  449. saveProduct (row, type) {
  450. console.log(row)
  451. // 防止多次添加产品
  452. if (this.isInster) {
  453. return
  454. }
  455. this.isInster = true
  456. const params = {
  457. 'salesReturnBillSn': this.orderSn,
  458. 'salesReturnBillNo': this.ordeDetail.salesReturnBillNo,
  459. 'salesBillSn': row.salesBillSn,
  460. 'salesBillNo': row.salesBillNo,
  461. 'salesBillDetailSn': row.salesBillDetailSn,
  462. 'price': row.price,
  463. 'cost': row.cost,
  464. 'productSn': row.productSn,
  465. 'celQty': row.celQty,
  466. 'hasReturnQty': row.hasReturnQty,
  467. 'warehouseLocationSn': row.warehouseLocationSn,
  468. 'warehouseSn': row.warehouseSn
  469. }
  470. // 编辑
  471. if (type == 'edit') {
  472. params.id = row.id
  473. params.qty = row.qty
  474. } else {
  475. params.salesQty = row.qty
  476. }
  477. salesReturnSaveProduct(params).then(res => {
  478. if (res.status == 200) {
  479. this.resetSearchForm(true)
  480. }
  481. this.isInster = false
  482. })
  483. },
  484. // 提交销售单
  485. handleSubmit () {
  486. salesReturnSubmit({ sn: this.orderSn }).then(res => {
  487. if (res.status == 200) {
  488. this.handleBack()
  489. this.$message.success(res.message)
  490. }
  491. })
  492. }
  493. },
  494. mounted () {
  495. this.orderId = this.$route.params.id
  496. this.orderSn = this.$route.params.sn
  497. this.buyerSn = this.$route.params.buyerSn
  498. this.getOrderDetail()
  499. this.getWarehouseCascade()
  500. },
  501. beforeRouteEnter (to, from, next) {
  502. next(vm => {
  503. console.log('beforeRouteEnter')
  504. })
  505. }
  506. }
  507. </script>
  508. <style lang="less">
  509. .pages-wrap{
  510. margin-top: 15px;
  511. .sTable{
  512. margin-top: 15px;
  513. }
  514. .total-bar{
  515. display: flex;
  516. align-items: center;
  517. justify-content: space-between;
  518. > div{
  519. &:last-child{
  520. display: flex;
  521. align-items: center;
  522. justify-content: space-between;
  523. > div{
  524. padding: 0 10px;
  525. }
  526. }
  527. }
  528. }
  529. }
  530. </style>