material.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. <template>
  2. <div>
  3. <header-title title="物料清单"></header-title>
  4. <ele-pro-table
  5. ref="table"
  6. row-key="id"
  7. :columns="materialColumns"
  8. :datasource="materialList"
  9. cache-key="prenatal-examination-material-list-table-2511031522"
  10. autoAmendPage
  11. :needPage="false"
  12. @refresh="$emit('refresh')"
  13. >
  14. <template v-slot:toolbar>
  15. <el-button type="primary" @click="openMaterialModal"
  16. >添加物料</el-button
  17. >
  18. </template>
  19. <template v-slot:selectColumn="{ row }">
  20. <el-checkbox
  21. v-model="row.selected"
  22. @change="selectedChange(row)"
  23. ></el-checkbox>
  24. </template>
  25. </ele-pro-table>
  26. <header-title title="产出清单" style="margin-top: 20px"></header-title>
  27. <ele-pro-table
  28. ref="table"
  29. row-key="id"
  30. :columns="outputDetailsColumns"
  31. :datasource="localOutputDetails"
  32. cache-key="prenatal-examination-output-list-table-2511031523"
  33. autoAmendPage
  34. :needPage="false"
  35. @refresh="localOutputDetailsRefresh"
  36. >
  37. <template v-slot:reportQuantity="{ row }">
  38. <div>
  39. <el-input-number
  40. size="small"
  41. v-model.number="row.reportQuantity"
  42. controls-position="right"
  43. :min="0"
  44. :max="reportQuantitymax(row)"
  45. @change="reportQuantityChange(row)"
  46. ></el-input-number>
  47. </div>
  48. </template>
  49. <template v-slot:qualifiedQuantity="{ row }">
  50. <el-input-number
  51. size="small"
  52. v-model.number="row.qualifiedQuantity"
  53. controls-position="right"
  54. :min="0"
  55. :max="qualifiedQuantityMax(row)"
  56. @change="qualifiedQuantityChange(row)"
  57. ></el-input-number>
  58. </template>
  59. <template v-slot:noQualifiedQuantity="{ row }">
  60. <el-input-number
  61. size="small"
  62. v-model.number="row.noQualifiedQuantity"
  63. controls-position="right"
  64. :min="0"
  65. :max="noQualifiedQuantityMax(row)"
  66. @change="noQualifiedQuantityChange(row)"
  67. ></el-input-number>
  68. </template>
  69. <template v-slot:msg="{ row }">
  70. <el-input
  71. v-model="row.msg"
  72. type="textarea"
  73. rows="1"
  74. autosize
  75. @change="$emit('update:outputDetails', localOutputDetails)"
  76. ></el-input>
  77. </template>
  78. </ele-pro-table>
  79. <materialModal ref="materialModalRef" @confirm="materialConfirm" />
  80. </div>
  81. </template>
  82. <script>
  83. import materialModal from './materialModal.vue';
  84. import {
  85. getMaterialQuotaInfo,
  86. getCategoryAndLevelByCategoryId
  87. } from '@/api/producetaskrecordrulesrecord/index';
  88. export default {
  89. components: {
  90. materialModal
  91. },
  92. props: {
  93. // 物料明细
  94. pickDetails: {
  95. type: Array,
  96. default: () => []
  97. },
  98. // 本次产出明细
  99. outputDetails: {
  100. type: Array,
  101. default: () => []
  102. },
  103. // 上到工序产出明细
  104. preOutputDetails: {
  105. type: Array,
  106. default: () => []
  107. },
  108. sumOutputDetails: {
  109. type: Array,
  110. default: () => []
  111. },
  112. // 工单id
  113. workOrderId: {
  114. type: [String, Number],
  115. required: true
  116. },
  117. // 规则id
  118. ruleId: {
  119. type: [String, Number],
  120. required: false
  121. },
  122. // 工序id
  123. produceTaskId: {
  124. type: [String, Number],
  125. required: true
  126. },
  127. // 工序实例id
  128. produceTaskInstanceId: {
  129. type: [String, Number],
  130. required: true
  131. },
  132. // 工序名称
  133. produceTaskName: {
  134. type: String,
  135. required: true
  136. },
  137. // BOM产品分类id
  138. bomCategoryId: {
  139. type: [String, Number],
  140. required: true
  141. },
  142. // 产出类型 1-物料本身 2-在制品 3-BOM标准产出
  143. outputType: {
  144. type: [Number],
  145. required: true
  146. },
  147. // 产品分类id
  148. categoryId: {
  149. type: [String, Number],
  150. required: false
  151. },
  152. // 执行状态
  153. executeStatus: {
  154. type: [Number],
  155. required: false
  156. }
  157. },
  158. watch: {
  159. pickDetails: {
  160. handler(newVal) {
  161. this.localPickDetails = JSON.parse(JSON.stringify(newVal)).map(
  162. (i) => {
  163. i.ruleId = this.ruleId;
  164. i.bomCategoryId = this.bomCategoryId;
  165. return i;
  166. }
  167. );
  168. },
  169. deep: true,
  170. immediate: true
  171. },
  172. outputDetails: {
  173. handler(newVal) {
  174. this.localOutputDetails = JSON.parse(JSON.stringify(newVal)).map(
  175. (i) => {
  176. i.ruleId = this.ruleId;
  177. i.outputType = this.outputType;
  178. i.bomCategoryId = this.bomCategoryId;
  179. i.id = null;
  180. return i;
  181. }
  182. );
  183. },
  184. deep: true,
  185. immediate: true
  186. },
  187. outputType: {
  188. handler() {
  189. // 重置产出明细
  190. this.localOutputDetails = [];
  191. this.localPickDetails = this.localPickDetails.map((item) => {
  192. return {
  193. ...item,
  194. selected: false
  195. };
  196. });
  197. // 根据不同的类型,重置物料明细
  198. if (this.outputType == 1) {
  199. this.$emit('update:outputDetails', this.localOutputDetails);
  200. // 1-物料本身
  201. } else if (this.outputType == 2) {
  202. // 2-在制品
  203. this.getCategoryAndLevelByCategoryId();
  204. } else {
  205. // 3 BOM标准产出
  206. this.setMaterialQuotaInfo();
  207. }
  208. }
  209. },
  210. ruleId: {
  211. handler() {
  212. // 更新物料明细的ruleId
  213. this.localPickDetails = this.localPickDetails.map((item) => {
  214. return {
  215. ...item,
  216. ruleId: this.ruleId
  217. };
  218. });
  219. // 更新产出明细的ruleId
  220. this.localOutputDetails = this.localOutputDetails.map((item) => {
  221. return {
  222. ...item,
  223. ruleId: this.ruleId
  224. };
  225. });
  226. // 通知父组件更新
  227. this.$emit('update:pickDetails', this.localPickDetails);
  228. this.$emit('update:outputDetails', this.localOutputDetails);
  229. }
  230. }
  231. },
  232. computed: {
  233. // 物料清单(包含上到工序产出明细)
  234. materialList() {
  235. return [...this.preOutputDetails, ...this.localPickDetails];
  236. },
  237. // 物料清单表头
  238. materialColumns() {
  239. const list = [
  240. {
  241. width: 45,
  242. type: 'index',
  243. columnKey: 'index',
  244. align: 'center'
  245. },
  246. {
  247. label: '类型',
  248. prop: 'categoryLevelNamePath',
  249. minWidth: 120
  250. },
  251. {
  252. label: '编码',
  253. prop: 'categoryCode',
  254. minWidth: 120
  255. },
  256. {
  257. label: '名称',
  258. prop: 'categoryName',
  259. minWidth: 120
  260. },
  261. {
  262. prop: 'model',
  263. label: '型号',
  264. align: 'center',
  265. showOverflowTooltip: true
  266. },
  267. {
  268. prop: 'specifications',
  269. label: '规格',
  270. align: 'center',
  271. width: 160,
  272. showOverflowTooltip: true
  273. },
  274. {
  275. prop: 'brandNo',
  276. label: '牌号',
  277. align: 'center'
  278. },
  279. {
  280. label: '工序名称',
  281. prop: 'produceTaskName',
  282. minWidth: 120
  283. },
  284. {
  285. label: '数量',
  286. prop: 'feedQuantity',
  287. minWidth: 120,
  288. formatter: (row) => {
  289. return (row.quantity || '') + (row.unit || '');
  290. }
  291. },
  292. {
  293. label: '当次消耗数量',
  294. prop: '',
  295. minWidth: 120,
  296. formatter: (row) => {
  297. // 产出为物料
  298. if (this.outputType == 1) {
  299. // 取值产出清单
  300. const outputItem = this.localOutputDetails.find(
  301. (item) => item.categoryCode === row.categoryCode
  302. );
  303. return (
  304. (outputItem ? outputItem.reportQuantity : 0) +
  305. (row.unit || '')
  306. );
  307. } else {
  308. // 产出为在制品 或 BOM标准产出
  309. // 查询基数
  310. if (!this.materialQuotaInfo) {
  311. return '0' + (row.unit || '');
  312. }
  313. const materialItem = this.materialQuotaInfo.materialQuota.find(
  314. (item) => item.categoryCode === row.categoryCode
  315. );
  316. if (!materialItem) {
  317. return '0' + (row.unit || '');
  318. }
  319. // 需要的物料数量比例
  320. let count =
  321. materialItem.count / this.materialQuotaInfo.baseCount;
  322. // 产出清单的报工数量 当次报工+累计报工
  323. const outputItem = this.localOutputDetails[0];
  324. if (!outputItem) {
  325. return '0' + (row.unit || '');
  326. }
  327. // 当次消耗
  328. let needQuantity = outputItem.reportQuantity * count;
  329. return needQuantity + (row.unit || '');
  330. }
  331. }
  332. },
  333. {
  334. label: '累计消耗数量',
  335. prop: '',
  336. minWidth: 120,
  337. formatter: (row) => {
  338. if (this.outputType == 1) {
  339. const outputItem = this.localOutputDetails.find(
  340. (item) => item.categoryCode == row.categoryCode
  341. );
  342. if (!outputItem) {
  343. return row.sumReportQuantity + (row.unit || '');
  344. }
  345. let count = 0;
  346. if (this.executeStatus === 2) {
  347. // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
  348. count =
  349. row.sumReportQuantity -
  350. (outputItem.reportQuantityCopy - outputItem.reportQuantity);
  351. } else {
  352. count = row.sumReportQuantity + outputItem.reportQuantity;
  353. }
  354. return count + (row.unit || '');
  355. } else {
  356. // 产出为在制品 或 BOM标准产出 累计消耗数量
  357. if (!this.materialQuotaInfo) {
  358. return row.sumReportQuantity + (row.unit || '');
  359. }
  360. const materialItem = this.materialQuotaInfo.materialQuota.find(
  361. (item) => item.categoryCode === row.categoryCode
  362. );
  363. if (!materialItem) {
  364. return row.sumReportQuantity + (row.unit || '');
  365. }
  366. const outputItem = this.localOutputDetails[0];
  367. if (!outputItem) {
  368. return row.sumReportQuantity + (row.unit || '');
  369. }
  370. // 单位产出所需物料比例
  371. const proportion =
  372. materialItem.count / this.materialQuotaInfo.baseCount;
  373. let cumulativeOutputQuantity = 0;
  374. if (this.executeStatus === 2) {
  375. // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
  376. cumulativeOutputQuantity =
  377. outputItem.sumReportQuantity -
  378. (outputItem.reportQuantityCopy - outputItem.reportQuantity);
  379. } else {
  380. cumulativeOutputQuantity =
  381. outputItem.sumReportQuantity + outputItem.reportQuantity;
  382. }
  383. const needQuantity = cumulativeOutputQuantity * proportion;
  384. // 已消耗数量转换
  385. // const sumReportQuantity = row.sumReportQuantity * proportion;
  386. const sumReportQuantity = row.sumReportQuantity;
  387. return needQuantity + sumReportQuantity + (row.unit || '');
  388. }
  389. }
  390. }
  391. ];
  392. if (this.outputType == 1) {
  393. list.push({
  394. prop: '',
  395. label: '选择',
  396. slot: 'selectColumn',
  397. align: 'center',
  398. fixed: 'right'
  399. });
  400. }
  401. return list;
  402. }
  403. },
  404. data() {
  405. return {
  406. localPickDetails: [],
  407. localOutputDetails: [],
  408. // bom配置的 标准产出信息
  409. materialQuotaInfo: null,
  410. // 产出清单表头
  411. outputDetailsColumns: [
  412. {
  413. width: 45,
  414. type: 'index',
  415. columnKey: 'index',
  416. align: 'center'
  417. },
  418. {
  419. label: '类型',
  420. prop: 'categoryLevelNamePath',
  421. minWidth: 120
  422. },
  423. {
  424. label: '编码',
  425. prop: 'categoryCode',
  426. minWidth: 120
  427. },
  428. {
  429. label: '名称',
  430. prop: 'categoryName',
  431. minWidth: 120
  432. },
  433. {
  434. prop: 'model',
  435. label: '型号',
  436. align: 'center',
  437. showOverflowTooltip: true
  438. },
  439. {
  440. prop: 'specifications',
  441. label: '规格',
  442. align: 'center',
  443. width: 160,
  444. showOverflowTooltip: true
  445. },
  446. {
  447. prop: 'brandNo',
  448. label: '牌号',
  449. align: 'center'
  450. },
  451. {
  452. label: '工序名称',
  453. prop: 'produceTaskName',
  454. minWidth: 120
  455. },
  456. {
  457. label: '当次报工数量',
  458. prop: 'reportQuantity',
  459. minWidth: 160,
  460. slot: 'reportQuantity'
  461. },
  462. {
  463. label: '当次合格数量',
  464. prop: 'qualifiedQuantity',
  465. minWidth: 160,
  466. slot: 'qualifiedQuantity'
  467. },
  468. {
  469. label: '当次不合格数量',
  470. prop: 'noQualifiedQuantity',
  471. minWidth: 160,
  472. slot: 'noQualifiedQuantity'
  473. },
  474. {
  475. label: '不合格原因',
  476. prop: 'msg',
  477. minWidth: 160,
  478. slot: 'msg'
  479. },
  480. {
  481. label: '已报工数量',
  482. prop: 'sumReportQuantity',
  483. minWidth: 120,
  484. formatter(row) {
  485. return (row.sumReportQuantity || 0) + row.unit;
  486. }
  487. },
  488. {
  489. label: '合格总数',
  490. prop: 'sumQualifiedQuantity',
  491. minWidth: 120,
  492. formatter(row) {
  493. return (row.sumQualifiedQuantity || 0) + (row.unit || '');
  494. }
  495. },
  496. {
  497. label: '不合格总数',
  498. prop: 'sumNoQualifiedQuantity',
  499. minWidth: 120,
  500. formatter(row) {
  501. return (row.sumNoQualifiedQuantity || 0) + (row.unit || '');
  502. }
  503. }
  504. ]
  505. };
  506. },
  507. mounted() {
  508. if (this.bomCategoryId && this.produceTaskId) {
  509. this.getMaterialQuotaInfo();
  510. }
  511. },
  512. methods: {
  513. // 选择物料
  514. openMaterialModal() {
  515. this.$refs.materialModalRef.open(
  516. {
  517. workOrderId: this.workOrderId,
  518. ruleId: this.ruleId,
  519. produceTaskId: this.produceTaskId
  520. },
  521. // ...this.localPickDetails, ...this.preOutputDetails
  522. []
  523. );
  524. },
  525. materialConfirm(data) {
  526. // 选择物料后添加
  527. console.log('data', data);
  528. data.forEach((newItem) => {
  529. const index = this.localPickDetails.findIndex(
  530. (item) => item.categoryCode === newItem.categoryCode
  531. );
  532. if (index !== -1) {
  533. // 存在则替换数量
  534. this.localPickDetails[index].quantity = newItem.quantity;
  535. } else {
  536. const sumItem = this.sumOutputDetails.find(
  537. (item) => item.categoryCode === newItem.categoryCode
  538. );
  539. let sumQualifiedQuantity = 0;
  540. let sumNoQualifiedQuantity = 0;
  541. let sumReportQuantity = 0;
  542. if (sumItem) {
  543. sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
  544. sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
  545. sumReportQuantity = sumItem.sumReportQuantity;
  546. }
  547. // 不存在则添加
  548. this.localPickDetails.push({
  549. ...newItem,
  550. reportQuantity: 0,
  551. ruleId: this.ruleId,
  552. bomCategoryId: this.bomCategoryId,
  553. produceTaskId: this.produceTaskId,
  554. produceTaskInstanceId: this.produceTaskInstanceId,
  555. produceTaskName: this.produceTaskName,
  556. workOrderId: this.workOrderId,
  557. sumQualifiedQuantity,
  558. sumNoQualifiedQuantity,
  559. sumReportQuantity
  560. });
  561. }
  562. });
  563. this.$emit('update:pickDetails', this.localPickDetails);
  564. },
  565. setMaterialQuotaInfo() {
  566. console.log('this.materialQuotaInfo', this.materialQuotaInfo);
  567. if (this.materialQuotaInfo && this.materialQuotaInfo.standardOutput) {
  568. const sumItem = this.sumOutputDetails.find(
  569. (i) =>
  570. i.categoryCode ===
  571. this.materialQuotaInfo.standardOutput.categoryCode
  572. );
  573. let sumQualifiedQuantity = 0;
  574. let sumNoQualifiedQuantity = 0;
  575. let sumReportQuantity = 0;
  576. if (sumItem) {
  577. sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
  578. sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
  579. sumReportQuantity = sumItem.sumReportQuantity;
  580. }
  581. // 赋值产出
  582. this.localOutputDetails = [
  583. {
  584. ...this.materialQuotaInfo.standardOutput,
  585. id: null,
  586. reportQuantity: 0,
  587. reportQuantityCopy: 0,
  588. qualifiedQuantity: 0,
  589. noQualifiedQuantity: 0,
  590. msg: '',
  591. sumReportQuantity,
  592. sumQualifiedQuantity,
  593. sumNoQualifiedQuantity,
  594. ruleId: this.ruleId,
  595. outputType: this.outputType,
  596. produceTaskId: this.produceTaskId,
  597. produceTaskInstanceId: this.produceTaskInstanceId,
  598. produceTaskName: this.produceTaskName,
  599. workOrderId: this.workOrderId
  600. }
  601. ];
  602. this.$emit('update:outputDetails', this.localOutputDetails);
  603. } else {
  604. this.$message.warning('未配置BOM标准产出信息');
  605. }
  606. },
  607. // 获取bom的产出清单
  608. async getMaterialQuotaInfo() {
  609. if (this.bomCategoryId && this.produceTaskId) {
  610. const data = await getMaterialQuotaInfo(
  611. this.bomCategoryId,
  612. this.produceTaskId
  613. );
  614. console.log('this.materialQuotaInfo', data);
  615. if (JSON.stringify(data) === '{}') {
  616. this.materialQuotaInfo = null;
  617. return;
  618. }
  619. this.materialQuotaInfo = data;
  620. }
  621. },
  622. // qualifiedQuantityMax 最大合格数量
  623. qualifiedQuantityMax(row) {
  624. return row.reportQuantity;
  625. },
  626. noQualifiedQuantityMax(row) {
  627. return row.reportQuantity;
  628. },
  629. selectedChange(row) {
  630. console.log('row', row);
  631. if (this.outputType != 1) return;
  632. if (row.selected) {
  633. // 判断是否存在
  634. const index = this.localOutputDetails.findIndex(
  635. (item) => item.categoryId === row.categoryId
  636. );
  637. if (index === -1) {
  638. const sumItem = this.sumOutputDetails.find(
  639. (i) => i.categoryCode === row.categoryCode
  640. );
  641. let sumQualifiedQuantity = 0;
  642. let sumNoQualifiedQuantity = 0;
  643. let sumReportQuantity = 0;
  644. if (sumItem) {
  645. sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
  646. sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
  647. sumReportQuantity = sumItem.sumReportQuantity;
  648. }
  649. // 不存在则添加
  650. this.localOutputDetails.push({
  651. ...row,
  652. id: null,
  653. reportQuantity: 0,
  654. reportQuantityCopy: 0,
  655. qualifiedQuantity: 0,
  656. noQualifiedQuantity: 0,
  657. msg: '',
  658. sumReportQuantity,
  659. sumQualifiedQuantity,
  660. sumNoQualifiedQuantity,
  661. ruleId: this.ruleId,
  662. outputType: this.outputType,
  663. bomCategoryId: this.bomCategoryId,
  664. produceTaskId: this.produceTaskId,
  665. produceTaskInstanceId: this.produceTaskInstanceId,
  666. produceTaskName: this.produceTaskName,
  667. workOrderId: this.workOrderId
  668. });
  669. } else {
  670. this.$message.warning('该物料已存在于产出清单中');
  671. }
  672. } else {
  673. // 取消选择则删除
  674. this.localOutputDetails = this.localOutputDetails.filter(
  675. (item) => !(item.categoryId === row.categoryId)
  676. );
  677. }
  678. this.$emit('update:outputDetails', this.localOutputDetails);
  679. },
  680. // getCategoryAndLevelByCategoryId 获取产品
  681. async getCategoryAndLevelByCategoryId() {
  682. const data = await getCategoryAndLevelByCategoryId(this.categoryId);
  683. if (data) {
  684. const sumItem = this.sumOutputDetails.find(
  685. (i) => i.categoryCode == data.categoryCode
  686. );
  687. let sumQualifiedQuantity = 0;
  688. let sumNoQualifiedQuantity = 0;
  689. let sumReportQuantity = 0;
  690. if (sumItem) {
  691. sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
  692. sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
  693. sumReportQuantity = sumItem.sumReportQuantity;
  694. }
  695. this.localOutputDetails = [
  696. {
  697. ...data,
  698. id: null,
  699. reportQuantity: 0,
  700. reportQuantityCopy: 0,
  701. qualifiedQuantity: 0,
  702. noQualifiedQuantity: 0,
  703. msg: '',
  704. sumReportQuantity,
  705. sumQualifiedQuantity,
  706. sumNoQualifiedQuantity,
  707. ruleId: this.ruleId,
  708. outputType: this.outputType,
  709. produceTaskId: this.produceTaskId,
  710. produceTaskInstanceId: this.produceTaskInstanceId,
  711. produceTaskName: this.produceTaskName,
  712. workOrderId: this.workOrderId
  713. }
  714. ];
  715. }
  716. this.$emit('update:outputDetails', this.localOutputDetails);
  717. console.log('this.localOutputDetails', this.localOutputDetails);
  718. console.log('this.materialQuotaInfo', this.materialQuotaInfo);
  719. },
  720. // 计算报工数量最大值
  721. reportQuantitymax(row) {
  722. if (this.outputType == 1) {
  723. // 查询物料本身
  724. const pickItem = this.localPickDetails.find(
  725. (item) => item.categoryCode === row.categoryCode
  726. );
  727. // 物料本身 不能超过已报工数量减领料数量
  728. // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
  729. if (this.executeStatus === 2) {
  730. return (
  731. pickItem.quantity -
  732. (pickItem.sumReportQuantity - row.reportQuantityCopy)
  733. );
  734. } else {
  735. return pickItem.quantity - pickItem.sumReportQuantity;
  736. }
  737. }
  738. if (row.outputType == 2 || row.outputType == 3) {
  739. // 基于物料配额限制最大可报工数量(兼容已缓存/已保存一次的编辑场景,并区分已执行状态)
  740. if (!this.materialQuotaInfo) return Infinity;
  741. const quota = this.materialQuotaInfo.materialQuota || [];
  742. if (!quota.length) return Infinity;
  743. const isExecuted = this.executeStatus === 2;
  744. const { baseCount } = this.materialQuotaInfo;
  745. if (!baseCount) return Infinity;
  746. // 计算每个物料的最大可报工数量
  747. const maxQuantities = quota.map((item) => {
  748. const pickItem = this.localPickDetails.find(
  749. (p) => p.categoryCode === item.categoryCode
  750. );
  751. if (!pickItem) {
  752. return Infinity;
  753. }
  754. // 单位产出所需物料比例
  755. const proportion = item.count / baseCount;
  756. // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
  757. let consumedQuantity = isExecuted
  758. ? row.sumReportQuantity - row.reportQuantityCopy
  759. : row.sumReportQuantity;
  760. // 已执行的比例换算,换算为需要多少物料数量
  761. const consumedProportion = consumedQuantity * proportion;
  762. // 最大可报工数量
  763. const maxQuantity =
  764. (pickItem.quantity - consumedProportion) / proportion;
  765. // 向下取整
  766. return Math.floor(maxQuantity);
  767. });
  768. // 返回最小的那个物料的最大可报工数量
  769. return Math.min(...maxQuantities);
  770. }
  771. return Infinity;
  772. },
  773. // 判断生成产出清单的物料数量是合格
  774. async validateOutputQuantities() {
  775. if (this.localOutputDetails.length == 0) {
  776. this.$message.warning(`产出清单不能为空`);
  777. return false;
  778. }
  779. for (const item of this.localOutputDetails) {
  780. if (!item.reportQuantity) {
  781. this.$message.warning(
  782. `请填写产出清单【${item.categoryName}】的当次报工数量`
  783. );
  784. return false;
  785. }
  786. // 判断当次合格数量 和 不合格数量 之和需要等于 报工数量
  787. if (!item.qualifiedQuantity) {
  788. this.$message.warning(
  789. `请填写产出清单【${item.categoryName}】的当次合格数量`
  790. );
  791. return false;
  792. }
  793. }
  794. if (this.outputType == 1) {
  795. if (
  796. this.localPickDetails.length == 0 &&
  797. this.preOutputDetails.length == 0
  798. ) {
  799. this.$message.warning(`物料清单不能为空`);
  800. return false;
  801. }
  802. for (const item of this.localOutputDetails) {
  803. const pickitem = this.localPickDetails.find(
  804. (pick) => pick.categoryCode == item.categoryCode
  805. );
  806. const prePickitem = this.preOutputDetails.find(
  807. (pick) => pick.categoryCode == item.categoryCode
  808. );
  809. if (pickitem == null && prePickitem == null) {
  810. this.$message.warning(
  811. `所需物料【${item.categoryName}】未在物料清单中找到`
  812. );
  813. return false;
  814. }
  815. if (item.reportQuantity > item.quantity) {
  816. this.$message.error(
  817. `物料【${item.categoryName}】的报工数量不能超过领料数量`
  818. );
  819. return false;
  820. }
  821. }
  822. }
  823. return true;
  824. },
  825. // 当次报工修改
  826. reportQuantityChange(row) {
  827. // 同步当前合格数量 和 不合格数量为0
  828. // 默认全部合格
  829. row.qualifiedQuantity = row.reportQuantity;
  830. row.noQualifiedQuantity = 0;
  831. this.$emit('update:outputDetails', this.localOutputDetails);
  832. },
  833. // qualifiedQuantityChange 当次合格数量变化 计算 noQualifiedQuantity不合格数量
  834. qualifiedQuantityChange(row) {
  835. row.noQualifiedQuantity = row.reportQuantity - row.qualifiedQuantity;
  836. this.$emit('update:outputDetails', this.localOutputDetails);
  837. },
  838. // 不合格数量变化
  839. noQualifiedQuantityChange(row) {
  840. row.qualifiedQuantity = row.reportQuantity - row.noQualifiedQuantity;
  841. this.$emit('update:outputDetails', this.localOutputDetails);
  842. },
  843. localOutputDetailsRefresh() {
  844. if (this.outputType == 1) {
  845. this.$emit('refresh', 'output');
  846. } else if (this.outputType == 2) {
  847. this.getCategoryAndLevelByCategoryId();
  848. } else {
  849. this.setMaterialQuotaInfo();
  850. }
  851. }
  852. }
  853. };
  854. </script>
  855. <style></style>