edit.vue 20 KB

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