grabEdit.vue 19 KB

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