grapEdit.vue 21 KB

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