grabEdit.vue 18 KB

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