edit.vue 22 KB

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