storage_goods.js 20 KB

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