grapEdit.vue 21 KB

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