edit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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)) ? toThousands(detailData.totalAmount,2) : '--' }}</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. {{ toThousands(record.cost * record.qty,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. 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. 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, !isEdit)
  390. this.$refs.chooseTable.refresh()
  391. this.spinning = false
  392. } else {
  393. this.spinning = false
  394. row.qty = row.qtyBackups
  395. }
  396. })
  397. },
  398. // 双击快速添加
  399. handleClickRow (record) {
  400. return {
  401. on: {
  402. dblclick: (event) => {
  403. event.stopPropagation()
  404. this.handleAdd(record)
  405. }
  406. }
  407. }
  408. },
  409. // 导入明细
  410. handleImport () {},
  411. // 删除
  412. handleDel (row, isAll) {
  413. const _this = this
  414. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  415. this.$confirm({
  416. title: '提示',
  417. content: content,
  418. centered: true,
  419. onOk () {
  420. if (isAll) { // 整单删除
  421. _this.spinning = true
  422. purchaseReturnDelAll({ purchaseReturnSn: _this.$route.params.sn }).then(res => {
  423. if (res.status == 200) {
  424. _this.$message.success(res.message)
  425. _this.getDetail(true, false)
  426. _this.$refs.chooseTable.refresh()
  427. _this.spinning = false
  428. } else {
  429. _this.spinning = false
  430. }
  431. })
  432. } else { // 单个删除
  433. _this.spinning = true
  434. purchaseReturnDetailDel({ id: row.id }).then(res => {
  435. if (res.status == 200) {
  436. _this.$message.success(res.message)
  437. _this.getDetail(true, false)
  438. _this.$refs.chooseTable.refresh()
  439. _this.spinning = false
  440. } else {
  441. _this.spinning = false
  442. }
  443. })
  444. }
  445. }
  446. })
  447. },
  448. // 提交
  449. handleSubmit () {
  450. const _this = this
  451. _this.spinning = true
  452. purchaseReturnSubmit({ id: this.detailData.id }).then(res => {
  453. if (res.status == 200) {
  454. this.$message.success(res.message)
  455. setTimeout(() => {
  456. _this.handleBack()
  457. _this.spinning = false
  458. }, 1000)
  459. } else {
  460. _this.spinning = false
  461. }
  462. })
  463. },
  464. // 返回列表
  465. handleBack () {
  466. this.$router.push({ name: 'purchaseReturnOutSyncList' })
  467. },
  468. // 已选产品 退货数量 blur
  469. qtyBlur (val, record) {
  470. // 光标移出,值发生改变再调用编辑接口
  471. if (val != record.qtyBackups) {
  472. this.handleAdd(record, 'edit')
  473. }
  474. },
  475. // 已选产品 退货单价 blur
  476. costBlur (val, record) {
  477. if (val && (val != record.costBackups)) {
  478. this.handleAdd(record, 'edit')
  479. }
  480. },
  481. // 仓库
  482. getWarehouse () {
  483. warehouseAllList({}).then(res => {
  484. if (res.status == 200) {
  485. this.warehouseList = res.data
  486. } else {
  487. this.warehouseList = []
  488. }
  489. })
  490. },
  491. filterOption (input, option) {
  492. return (
  493. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  494. )
  495. },
  496. // 获取详情
  497. getDetail (type, refresh) {
  498. purchaseReturnDetailSn({ sn: this.$route.params.sn }).then(res => {
  499. this.detailData = res.data || null
  500. if (!type) {
  501. this.resetSearchForm()
  502. } else {
  503. if (!refresh) {
  504. this.$refs.table.refresh(true)
  505. }
  506. }
  507. })
  508. },
  509. pageInit () {
  510. this.getWarehouse()
  511. this.getDetail(true, true)
  512. this.$refs.chooseTable.refresh(true)
  513. }
  514. },
  515. mounted () {
  516. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  517. this.pageInit()
  518. }
  519. },
  520. activated () {
  521. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  522. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  523. this.pageInit()
  524. }
  525. },
  526. beforeRouteEnter (to, from, next) {
  527. next(vm => {})
  528. }
  529. }
  530. </script>
  531. <style lang="less">
  532. .purchaseReturnEdit-wrap{
  533. position: relative;
  534. height: 100%;
  535. padding-bottom: 51px;
  536. box-sizing: border-box;
  537. >.ant-spin-nested-loading{
  538. overflow-y: auto;
  539. height: 100%;
  540. }
  541. .purchaseReturnEdit-back, .purchaseReturnEdit-cont{
  542. margin-bottom: 10px;
  543. }
  544. }
  545. </style>