salesReturnGrabEdit.vue 20 KB

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