edit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. :max="record.refundableQty"
  175. placeholder="请输入"
  176. @blur="e => qtyBlur(e.target.value, record)"
  177. style="width: 100%;" />
  178. </template>
  179. <!-- 退货单价 -->
  180. <template slot="price" slot-scope="text, record">
  181. <a-input-number
  182. size="small"
  183. id="purchaseReturnEdit-cost"
  184. v-model="record.cost"
  185. :precision="2"
  186. :min="0"
  187. :max="999999"
  188. placeholder="请输入"
  189. @blur="e => costBlur(e.target.value, record)"
  190. style="width: 100%;" />
  191. </template>
  192. <!-- 退货金额合计 amount-->
  193. <template slot="amount" slot-scope="text, record">
  194. {{ (record.cost * record.qty).toFixed(2) }}
  195. </template>
  196. <!-- 操作 -->
  197. <template slot="action" slot-scope="text, record">
  198. <a-button size="small" type="link" class="button-error" @click="handleDel(record)" id="purchaseReturnEdit-del-btn">删除</a-button>
  199. </template>
  200. </s-table>
  201. </a-collapse-panel>
  202. </a-collapse>
  203. </a-card>
  204. </a-spin>
  205. <a-card size="small" :bordered="false" class="affix-cont">
  206. <a-button
  207. type="primary"
  208. id="purchaseReturnEdit-submit"
  209. size="large"
  210. :disabled="spinning"
  211. class="button-primary"
  212. @click="handleSubmit"
  213. style="padding: 0 60px;">提交</a-button>
  214. </a-card>
  215. </div>
  216. </template>
  217. <script>
  218. import { commonMixin } from '@/utils/mixin'
  219. import { STable, VSelect } from '@/components'
  220. import Print from '@/views/common/print.vue'
  221. import { hdPrint } from '@/libs/JGPrint'
  222. import { stockDetailProductList } from '@/api/sparePartsRet'
  223. import { warehouseAllList } from '@/api/warehouse'
  224. import {
  225. purchaseReturnDetailList,
  226. purchaseReturnDetailSave,
  227. purchaseReturnDetailDel,
  228. purchaseReturnSubmit,
  229. purchaseReturnDelAll,
  230. purchaseReturnDetailPrint,
  231. purchaseReturnDetailExport,
  232. purchaseReturnDetailSn } from '@/api/purchaseReturn'
  233. export default {
  234. name: 'PurchaseReturnEdit',
  235. components: { STable, VSelect, Print },
  236. mixins: [commonMixin],
  237. data () {
  238. return {
  239. spinning: false,
  240. detailData: null,
  241. queryParam: {
  242. purchaseBillNo: '',
  243. productCode: '',
  244. productName: ''
  245. },
  246. dataSource: [],
  247. disabled: false, // 查询、重置按钮是否可操作
  248. advanced: false, // 高级搜索 展开/关闭
  249. // 表头
  250. columns: [
  251. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  252. { title: '产品编码', dataIndex: 'productCode', width: '19%', align: 'center', customRender: function (text) { return text || '--' } },
  253. { title: '产品名称', dataIndex: 'productName', width: '19%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  254. { title: '仓库', dataIndex: 'warehouseName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  255. { title: '仓位', dataIndex: 'warehouseLocationName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  256. { title: '库存数量', dataIndex: 'currentQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  257. { title: '单位', dataIndex: 'unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  258. { title: '退货单价', scopedSlots: { customRender: 'returnPrice' }, width: '8%', align: 'center' },
  259. { title: '退货数量', scopedSlots: { customRender: 'returnQty' }, width: '8%', align: 'center' },
  260. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  261. ],
  262. // 加载数据方法 必须为 Promise 对象
  263. loadData: parameter => {
  264. this.disabled = true
  265. return stockDetailProductList(Object.assign(parameter, this.queryParam)).then(res => {
  266. const data = res.data
  267. const no = (data.pageNo - 1) * data.pageSize
  268. for (var i = 0; i < data.list.length; i++) {
  269. data.list[i].no = no + i + 1
  270. }
  271. this.dataSource = data.list
  272. this.disabled = false
  273. return data
  274. })
  275. },
  276. // 表头
  277. chooseColumns: [
  278. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  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: 'warehouseName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  282. { title: '仓位', dataIndex: 'warehouseLocationName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  283. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  284. { title: '退货单价', scopedSlots: { customRender: 'price' }, width: '10%', align: 'center' },
  285. { title: '退货数量', scopedSlots: { customRender: 'qty' }, width: '10%', align: 'center' },
  286. { title: '退货金额', scopedSlots: { customRender: 'amount' }, width: '6%', align: 'center' },
  287. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  288. ],
  289. chooseDisabled: false,
  290. chooseQueryParam: {
  291. productCode: '',
  292. productName: ''
  293. },
  294. // 加载数据方法 必须为 Promise 对象
  295. chooseLoadData: parameter => {
  296. return purchaseReturnDetailList(Object.assign(parameter,
  297. this.chooseQueryParam,
  298. {
  299. purchaseReturnSn: this.$route.params.sn,
  300. orderBy: 'qpls_purchase_return_bill_detail.CREATE_DATE desc'
  301. })).then(res => {
  302. const data = res.data
  303. const no = (data.pageNo - 1) * data.pageSize
  304. for (var i = 0; i < data.list.length; i++) {
  305. data.list[i].no = no + i + 1
  306. data.list[i].qtyBackups = data.list[i].qty
  307. data.list[i].costBackups = data.list[i].cost
  308. data.list[i].refundableQty = data.list[i].purchaseBillRefundableQty
  309. }
  310. this.dataSource = data.list
  311. return data
  312. })
  313. },
  314. warehouseList: [] // 仓库列表
  315. }
  316. },
  317. methods: {
  318. // 打印预览/快捷打印
  319. handlePrint (type, printerType) {
  320. const _this = this
  321. _this.spinning = true
  322. let url = purchaseReturnDetailPrint
  323. const params = { sn: this.$route.params.sn }
  324. if (type == 'export') { // 导出
  325. url = purchaseReturnDetailExport
  326. }
  327. // 打印或导出
  328. hdPrint(printerType, type, url, params, '采购退货单', function () {
  329. _this.spinning = false
  330. })
  331. },
  332. resetSearchForm () {
  333. this.queryParam.productCode = ''
  334. this.queryParam.productName = ''
  335. this.queryParam.warehouseSn = undefined
  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. purchaseReturnDetailSn: row.purchaseReturnDetailSn,
  359. qty: isEdit ? row.qty : row.returnQty, // 退货数量
  360. productSn: row.productSn,
  361. productCode: row.productCode,
  362. productOrigCode: row.productOrigCode,
  363. productTypeSn1: row.productTypeSn1,
  364. productTypeSn2: row.productTypeSn2,
  365. productTypeSn3: row.productTypeSn3,
  366. brandSn: row.brandSn,
  367. warehouseLocationSn: row.warehouseLocationSn,
  368. warehouseSn: row.warehouseSn,
  369. productExpiryDate: row.productExpiryDate,
  370. cost: isEdit ? row.cost : row.returnPrice,
  371. remarks: row.remarks,
  372. promotionFlag: row.promotionFlag
  373. }
  374. if (isEdit) { // 编辑
  375. // 清空退货数量时,值应保持未清空前的值,因退货数量都不可为空
  376. if (!row.qty) {
  377. row.qty = row.qtyBackups
  378. return
  379. }
  380. if (!row.cost) {
  381. row.cost = row.costBackups
  382. return
  383. }
  384. }
  385. this.spinning = true
  386. purchaseReturnDetailSave(params).then(res => {
  387. if (res.status == 200) {
  388. this.$message.success(res.message)
  389. this.getDetail(true, true)
  390. this.$refs.chooseTable.refresh()
  391. this.spinning = false
  392. } else {
  393. this.spinning = false
  394. }
  395. })
  396. },
  397. // 双击快速添加
  398. handleClickRow (record) {
  399. return {
  400. on: {
  401. dblclick: (event) => {
  402. this.handleAdd(record)
  403. }
  404. }
  405. }
  406. },
  407. // 导入明细
  408. handleImport () {},
  409. // 删除
  410. handleDel (row, isAll) {
  411. const _this = this
  412. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  413. this.$confirm({
  414. title: '提示',
  415. content: content,
  416. centered: true,
  417. onOk () {
  418. if (isAll) { // 整单删除
  419. _this.spinning = true
  420. purchaseReturnDelAll({ purchaseReturnSn: _this.$route.params.sn }).then(res => {
  421. if (res.status == 200) {
  422. _this.$message.success(res.message)
  423. _this.getDetail(true, true)
  424. _this.$refs.chooseTable.refresh()
  425. _this.spinning = false
  426. } else {
  427. _this.spinning = false
  428. }
  429. })
  430. } else { // 单个删除
  431. _this.spinning = true
  432. purchaseReturnDetailDel({ id: row.id }).then(res => {
  433. if (res.status == 200) {
  434. _this.$message.success(res.message)
  435. _this.getDetail(true, true)
  436. _this.$refs.chooseTable.refresh()
  437. _this.spinning = false
  438. } else {
  439. _this.spinning = false
  440. }
  441. })
  442. }
  443. }
  444. })
  445. },
  446. // 提交
  447. handleSubmit () {
  448. const _this = this
  449. _this.spinning = true
  450. purchaseReturnSubmit({ id: this.detailData.id }).then(res => {
  451. if (res.status == 200) {
  452. this.$message.success(res.message)
  453. setTimeout(() => {
  454. _this.handleBack()
  455. _this.spinning = false
  456. }, 1000)
  457. } else {
  458. _this.spinning = false
  459. }
  460. })
  461. },
  462. // 返回列表
  463. handleBack () {
  464. this.$router.push({ name: 'purchaseReturnOutSyncList' })
  465. },
  466. // 已选产品 退货数量 blur
  467. qtyBlur (val, record) {
  468. // 光标移出,值发生改变再调用编辑接口
  469. if (val != record.qtyBackups) {
  470. this.handleAdd(record, 'edit')
  471. }
  472. },
  473. // 已选产品 退货单价 blur
  474. costBlur (val, record) {
  475. if (val && (val != record.costBackups)) {
  476. this.handleAdd(record, 'edit')
  477. }
  478. },
  479. // 仓库
  480. getWarehouse () {
  481. warehouseAllList({}).then(res => {
  482. if (res.status == 200) {
  483. this.warehouseList = res.data
  484. } else {
  485. this.warehouseList = []
  486. }
  487. })
  488. },
  489. filterOption (input, option) {
  490. return (
  491. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  492. )
  493. },
  494. // 获取详情
  495. getDetail (type, refresh) {
  496. purchaseReturnDetailSn({ sn: this.$route.params.sn }).then(res => {
  497. this.detailData = res.data || null
  498. if (!type) {
  499. this.resetSearchForm()
  500. } else {
  501. if (!refresh) {
  502. this.$refs.table.refresh(true)
  503. }
  504. }
  505. })
  506. },
  507. pageInit () {
  508. this.getWarehouse()
  509. this.getDetail(true, true)
  510. this.$refs.chooseTable.refresh(true)
  511. }
  512. },
  513. mounted () {
  514. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  515. this.pageInit()
  516. }
  517. },
  518. activated () {
  519. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  520. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  521. this.pageInit()
  522. }
  523. },
  524. beforeRouteEnter (to, from, next) {
  525. next(vm => {})
  526. }
  527. }
  528. </script>
  529. <style lang="less">
  530. .purchaseReturnEdit-wrap{
  531. position: relative;
  532. height: 100%;
  533. padding-bottom: 51px;
  534. box-sizing: border-box;
  535. >.ant-spin-nested-loading{
  536. overflow-y: scroll;
  537. height: 100%;
  538. }
  539. .purchaseReturnEdit-back, .purchaseReturnEdit-cont{
  540. margin-bottom: 10px;
  541. }
  542. }
  543. </style>