storage_goods.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. export default {
  7. data() {
  8. return {
  9. brandList: [],
  10. ClassifyList: [],
  11. goodsMaterialList: []
  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={[diyRequired.bind(this)((rule, value)=>{
  32. if(this.logs){
  33. this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
  34. }
  35. this?.tishicuowu?.()
  36. return new Error('必须填写')
  37. })]}
  38. >
  39. <el-select
  40. value={row[column.columnAttributes.prop]}
  41. onInput={val => {
  42. row[column.columnAttributes.prop] = val
  43. }}
  44. onChange={val => {
  45. this.shanchujichu(row, 0)
  46. if (val) {
  47. row[column.columnAttributes.propName] = this.brandList.find(item => item.id == val).brandName
  48. } else {
  49. row[column.columnAttributes.propName] = ''
  50. }
  51. }}
  52. placeholder="请选择"
  53. >
  54. {this.brandList.map((item, index_) => (
  55. <el-option key={index_} label={item.brandName} value={item.id}></el-option>
  56. ))}
  57. </el-select>
  58. </el-form-item>
  59. </div>
  60. ) : (
  61. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  62. )
  63. }
  64. },
  65. {
  66. columnAttributes: {
  67. label: '*商品大类',
  68. prop: 'mainId',
  69. propName: 'mainName',
  70. width: 160
  71. },
  72. render: (h, { row, column, index }) => {
  73. return this.isEditIndex == index ? (
  74. <div class="redbordererr">
  75. <el-form-item
  76. label=""
  77. lebel-width="0px"
  78. prop={`items.${index}.${column.columnAttributes.prop}`}
  79. rules={[diyRequired.bind(this)((rule, value)=>{
  80. if(this.logs){
  81. this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
  82. }
  83. this?.tishicuowu?.()
  84. return new Error('必须填写')
  85. })]}
  86. >
  87. <el-select
  88. value={row[column.columnAttributes.prop]}
  89. onInput={val => {
  90. row[column.columnAttributes.prop] = val
  91. }}
  92. onChange={val => {
  93. this.shanchujichu(row, 1)
  94. if (val) {
  95. row[column.columnAttributes.propName] = this.ClassifyList.find(
  96. item => item.categoryId == val
  97. ).name
  98. } else {
  99. row[column.columnAttributes.propName] = ''
  100. }
  101. }}
  102. placeholder="请选择"
  103. >
  104. {this.ClassifyList.map((item, index_) => (
  105. <el-option key={index_} label={item.name} value={item.categoryId}></el-option>
  106. ))}
  107. </el-select>
  108. </el-form-item>
  109. </div>
  110. ) : (
  111. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  112. )
  113. }
  114. },
  115. {
  116. columnAttributes: {
  117. label: '*商品小类',
  118. prop: 'smallId',
  119. propName: 'smallName',
  120. width: 160
  121. },
  122. render: (h, { row, column, index }) => {
  123. return this.isEditIndex == index ? (
  124. <div class="redbordererr">
  125. <el-form-item
  126. label=""
  127. lebel-width="0px"
  128. prop={`items.${index}.${column.columnAttributes.prop}`}
  129. rules={[diyRequired.bind(this)((rule, value)=>{
  130. if(this.logs){
  131. this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
  132. }
  133. this?.tishicuowu?.()
  134. return new Error('必须填写')
  135. })]}
  136. >
  137. <el-select
  138. value={row[column.columnAttributes.prop]}
  139. onInput={val => {
  140. row[column.columnAttributes.prop] = val
  141. }}
  142. onChange={val => {
  143. this.shanchujichu(row, 2)
  144. if (val) {
  145. row[column.columnAttributes.propName] = (
  146. this.ClassifyList.find(item => item.categoryId == row.mainId)?.children || []
  147. ).find(item => item.categoryId == val).name
  148. } else {
  149. row[column.columnAttributes.propName] = ''
  150. }
  151. }}
  152. placeholder="请选择"
  153. >
  154. {(this.ClassifyList.find(item => item.categoryId == row.mainId)?.children || []).map(
  155. (item, index_) => (
  156. <el-option key={index_} label={item.name} value={item.categoryId}></el-option>
  157. )
  158. )}
  159. </el-select>
  160. </el-form-item>
  161. </div>
  162. ) : (
  163. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  164. )
  165. }
  166. },
  167. {
  168. columnAttributes: {
  169. label: '*商品名称',
  170. prop: 'goodsMaterialId',
  171. propName: 'goodsMaterialName',
  172. width: 160
  173. },
  174. render: (h, { row, column, index }) => {
  175. return this.isEditIndex == index ? (
  176. <div class="redbordererr">
  177. <el-form-item
  178. label=""
  179. lebel-width="0px"
  180. prop={`items.${index}.${column.columnAttributes.prop}`}
  181. rules={[diyRequired.bind(this)((rule, value)=>{
  182. if(this.logs){
  183. this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
  184. }
  185. this?.tishicuowu?.()
  186. return new Error('必须填写')
  187. })]}
  188. >
  189. <el-select
  190. value={row[column.columnAttributes.prop]}
  191. onInput={val => {
  192. row[column.columnAttributes.prop] = val
  193. }}
  194. onChange={val => {
  195. this.shanchujichu(row, 3)
  196. if (val) {
  197. var data = this.goodsMaterialList
  198. .filter(
  199. item =>
  200. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  201. )
  202. .find(item => item.id == val)
  203. row[column.columnAttributes.propName] = data?.goodsName
  204. this.getGoodsDetl(data, res => {
  205. if (!!~[0,1].indexOf(this.formDialogType)) {
  206. row['specsName'] = res?.specsName
  207. row['unit'] = res?.unit
  208. row['stockQty'] = res?.stockQty
  209. row['factoryNo'] = res?.factoryNo
  210. row['insideQty'] =
  211. res.items
  212. .filter(item => item.type === 'INSIDE')
  213. .map(item => item.qty)
  214. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * Number(row?.qty)
  215. row['outQty'] =
  216. res.items
  217. .filter(item => item.type === 'OUT')
  218. .map(item => item.qty)
  219. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * Number(row?.qty)
  220. row['partsQty'] =
  221. res.items
  222. .filter(item => item.type === 'PARTS')
  223. .map(item => item.qty)
  224. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * Number(row?.qty)
  225. }
  226. })
  227. } else {
  228. row[column.columnAttributes.propName] = ''
  229. row['specsName'] = ''
  230. row['unit'] = ''
  231. row['insideQty'] = ''
  232. row['outQty'] = ''
  233. row['partsQty'] = ''
  234. row['stockQty'] = ''
  235. row['factoryNo'] = ''
  236. }
  237. }}
  238. filterable={true}
  239. placeholder="请选择"
  240. >
  241. {this.goodsMaterialList
  242. .filter(
  243. item =>
  244. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  245. )
  246. .map((item, index_) => (
  247. <el-option key={index_} label={item.goodsName} value={item.id}></el-option>
  248. ))}
  249. </el-select>
  250. </el-form-item>
  251. </div>
  252. ) : (
  253. <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
  254. )
  255. }
  256. },
  257. {
  258. columnAttributes: {
  259. label: '厂物料编码',
  260. prop: 'factoryNo',
  261. width: 120
  262. }
  263. },
  264. {
  265. columnAttributes: {
  266. label: '规格型号',
  267. prop: 'specsName',
  268. width: 120
  269. }
  270. },
  271. {
  272. columnAttributes: {
  273. label: '单位',
  274. prop: 'unit'
  275. },
  276. render: (h, { row, column, index }) => {
  277. return <div style="padding:0 6px">{{ C: '整套', I: '单个' }[row[column.columnAttributes.prop]] || ''}</div>
  278. }
  279. },
  280. {
  281. columnAttributes: {
  282. label: '*采购数量',
  283. prop: 'qty',
  284. width: 160
  285. },
  286. render: (h, { row, column, index }) => {
  287. return this.isEditIndex == index ? (
  288. <div class="redbordererr">
  289. <el-form-item
  290. label=""
  291. lebel-width="0px"
  292. prop={`items.${index}.${column.columnAttributes.prop}`}
  293. rules={[diyRequired.bind(this)((rule, value)=>{
  294. if(this.logs){
  295. this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
  296. }
  297. this?.tishicuowu?.()
  298. return new Error('必须填写')
  299. })]}
  300. >
  301. <el-input
  302. value={row[column.columnAttributes.prop]}
  303. onInput={val => {
  304. row[column.columnAttributes.prop] = val <= 0 ? 0 : Number(val)
  305. this.getGoodsDetl(
  306. this.goodsMaterialList
  307. .filter(
  308. item =>
  309. item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
  310. )
  311. .find(item => item.id == row.goodsMaterialId),
  312. res => {
  313. if (!!~[0,1].indexOf(this.formDialogType)) {
  314. row['insideQty'] =
  315. res.items
  316. .filter(item => item.type === 'INSIDE')
  317. .map(item => item.qty)
  318. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) *
  319. row[column.columnAttributes.prop]
  320. row['outQty'] =
  321. res.items
  322. .filter(item => item.type === 'OUT')
  323. .map(item => item.qty)
  324. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) *
  325. row[column.columnAttributes.prop]
  326. row['partsQty'] =
  327. res.items
  328. .filter(item => item.type === 'PARTS')
  329. .map(item => item.qty)
  330. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) *
  331. row[column.columnAttributes.prop]
  332. }
  333. }
  334. )
  335. }}
  336. type="number"
  337. placeholder="请输入"
  338. ></el-input>
  339. </el-form-item>
  340. </div>
  341. ) : (
  342. <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
  343. )
  344. }
  345. },
  346. {
  347. columnAttributes: {
  348. label: '内机数量',
  349. prop: 'insideQty'
  350. }
  351. },
  352. {
  353. columnAttributes: {
  354. label: '外机数量',
  355. prop: 'outQty'
  356. }
  357. },
  358. {
  359. columnAttributes: {
  360. label: '配件数量',
  361. prop: 'partsQty'
  362. }
  363. },
  364. {
  365. columnAttributes: {
  366. label: '导入内机条码数量',
  367. prop: 'insideCodeQty',
  368. width: 120
  369. }
  370. },
  371. {
  372. columnAttributes: {
  373. label: '导入外机条码数量',
  374. prop: 'outCodeQty',
  375. width: 120
  376. }
  377. },
  378. {
  379. columnAttributes: {
  380. label: '导入配件条码数量',
  381. prop: 'partsCodeQty',
  382. width: 120
  383. }
  384. },
  385. {
  386. columnAttributes: {
  387. label: '*采购价格',
  388. prop: 'price',
  389. width: 160
  390. },
  391. render: (h, { row, column, index }) => {
  392. return this.isEditIndex == index ? (
  393. <div class="redbordererr">
  394. <el-form-item
  395. label=""
  396. lebel-width="0px"
  397. prop={`items.${index}.${column.columnAttributes.prop}`}
  398. rules={[diyRequired.bind(this)((rule, value)=>{
  399. if(this.logs){
  400. this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
  401. }
  402. this?.tishicuowu?.()
  403. return new Error('必须填写')
  404. })]}
  405. >
  406. <el-input
  407. value={row[column.columnAttributes.prop]}
  408. onInput={val => {
  409. row[column.columnAttributes.prop] = val
  410. }}
  411. type="number"
  412. placeholder="请输入"
  413. ></el-input>
  414. </el-form-item>
  415. </div>
  416. ) : (
  417. <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
  418. )
  419. }
  420. },
  421. {
  422. columnAttributes: {
  423. label: '采购金额',
  424. prop: 'amount',
  425. width: 160
  426. },
  427. render: (h, { row, column, index }) => {
  428. return <div style="padding:0 6px">{Number(row['qty']) * Number(row['price'])}</div>
  429. }
  430. },
  431. {
  432. columnAttributes: {
  433. label: '库存数量',
  434. prop: 'stockQty'
  435. }
  436. },
  437. ...(() => {
  438. if (this.formDialogType < 2 && !~['WAIT', 'OK', 'FAIL'].indexOf(this.formData.status)) {
  439. return [
  440. {
  441. columnAttributes: {
  442. label: '操作',
  443. fixed: 'right',
  444. width: 140
  445. },
  446. render: (h, { row, column, index }) => {
  447. return (
  448. <div style="padding:0 6px" class="operation-btns">
  449. {[
  450. this.isEditIndex == index ? (
  451. <el-button
  452. type="text"
  453. onClick={() => {
  454. this.$refs.formRef.validateField(
  455. this.getVfyKey(this.isEditIndex),
  456. (valid, invalidFields, errLabels) => {
  457. if (valid && this.eidtItems()) {
  458. this.isEditIndex = -1
  459. }
  460. }
  461. )
  462. }}
  463. >
  464. 保存
  465. </el-button>
  466. ) : null,
  467. this.isEditIndex == -1 ? (
  468. <el-button
  469. type="text"
  470. onClick={() => {
  471. this.isEditIndex = index
  472. }}
  473. >
  474. 编辑
  475. </el-button>
  476. ) : null,
  477. <el-button
  478. type="text"
  479. onClick={() => {
  480. this.delGoodsInfo(row, index)
  481. }}
  482. >
  483. 删除
  484. </el-button>
  485. ]}
  486. </div>
  487. )
  488. }
  489. }
  490. ]
  491. } else if (this.formDialogType < 2 && !!~[].indexOf(this.formData.status) && this.joinCode) {
  492. return [
  493. {
  494. columnAttributes: {
  495. label: '操作',
  496. fixed: 'right',
  497. width: 140
  498. },
  499. render: (h, { row, column, index }) => {
  500. return (
  501. <div style="padding:0 6px" class="operation-btns">
  502. {this.importButton(goodsPurchaseItemImportCode, '导入条码', { purchaseItemId: row.id }, () => { }, () => {
  503. if (this.formData.id) {
  504. // 更新表单信息
  505. goodsPurchaseDetail({ id: this.formData.id }).then(res => {
  506. Object.assign(this.formData, res.data, {
  507. fileUrl: res.data.fileUrl ? [{ url: res.data.fileUrl }] : [],
  508. items: res.data.items.map(item => ({ ...item, details: {} }))
  509. })
  510. })
  511. }
  512. })}
  513. </div>
  514. )
  515. }
  516. }
  517. ]
  518. }
  519. return []
  520. })()
  521. ]
  522. }
  523. },
  524. methods: {
  525. getBaseList() {
  526. getBrandList({
  527. status: true
  528. }).then(res => {
  529. this.brandList = res.data
  530. })
  531. getClassifyList({
  532. type: 2,
  533. status: true
  534. }).then(res => {
  535. this.ClassifyList = res.data
  536. })
  537. goodsMaterialList({
  538. pageNum: 1,
  539. pageSize: -1,
  540. params: []
  541. }).then(res => {
  542. this.goodsMaterialList = res.data.records
  543. .filter(item => item.isVirtyual !== 'YES' && item.state == 'ON')
  544. .map(item => ({ ...item, details: {} }))
  545. })
  546. },
  547. shanchujichu(row, num) {
  548. if (num <= 0) {
  549. }
  550. if (num <= 1) {
  551. row.smallId = ''
  552. row.smallName = ''
  553. }
  554. if (num <= 2) {
  555. row.goodsMaterialId = ''
  556. row.goodsMaterialName = ''
  557. row.specsName = ''
  558. row.unit = ''
  559. row.insideQty = ''
  560. row.outQty = ''
  561. row.partsQty = ''
  562. row.stockQty = ''
  563. row.factoryNo = ''
  564. }
  565. },
  566. getVfyKey(index, bool = true) {
  567. return [
  568. ...(() => {
  569. if (bool) {
  570. return [`items`]
  571. }
  572. return []
  573. })(),
  574. ...(() => {
  575. if (index > -1) {
  576. return [
  577. `items.${index}.brandId`,
  578. `items.${index}.mainId`,
  579. `items.${index}.smallId`,
  580. `items.${index}.goodsMaterialId`,
  581. `items.${index}.qty`,
  582. `items.${index}.price`
  583. ]
  584. }
  585. return []
  586. })()
  587. ]
  588. },
  589. eidtItems() {
  590. try {
  591. this.formData.items.map((item, index) => {
  592. this.formData.items.map((item2, index2) => {
  593. if (
  594. index !== index2 &&
  595. `${item.brandId}_${item.mainId}_${item.smallId}_${item.goodsMaterialId}` ==
  596. `${item2.brandId}_${item2.mainId}_${item2.smallId}_${item2.goodsMaterialId}`
  597. ) {
  598. throw new Error('')
  599. }
  600. })
  601. })
  602. } catch (error) {
  603. this.$message.warning('重复')
  604. return false
  605. }
  606. return true
  607. },
  608. // 添加商品信息
  609. addGoodsInfo() {
  610. if (this.isEditIndex > -1) {
  611. this.$refs.formRef.validateField(this.getVfyKey(this.isEditIndex), (valid, invalidFields, errLabels) => {
  612. if (valid && this.eidtItems()) {
  613. this.formData.items.unshift({
  614. brandId: '',
  615. brandName: '',
  616. mainId: '',
  617. mainName: '',
  618. smallId: '',
  619. smallName: '',
  620. goodsMaterialId: '',
  621. goodsMaterialName: '',
  622. specsName: '',
  623. unit: '',
  624. qty: '',
  625. insideQty: '',
  626. outQty: '',
  627. partsQty: '',
  628. insideCodeQty: '',
  629. outCodeQty: '',
  630. partsCodeQty: '',
  631. price: '',
  632. amount: '',
  633. stockQty: '',
  634. factoryNo: "",
  635. })
  636. this.isEditIndex = 0
  637. }
  638. })
  639. } else if (this.eidtItems()) {
  640. this.formData.items.unshift({
  641. brandId: '',
  642. brandName: '',
  643. mainId: '',
  644. mainName: '',
  645. smallId: '',
  646. smallName: '',
  647. goodsMaterialId: '',
  648. goodsMaterialName: '',
  649. specsName: '',
  650. unit: '',
  651. qty: '',
  652. insideQty: '',
  653. outQty: '',
  654. partsQty: '',
  655. insideCodeQty: '',
  656. outCodeQty: '',
  657. partsCodeQty: '',
  658. price: '',
  659. amount: '',
  660. stockQty: '',
  661. factoryNo: ''
  662. })
  663. this.isEditIndex = 0
  664. }
  665. },
  666. delGoodsInfo(row, index) {
  667. if (index > this.isEditIndex) {
  668. this.formData?.items?.splice(index, 1)
  669. } else if (index == this.isEditIndex) {
  670. this.formData?.items?.splice(index, 1)
  671. this.isEditIndex = -1
  672. }
  673. }
  674. }
  675. }