salesReturnEdit.vue 21 KB

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