grabEdit.vue 21 KB

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