salesReturnGrabEdit.vue 21 KB

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