salesReturnEdit.vue 21 KB

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