storage_goods.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  2. import { getBrandList } from '@/api/miniapp'
  3. import { getClassifyList } from '@/api/goods'
  4. import { goodsMaterialList, goodsMaterialDetail } from '@/api/commercialMaterial.js'
  5. export default {
  6. data() {
  7. return {
  8. brandList: [],
  9. ClassifyList: [],
  10. goodsMaterialList: [],
  11. isEditIndex: -1
  12. }
  13. },
  14. computed: {
  15. storage_goods() {
  16. return [
  17. {
  18. columnAttributes: {
  19. label: '品牌',
  20. prop: 'brandId',
  21. propName: 'brandName',
  22. width: 160
  23. },
  24. render: (h, { row, column, index }) => {
  25. return this.isEditIndex == index ? (
  26. <div class="redbordererr">
  27. <el-form-item
  28. label=""
  29. lebel-width="0px"
  30. prop={`items.${index}.${column.columnAttributes.prop}`}
  31. rules={required}
  32. >
  33. <el-select
  34. value={row[column.columnAttributes.prop]}
  35. onInput={val => {
  36. row[column.columnAttributes.prop] = val
  37. }}
  38. onChange={val => {
  39. this.shanchujichu(row, 0)
  40. if (val) {
  41. row[column.columnAttributes.propName] = this.brandList.find(item => item.id == val).brandName
  42. } else {
  43. row[column.columnAttributes.propName] = ''
  44. }
  45. }}
  46. placeholder="请选择"
  47. >
  48. {this.brandList.map((item, index_) => (
  49. <el-option key={index_} label={item.brandName} value={item.id}></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.shanchujichu(row, 1)
  82. if (val) {
  83. row[column.columnAttributes.propName] = this.ClassifyList.find(
  84. item => item.categoryId == val
  85. ).name
  86. } else {
  87. row[column.columnAttributes.propName] = ''
  88. }
  89. }}
  90. placeholder="请选择"
  91. >
  92. {this.ClassifyList.map((item, index_) => (
  93. <el-option key={index_} label={item.name} value={item.categoryId}></el-option>
  94. ))}
  95. </el-select>
  96. </el-form-item>
  97. </div>
  98. ) : (
  99. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  100. )
  101. }
  102. },
  103. {
  104. columnAttributes: {
  105. label: '商品小类',
  106. prop: 'smallId',
  107. propName: 'smallName',
  108. width: 160
  109. },
  110. render: (h, { row, column, index }) => {
  111. return this.isEditIndex == index ? (
  112. <div class="redbordererr">
  113. <el-form-item
  114. label=""
  115. lebel-width="0px"
  116. prop={`items.${index}.${column.columnAttributes.prop}`}
  117. rules={required}
  118. >
  119. <el-select
  120. value={row[column.columnAttributes.prop]}
  121. onInput={val => {
  122. row[column.columnAttributes.prop] = val
  123. }}
  124. onChange={val => {
  125. this.shanchujichu(row, 2)
  126. if (val) {
  127. row[column.columnAttributes.propName] = (
  128. this.ClassifyList.find(item => item.categoryId == row.mainId)?.children || []
  129. ).find(item => item.categoryId == val).name
  130. } else {
  131. row[column.columnAttributes.propName] = ''
  132. }
  133. }}
  134. placeholder="请选择"
  135. >
  136. {(this.ClassifyList.find(item => item.categoryId == row.mainId)?.children || []).map(
  137. (item, index_) => (
  138. <el-option key={index_} label={item.name} value={item.categoryId}></el-option>
  139. )
  140. )}
  141. </el-select>
  142. </el-form-item>
  143. </div>
  144. ) : (
  145. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  146. )
  147. }
  148. },
  149. {
  150. columnAttributes: {
  151. label: '商品名称',
  152. prop: 'goodsMaterialId',
  153. propName: 'goodsMaterialName',
  154. width: 160
  155. },
  156. render: (h, { row, column, index }) => {
  157. return this.isEditIndex == index ? (
  158. <div class="redbordererr">
  159. <el-form-item
  160. label=""
  161. lebel-width="0px"
  162. prop={`items.${index}.${column.columnAttributes.prop}`}
  163. rules={required}
  164. >
  165. <el-select
  166. value={row[column.columnAttributes.prop]}
  167. onInput={val => {
  168. row[column.columnAttributes.prop] = val
  169. }}
  170. onChange={val => {
  171. this.shanchujichu(row, 3)
  172. if (val) {
  173. var data = this.goodsMaterialList
  174. .filter(
  175. item =>
  176. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  177. )
  178. .find(item => item.id == val)
  179. row[column.columnAttributes.propName] = data?.goodsName
  180. this.getGoodsDetl(data, res => {
  181. if (this.formDialogType == 0) {
  182. row['specsName'] = res?.specsName
  183. row['unit'] = res?.unit
  184. row['insideQty'] = res?.insideQty
  185. row['outQty'] = res?.outQty
  186. row['partsQty'] = res?.partsQty
  187. row['stockQty'] = res?.stockQty
  188. }
  189. })
  190. } else {
  191. row[column.columnAttributes.propName] = ''
  192. row['specsName'] = ''
  193. row['unit'] = ''
  194. row['insideQty'] = ''
  195. row['outQty'] = ''
  196. row['partsQty'] = ''
  197. row['stockQty'] = ''
  198. }
  199. }}
  200. placeholder="请选择"
  201. >
  202. {this.goodsMaterialList
  203. .filter(
  204. item =>
  205. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  206. )
  207. .map((item, index_) => (
  208. <el-option key={index_} label={item.goodsName} value={item.id}></el-option>
  209. ))}
  210. </el-select>
  211. </el-form-item>
  212. </div>
  213. ) : (
  214. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  215. )
  216. }
  217. },
  218. {
  219. columnAttributes: {
  220. label: '规格型号',
  221. prop: 'specsName',
  222. width: 120
  223. }
  224. },
  225. {
  226. columnAttributes: {
  227. label: '单位',
  228. prop: 'unit'
  229. },
  230. render: (h, { row, column, index }) => {
  231. return <div style="padding:0 6px">{{ C: '整套', I: '单个' }[row[column.columnAttributes.prop]] || ''}</div>
  232. }
  233. },
  234. {
  235. columnAttributes: {
  236. label: '采购数量',
  237. prop: 'qty',
  238. width: 160
  239. },
  240. render: (h, { row, column, index }) => {
  241. return this.isEditIndex == index ? (
  242. <div class="redbordererr">
  243. <el-form-item
  244. label=""
  245. lebel-width="0px"
  246. prop={`items.${index}.${column.columnAttributes.prop}`}
  247. rules={required}
  248. >
  249. <el-input
  250. value={row[column.columnAttributes.prop]}
  251. onInput={val => {
  252. row[column.columnAttributes.prop] = val <= 0 ? 0 : Number(val)
  253. }}
  254. type="number"
  255. placeholder="请输入"
  256. ></el-input>
  257. </el-form-item>
  258. </div>
  259. ) : (
  260. <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
  261. )
  262. }
  263. },
  264. {
  265. columnAttributes: {
  266. label: '内机数量',
  267. prop: 'insideQty'
  268. }
  269. },
  270. {
  271. columnAttributes: {
  272. label: '外机数量',
  273. prop: 'outQty'
  274. }
  275. },
  276. {
  277. columnAttributes: {
  278. label: '配件数量',
  279. prop: 'partsQty'
  280. }
  281. },
  282. {
  283. columnAttributes: {
  284. label: '导入内机条码数量',
  285. prop: 'insideCodeQty',
  286. width: 120
  287. }
  288. },
  289. {
  290. columnAttributes: {
  291. label: '导入外机条码数量',
  292. prop: 'outCodeQty',
  293. width: 120
  294. }
  295. },
  296. {
  297. columnAttributes: {
  298. label: '导入配件条码数量',
  299. prop: 'partsCodeQty',
  300. width: 120
  301. }
  302. },
  303. {
  304. columnAttributes: {
  305. label: '采购价格',
  306. prop: 'price',
  307. width: 160
  308. },
  309. render: (h, { row, column, index }) => {
  310. return this.isEditIndex == index ? (
  311. <div class="redbordererr">
  312. <el-form-item
  313. label=""
  314. lebel-width="0px"
  315. prop={`items.${index}.${column.columnAttributes.prop}`}
  316. rules={required}
  317. >
  318. <el-input
  319. value={row[column.columnAttributes.prop]}
  320. onInput={val => {
  321. row[column.columnAttributes.prop] = val
  322. }}
  323. type="number"
  324. placeholder="请输入"
  325. ></el-input>
  326. </el-form-item>
  327. </div>
  328. ) : (
  329. <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
  330. )
  331. }
  332. },
  333. {
  334. columnAttributes: {
  335. label: '采购金额',
  336. prop: 'amount',
  337. width: 160
  338. },
  339. render: (h, { row, column, index }) => {
  340. return <div style="padding:0 6px">{Number(row['qty']) * Number(row['price'])}</div>
  341. }
  342. },
  343. {
  344. columnAttributes: {
  345. label: '库存数量',
  346. prop: 'stockQty'
  347. }
  348. },
  349. ...(() => {
  350. if (this.formDialogType < 2) {
  351. return [
  352. {
  353. columnAttributes: {
  354. label: '操作',
  355. fixed: 'right',
  356. width: 140
  357. },
  358. render: (h, { row, column, index }) => {
  359. return (
  360. <div style="padding:0 6px" class="operation-btns">
  361. {!~['SAVE', 'WAIT', 'OK', 'FAIL'].indexOf(this.formData.status) ? (
  362. [
  363. this.isEditIndex == index ? (
  364. <el-button
  365. type="text"
  366. onClick={() => {
  367. this.$refs.formRef.validateField(
  368. this.getVfyKey(this.isEditIndex),
  369. (valid, invalidFields, errLabels) => {
  370. if (valid && this.eidtItems()) {
  371. this.isEditIndex = -1
  372. }
  373. }
  374. )
  375. }}
  376. >
  377. 保存
  378. </el-button>
  379. ) : null,
  380. this.isEditIndex == -1 ? (
  381. <el-button
  382. type="text"
  383. onClick={() => {
  384. this.isEditIndex = index
  385. }}
  386. >
  387. 编辑
  388. </el-button>
  389. ) : null,
  390. <el-button
  391. type="text"
  392. onClick={() => {
  393. this.delGoodsInfo(row, index)
  394. }}
  395. >
  396. 删除
  397. </el-button>
  398. ]
  399. ) : !!~['SAVE'].indexOf(this.formData.status) ? (
  400. <el-button type="text" onClick={() => {}}>
  401. 导入条码
  402. </el-button>
  403. ) : null}
  404. </div>
  405. )
  406. }
  407. }
  408. ]
  409. }
  410. return []
  411. })()
  412. ]
  413. }
  414. },
  415. methods: {
  416. getBaseList() {
  417. getBrandList({
  418. status: true
  419. }).then(res => {
  420. this.brandList = res.data
  421. })
  422. getClassifyList({
  423. type: 2,
  424. status: true
  425. }).then(res => {
  426. this.ClassifyList = res.data
  427. })
  428. goodsMaterialList({
  429. pageNum: 1,
  430. pageSize: -1,
  431. params: []
  432. }).then(res => {
  433. this.goodsMaterialList = res.data.records.map(item => ({ ...item, details: {} }))
  434. })
  435. },
  436. shanchujichu(row, num) {
  437. if (num <= 0) {
  438. }
  439. if (num <= 1) {
  440. row.smallId = ''
  441. row.smallName = ''
  442. }
  443. if (num <= 2) {
  444. row.goodsMaterialId = ''
  445. row.goodsMaterialName = ''
  446. row.specsName = ''
  447. row.unit = ''
  448. row.insideQty = ''
  449. row.outQty = ''
  450. row.partsQty = ''
  451. row.stockQty = ''
  452. }
  453. },
  454. getGoodsDetl(row, cb, key = 'id') {
  455. if (!row?.details?.id) {
  456. goodsMaterialDetail({ id: row[key] }).then(res => {
  457. Object.assign(row.details, res.data || {})
  458. cb(row.details)
  459. })
  460. } else {
  461. cb(row.details)
  462. }
  463. },
  464. getVfyKey(index, bool = true) {
  465. return [
  466. ...(() => {
  467. if (bool) {
  468. return [`items`]
  469. }
  470. return []
  471. })(),
  472. ...(() => {
  473. if (index > -1) {
  474. return [
  475. `items.${index}.brandId`,
  476. `items.${index}.mainId`,
  477. `items.${index}.smallId`,
  478. `items.${index}.goodsMaterialId`,
  479. `items.${index}.qty`,
  480. `items.${index}.price`
  481. ]
  482. }
  483. return []
  484. })()
  485. ]
  486. },
  487. eidtItems() {
  488. try {
  489. this.formData.items.map((item, index) => {
  490. this.formData.items.map((item2, index2) => {
  491. if (
  492. index !== index2 &&
  493. `${item.brandId}_${item.mainId}_${item.smallId}_${item.goodsMaterialId}` ==
  494. `${item2.brandId}_${item2.mainId}_${item2.smallId}_${item2.goodsMaterialId}`
  495. ) {
  496. throw new Error('')
  497. }
  498. })
  499. })
  500. } catch (error) {
  501. this.$message.warning('重复')
  502. return false
  503. }
  504. return true
  505. },
  506. // 添加商品信息
  507. addGoodsInfo() {
  508. if (this.isEditIndex > -1) {
  509. this.$refs.formRef.validateField(this.getVfyKey(this.isEditIndex), (valid, invalidFields, errLabels) => {
  510. if (valid && this.eidtItems()) {
  511. this.formData.items.unshift({
  512. brandId: '',
  513. brandName: '',
  514. mainId: '',
  515. mainName: '',
  516. smallId: '',
  517. smallName: '',
  518. goodsMaterialId: '',
  519. goodsMaterialName: '',
  520. specsName: '',
  521. unit: '',
  522. qty: '',
  523. insideQty: '',
  524. outQty: '',
  525. partsQty: '',
  526. insideCodeQty: '',
  527. outCodeQty: '',
  528. partsCodeQty: '',
  529. price: '',
  530. amount: '',
  531. stockQty: ''
  532. })
  533. this.isEditIndex = 0
  534. }
  535. })
  536. } else if (this.eidtItems()) {
  537. this.formData.items.unshift({
  538. brandId: '',
  539. brandName: '',
  540. mainId: '',
  541. mainName: '',
  542. smallId: '',
  543. smallName: '',
  544. goodsMaterialId: '',
  545. goodsMaterialName: '',
  546. specsName: '',
  547. unit: '',
  548. qty: '',
  549. insideQty: '',
  550. outQty: '',
  551. partsQty: '',
  552. insideCodeQty: '',
  553. outCodeQty: '',
  554. partsCodeQty: '',
  555. price: '',
  556. amount: '',
  557. stockQty: ''
  558. })
  559. this.isEditIndex = 0
  560. }
  561. },
  562. delGoodsInfo(row, index) {
  563. if (index > this.isEditIndex) {
  564. this.formData?.items?.splice(index, 1)
  565. } else if (index == this.isEditIndex) {
  566. this.formData?.items?.splice(index, 1)
  567. this.isEditIndex = -1
  568. }
  569. }
  570. }
  571. }