salesReturnEdit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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">
  12. <a-button
  13. key="3"
  14. type="default"
  15. class="button-info"
  16. id="salesReturnEdit-preview-btn"
  17. v-if="$hasPermissions('B_salesReturnPrint')"
  18. :disabled="chooseLoadData.length==0"
  19. @click="handlePrint('preview')">打印预览</a-button>
  20. <a-button
  21. key="2"
  22. type="primary"
  23. class="button-info"
  24. id="salesReturnEdit-print-btn"
  25. v-if="$hasPermissions('B_salesReturnPrint')"
  26. :disabled="chooseLoadData.length==0"
  27. @click="handlePrint('print')">快捷打印</a-button>
  28. <a-divider type="vertical" />
  29. <a-button
  30. key="1"
  31. type="primary"
  32. class="button-warning"
  33. id="salesReturnEdit-export-btn"
  34. v-if="$hasPermissions('B_salesReturnExport')"
  35. :disabled="chooseLoadData.length==0"
  36. @click="handlePrint('export')">导出Excel</a-button>
  37. </template>
  38. </a-page-header>
  39. <a-card size="small" :bordered="false" class="salesReturnEdit-cont">
  40. <!-- 查询配件列表 -->
  41. <queryPart ref="partQuery" :returnReasonList="returnReasonList" :newLoading="isInster" @add="saveProduct"></queryPart>
  42. </a-card>
  43. <a-card size="small" :bordered="false" class="salesReturnEdit-cont">
  44. <a-alert style="margin-bottom: 10px;" type="info">
  45. <div slot="message" class="total-bar">
  46. <div>
  47. <span>申请退货数量:{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }};</span>
  48. <span v-if="$hasPermissions('B_isShowPrice')">参考退货金额:{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}元;</span>
  49. </div>
  50. </div>
  51. </a-alert>
  52. <div class="table-page-search-wrapper" style="display:flex;align-items: center;justify-content: space-between;">
  53. <div style="width:80%;">
  54. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  55. <a-row :gutter="15">
  56. <a-col :md="6" :sm="24">
  57. <a-form-item label="产品编码">
  58. <a-input v-model.trim="productForm.productCode" allowClear placeholder="请输入产品编码"/>
  59. </a-form-item>
  60. </a-col>
  61. <a-col :md="6" :sm="24">
  62. <a-form-item label="产品名称">
  63. <a-input v-model.trim="productForm.productName" allowClear placeholder="请输入产品名称"/>
  64. </a-form-item>
  65. </a-col>
  66. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  67. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled">查询</a-button>
  68. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled">重置</a-button>
  69. </a-col>
  70. </a-row>
  71. </a-form>
  72. </div>
  73. <div>
  74. <a-button type="primary" class="button-info" id="salesReturnEdit-import-btn" @click="openGuideModal=true">导入产品</a-button>
  75. </div>
  76. </div>
  77. <!-- 已选配件列表 -->
  78. <s-table
  79. class="sTable"
  80. ref="table"
  81. size="small"
  82. :rowKey="(record) => record.id"
  83. :columns="columns"
  84. :data="loadData"
  85. :defaultLoadData="false"
  86. :scroll="{ y: 300 }"
  87. bordered>
  88. <!-- 本次退货数量 -->
  89. <template slot="qty" slot-scope="text, record">
  90. <a-input-number
  91. id="salesReturn-qty"
  92. size="small"
  93. v-model="record.qty"
  94. :precision="0"
  95. :min="0"
  96. :max="999999"
  97. placeholder="请输入"
  98. @blur="e => onCellBlur(e.target.value, record, 'qty')"
  99. style="width: 100%;" />
  100. </template>
  101. <!-- 退货原因 -->
  102. <template slot="returnReason" slot-scope="text, record">
  103. <a-select
  104. style="width:100%;"
  105. v-model="record.returnReason"
  106. @change="updateReason(record)"
  107. placeholder="请选择退货原因"
  108. >
  109. <a-select-option v-for="item in returnReasonList" :value="item.code">
  110. {{ item.dispName }}
  111. </a-select-option>
  112. </a-select>
  113. </template>
  114. <!-- 操作 -->
  115. <template slot="action" slot-scope="text, record">
  116. <a-button
  117. size="small"
  118. type="link"
  119. :loading="delLoading"
  120. class="button-error"
  121. @click="handleDel(record)"
  122. id="salesReturn-Del">删除</a-button>
  123. </template>
  124. </s-table>
  125. </a-card>
  126. </a-spin>
  127. <div class="affix-cont">
  128. <a-button
  129. size="large"
  130. style="padding: 0 60px;"
  131. :disabled="spinning"
  132. type="primary"
  133. class="button-primary"
  134. @click="beforeSubmit()"
  135. id="salesReturn-handleSubmit">提交</a-button>
  136. </div>
  137. <!-- 选择审核人员 -->
  138. <chooseDepartUserModal :openModal="openDepartUserModal" @close="openDepartUserModal=false" @submit="handleSubmit"></chooseDepartUserModal>
  139. <!-- 导入产品 -->
  140. <importGuideModal :openModal="openGuideModal" :params="{salesReturnBillSn: $route.params.sn, grabFlag: ordeDetail.grabFlag}" @close="closeGuideModel" @ok="hanldeOk" />
  141. </div>
  142. </template>
  143. <script>
  144. import { commonMixin } from '@/utils/mixin'
  145. import { STable, VSelect } from '@/components'
  146. import { printFun, exportExcel } from '@/libs/JGPrint.js'
  147. import ImportGuideModal from './importGuideModal.vue'
  148. import queryPart from './queryPart.vue'
  149. import EditableCell from '@/views/common/editInput.js'
  150. import chooseDepartUserModal from './chooseDepartUserModal.vue'
  151. import { salesReturnDetail, salesReturnSubmit, salesReturnBatchInsert, salesReturnPrint, salesReturnExport } from '@/api/salesReturn'
  152. import {
  153. salesReturnDetailList,
  154. salesReturnDetailDel,
  155. salesReturnDetailInsert,
  156. salesReturnDetailUpdateQty,
  157. salesReturnDetailUpdateReason
  158. } from '@/api/salesReturnDetail'
  159. export default {
  160. name: 'SalesReturnEdit',
  161. mixins: [commonMixin],
  162. components: {
  163. STable,
  164. VSelect,
  165. queryPart,
  166. EditableCell,
  167. ImportGuideModal,
  168. chooseDepartUserModal
  169. },
  170. data () {
  171. return {
  172. spinning: false,
  173. orderId: null,
  174. orderSn: null,
  175. buyerSn: null,
  176. disabled: false,
  177. isInster: false, // 是否正在添加产品
  178. openDepartUserModal: false,
  179. ordeDetail: { discountAmount: 0 },
  180. delLoading: false,
  181. // 已选产品
  182. dataSource: [],
  183. productForm: {
  184. salesReturnBillSn: '',
  185. productName: '',
  186. productCode: ''
  187. },
  188. chooseLoadData: [],
  189. // 加载数据方法 必须为 Promise 对象
  190. loadData: parameter => {
  191. this.disabled = true
  192. // 查询总计
  193. this.productForm.salesReturnBillSn = this.$route.params.sn
  194. return salesReturnDetailList(Object.assign(parameter, this.productForm)).then(res => {
  195. let data
  196. if (res.status == 200) {
  197. data = res.data
  198. const no = (data.pageNo - 1) * data.pageSize
  199. for (var i = 0; i < data.list.length; i++) {
  200. data.list[i].no = no + i + 1
  201. data.list[i].qtyBackups = data.list[i].qty
  202. data.list[i].priceBackups = data.list[i].price
  203. }
  204. this.disabled = false
  205. this.chooseLoadData = data.list
  206. this.total = res.data.count
  207. }
  208. return data
  209. })
  210. },
  211. openGuideModal: false, // 导入产品引导
  212. total: 0,
  213. returnReasonList: [] // 申请退货列表
  214. }
  215. },
  216. computed: {
  217. columns () {
  218. const arr = [
  219. { title: '序号', dataIndex: 'no', align: 'center', width: '4%' },
  220. { title: '产品编码', dataIndex: 'productEntity.code', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  221. { title: '产品名称', dataIndex: 'productEntity.name', width: '25%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  222. { title: '单位', dataIndex: 'productEntity.unit', align: 'center', width: '6%', customRender: function (text) { return text || '--' } },
  223. { title: '申请退货数量', dataIndex: 'qty', align: 'center', width: '8%', scopedSlots: { customRender: 'qty' } },
  224. { title: '退货原因', dataIndex: 'returnReason', align: 'center', width: '13%', scopedSlots: { customRender: 'returnReason' } },
  225. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  226. ]
  227. if (this.$hasPermissions('B_isShowPrice')) { // 售价权限
  228. arr.splice(4, 0, { title: '参考退货单价', dataIndex: 'price', align: 'center', width: '8%', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  229. arr.splice(7, 0, { title: '参考退货金额', align: 'center', dataIndex: 'totalAmount', width: '8%', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  230. }
  231. return arr
  232. }
  233. },
  234. methods: {
  235. // 返回
  236. handleBack () {
  237. this.$router.push({ name: 'salesReturnList', query: { closeLastOldTab: true } })
  238. },
  239. // 已选产品 blur
  240. onCellBlur (val, record, type) {
  241. const valBackups = record.qtyBackups
  242. // 光标移出,值发生改变再调用编辑接口
  243. if (val && val != valBackups) {
  244. this.spinning = true
  245. salesReturnDetailUpdateQty({
  246. salesReturnDetailSn: record.salesReturnDetailSn,
  247. qty: record.qty,
  248. price: record.price
  249. }).then(res => {
  250. if (res.status == 200) {
  251. this.resetTable(false)
  252. this.$message.success(res.message)
  253. this.spinning = false
  254. record.qtyBackups = record.qty
  255. } else {
  256. this.spinning = false
  257. record.qty = valBackups
  258. }
  259. })
  260. } else {
  261. record.qty = valBackups
  262. }
  263. },
  264. // 修改退货原因
  265. updateReason (row) {
  266. this.spinning = true
  267. salesReturnDetailUpdateReason({
  268. salesReturnDetailSn: row.salesReturnDetailSn,
  269. returnReason: row.returnReason
  270. }).then(res => {
  271. if (res.status == 200) {
  272. this.resetTable(false)
  273. this.$message.success(res.message)
  274. }
  275. this.spinning = false
  276. })
  277. },
  278. // 获取单据详细
  279. getOrderDetail () {
  280. salesReturnDetail({ sn: this.orderSn }).then(res => {
  281. this.ordeDetail = res.data || null
  282. })
  283. },
  284. // 删除产品
  285. handleDel (row) {
  286. const _this = this
  287. this.$confirm({
  288. title: '提示',
  289. content: '确认要删除吗?',
  290. centered: true,
  291. closable: true,
  292. onOk () {
  293. _this.delLoading = true
  294. _this.spinning = true
  295. salesReturnDetailDel({ salesReturnDetailSn: row.salesReturnDetailSn }).then(res => {
  296. if (res.status == 200) {
  297. _this.resetTable(false)
  298. }
  299. _this.$message.info(res.message)
  300. _this.delLoading = false
  301. _this.spinning = false
  302. })
  303. }
  304. })
  305. },
  306. resetTable (flag) {
  307. this.$refs.table.refresh(flag)
  308. this.getOrderDetail()
  309. },
  310. // 重置
  311. resetSearchForm (flag) {
  312. this.productForm.productName = ''
  313. this.productForm.productCode = ''
  314. this.$refs.table.refresh(!!flag)
  315. this.getOrderDetail()
  316. },
  317. // 添加或修改产品
  318. saveProduct (row) {
  319. console.log(row)
  320. // 防止多次添加产品
  321. if (this.isInster) {
  322. return
  323. }
  324. if (!row.returnReason) {
  325. this.$message.info('请选择退货原因')
  326. return
  327. }
  328. this.isInster = true
  329. const params = {
  330. 'salesReturnBillSn': this.orderSn,
  331. 'salesReturnBillNo': this.ordeDetail.salesReturnBillNo,
  332. 'price': row.productPrice,
  333. 'cost': row.lastStockCost,
  334. 'returnReason': row.returnReason,
  335. 'productSn': row.productSn,
  336. 'qty': row.qty
  337. }
  338. this.spinning = true
  339. salesReturnDetailInsert(params).then(res => {
  340. if (res.status == 200) {
  341. this.resetSearchForm(true)
  342. this.$message.success(res.message)
  343. }
  344. this.isInster = false
  345. this.spinning = false
  346. })
  347. },
  348. beforeSubmit () {
  349. if (this.total) {
  350. this.openDepartUserModal = true
  351. } else {
  352. this.$message.info('请添加产品')
  353. }
  354. },
  355. // 提交销售退货
  356. handleSubmit (data) {
  357. this.spinning = true
  358. salesReturnSubmit({ salesReturnBillSn: this.orderSn, ...data }).then(res => {
  359. if (res.status == 200) {
  360. this.handleBack()
  361. this.$message.success(res.message)
  362. }
  363. this.spinning = false
  364. })
  365. },
  366. closeGuideModel () {
  367. this.openGuideModal = false
  368. },
  369. // 导入产品
  370. hanldeOk (obj) {
  371. salesReturnBatchInsert(obj).then(res => {
  372. if (res.status == 200) {
  373. this.resetTable(true)
  374. }
  375. })
  376. },
  377. // 打印预览/快捷打印
  378. handlePrint (type) {
  379. const _this = this
  380. const a = ['WAIT_CUSTOMER_SERVICE_CONFIRM', 'WAIT_FINANCIAL_AUDIT', 'FINANCIAL_REJECT', 'FINISH'].find(item => item == this.detailData.billStatus)
  381. const status = a ? 'SALES_RETURN_AMOUNT' : 'SALES_RETURN_REASON'
  382. const params = { sn: this.$route.params.sn, status: status }
  383. _this.spinning = true
  384. // 导出
  385. if (type == 'export') {
  386. exportExcel(salesReturnExport, params, '销售退货', function () {
  387. _this.spinning = false
  388. })
  389. } else {
  390. // 打印或预览
  391. printFun(salesReturnPrint, params, type, '销售退货', () => {
  392. _this.spinning = false
  393. })
  394. }
  395. },
  396. pageInit () {
  397. this.orderSn = this.$route.params.sn
  398. this.buyerSn = this.$route.params.buyerSn
  399. this.resetSearchForm(true)
  400. this.$refs.partQuery.pageInit(this.buyerSn, 0)
  401. this.returnReasonList = this.$store.state.app.returnReason
  402. }
  403. },
  404. mounted () {
  405. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  406. this.pageInit()
  407. }
  408. },
  409. activated () {
  410. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  411. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  412. this.pageInit()
  413. }
  414. },
  415. beforeRouteEnter (to, from, next) {
  416. next(vm => {})
  417. }
  418. }
  419. </script>
  420. <style lang="less">
  421. .salesReturnEdit-wrap{
  422. position: relative;
  423. height: 100%;
  424. padding-bottom: 51px;
  425. box-sizing: border-box;
  426. >.ant-spin-nested-loading{
  427. overflow-y: scroll;
  428. height: 100%;
  429. }
  430. .salesReturnEdit-cont{
  431. margin-top: 10px;
  432. .total-bar{
  433. display: flex;
  434. align-items: center;
  435. justify-content: space-between;
  436. > div{
  437. &:last-child{
  438. display: flex;
  439. align-items: center;
  440. justify-content: space-between;
  441. > div{
  442. padding: 0 10px;
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. </style>