salesReturnEdit.vue 21 KB

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