grapEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <div class="purchaseReturnEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="purchaseReturnEdit-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="purchaseReturnEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;" v-if="detailData">供应商名称:{{ detailData.returnTargetName || '--' }}</span>
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template slot="extra" v-if="$hasPermissions('B_purchaseReturnPrint')">
  12. <Print :disabled="dataSource.length==0" @handlePrint="handlePrint"></Print>
  13. </template>
  14. </a-page-header>
  15. <!-- 选择产品 -->
  16. <a-card size="small" :bordered="false" class="purchaseReturnEdit-cont">
  17. <div class="purchaseReturnEdit-cont">
  18. <a-collapse :activeKey="['1']">
  19. <a-collapse-panel key="1" header="选择产品">
  20. <!-- 筛选条件 -->
  21. <div class="table-page-search-wrapper">
  22. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  23. <a-row :gutter="15">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="采购单号" prop="purchaseBillNo">
  26. <a-input id="purchaseReturnEdit-purchaseBillNo" v-model.trim="queryParam.purchaseBillNo" placeholder="请输入采购单号" allowClear />
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-item label="产品编码" prop="productCode">
  31. <a-input id="purchaseReturnEdit-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  32. </a-form-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="产品名称" prop="productName">
  36. <a-input id="purchaseReturnEdit-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  37. </a-form-item>
  38. </a-col>
  39. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  40. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="purchaseReturnList-refresh">查询</a-button>
  41. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="purchaseReturnList-reset">重置</a-button>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. </div>
  46. <!-- 列表 -->
  47. <s-table
  48. class="sTable"
  49. ref="table"
  50. size="small"
  51. :rowKey="(record) => record.id"
  52. :columns="columns"
  53. :data="loadData"
  54. :defaultLoadData="false"
  55. :pageSize="10"
  56. :scroll="{ y: 149 }"
  57. bordered>
  58. <!-- 数量 -->
  59. <template slot="returnQty" slot-scope="text, record">
  60. <a-input-number
  61. size="small"
  62. id="purchaseReturnEdit-returnQty"
  63. v-model="record.returnQty"
  64. :precision="0"
  65. :min="1"
  66. :max="record.refundableQty"
  67. placeholder="请输入"
  68. style="width: 100%;" />
  69. </template>
  70. <!-- 单价 -->
  71. <template slot="returnPrice" slot-scope="text, record">
  72. <a-input-number
  73. size="small"
  74. id="purchaseReturnEdit-returnPrice"
  75. v-model="record.returnPrice"
  76. :precision="2"
  77. :min="0"
  78. :max="999999"
  79. placeholder="请输入"
  80. style="width: 100%;" />
  81. </template>
  82. <!-- 操作 -->
  83. <template slot="action" slot-scope="text, record">
  84. <span v-if="record.refundableQty==0">--</span>
  85. <a-button
  86. v-else
  87. size="small"
  88. type="link"
  89. class="button-primary"
  90. @click="handleAdd(record)"
  91. id="purchaseReturnEdit-add-btn">添加</a-button>
  92. </template>
  93. </s-table>
  94. </a-collapse-panel>
  95. </a-collapse>
  96. </div>
  97. </a-card>
  98. <!-- 已选产品 -->
  99. <a-card size="small" :bordered="false" class="purchaseReturnEdit-cont">
  100. <a-collapse :activeKey="['1']">
  101. <a-collapse-panel key="1">
  102. <template slot="header">
  103. 已选产品
  104. <!-- <a-button
  105. size="small"
  106. type="primary"
  107. class="button-error"
  108. id="purchaseReturnEdit-delAll-btn"
  109. @click.stop="handleDel('', 'all')"
  110. style="margin-right: 10px;float: right;">整单删除</a-button> -->
  111. </template>
  112. <!-- 总计 -->
  113. <a-alert type="info" style="margin-bottom:10px">
  114. <div slot="message">
  115. 总款数<strong>{{ (detailData&&(detailData.totalCategory || detailData.totalCategory==0)) ? detailData.totalCategory : '--' }}</strong> ,
  116. 总数量<strong>{{ (detailData&&(detailData.totalQty || detailData.totalQty==0)) ? detailData.totalQty : '--' }}</strong> ,
  117. 总金额<strong>{{ (detailData&&(detailData.totalAmount || detailData.totalAmount==0)) ? '¥'+detailData.totalAmount : '--' }}</strong>
  118. </div>
  119. </a-alert>
  120. <!-- 筛选条件 -->
  121. <a-row :gutter="15" justify="space-between">
  122. <a-col :span="17">
  123. <div class="table-page-search-wrapper">
  124. <a-form layout="inline" @keyup.enter.native="$refs.chooseTable.refresh(true)">
  125. <a-row :gutter="15">
  126. <a-col :md="9" :sm="24">
  127. <a-form-item label="产品编码" prop="productCode">
  128. <a-input id="bulkReturnGoodsEdit-productCode" v-model.trim="chooseQueryParam.productCode" placeholder="请输入产品编码" allowClear />
  129. </a-form-item>
  130. </a-col>
  131. <a-col :md="9" :sm="24">
  132. <a-form-item label="产品名称" prop="productName">
  133. <a-input id="bulkReturnGoodsEdit-productName" v-model.trim="chooseQueryParam.productName" placeholder="请输入产品名称" allowClear />
  134. </a-form-item>
  135. </a-col>
  136. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  137. <a-button type="primary" @click="$refs.chooseTable.refresh(true)" :disabled="chooseDisabled" id="bulkReturnGoodsEdit-refresh">查询</a-button>
  138. <a-button style="margin-left: 8px" @click="chooseResetSearchForm" :disabled="chooseDisabled" id="bulkReturnGoodsEdit-reset">重置</a-button>
  139. </a-col>
  140. </a-row>
  141. </a-form>
  142. </div>
  143. </a-col>
  144. <a-col :span="7" style="text-align: right;"></a-col>
  145. </a-row>
  146. <!-- 列表 -->
  147. <s-table
  148. class="sTable"
  149. ref="chooseTable"
  150. size="small"
  151. :rowKey="(record) => record.id"
  152. :columns="chooseColumns"
  153. :data="chooseLoadData"
  154. :defaultLoadData="false"
  155. :pageSize="10"
  156. :scroll="{ y: 149 }"
  157. bordered>
  158. <!-- 退货数量 -->
  159. <template slot="qty" slot-scope="text, record">
  160. <a-input-number
  161. size="small"
  162. id="purchaseReturnEdit-qty"
  163. v-model="record.qty"
  164. :precision="0"
  165. :min="1"
  166. :max="record.refundableQty"
  167. placeholder="请输入"
  168. @blur="e => qtyBlur(e.target.value, record)"
  169. style="width: 100%;" />
  170. </template>
  171. <!-- 退货单价 -->
  172. <template slot="price" slot-scope="text, record">
  173. <a-input-number
  174. size="small"
  175. id="purchaseReturnEdit-cost"
  176. v-model="record.cost"
  177. :precision="2"
  178. :min="0"
  179. :max="999999"
  180. placeholder="请输入"
  181. @blur="e => costBlur(e.target.value, record)"
  182. style="width: 100%;" />
  183. </template>
  184. <!-- 退货金额合计 amount-->
  185. <template slot="amount" slot-scope="text, record">
  186. {{ (record.cost * record.qty).toFixed(2) }}
  187. </template>
  188. <!-- 操作 -->
  189. <template slot="action" slot-scope="text, record">
  190. <a-button size="small" type="link" class="button-error" @click="handleDel(record)" id="purchaseReturnEdit-del-btn">删除</a-button>
  191. </template>
  192. </s-table>
  193. </a-collapse-panel>
  194. </a-collapse>
  195. </a-card>
  196. </a-spin>
  197. <a-card size="small" :bordered="false" class="affix-cont">
  198. <a-button
  199. type="primary"
  200. id="purchaseReturnEdit-submit"
  201. size="large"
  202. :disabled="spinning"
  203. class="button-primary"
  204. @click="handleSubmit"
  205. style="padding: 0 60px;">提交</a-button>
  206. </a-card>
  207. </div>
  208. </template>
  209. <script>
  210. import { commonMixin } from '@/utils/mixin'
  211. import { STable, VSelect } from '@/components'
  212. import Print from '@/views/common/print.vue'
  213. import { hdPrint } from '@/libs/JGPrint'
  214. import {
  215. purchaseReturnPurchaseBillNoSyncList,
  216. purchaseReturnDetailList,
  217. purchaseReturnDetailSave,
  218. purchaseReturnDetailDel,
  219. purchaseReturnSubmit,
  220. purchaseReturnDelAll,
  221. purchaseReturnDetailPrint,
  222. purchaseReturnDetailExport,
  223. purchaseReturnDetailSn } from '@/api/purchaseReturn'
  224. export default {
  225. name: 'PurchaseReturnEdit',
  226. components: { STable, VSelect, Print },
  227. mixins: [commonMixin],
  228. data () {
  229. return {
  230. spinning: false,
  231. detailData: null,
  232. queryParam: {
  233. purchaseBillNo: '',
  234. productCode: '',
  235. productName: ''
  236. },
  237. dataSource: [],
  238. disabled: false, // 查询、重置按钮是否可操作
  239. advanced: false, // 高级搜索 展开/关闭
  240. // 表头
  241. columns: [
  242. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  243. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  244. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  245. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  246. { title: '采购价格', dataIndex: 'price', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  247. { title: '采购数量', dataIndex: 'qty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  248. // { title: '已退数量', dataIndex: 'refundableQty', width: '9%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  249. { title: '可退数量', dataIndex: 'refundableQty', width: '7%', align: 'center' },
  250. { title: '库存数量', dataIndex: 'stock.currentStockQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  251. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  252. { title: '退货单价', scopedSlots: { customRender: 'returnPrice' }, width: '8%', align: 'center' },
  253. { title: '退货数量', scopedSlots: { customRender: 'returnQty' }, width: '8%', align: 'center' },
  254. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  255. ],
  256. // 加载数据方法 必须为 Promise 对象
  257. loadData: parameter => {
  258. this.disabled = true
  259. this.queryParam.returnTargetType = this.detailData.returnTargetType
  260. return purchaseReturnPurchaseBillNoSyncList(Object.assign(parameter, this.queryParam)).then(res => {
  261. const data = res.data
  262. const no = (data.pageNo - 1) * data.pageSize
  263. for (var i = 0; i < data.list.length; i++) {
  264. data.list[i].no = no + i + 1
  265. }
  266. this.disabled = false
  267. return data
  268. })
  269. },
  270. chooseDisabled: false,
  271. chooseQueryParam: {
  272. productCode: '',
  273. productName: ''
  274. },
  275. // 表头
  276. chooseColumns: [
  277. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  278. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  279. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  280. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  281. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  282. { title: '退货单价', scopedSlots: { customRender: 'price' }, width: '10%', align: 'center' },
  283. { title: '退货数量', scopedSlots: { customRender: 'qty' }, width: '10%', align: 'center' },
  284. { title: '退货金额', scopedSlots: { customRender: 'amount' }, width: '6%', align: 'center' },
  285. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  286. ],
  287. // 加载数据方法 必须为 Promise 对象
  288. chooseLoadData: parameter => {
  289. return purchaseReturnDetailList(Object.assign(parameter, this.chooseQueryParam, { purchaseReturnSn: this.$route.params.sn, orderBy: 'qpls_purchase_return_bill_detail.CREATE_DATE desc' })).then(res => {
  290. const data = res.data
  291. const no = (data.pageNo - 1) * data.pageSize
  292. for (var i = 0; i < data.list.length; i++) {
  293. data.list[i].no = no + i + 1
  294. data.list[i].qtyBackups = data.list[i].qty
  295. data.list[i].costBackups = data.list[i].cost
  296. data.list[i].refundableQty = data.list[i].purchaseBillRefundableQty
  297. }
  298. this.dataSource = data.list
  299. return data
  300. })
  301. }
  302. }
  303. },
  304. methods: {
  305. // 打印预览/快捷打印
  306. handlePrint (type, printerType) {
  307. const _this = this
  308. _this.spinning = true
  309. let url = purchaseReturnDetailPrint
  310. const params = { sn: this.$route.params.sn }
  311. if (type == 'export') { // 导出
  312. url = purchaseReturnDetailExport
  313. }
  314. // 打印或导出
  315. hdPrint(printerType, type, url, params, '采购退货单', function () {
  316. _this.spinning = false
  317. })
  318. },
  319. // 重置
  320. resetSearchForm () {
  321. this.queryParam.purchaseBillNo = ''
  322. this.queryParam.productCode = ''
  323. this.queryParam.productName = ''
  324. this.$refs.table.refresh(true)
  325. },
  326. // 已选产品 重置
  327. chooseResetSearchForm () {
  328. this.chooseQueryParam.productCode = ''
  329. this.chooseQueryParam.productName = ''
  330. this.$refs.chooseTable.refresh(true)
  331. },
  332. // 添加/编辑
  333. handleAdd (row, isEdit) {
  334. // 添加时退货数量字段名为returnQty,编辑时退货数量字段名为qty
  335. if (!isEdit && !row.returnPrice) {
  336. this.$message.warning('请输入退货价格')
  337. return
  338. }
  339. if (!isEdit && !row.returnQty) {
  340. this.$message.warning('请输入退货数量')
  341. return
  342. }
  343. const params = {
  344. id: isEdit ? row.id : undefined,
  345. purchaseReturnSn: this.$route.params.sn,
  346. purchaseBillSn: row.purchaseBillSn,
  347. purchaseBillNo: row.purchaseBillNo,
  348. purchaseBillDetailSn: row.purchaseBillDetailSn,
  349. qty: isEdit ? row.qty : row.returnQty, // 退货数量
  350. productSn: row.productSn,
  351. cost: isEdit ? row.cost : row.returnPrice,
  352. remarks: row.remarks,
  353. promotionFlag: row.promotionFlag
  354. }
  355. if (isEdit) { // 编辑
  356. // 清空退货数量时,值应保持未清空前的值,因退货数量都不可为空
  357. if (!row.qty) {
  358. row.qty = row.qtyBackups
  359. return
  360. }
  361. if (!row.cost) {
  362. row.cost = row.costBackups
  363. return
  364. }
  365. }
  366. this.spinning = true
  367. purchaseReturnDetailSave(params).then(res => {
  368. if (res.status == 200) {
  369. this.$message.success(res.message)
  370. // this.$refs.table.refresh()
  371. this.$refs.chooseTable.refresh()
  372. this.spinning = false
  373. } else {
  374. this.spinning = false
  375. }
  376. })
  377. },
  378. // 双击快速添加
  379. handleClickRow (record) {
  380. return {
  381. on: {
  382. dblclick: (event) => {
  383. this.handleAdd(record)
  384. }
  385. }
  386. }
  387. },
  388. // 导入明细
  389. handleImport () {},
  390. // 删除
  391. handleDel (row, isAll) {
  392. const _this = this
  393. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  394. this.$confirm({
  395. title: '提示',
  396. content: content,
  397. centered: true,
  398. onOk () {
  399. if (isAll) { // 整单删除
  400. _this.spinning = true
  401. purchaseReturnDelAll({ purchaseReturnSn: _this.$route.params.sn }).then(res => {
  402. if (res.status == 200) {
  403. _this.$message.success(res.message)
  404. // _this.$refs.table.refresh()
  405. _this.$refs.chooseTable.refresh()
  406. _this.spinning = false
  407. } else {
  408. _this.spinning = false
  409. }
  410. })
  411. } else { // 单个删除
  412. _this.spinning = true
  413. purchaseReturnDetailDel({ id: row.id }).then(res => {
  414. if (res.status == 200) {
  415. _this.$message.success(res.message)
  416. // _this.$refs.table.refresh()
  417. _this.$refs.chooseTable.refresh()
  418. _this.spinning = false
  419. } else {
  420. _this.spinning = false
  421. }
  422. })
  423. }
  424. }
  425. })
  426. },
  427. // 提交
  428. handleSubmit () {
  429. const _this = this
  430. _this.spinning = true
  431. purchaseReturnSubmit({ id: _this.detailData.id }).then(res => {
  432. if (res.status == 200) {
  433. this.$message.success(res.message)
  434. setTimeout(() => {
  435. _this.handleBack()
  436. _this.spinning = false
  437. }, 1000)
  438. } else {
  439. _this.spinning = false
  440. }
  441. })
  442. },
  443. // 返回列表
  444. handleBack () {
  445. this.$router.push({ name: 'purchaseReturnOutSyncList' })
  446. },
  447. // 已选产品 退货数量 blur
  448. qtyBlur (val, record) {
  449. // 光标移出,值发生改变再调用编辑接口
  450. if (val != record.qtyBackups) {
  451. this.handleAdd(record, 'edit')
  452. }
  453. },
  454. // 已选产品 退货单价 blur
  455. costBlur (val, record) {
  456. if (val && (val != record.costBackups)) {
  457. this.handleAdd(record, 'edit')
  458. }
  459. },
  460. // 获取详情
  461. getDetail () {
  462. purchaseReturnDetailSn({ sn: this.$route.params.sn }).then(res => {
  463. this.detailData = res.data || null
  464. this.resetSearchForm()
  465. })
  466. }
  467. },
  468. mounted () {
  469. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  470. this.$refs.chooseTable.refresh(true)
  471. this.getDetail()
  472. }
  473. },
  474. activated () {
  475. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  476. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  477. this.$refs.chooseTable.refresh(true)
  478. this.getDetail()
  479. }
  480. },
  481. beforeRouteEnter (to, from, next) {
  482. next(vm => {})
  483. }
  484. }
  485. </script>
  486. <style lang="less">
  487. .purchaseReturnEdit-wrap{
  488. position: relative;
  489. height: 100%;
  490. padding-bottom: 51px;
  491. box-sizing: border-box;
  492. >.ant-spin-nested-loading{
  493. overflow-y: scroll;
  494. height: 100%;
  495. }
  496. .purchaseReturnEdit-back, .purchaseReturnEdit-cont{
  497. margin-bottom: 10px;
  498. }
  499. }
  500. </style>