edit.vue 22 KB

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