storage_goods.js 19 KB

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