edit.vue 19 KB

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