storage_codes.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. import { required } from '@/components/template/rules_verify.js'
  2. import {
  3. goodsPurchaseItemAddCode,
  4. goodsPurchaseCodeList,
  5. goodsPurchaseItemDelCode
  6. } from '@/api/goodsPurchasedStored.js'
  7. export default {
  8. data() {
  9. return {}
  10. },
  11. computed: {
  12. storage_codes() {
  13. return [
  14. {
  15. columnAttributes: {
  16. label: '品牌',
  17. prop: 'brandId',
  18. propName: 'brandName',
  19. width: 160
  20. },
  21. render: (h, { row, column, index }) => {
  22. return this.isEditIndex == index ? (
  23. <div class="redbordererr">
  24. <el-form-item
  25. label=""
  26. lebel-width="0px"
  27. prop={`items.${index}.${column.columnAttributes.prop}`}
  28. rules={required}
  29. >
  30. <el-select
  31. value={row[column.columnAttributes.prop]}
  32. onInput={val => {
  33. row[column.columnAttributes.prop] = val
  34. }}
  35. onChange={val => {
  36. this.shanchuCodejichu(row, 0)
  37. if (val) {
  38. row[column.columnAttributes.propName] = this.arrQC(this.formData.items, {
  39. value: 'brandId',
  40. label: 'brandName'
  41. }).find(item => item.value == val).label
  42. } else {
  43. row[column.columnAttributes.propName] = ''
  44. }
  45. }}
  46. placeholder="请选择"
  47. >
  48. {this.arrQC(this.formData.items, { value: 'brandId', label: 'brandName' }).map((item, index_) => (
  49. <el-option key={index_} label={item.label} value={item.value}></el-option>
  50. ))}
  51. </el-select>
  52. </el-form-item>
  53. </div>
  54. ) : (
  55. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  56. )
  57. }
  58. },
  59. {
  60. columnAttributes: {
  61. label: '商品大类',
  62. prop: 'mainId',
  63. propName: 'mainName',
  64. width: 160
  65. },
  66. render: (h, { row, column, index }) => {
  67. return this.isEditIndex == index ? (
  68. <div class="redbordererr">
  69. <el-form-item
  70. label=""
  71. lebel-width="0px"
  72. prop={`items.${index}.${column.columnAttributes.prop}`}
  73. rules={required}
  74. >
  75. <el-select
  76. value={row[column.columnAttributes.prop]}
  77. onInput={val => {
  78. row[column.columnAttributes.prop] = val
  79. }}
  80. onChange={val => {
  81. this.shanchuCodejichu(row, 1)
  82. if (val) {
  83. row[column.columnAttributes.propName] = this.arrQC(
  84. this.formData.items.filter(item => item.brandId === row.brandId),
  85. { value: 'mainId', label: 'mainName' }
  86. ).find(item => item.value == val).label
  87. } else {
  88. row[column.columnAttributes.propName] = ''
  89. }
  90. }}
  91. placeholder="请选择"
  92. >
  93. {this.arrQC(
  94. this.formData.items.filter(item => item.brandId === row.brandId),
  95. { value: 'mainId', label: 'mainName' }
  96. ).map((item, index_) => (
  97. <el-option key={index_} label={item.label} value={item.value}></el-option>
  98. ))}
  99. </el-select>
  100. </el-form-item>
  101. </div>
  102. ) : (
  103. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  104. )
  105. }
  106. },
  107. {
  108. columnAttributes: {
  109. label: '商品小类',
  110. prop: 'smallId',
  111. propName: 'smallName',
  112. width: 160
  113. },
  114. render: (h, { row, column, index }) => {
  115. return this.isEditIndex == index ? (
  116. <div class="redbordererr">
  117. <el-form-item
  118. label=""
  119. lebel-width="0px"
  120. prop={`items.${index}.${column.columnAttributes.prop}`}
  121. rules={required}
  122. >
  123. <el-select
  124. value={row[column.columnAttributes.prop]}
  125. onInput={val => {
  126. row[column.columnAttributes.prop] = val
  127. }}
  128. onChange={val => {
  129. this.shanchuCodejichu(row, 2)
  130. if (val) {
  131. row[column.columnAttributes.propName] = this.arrQC(
  132. this.formData.items.filter(
  133. item => item.brandId === row.brandId && item.mainId === row.mainId
  134. ),
  135. { value: 'smallId', label: 'smallName' }
  136. ).find(item => item.value == val).label
  137. } else {
  138. row[column.columnAttributes.propName] = ''
  139. }
  140. }}
  141. placeholder="请选择"
  142. >
  143. {this.arrQC(
  144. this.formData.items.filter(item => item.brandId === row.brandId && item.mainId === row.mainId),
  145. { value: 'smallId', label: 'smallName' }
  146. ).map((item, index_) => (
  147. <el-option key={index_} label={item.label} value={item.value}></el-option>
  148. ))}
  149. </el-select>
  150. </el-form-item>
  151. </div>
  152. ) : (
  153. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  154. )
  155. }
  156. },
  157. {
  158. columnAttributes: {
  159. label: '商品名称',
  160. prop: 'goodsMaterialId',
  161. propName: 'goodsMaterialName',
  162. width: 160
  163. },
  164. render: (h, { row, column, index }) => {
  165. return this.isEditIndex == index ? (
  166. <div class="redbordererr">
  167. <el-form-item
  168. label=""
  169. lebel-width="0px"
  170. prop={`items.${index}.${column.columnAttributes.prop}`}
  171. rules={required}
  172. >
  173. <el-select
  174. value={row[column.columnAttributes.prop]}
  175. onInput={val => {
  176. row[column.columnAttributes.prop] = val
  177. }}
  178. onChange={val => {
  179. this.shanchuCodejichu(row, 3)
  180. if (val) {
  181. var data = this.arrQC(
  182. this.formData.items.filter(
  183. item =>
  184. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  185. ),
  186. { value: 'goodsMaterialId', label: 'goodsMaterialName' }
  187. ).find(item => item.value == val)
  188. this.getGoodsDetl(data?.data, res => {}, 'goodsMaterialId')
  189. row[column.columnAttributes.propName] = data.label
  190. row['specsName'] = data?.data?.specsName
  191. row['goodsPurchaseItemId'] = data?.data?.id
  192. } else {
  193. row[column.columnAttributes.propName] = ''
  194. row['specsName'] = ''
  195. row['goodsPurchaseItemId'] = ''
  196. }
  197. }}
  198. placeholder="请选择"
  199. >
  200. {this.arrQC(
  201. this.formData.items.filter(
  202. item =>
  203. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  204. ),
  205. { value: 'goodsMaterialId', label: 'goodsMaterialName' }
  206. ).map((item, index_) => (
  207. <el-option key={index_} label={item.label} value={item.value}></el-option>
  208. ))}
  209. </el-select>
  210. </el-form-item>
  211. </div>
  212. ) : (
  213. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  214. )
  215. }
  216. },
  217. {
  218. columnAttributes: {
  219. label: '规格型号',
  220. prop: 'specsName',
  221. width: 120
  222. }
  223. },
  224. {
  225. columnAttributes: {
  226. label: '物料类型',
  227. prop: 'goodsMaterialItemType',
  228. width: 160
  229. },
  230. render: (h, { row, column, index }) => {
  231. return this.isEditIndex == index ? (
  232. <div class="redbordererr">
  233. <el-form-item
  234. label=""
  235. lebel-width="0px"
  236. prop={`codeInfoList.${index}.${column.columnAttributes.prop}`}
  237. rules={required}
  238. >
  239. <el-select
  240. value={row[column.columnAttributes.prop]}
  241. onInput={val => {
  242. row[column.columnAttributes.prop] = val
  243. }}
  244. onChange={val => {
  245. this.shanchuCodejichu(row, 4)
  246. }}
  247. placeholder="请选择"
  248. >
  249. {[
  250. { value: 'INSIDE', label: '内机' },
  251. { value: 'OUT', label: '外机' },
  252. { value: 'PARTS', label: '配件' }
  253. ].map((item, index_) => (
  254. <el-option key={index_} label={item.label} value={item.value}></el-option>
  255. ))}
  256. </el-select>
  257. </el-form-item>
  258. </div>
  259. ) : (
  260. <div style="padding:0 6px">
  261. {[
  262. { value: 'INSIDE', label: '内机' },
  263. { value: 'OUT', label: '外机' },
  264. { value: 'PARTS', label: '配件' }
  265. ].find(item => item.value == row[column.columnAttributes.prop])?.label || ''}
  266. </div>
  267. )
  268. }
  269. },
  270. {
  271. columnAttributes: {
  272. label: '物料名称',
  273. prop: 'goodsMaterialItemId',
  274. propName: 'goodsMaterialItemName',
  275. width: 160
  276. },
  277. render: (h, { row, column, index }) => {
  278. return this.isEditIndex == index ? (
  279. <div class="redbordererr">
  280. <el-form-item
  281. label=""
  282. lebel-width="0px"
  283. prop={`codeInfoList.${index}.${column.columnAttributes.prop}`}
  284. rules={required}
  285. >
  286. <el-select
  287. value={row[column.columnAttributes.prop]}
  288. onInput={val => {
  289. row[column.columnAttributes.prop] = val
  290. }}
  291. onChange={val => {
  292. this.shanchuCodejichu(row, 5)
  293. if (val) {
  294. var data = (
  295. this.formData.items.find(
  296. item =>
  297. item.brandId === row.brandId &&
  298. item.mainId === row.mainId &&
  299. item.smallId === row.smallId &&
  300. item.goodsMaterialId === row.goodsMaterialId
  301. )?.details?.items || []
  302. )
  303. .filter(item => item.type == row.goodsMaterialItemType)
  304. .find(item => item.id == val)
  305. row[column.columnAttributes.propName] = data.name
  306. row['uniqueCode'] = data.uniqueCode
  307. row['codeQty'] = data.uniqueCode == 'YES' ? 1 : ''
  308. } else {
  309. row[column.columnAttributes.propName] = ''
  310. row['uniqueCode'] = ''
  311. row['codeQty'] = ''
  312. }
  313. }}
  314. placeholder="请选择"
  315. >
  316. {(
  317. this.formData.items.find(
  318. item =>
  319. item.brandId === row.brandId &&
  320. item.mainId === row.mainId &&
  321. item.smallId === row.smallId &&
  322. item.goodsMaterialId === row.goodsMaterialId
  323. )?.details?.items || []
  324. )
  325. .filter(item => item.type == row.goodsMaterialItemType)
  326. .map((item, index_) => (
  327. <el-option key={index_} label={item.name} value={item.id}></el-option>
  328. ))}
  329. </el-select>
  330. </el-form-item>
  331. </div>
  332. ) : (
  333. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  334. )
  335. }
  336. },
  337. {
  338. columnAttributes: {
  339. label: '是否一物一码',
  340. prop: 'uniqueCode',
  341. width: 120
  342. },
  343. render: (h, { row, column, index }) => {
  344. return (
  345. <div style="padding:0 6px">
  346. {[
  347. { value: 'YES', label: '是' },
  348. { value: 'NO', label: '否' }
  349. ].find(item => item.value == row[column.columnAttributes.prop])?.label || ''}
  350. </div>
  351. )
  352. }
  353. },
  354. {
  355. columnAttributes: {
  356. label: '条码',
  357. prop: 'code',
  358. width: 160
  359. },
  360. render: (h, { row, column, index }) => {
  361. return this.isEditIndex == index ? (
  362. <div class="redbordererr">
  363. <el-form-item
  364. label=""
  365. lebel-width="0px"
  366. prop={`codeInfoList.${index}.${column.columnAttributes.prop}`}
  367. rules={required}
  368. >
  369. <el-input
  370. value={row[column.columnAttributes.prop]}
  371. onInput={val => {
  372. row[column.columnAttributes.prop] = val
  373. }}
  374. placeholder="请输入"
  375. ></el-input>
  376. </el-form-item>
  377. </div>
  378. ) : (
  379. <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
  380. )
  381. }
  382. },
  383. {
  384. columnAttributes: {
  385. label: '数量',
  386. prop: 'codeQty',
  387. width: 160
  388. },
  389. render: (h, { row, column, index }) => {
  390. return this.isEditIndex == index && row.uniqueCode == 'NO' ? (
  391. <div class="redbordererr">
  392. <el-form-item
  393. label=""
  394. lebel-width="0px"
  395. prop={`codeInfoList.${index}.${column.columnAttributes.prop}`}
  396. rules={required}
  397. >
  398. <el-input
  399. value={row[column.columnAttributes.prop]}
  400. onInput={val => {
  401. row[column.columnAttributes.prop] = val
  402. }}
  403. placeholder="请输入"
  404. ></el-input>
  405. </el-form-item>
  406. </div>
  407. ) : (
  408. <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
  409. )
  410. }
  411. },
  412. ...(() => {
  413. if (this.formDialogType < 2) {
  414. return [
  415. {
  416. columnAttributes: {
  417. label: '操作',
  418. fixed: 'right',
  419. width: 140
  420. },
  421. render: (h, { row, column, index }) => {
  422. return (
  423. <div style="padding:0 6px" class="operation-btns">
  424. {this.formDialogType == 0
  425. ? null
  426. : this.formDialogType == 1
  427. ? [
  428. this.isEditIndex == index ? (
  429. <el-button
  430. type="text"
  431. onClick={() => {
  432. this.addCode(row)
  433. }}
  434. >
  435. 保存
  436. </el-button>
  437. ) : null,
  438. this.isEditIndex == -1 ? (
  439. <el-button
  440. type="text"
  441. onClick={() => {
  442. this.getGoodsDetl(
  443. this.formData.items.find(
  444. item =>
  445. item.brandId === row.brandId &&
  446. item.mainId === row.mainId &&
  447. item.smallId === row.smallId &&
  448. item.goodsMaterialId === row.goodsMaterialId
  449. ),
  450. res => {
  451. this.isEditIndex = index
  452. },
  453. 'goodsMaterialId'
  454. )
  455. }}
  456. >
  457. 编辑
  458. </el-button>
  459. ) : null,
  460. <el-button
  461. type="text"
  462. onClick={() => {
  463. this.delCode(row, index)
  464. }}
  465. >
  466. 删除
  467. </el-button>
  468. ]
  469. : null}
  470. </div>
  471. )
  472. }
  473. }
  474. ]
  475. }
  476. return []
  477. })()
  478. ]
  479. }
  480. },
  481. methods: {
  482. getGoodsPurchaseCodeList() {
  483. if (this.formData.id) {
  484. goodsPurchaseCodeList({
  485. pageNum: 1,
  486. pageSize: -1,
  487. params: [{ param: 'c.goods_purchase_id', compare: '=', value: this.formData.id }]
  488. }).then(res => {
  489. this.formData.codeInfoList = res.data.records
  490. })
  491. }
  492. },
  493. arrQC(list, qz = { label: '', value: '' }) {
  494. var obj = {}
  495. for (var item of list) {
  496. obj[item[qz?.value || 'value']] = item
  497. }
  498. return Object.keys(obj).map(key => {
  499. return {
  500. data: obj[key],
  501. value: key,
  502. label: obj[key][qz?.label || 'label']
  503. }
  504. })
  505. },
  506. shanchuCodejichu(row, num) {
  507. if (num <= 0) {
  508. row.mainId = ''
  509. row.mainName = ''
  510. }
  511. if (num <= 1) {
  512. row.smallId = ''
  513. row.smallName = ''
  514. }
  515. if (num <= 2) {
  516. row.goodsMaterialId = ''
  517. row.goodsMaterialName = ''
  518. row.goodsPurchaseItemId = ''
  519. row.specsName = ''
  520. }
  521. if (num <= 3) {
  522. row.goodsMaterialItemType = ''
  523. }
  524. if (num <= 4) {
  525. row.goodsMaterialItemId = ''
  526. row.goodsMaterialItemName = ''
  527. row.codeQty = ''
  528. }
  529. if (num <= 5) {
  530. row.uniqueCode = ''
  531. row.code = ''
  532. }
  533. },
  534. getCodeVfyKey() {
  535. return [
  536. `codeInfoList.${this.isEditIndex}.brandId`,
  537. `codeInfoList.${this.isEditIndex}.mainId`,
  538. `codeInfoList.${this.isEditIndex}.smallId`,
  539. `codeInfoList.${this.isEditIndex}.goodsMaterialId`,
  540. `codeInfoList.${this.isEditIndex}.goodsMaterialItemType`,
  541. `codeInfoList.${this.isEditIndex}.goodsMaterialItemId`,
  542. `codeInfoList.${this.isEditIndex}.code`,
  543. `codeInfoList.${this.isEditIndex}.codeQty`
  544. ]
  545. },
  546. eidtCodeItems() {
  547. // try {
  548. // this.formData.codeInfoList.map((item, index) => {
  549. // this.formData.codeInfoList.map((item2, index2) => {
  550. // if (
  551. // index !== index2 &&
  552. // `${item.brandId}_${item.mainId}_${item.smallId}_${item.goodsMaterialId}_${item.goodsMaterialItemType}_${item.goodsMaterialItemId}` ==
  553. // `${item2.brandId}_${item2.mainId}_${item2.smallId}_${item2.goodsMaterialId}_${item2.goodsMaterialItemType}_${item2.goodsMaterialItemId}`
  554. // ) {
  555. // throw new Error('')
  556. // }
  557. // })
  558. // })
  559. // } catch (error) {
  560. // this.$message.warning('重复')
  561. // return false
  562. // }
  563. return true
  564. },
  565. // 添加条码信息
  566. addCodeInfo() {
  567. this.formData.codeInfoList.unshift({
  568. brandId: '',
  569. brandName: '',
  570. mainId: '',
  571. mainName: '',
  572. smallId: '',
  573. smallName: '',
  574. goodsMaterialId: '',
  575. goodsMaterialName: '',
  576. specsName: '',
  577. goodsMaterialItemType: '',
  578. goodsMaterialItemId: '',
  579. goodsMaterialItemName: '',
  580. uniqueCode: '',
  581. code: '',
  582. codeQty: '',
  583. goodsPurchaseItemId: '',
  584. goodsPurchaseId: this.formData.id
  585. })
  586. this.isEditIndex = 0
  587. },
  588. addCode(row) {
  589. if (this.isEditIndex > -1) {
  590. this.$refs.formRef.validateField(this.getCodeVfyKey(), (valid, invalidFields, errLabels) => {
  591. if (valid && this.eidtCodeItems()) {
  592. goodsPurchaseItemAddCode({
  593. codeList: [{ ...row }]
  594. }).then(res => {
  595. this.isEditIndex = -1
  596. this.getGoodsPurchaseCodeList()
  597. })
  598. }
  599. })
  600. }
  601. },
  602. delCode(row, index) {
  603. if (row.id) {
  604. goodsPurchaseItemDelCode({
  605. codeId: row.id,
  606. id: row.goodsPurchaseId
  607. }).then(res => {
  608. this.getGoodsPurchaseCodeList()
  609. })
  610. } else {
  611. this.formData?.codeInfoList?.splice(index, 1)
  612. if (index == this.isEditIndex) {
  613. this.isEditIndex = -1
  614. }
  615. }
  616. }
  617. }
  618. }