salesReturnGrabEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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) ? toThousands(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) ? toThousands(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. type="primary"
  85. ghost
  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">{{ toThousands(record.price * record.qty) }}</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. const _this = this
  187. return {
  188. spinning: false,
  189. orderId: null,
  190. orderSn: null,
  191. buyerSn: null,
  192. disabled: false,
  193. openModal: false,
  194. isInster: false, // 是否正在添加产品
  195. ordeDetail: { discountAmount: 0 },
  196. delLoading: false,
  197. warehouseCascadeData: [], // 仓库仓位
  198. // 已选产品
  199. dataSource: [],
  200. productForm: {
  201. productCode: '',
  202. productName: '',
  203. orderBy: 'sales_return_bill_detail.CREATE_DATE desc'
  204. },
  205. countData: null,
  206. // 表头
  207. columns: [
  208. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  209. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  210. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '12%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  211. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', align: 'center', width: '10%', customRender: function (text) { return text || '--' } },
  212. { title: '销售单号', dataIndex: 'salesBillNo', align: 'center', width: '8%', customRender: function (text) { return text || '--' } },
  213. { title: '售价', dataIndex: 'price', align: 'right', width: '4%', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') }},
  214. { title: '单位', dataIndex: 'dealerProductEntity.unit', align: 'center', width: '4%', customRender: function (text) { return text || '--' } },
  215. { title: '销售数量', dataIndex: 'salesQty', align: 'center', width: '5%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  216. { title: '本次退货数量', dataIndex: 'qty', align: 'center', width: '7%', scopedSlots: { customRender: 'qty' } },
  217. { title: '废品数量', dataIndex: 'celQty', align: 'center', width: '6%', scopedSlots: { customRender: 'celQty' } },
  218. { title: '仓库仓位', scopedSlots: { customRender: 'warehouse' }, width: '10%', align: 'center' },
  219. { title: '退货金额小计', align: 'right', scopedSlots: { customRender: 'returnAmount' }, width: '7%' },
  220. { title: '折后金额小计', dataIndex: 'discountedAmount', align: 'right', width: '7%', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  221. { title: '操作', scopedSlots: { customRender: 'action' }, width: '5%', align: 'center' }
  222. ],
  223. chooseLoadData: [],
  224. // 加载数据方法 必须为 Promise 对象
  225. loadData: parameter => {
  226. this.disabled = true
  227. // 查询总计
  228. this.productForm.salesReturnBillSn = this.$route.params.sn
  229. this.getQueryCount(Object.assign(parameter, this.productForm))
  230. return salesReturnDetailList(Object.assign(parameter, this.productForm)).then(res => {
  231. let data
  232. if (res.status == 200) {
  233. data = res.data
  234. const no = (data.pageNo - 1) * data.pageSize
  235. for (var i = 0; i < data.list.length; i++) {
  236. data.list[i].no = no + i + 1
  237. data.list[i].qtyBackups = data.list[i].qty
  238. data.list[i].celQtyBackups = data.list[i].celQty
  239. const warehouseSn = data.list[i].warehouseSn || undefined
  240. const warehouseLocationSn = data.list[i].warehouseLocationSn || undefined
  241. if (warehouseSn || warehouseLocationSn) {
  242. data.list[i].warehouseSnBackups = warehouseSn
  243. data.list[i].warehouseLocationSnBackups = warehouseLocationSn
  244. data.list[i].warehouseCascade = [warehouseSn, warehouseLocationSn]
  245. } else {
  246. data.list[i].warehouseCascade = undefined
  247. }
  248. }
  249. this.disabled = false
  250. this.chooseLoadData = data.list
  251. }
  252. return data
  253. })
  254. },
  255. printerType: 'NEEDLE' // 打印机类型
  256. }
  257. },
  258. methods: {
  259. // 返回
  260. handleBack () {
  261. this.$router.push({ path: '/salesManagement/salesReturn/list' })
  262. },
  263. // 选择客户成功
  264. chooseCustomOk (data) {},
  265. handleEditCustom () {
  266. this.openModal = true
  267. },
  268. // 已选产品 blur
  269. onCellBlur (val, record, type) {
  270. let valBackups
  271. if (type == 'qty') {
  272. valBackups = record.qtyBackups
  273. } else if (type == 'celQty') {
  274. valBackups = record.celQtyBackups
  275. }
  276. // 光标移出,值发生改变再调用编辑接口
  277. if (val && val != valBackups) {
  278. if (Number(record.celQty) > Number(record.qty)) {
  279. this.$message.info('废品数量不可大于本次退货数量')
  280. this.reductionVal(record, type, valBackups)
  281. } else {
  282. this.saveProduct(record, 'edit')
  283. }
  284. } else {
  285. this.reductionVal(record, type, valBackups)
  286. }
  287. },
  288. reductionVal (record, type, valBackups) {
  289. if (type == 'qty') {
  290. record.qty = valBackups
  291. } else if (type == 'celQty') {
  292. record.celQty = valBackups
  293. }
  294. },
  295. // 仓库仓位 级联 列表
  296. getWarehouseCascade () {
  297. warehouseCascadeList({}).then(res => {
  298. if (res.status == 200) {
  299. res.data.map(item => {
  300. item.sn = item.warehouseSn
  301. if (item.warehouseLocationList) {
  302. item.warehouseLocationList.map(subItem => {
  303. subItem.sn = subItem.warehouseLocationSn
  304. })
  305. }
  306. })
  307. this.warehouseCascadeData = res.data
  308. } else {
  309. this.warehouseCascadeData = []
  310. }
  311. })
  312. },
  313. // 修改仓库仓位
  314. changeWarehouseCascade (val, opt, ind) {
  315. console.log(val, opt, ind)
  316. let loadData = this.chooseLoadData[ind]
  317. if (val.length < 2) {
  318. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  319. const warehouseSnBackups = loadData.warehouseSnBackups || undefined
  320. const warehouseLocationSnBackups = loadData.warehouseLocationSnBackups || undefined
  321. loadData.warehouseSn = warehouseSnBackups
  322. loadData.warehouseLocationSn = warehouseLocationSnBackups
  323. if (warehouseSnBackups || warehouseLocationSnBackups) {
  324. loadData.warehouseCascade = [warehouseSnBackups, warehouseLocationSnBackups]
  325. } else {
  326. loadData.warehouseCascade = undefined
  327. }
  328. } else {
  329. loadData.warehouseSn = val[0] ? val[0] : ''
  330. loadData.warehouseLocationSn = val[1] ? val[1] : ''
  331. loadData.warehouseSnBackups = val[0] ? val[0] : ''
  332. loadData.warehouseLocationSnBackups = val[1] ? val[1] : ''
  333. loadData = this.chooseLoadData[ind]
  334. console.log(loadData)
  335. this.saveProduct(loadData, 'edit')
  336. }
  337. },
  338. // 重置列表
  339. resetForm () {
  340. this.productForm = {
  341. productName: '',
  342. productCode: '',
  343. orderBy: 'sales_return_bill_detail.CREATE_DATE desc'
  344. }
  345. this.$refs.table.refresh(true)
  346. },
  347. // 明细统计
  348. getQueryCount (params) {
  349. salesReturnQueryCount(params).then(res => {
  350. this.countData = res.data || null
  351. })
  352. },
  353. // 获取单据详细
  354. getOrderDetail (flag) {
  355. salesReturnDetail({ sn: this.orderSn }).then(res => {
  356. this.ordeDetail = res.data || null
  357. if (!flag) {
  358. this.$refs.queryPart.pageInit(this.buyerSn, this.ordeDetail && this.ordeDetail.priceType || '')
  359. }
  360. })
  361. },
  362. // 打折
  363. salesReturnDiscount () {
  364. this.spinning = true
  365. salesReturnDiscount({
  366. discountAmount: this.ordeDetail.discountAmount || 0,
  367. salesReturnSn: this.ordeDetail.salesReturnSn,
  368. id: this.ordeDetail.id
  369. }).then(res => {
  370. if (res.status == 200) {
  371. this.getOrderDetail(true)
  372. this.$refs.table.refresh(true)
  373. this.spinning = false
  374. } else {
  375. this.spinning = false
  376. }
  377. })
  378. },
  379. // 整单删除
  380. salesReturnDelAll () {
  381. const _this = this
  382. this.$confirm({
  383. title: '提示',
  384. content: '确认要整单删除吗?',
  385. centered: true,
  386. closable: true,
  387. onOk () {
  388. _this.delLoading = true
  389. _this.spinning = true
  390. salesReturnDelAll({ sn: _this.ordeDetail.salesReturnSn }).then(res => {
  391. if (res.status == 200) {
  392. _this.resetSearchForm(true)
  393. _this.$refs.queryPart.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. if (flag) {
  428. this.getOrderDetail()
  429. }
  430. },
  431. // 添加或修改产品
  432. saveProduct (row, type) {
  433. console.log(row)
  434. // 防止多次添加产品
  435. if (this.isInster) {
  436. return
  437. }
  438. this.isInster = true
  439. const params = {
  440. 'salesReturnBillSn': this.orderSn,
  441. 'salesReturnBillNo': this.ordeDetail.salesReturnNo,
  442. 'salesBillSn': row.salesBillSn,
  443. 'salesBillNo': row.salesBillNo,
  444. 'salesBillDetailSn': row.salesBillDetailSn,
  445. 'price': row.price,
  446. 'cost': row.cost,
  447. 'productSn': row.productSn,
  448. 'celQty': row.celQty,
  449. 'qty': row.returnQty,
  450. 'hasReturnQty': row.hasReturnQty,
  451. 'warehouseLocationSn': row.warehouseLocationSn,
  452. 'warehouseSn': row.warehouseSn
  453. }
  454. // 编辑
  455. if (type == 'edit') {
  456. params.id = row.id
  457. params.qty = row.qty
  458. } else {
  459. params.salesQty = row.qty
  460. }
  461. this.spinning = true
  462. salesReturnSaveProduct(params).then(res => {
  463. this.resetSearchForm(type == 'edit')
  464. if (type == 'new') {
  465. this.getOrderDetail()
  466. }
  467. this.isInster = false
  468. this.spinning = false
  469. })
  470. },
  471. // 提交销售单
  472. handleSubmit () {
  473. this.spinning = true
  474. salesReturnSubmit({ sn: this.orderSn }).then(res => {
  475. if (res.status == 200) {
  476. this.handleBack()
  477. this.$message.success(res.message)
  478. this.spinning = false
  479. } else {
  480. this.spinning = false
  481. }
  482. })
  483. },
  484. // 打印预览/快捷打印
  485. handlePrint (type, printerType) {
  486. const _this = this
  487. _this.spinning = true
  488. let url = salesReturnDetailPrint
  489. const params = { sn: this.$route.params.sn }
  490. if (type == 'export') { // 导出
  491. url = salesDetailExport
  492. }
  493. // 打印或导出
  494. hdPrint(printerType, type, url, params, '销售退货', function () {
  495. _this.spinning = false
  496. })
  497. },
  498. pageInit () {
  499. this.orderId = this.$route.params.id
  500. this.orderSn = this.$route.params.sn
  501. this.buyerSn = this.$route.params.buyerSn
  502. this.getOrderDetail()
  503. this.getWarehouseCascade()
  504. this.resetForm()
  505. }
  506. },
  507. mounted () {
  508. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  509. this.pageInit()
  510. }
  511. },
  512. activated () {
  513. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  514. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  515. this.pageInit()
  516. }
  517. },
  518. beforeRouteEnter (to, from, next) {
  519. next(vm => {})
  520. }
  521. }
  522. </script>
  523. <style lang="less">
  524. .salesReturnEdit-wrap{
  525. position: relative;
  526. height: 100%;
  527. box-sizing: border-box;
  528. >.ant-spin-nested-loading{
  529. overflow-y: auto;
  530. height: 100%;
  531. }
  532. .pages-wrap{
  533. margin-top: 10px;
  534. .total-bar{
  535. display: flex;
  536. align-items: center;
  537. justify-content: space-between;
  538. > div{
  539. &:last-child{
  540. display: flex;
  541. align-items: center;
  542. justify-content: space-between;
  543. > div{
  544. padding: 0 10px;
  545. }
  546. }
  547. }
  548. }
  549. }
  550. }
  551. </style>