grapEdit.vue 21 KB

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