edit.vue 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <header-title title="基本信息">
  5. <el-button @click="cancel">返回</el-button>
  6. <el-button
  7. type="primary"
  8. @click="save"
  9. :loading="loading"
  10. v-if="type != 'detail'"
  11. >保存</el-button
  12. >
  13. <el-button
  14. type="primary"
  15. @click="handleReporting"
  16. :loading="loading"
  17. v-if="type != 'detail'"
  18. >报工完成</el-button
  19. >
  20. </header-title>
  21. <base-info
  22. ref="baseInfoRefs"
  23. v-if="form"
  24. :form="form"
  25. :btnType="type"
  26. :qualityType1="qualityType"
  27. @changeModel="changeModel"
  28. @changeNumber="changeNumber"
  29. @quantityAssignment="quantityAssignment"
  30. @changeInspectionStandardsModel="changeInspectionStandardsModel"
  31. @quantityCalculation="quantityCalculation"
  32. ></base-info>
  33. <header-title title="样品信息"></header-title>
  34. <el-form label-width="110px">
  35. <el-row>
  36. <el-col :span="6">
  37. <el-form-item label="样品合格数:" prop="sampleQualifiedNumber">
  38. <el-input
  39. type="number"
  40. :min="0"
  41. disabled
  42. v-model="form.sampleQualifiedNumber"
  43. placeholder=""
  44. ></el-input>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="6">
  48. <el-form-item label="样品不合格数:" prop="sampleNoQualifiedNumber">
  49. <el-input
  50. type="number"
  51. :min="0"
  52. disabled
  53. v-model="form.sampleNoQualifiedNumber"
  54. placeholder=""
  55. ></el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="6">
  59. <el-form-item label="样品合格率:" prop="sampleQualificationRate">
  60. <el-input v-model="form.sampleQualificationRate" disabled />
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="6">
  64. <el-form-item
  65. label="样品不合格率:"
  66. prop="sampleNoQualificationRate"
  67. >
  68. <el-input v-model="form.sampleNoQualificationRate" disabled />
  69. </el-form-item>
  70. </el-col>
  71. </el-row>
  72. <el-row>
  73. <el-col :span="6">
  74. <el-form-item label="样品类型:" prop="samplesType">
  75. <el-input disabled :value="sampletypeVal(form.conditionType)" />
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="6">
  79. <el-form-item label="样品数量:" prop="sampleQuantity">
  80. <el-input type="number" disabled v-model="form.sampleQuantity" />
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="6">
  84. <el-form-item label="样品重量:" prop="sampleWeight">
  85. <el-input type="number" disabled v-model="form.sampleWeight" />
  86. </el-form-item>
  87. </el-col>
  88. </el-row>
  89. </el-form>
  90. <quality-content-tabs
  91. v-if="form.id"
  92. ref="tabsRef"
  93. :type="type"
  94. :ids="this.$route.query.id"
  95. :sample-list="sampleList"
  96. :activeName="activeName"
  97. :scheme-list="schemeList"
  98. :loading="loading"
  99. :form="form"
  100. :productId="productId"
  101. :status="statusType"
  102. @handleSelectionChange="handleSelectionChange1"
  103. @batch-quality="batchQuality"
  104. @batch-dispose="batchDispose"
  105. @handleDetail="handleDetail"
  106. @inputWeight="inputWeight"
  107. @handleDispose="handleDispose"
  108. @changeSamUnit="changeSamUnit"
  109. @handleSample1="handleSample1"
  110. @handleSampleSubmit="handleSampleSubmit"
  111. @getConditionType="getConditionType"
  112. @countQualityResults="countQualityResults"
  113. @setSchemeList="setSchemeList"
  114. @sampleListChange="sampleListChange"
  115. />
  116. </el-card>
  117. <sampleListDialog
  118. ref="detailRef"
  119. @handleConfirm="handleConfirm"
  120. @handleDispose="handleDispose"
  121. ></sampleListDialog>
  122. <sampleDisposeDialog
  123. v-if="sampleDisposeVisble"
  124. :sampleDisposeVisble.sync="sampleDisposeVisble"
  125. ref="disposeRef"
  126. @handleDisposeConfirm="handleDisposeConfirm"
  127. :rowData="rowData"
  128. @close="closeDispose"
  129. @handleDispose="handleDispose"
  130. ></sampleDisposeDialog>
  131. </div>
  132. </template>
  133. <script>
  134. import baseInfo from './components/baseInfo.vue';
  135. // import QualityContentTabs from './components/QualityContentTabs.vue';
  136. import QualityContentTabs from './components/newQualityContentTabs.vue';
  137. import { getCode, getCodeList } from '@/api/login';
  138. import {
  139. save,
  140. update,
  141. getById,
  142. exeReportWork,
  143. queryQualitySamplContent,
  144. queryQualityTempleContent,
  145. queryQualityInventory
  146. } from '@/api/inspectionWork';
  147. import dictMixins from '@/mixins/dictMixins';
  148. // import term from './term';
  149. import sampleListDialog from './components/sampleListDialog.vue';
  150. import sampleDisposeDialog from './components/sampleDisposeDialog.vue';
  151. import { finishPageTab } from '@/utils/page-tab-util';
  152. export default {
  153. components: {
  154. baseInfo,
  155. QualityContentTabs,
  156. sampleListDialog,
  157. sampleDisposeDialog
  158. },
  159. mixins: [dictMixins],
  160. computed: {
  161. sampletypeVal() {
  162. return (row) => {
  163. if (row == 1) {
  164. return '整样';
  165. }
  166. return '小样';
  167. };
  168. }
  169. },
  170. // p:{
  171. // sampletypeVal()=>{
  172. // return
  173. // }
  174. // },
  175. data() {
  176. const defaultForm = function () {
  177. return {
  178. code: '',
  179. qualityType: null,
  180. qualityModeproduceRoutingId: '',
  181. produceRoutingName: '',
  182. produceTaskId: '',
  183. produceTaskName: '',
  184. productName: '',
  185. productCode: '',
  186. batchNo: '',
  187. specification: '',
  188. modelType: '',
  189. brandNo: '',
  190. total: '',
  191. qualifiedNumber: '',
  192. noQualifiedNumber: '',
  193. groupId: '',
  194. groupName: '',
  195. qualityId: '',
  196. qualityName: '',
  197. qualityTime: '',
  198. hours: '',
  199. qualificationRate: '',
  200. noQualificationRate: '',
  201. totalWeight: '',
  202. sampleNumber: '',
  203. imgUrl: [],
  204. qualityTimeStart: '',
  205. qualityTimeEnd: '',
  206. templateList: [],
  207. qualityIdList: [],
  208. sampleMeasureUnit: '',
  209. conditionType: null
  210. };
  211. };
  212. return {
  213. rowData: null,
  214. defaultForm,
  215. sampleDisposeVisble: false,
  216. // 表单数据
  217. form: { ...defaultForm() },
  218. voList: [],
  219. // 表单验证规则
  220. categoryParamList: [],
  221. type: '',
  222. title: '',
  223. loading: false,
  224. tabTaskId: null,
  225. // activeName: '2',
  226. packingList: [],
  227. // 样品清单,处置,批量处置,批量质检,质检的操作
  228. sampleList: [],
  229. schemeList: [],
  230. inventoryList: [],
  231. activeName: '1',
  232. isValid: true,
  233. isStatus: true,
  234. SampleListbyReportList: [],
  235. qualityTimeStart: '',
  236. isReportProcessProduce: false,
  237. addStatus: [],
  238. statusType: false
  239. };
  240. },
  241. watch: {
  242. '$route.query.id': {
  243. handler(id) {
  244. if (id) {
  245. this.getDetail();
  246. } else {
  247. this.form = { ...defaultForm() };
  248. }
  249. }
  250. },
  251. // 样品清单
  252. sampleList: {
  253. handler(newVal) {
  254. if (!newVal || newVal.length == 0) {
  255. return;
  256. }
  257. console.log(newVal, 'newVal 12');
  258. // 默认赋值质检结果
  259. this.setInspectionResults(newVal);
  260. },
  261. deep: true,
  262. immediate: true
  263. },
  264. form: {
  265. handler(newVal) {
  266. console.log(newVal, 'newVal 新的form');
  267. },
  268. deep: true,
  269. immediate: true
  270. },
  271. 'form.qualityResults': {
  272. handler(newVal, oldVal) {
  273. if (!newVal && oldVal) {
  274. this.form.qualityResults = oldVal;
  275. }
  276. }
  277. }
  278. },
  279. created() {
  280. this.open();
  281. if (this.$route.query.id) {
  282. this.getDetail();
  283. }
  284. },
  285. methods: {
  286. //合格与不合格数变化处理逻辑
  287. quantityCalculation(val) {
  288. this.$refs.tabsRef.setSampleList(val, this.form.total);
  289. },
  290. setInspectionResults(list) {
  291. this.$nextTick(() => {
  292. let qualityResults = this.form.qualityResults;
  293. let showArrange = this.$refs.baseInfoRefs.showArrange;
  294. if (showArrange == '1') return;
  295. if (qualityResults == null || qualityResults == undefined) {
  296. for (let i = 0; i < list.length; i++) {
  297. let el = list[i];
  298. if (el.qualityResults == 2) {
  299. this.$set(this.form, 'qualityResults', 2);
  300. return;
  301. }
  302. }
  303. this.$set(this.form, 'qualityResults', 1);
  304. console.log(list, 'list');
  305. console.log(this.form.qualityResults, '质检结果');
  306. }
  307. });
  308. },
  309. //
  310. calculate(list) {
  311. if (list.length == 0) {
  312. this.form.sampleQuantity = 0;
  313. this.form.sampleWeight = 0;
  314. }
  315. let sampleQuantity = 0; // 样品数量
  316. let sampleWeight = 0; // 样品重量
  317. let sampleQualifiedNumber = 0; // 样品合格数
  318. let sampleNoQualifiedNumber = 0; // 样品不合格数
  319. list.forEach((el) => {
  320. sampleQuantity += el.measureQuantity - 0;
  321. sampleWeight += el.weight - 0;
  322. if (el.qualityResults != 2) {
  323. sampleQualifiedNumber += el.measureQuantity - 0;
  324. } else {
  325. sampleNoQualifiedNumber += el.measureQuantity - 0;
  326. }
  327. });
  328. // 计算合格率和不合格率(百分比形式)
  329. let sampleQualificationRate = '';
  330. let sampleNoQualificationRate = '';
  331. if (
  332. (sampleQualifiedNumber || sampleQualifiedNumber == 0) &&
  333. sampleQuantity !== 0
  334. ) {
  335. sampleQualificationRate =
  336. ((sampleQualifiedNumber / sampleQuantity) * 100).toFixed(2) || '';
  337. sampleNoQualificationRate =
  338. ((sampleNoQualifiedNumber / sampleQuantity) * 100).toFixed(2) || '';
  339. }
  340. if (sampleQualificationRate || sampleQualificationRate == '0.00') {
  341. if (isNaN(sampleQualificationRate)) {
  342. sampleQualificationRate = '0%';
  343. } else {
  344. sampleQualificationRate = sampleQualificationRate + '%';
  345. }
  346. }
  347. if (sampleNoQualificationRate || sampleNoQualificationRate == '0.00') {
  348. if (isNaN(sampleNoQualificationRate)) {
  349. sampleNoQualificationRate = '0%';
  350. } else {
  351. sampleNoQualificationRate = sampleNoQualificationRate + '%';
  352. }
  353. }
  354. // let resultsTotal = this.form.total - sampleQuantity;
  355. // if (sampleQuantity == sampleQualifiedNumber) {
  356. // // this.$set(this.form, 'qualifiedNumber', resultsTotal);
  357. // // this.$set(this.form, 'noQualifiedNumber', 0);
  358. // this.$set(this.form, 'qualificationRate', '100%');
  359. // this.$set(this.form, 'noQualificationRate', '0');
  360. // this.$set(this.form, 'qualityResults', 1);
  361. // } else {
  362. // // this.$set(this.form, 'noQualifiedNumber', resultsTotal);
  363. // // this.$set(this.form, 'qualifiedNumber', 0);
  364. // this.$set(this.form, 'qualificationRate', '0');
  365. // this.$set(this.form, 'noQualificationRate', '100%');
  366. // this.$set(this.form, 'qualityResults', 2);
  367. // }
  368. this.$nextTick(() => {
  369. let showArrange = this.$refs.baseInfoRefs.showArrange;
  370. if (showArrange != '1' && sampleQuantity == sampleQualifiedNumber) {
  371. this.$set(this.form, 'qualificationRate', '100%');
  372. this.$set(this.form, 'noQualificationRate', '0');
  373. this.$set(this.form, 'qualityResults', 1);
  374. }
  375. if (showArrange != '1' && sampleQuantity != sampleQualifiedNumber) {
  376. this.$set(this.form, 'qualificationRate', '0');
  377. this.$set(this.form, 'noQualificationRate', '100%');
  378. this.$set(this.form, 'qualityResults', 2);
  379. }
  380. });
  381. // this.$set(this.form, 'resultsTotal', resultsTotal);
  382. this.$set(
  383. this.form,
  384. 'sampleQualificationRate',
  385. sampleQualificationRate
  386. );
  387. this.$set(
  388. this.form,
  389. 'sampleNoQualificationRate',
  390. sampleNoQualificationRate
  391. );
  392. this.$set(this.form, 'sampleQuantity', sampleQuantity);
  393. this.$set(this.form, 'sampleWeight', sampleWeight);
  394. this.$set(this.form, 'sampleQualifiedNumber', sampleQualifiedNumber);
  395. this.$set(
  396. this.form,
  397. 'sampleNoQualifiedNumber',
  398. sampleNoQualifiedNumber
  399. );
  400. // 数量赋值
  401. this.quantityAssignment();
  402. },
  403. // 计算合格数不合格数
  404. quantityAssignment() {
  405. let noQualifiedNumber = 0;
  406. let qualifiedNumber = 0;
  407. let data = this.form;
  408. let total = data.total - 0;
  409. if (this.form.qualityResults == 2) {
  410. noQualifiedNumber = total - (data.sampleQualifiedNumber - 0);
  411. qualifiedNumber = total - noQualifiedNumber;
  412. } else {
  413. qualifiedNumber = total - (data.sampleNoQualifiedNumber - 0);
  414. noQualifiedNumber = total - qualifiedNumber;
  415. }
  416. this.$set(this.form, 'qualifiedNumber', qualifiedNumber);
  417. this.$set(this.form, 'noQualifiedNumber', noQualifiedNumber);
  418. this.$set(
  419. this.form,
  420. 'qualificationRate',
  421. ((qualifiedNumber / total) * 100).toFixed(2)+ '%'
  422. );
  423. this.$set(
  424. this.form,
  425. 'noQualificationRate',
  426. ((noQualifiedNumber / total) * 100).toFixed(2)+ '%'
  427. );
  428. },
  429. //切换检验方式
  430. changeModel(val, flag) {
  431. this.$refs.tabsRef.tableSelClear();
  432. this.sampleList = [];
  433. this.$refs.tabsRef.tabsChange('1');
  434. this.$refs.tabsRef.tabsConditionType(null);
  435. this.form.qualityMode = val;
  436. //检验方式 全检
  437. if (this.form.qualityMode == 1) {
  438. this.activeName = '2';
  439. this.form.sampleNumber = '';
  440. this.changeGetSampleList(this.inventoryList);
  441. } else {
  442. this.activeName = '1';
  443. if (!flag) {
  444. this.sampleList = [];
  445. }
  446. }
  447. this.calculate([]);
  448. },
  449. //根据类型判断样品清单现实列表数据
  450. async getProSamList(list) {
  451. //生产检验
  452. if (this.qualityType == 2) {
  453. if (this.form.qualityMode != null) {
  454. const ProductSampleList = [];
  455. for (const oldItem of list) {
  456. const count = oldItem.measureQuantity;
  457. const newMeasureQuantity = oldItem.measureQuantity / count;
  458. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  459. // 遍历新数组设置 qualityResults 默认值
  460. this.schemeList.forEach((item) => {
  461. if (typeof item === 'object' && item !== null) {
  462. item.qualityResults = 1; // 设置默认值
  463. }
  464. delete item.id;
  465. });
  466. delete oldItem.id;
  467. if (
  468. oldItem.qualitySampleTemplateList == undefined ||
  469. oldItem.qualitySampleTemplateList == null ||
  470. oldItem.qualitySampleTemplateList.length == 0
  471. ) {
  472. oldItem.qualitySampleTemplateList = JSON.parse(
  473. JSON.stringify(this.schemeList)
  474. );
  475. for (let i = 0; i < count; i++) {
  476. ProductSampleList.push({
  477. ...oldItem,
  478. measureQuantity: newMeasureQuantity,
  479. weight: newWeight,
  480. sampleCode: await this.getSampleCode(),
  481. qualitySampleTemplateList: JSON.parse(
  482. JSON.stringify(this.schemeList)
  483. )
  484. });
  485. }
  486. this.sampleList = ProductSampleList;
  487. this.calculate(this.sampleList);
  488. const pNum = ProductSampleList.reduce((sum, item) => {
  489. return sum + Number(item.weight || 0);
  490. }, 0);
  491. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  492. } else {
  493. for (let i = 0; i < count; i++) {
  494. ProductSampleList.push({
  495. ...oldItem,
  496. measureQuantity: newMeasureQuantity,
  497. weight: newWeight,
  498. sampleCode: await this.getSampleCode(),
  499. qualitySampleTemplateList: JSON.parse(
  500. JSON.stringify(oldItem.qualitySampleTemplateList)
  501. )
  502. });
  503. }
  504. this.sampleList = ProductSampleList;
  505. this.calculate(this.sampleList);
  506. const pNum = ProductSampleList.reduce((sum, item) => {
  507. return sum + Number(item.weight || 0);
  508. }, 0);
  509. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  510. }
  511. }
  512. }
  513. } else {
  514. // this.sampleList = list;
  515. this.sampleList = this.addStatus;
  516. }
  517. },
  518. // 创建计量数量为1的样品清单函数,用于计数类型的
  519. async createSampleList(list) {
  520. if (this.form.qualityMode != null) {
  521. this.$message.closeAll();
  522. this.$message('正在生成样品清单');
  523. const ProductSampleList = [];
  524. for (const oldItem of list) {
  525. const count = oldItem.measureQuantity ? oldItem.measureQuantity : 1;
  526. const newMeasureQuantity = oldItem.measureQuantity / count;
  527. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  528. // 遍历新数组设置 qualityResults 默认值
  529. this.schemeList.forEach((item) => {
  530. if (typeof item === 'object' && item !== null) {
  531. item.qualityResults = 1; // 设置默认值
  532. }
  533. delete item.id;
  534. });
  535. delete oldItem.id;
  536. if (
  537. oldItem.qualitySampleTemplateList == undefined ||
  538. oldItem.qualitySampleTemplateList == null ||
  539. oldItem.qualitySampleTemplateList.length == 0
  540. ) {
  541. oldItem.qualitySampleTemplateList = JSON.parse(
  542. JSON.stringify(this.schemeList)
  543. );
  544. for (let i = 0; i < count; i++) {
  545. ProductSampleList.push({
  546. ...oldItem,
  547. measureQuantity: newMeasureQuantity,
  548. weight: newWeight,
  549. sampleCode: await this.getSampleCode(),
  550. qualitySampleTemplateList: JSON.parse(
  551. JSON.stringify(this.schemeList)
  552. )
  553. });
  554. }
  555. this.sampleList = ProductSampleList;
  556. this.calculate(this.sampleList);
  557. const pNum = ProductSampleList.reduce((sum, item) => {
  558. return sum + Number(item.weight || 0);
  559. }, 0);
  560. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  561. } else {
  562. for (let i = 0; i < count; i++) {
  563. ProductSampleList.push({
  564. ...oldItem,
  565. measureQuantity: newMeasureQuantity,
  566. weight: newWeight,
  567. sampleCode: await this.getSampleCode(),
  568. qualitySampleTemplateList: JSON.parse(
  569. JSON.stringify(oldItem.qualitySampleTemplateList)
  570. )
  571. });
  572. }
  573. this.sampleList = ProductSampleList;
  574. this.calculate(this.sampleList);
  575. const pNum = ProductSampleList.reduce((sum, item) => {
  576. return sum + Number(item.weight || 0);
  577. }, 0);
  578. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  579. }
  580. }
  581. }
  582. },
  583. // 全检计量计重的样品清单函数
  584. async updatePackingList(list, sampleCount) {
  585. // for (let i = 0; i < list.length; i++) {
  586. // list[i].sampleCode = await this.getSampleCode();
  587. // }
  588. const dataList = [];
  589. let currentNum = sampleCount - list.length;
  590. let currentNum1 = sampleCount;
  591. // console.log(this.selectedList);
  592. let count = list ? list.length : 0;
  593. const codeList = await this.batchCodes(count);
  594. for (const [index, item] of list.entries()) {
  595. const qualitySampleTemplateList = item.qualitySampleTemplateList
  596. ?.length
  597. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  598. : JSON.parse(
  599. JSON.stringify(
  600. this.schemeList.map((item) => {
  601. item['qualityResults'] = 1;
  602. return item;
  603. })
  604. )
  605. );
  606. if (sampleCount >= list.length) {
  607. dataList.push({
  608. ...item,
  609. measureQuantity: item.measureQuantity, //作为计量数量
  610. // sampleCode: await this.getSampleCode(),
  611. sampleCode: codeList[index],
  612. qualitySampleTemplateList
  613. });
  614. }
  615. }
  616. this.sampleList = dataList;
  617. this.calculate(this.sampleList);
  618. this.sampleNumber = this.sampleList.length;
  619. },
  620. // 切换检验方式为全检后生成样品
  621. changeGetSampleList(list) {
  622. this.$message.closeAll();
  623. this.$message('正在生成样品清单');
  624. // // 计量类型1是数量,2是重量
  625. // if (this.form.inspectionStandards == 1) {
  626. // this.createSampleList(list);
  627. // }
  628. // if (this.form.inspectionStandards == 2) {
  629. // this.updatePackingList(list, this.form.total);
  630. // // this.handleWeightFullSample(this.form.total);
  631. // }
  632. this.updatePackingList(list, this.form.total);
  633. },
  634. //输入取样数量
  635. changeNumber(val) {
  636. if (this.form.qualityMode !== 2) {
  637. return;
  638. }
  639. if (val <= 0) {
  640. this.$refs.showPackingListTable.clearSelection();
  641. return;
  642. }
  643. if (this.qualityType == 2) {
  644. //生产检验的抽检逻辑
  645. if (val > this.packingList[0].measureQuantity) {
  646. this.$message.warning('取样数量不能大于来源清单的计量数量!');
  647. return;
  648. }
  649. const ProductSampleList = [];
  650. this.packingList.forEach((oldItem) => {
  651. const count = oldItem.measureQuantity;
  652. const newMeasureQuantity = oldItem.measureQuantity / count;
  653. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  654. delete oldItem.id;
  655. // 遍历新数组设置 qualityResults 默认值
  656. this.schemeList.forEach((item) => {
  657. if (typeof item === 'object' && item !== null) {
  658. item.qualityResults = 1; // 设置默认值
  659. }
  660. delete item.id;
  661. });
  662. for (let i = 0; i < val; i++) {
  663. ProductSampleList.push({
  664. ...oldItem,
  665. measureQuantity: newMeasureQuantity,
  666. weight: newWeight,
  667. qualitySampleTemplateList: JSON.parse(
  668. JSON.stringify(this.schemeList)
  669. )
  670. });
  671. }
  672. });
  673. this.sampleList = ProductSampleList;
  674. this.calculate(this.sampleList);
  675. const pNum = ProductSampleList.reduce((sum, item) => {
  676. return sum + Number(item.weight || 0);
  677. }, 0);
  678. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  679. } else {
  680. if (val > this.packingList.length) {
  681. this.$message.warning('取样数量不能大于物料明细总数!');
  682. return;
  683. }
  684. const rows = this.packingList.slice(0, val);
  685. rows.forEach((row) => {
  686. this.$refs.showPackingListTable.toggleRowSelection(row);
  687. });
  688. }
  689. },
  690. getNowDate() {
  691. let date = new Date(),
  692. obj = {
  693. year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
  694. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  695. strDate: date.getDate(), // 获取当前日(1-31)
  696. hour: date.getHours(), //获取当前小时(0 ~ 23)
  697. minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
  698. second: date.getSeconds() //获取当前秒数(0 ~ 59)
  699. };
  700. Object.keys(obj).forEach((key) => {
  701. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  702. });
  703. return obj;
  704. },
  705. //来源清单勾选事件
  706. handleSelectionChange1(selection) {
  707. if (this.form.qualityMode === 2) {
  708. this.selectedList = selection;
  709. this.activeName = '1';
  710. if (this.schemeList.length == 0) {
  711. for (let i = 0; i < selection.length; i++) {
  712. this.$set(selection[i], 'qualityStatus', 2);
  713. // 遍历新数组设置 qualityResults 默认值
  714. this.schemeList.forEach((item) => {
  715. if (typeof item === 'object' && item !== null) {
  716. item.qualityResults = 1; // 设置默认值
  717. }
  718. delete item.id;
  719. });
  720. this.$set(
  721. selection[i],
  722. 'qualitySampleTemplateList',
  723. JSON.parse(JSON.stringify(this.schemeList))
  724. );
  725. }
  726. }
  727. // this.sampleList = selection;
  728. //赋值取样数量
  729. this.form.sampleNumber = selection.length;
  730. }
  731. },
  732. async open() {
  733. this.type = this.$route.query.type;
  734. this.qualityType = this.$route.query.qualityType;
  735. this.title =
  736. this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
  737. if (this.type == 'add') {
  738. const code = await getCode('quality_work_order_code');
  739. this.form.code = code;
  740. } else {
  741. if (
  742. this.$route.query.qualityTimeStart != '' ||
  743. this.$route.query.qualityTimeStart != null ||
  744. this.$route.query.qualityTimeStart != undefined
  745. ) {
  746. this.qualityTimeStart = this.getNowTime();
  747. }
  748. }
  749. },
  750. getNowTime() {
  751. const nowDate = this.getNowDate();
  752. return (
  753. nowDate.year +
  754. '-' +
  755. nowDate.month +
  756. '-' +
  757. nowDate.strDate +
  758. ' ' +
  759. nowDate.hour +
  760. ':' +
  761. nowDate.minute +
  762. ':' +
  763. nowDate.second
  764. );
  765. },
  766. getNowTimes() {
  767. const nowDate = this.getNowDate();
  768. return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate;
  769. },
  770. async getDetail() {
  771. getById(this.$route.query.id).then((res) => {
  772. this.form = res.data;
  773. console.log(this.form, 'this.form');
  774. this.form.qualityIdList = this.form.qualityId
  775. ? this.form.qualityId.split(',')
  776. : [];
  777. this.productId = res.data.productId || '';
  778. this.statusType = this.form.status == 1 ? true : false;
  779. this.isReportProcessProduce =
  780. this.form.isReportProcessProduce == 1 ? true : false;
  781. this.tabTaskId =
  782. this.categoryParamList[0] && this.categoryParamList[0].id;
  783. if (this.form.groupId) {
  784. this.$nextTick(() => {
  785. this.$refs.baseInfoRefs?.getUserList({
  786. groupId: this.form.groupId
  787. });
  788. });
  789. }
  790. if (this.form.produceRoutingId) {
  791. this.$nextTick(() => {
  792. this.$refs.baseInfoRefs?.getTaskList();
  793. });
  794. }
  795. });
  796. // await this.queryQualityInventory()
  797. // 质检方案
  798. await this.queryQualityTempleContent();
  799. // 样品清单
  800. await this.queryQualitySamplContent();
  801. // 来源清单
  802. await this.getQueryQualityInventory();
  803. },
  804. // getNewData(val) {
  805. // console.log(val, '清单列表')
  806. // this.packingList = val
  807. // },
  808. // async queryQualityInventory() {
  809. // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
  810. // console.log(res, '清单列表');
  811. // this.packingList = res;
  812. // },
  813. changeSamUnit(val) {
  814. this.$set(this.form, 'sampleMeasureUnit', val);
  815. },
  816. async handleSample1(val, data) {
  817. this.sampleList = [];
  818. if (this.selectedList == undefined || this.selectedList.length == 0) {
  819. this.activeName = '1';
  820. this.$message.warning('请先选择样品!');
  821. return;
  822. }
  823. if (val == 1) {
  824. this.activeName = '2';
  825. if (this.form.isUnpack == 1) {
  826. for (let i = 0; i < this.selectedList.length; i++) {
  827. for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
  828. // 不拆计算每个重量
  829. let newWeight = parseFloat(
  830. (
  831. this.selectedList[i].weight /
  832. this.selectedList[i].measureQuantity
  833. ).toFixed(4)
  834. );
  835. if (
  836. this.selectedList[i].qualitySampleTemplateList == undefined ||
  837. this.selectedList[i].qualitySampleTemplateList == null ||
  838. this.selectedList[i].qualitySampleTemplateList.length == 0
  839. ) {
  840. this.sampleList.push({
  841. ...this.selectedList[i],
  842. sampleCode: await this.getSampleCode(),
  843. measureQuantity: 1,
  844. qualitySampleTemplateList: JSON.parse(
  845. JSON.stringify(this.schemeList)
  846. ),
  847. weight: newWeight || 0
  848. });
  849. } else {
  850. this.sampleList.push({
  851. ...this.selectedList[i],
  852. sampleCode: await this.getSampleCode(),
  853. measureQuantity: 1,
  854. qualitySampleTemplateList: JSON.parse(
  855. JSON.stringify(
  856. this.selectedList[i].qualitySampleTemplateList
  857. )
  858. ),
  859. weight: newWeight || 0
  860. });
  861. }
  862. }
  863. }
  864. } else if (this.form.isUnpack == 2) {
  865. // 不拆计算每个重量
  866. let newWeight = parseFloat(
  867. (
  868. this.selectedList[0].weight /
  869. this.selectedList[0].measureQuantity
  870. ).toFixed(4)
  871. );
  872. for (let i = 0; i < this.selectedList[0].measureQuantity; i++) {
  873. if (
  874. this.selectedList[0].qualitySampleTemplateList == undefined ||
  875. this.selectedList[0].qualitySampleTemplateList == null ||
  876. this.selectedList[0].qualitySampleTemplateList.length == 0
  877. ) {
  878. this.sampleList.push({
  879. ...this.selectedList[0],
  880. sampleCode: await this.getSampleCode(),
  881. measureQuantity: 1,
  882. qualitySampleTemplateList: JSON.parse(
  883. JSON.stringify(this.schemeList)
  884. ),
  885. weight: newWeight || 0
  886. });
  887. } else {
  888. this.sampleList.push({
  889. ...this.selectedList[0],
  890. sampleCode: await this.getSampleCode(),
  891. measureQuantity: 1,
  892. qualitySampleTemplateList: JSON.parse(
  893. JSON.stringify(
  894. this.selectedList[0].qualitySampleTemplateList
  895. )
  896. ),
  897. weight: newWeight || 0
  898. });
  899. }
  900. }
  901. }
  902. //取整样=勾选数据
  903. // this.sampleList = this.selectedList;
  904. this.$message.success('取样成功!');
  905. } else if (val == 2) {
  906. console.log(data, 'datadatadatadataxiaoyang');
  907. }
  908. this.calculate(this.sampleList);
  909. },
  910. async handleSampleSubmit(data, specifications) {
  911. this.sampleList = [];
  912. if (!this.selectedList || this.selectedList.length == 0) {
  913. this.$message.warning('请先选择样品!');
  914. return;
  915. }
  916. const measureQ = data.measureQ || 1;
  917. const unit = data.sampleUnit;
  918. const sampleCount = Number(data.portion);
  919. try {
  920. if (this.isStandard1OrWeightSample()) {
  921. // 新增校验 数量 取整样 ***
  922. if (this.form.conditionType == 1) {
  923. let isFlag = this.validateSampleQuantity(
  924. sampleCount,
  925. specifications
  926. );
  927. if (!isFlag) return;
  928. }
  929. // ***
  930. //抽检计量整样小样或者抽检计重小样
  931. if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
  932. return; //取样数量验证
  933. if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
  934. return; // 若计量单位为重量,还需验证总重量是否足够
  935. await this.getNewFullSampleList(
  936. Math.ceil(sampleCount),
  937. // sampleCount,
  938. measureQ,
  939. unit,
  940. specifications
  941. );
  942. // 这里是取整样 非数量
  943. } else if (this.isWeightStandardFullSample()) {
  944. console.log('这里是取整样 吗');
  945. //抽检取计重取整样
  946. if (!this.validateSampleCount(sampleCount, specifications)) return;
  947. await this.handleWeightFullSample(sampleCount, specifications);
  948. }
  949. this.activeName = '2';
  950. this.$refs.tabsRef.tabsChange('2');
  951. } catch (error) {
  952. console.error('取样处理失败:', error);
  953. this.$message.error('取样处理失败');
  954. }
  955. this.calculate(this.sampleList);
  956. },
  957. // 当计量类型 是数量的时候 取整样 校验
  958. validateSampleQuantity(sampleCount, specifications) {
  959. let packingUnit = this.selectedList[0].packingUnit?.trim() || '';
  960. let totalS = 0;
  961. let labelKey =
  962. packingUnit == specifications.conversionUnit.trim()
  963. ? 'packingQuantity'
  964. : 'measureQuantity';
  965. let labelName = labelKey == 'packingQuantity' ? '包装数量' : '计量数量';
  966. totalS = this.selectedList.reduce(
  967. (total, el) => total + el[labelKey],
  968. 0
  969. );
  970. if (sampleCount > totalS) {
  971. this.$message.info(
  972. `所填的条目数量不能超过所选${labelName}总和${totalS}`
  973. );
  974. return false;
  975. }
  976. return true;
  977. },
  978. //获取样品编码
  979. async getSampleCode() {
  980. return await getCode('sample_code');
  981. },
  982. async getNewSampleList(measureQ, unit, nums) {
  983. this.sampleList = [];
  984. if (!this.selectedList || this.selectedList.length == 0) {
  985. this.$message.warning('请先选择来源清单!');
  986. return;
  987. }
  988. this.activeName = '2';
  989. this.$refs.tabsRef.tabsChange('2');
  990. if (this.form.isUnpack == 1) {
  991. // 1 拆包 2 不拆
  992. let measureQuantity = 1;
  993. if (this.form.conditionType == 2) {
  994. measureQuantity = measureQ;
  995. }
  996. for (let i = 0; i < this.selectedList.length; i++) {
  997. if (
  998. this.selectedList[i].qualitySampleTemplateList == undefined ||
  999. this.selectedList[i].qualitySampleTemplateList == null ||
  1000. this.selectedList[i].qualitySampleTemplateList.length == 0
  1001. ) {
  1002. this.sampleList.push({
  1003. ...this.selectedList[i],
  1004. sampleCode: await this.getSampleCode(),
  1005. measureQuantity: measureQuantity,
  1006. qualitySampleTemplateList: JSON.parse(
  1007. JSON.stringify(this.schemeList)
  1008. ),
  1009. measureUnit: unit
  1010. });
  1011. } else {
  1012. this.sampleList.push({
  1013. ...this.selectedList[i],
  1014. sampleCode: await this.getSampleCode(),
  1015. measureQuantity: measureQuantity,
  1016. qualitySampleTemplateList: JSON.parse(
  1017. JSON.stringify(this.selectedList[i].qualitySampleTemplateList)
  1018. ),
  1019. measureUnit: unit
  1020. });
  1021. }
  1022. }
  1023. } else if (this.form.isUnpack == 2) {
  1024. if (this.form.conditionType == 1) {
  1025. measureQ = 1;
  1026. }
  1027. // 不拆计算每个重量
  1028. let newWeight = parseFloat(
  1029. (
  1030. this.selectedList[0].weight / this.selectedList[0].measureQuantity
  1031. ).toFixed(4)
  1032. );
  1033. for (let i = 0; i < nums; i++) {
  1034. if (
  1035. this.selectedList[0].qualitySampleTemplateList == undefined ||
  1036. this.selectedList[0].qualitySampleTemplateList == null ||
  1037. this.selectedList[0].qualitySampleTemplateList.length == 0
  1038. ) {
  1039. this.sampleList.push({
  1040. ...this.selectedList[0],
  1041. sampleCode: await this.getSampleCode(),
  1042. measureQuantity: measureQ,
  1043. qualitySampleTemplateList: JSON.parse(
  1044. JSON.stringify(this.schemeList)
  1045. ),
  1046. measureUnit: unit,
  1047. weight: newWeight || 0
  1048. });
  1049. } else {
  1050. this.sampleList.push({
  1051. ...this.selectedList[0],
  1052. sampleCode: await this.getSampleCode(),
  1053. measureQuantity: measureQ,
  1054. qualitySampleTemplateList: JSON.parse(
  1055. JSON.stringify(this.selectedList[0].qualitySampleTemplateList)
  1056. ),
  1057. measureUnit: unit,
  1058. weight: newWeight || 0
  1059. });
  1060. // this.sampleList.push({
  1061. // ...this.selectedList[0],
  1062. // sampleCode: await this.getSampleCode(),
  1063. // measureQuantity: measureQ,
  1064. // measureUnit: unit,
  1065. // weight: newWeight || 0,
  1066. // });
  1067. }
  1068. }
  1069. }
  1070. // this.sampleList = this.selectedList.map(oldItem => {
  1071. // const newItem = JSON.parse(JSON.stringify(oldItem));
  1072. // newItem.measureQuantity = measureQ;
  1073. // newItem.measureUnit = unit;
  1074. // return newItem;
  1075. // });
  1076. this.calculate(this.sampleList);
  1077. this.$refs.tabsRef.tabsChange('2');
  1078. },
  1079. async getQueryQualityInventory() {
  1080. const res = await queryQualityInventory({
  1081. qualityWorkerId: this.$route.query.id,
  1082. size: -1
  1083. });
  1084. if (res.list.length > 0) {
  1085. this.inventoryList = res.list;
  1086. }
  1087. },
  1088. async queryQualitySamplContent() {
  1089. const res = await queryQualitySamplContent({
  1090. qualityWorkerId: this.$route.query.id,
  1091. size: 1000
  1092. });
  1093. let addStatus = res.list.map((item) => {
  1094. item.isValid = true;
  1095. // item.disposeTime = item.disposeTime
  1096. // ? item.disposeTime.split(' ')[0]
  1097. // : null;
  1098. item.sampleDate = item.sampleDate
  1099. ? item.sampleDate.split(' ')[0]
  1100. : null;
  1101. return {
  1102. ...item
  1103. };
  1104. });
  1105. if (addStatus.length > 0) {
  1106. this.sampleList = addStatus;
  1107. // this.calculate(this.sampleList);
  1108. this.addStatus = addStatus;
  1109. } else {
  1110. this.getProSamList(this.packingList);
  1111. }
  1112. },
  1113. async queryQualityTempleContent() {
  1114. const res = await queryQualityTempleContent({
  1115. qualityWorkerId: this.$route.query.id,
  1116. page: 1,
  1117. size: 10000
  1118. });
  1119. this.schemeList = res.list;
  1120. },
  1121. // 取样
  1122. getConditionType(val) {
  1123. this.form.conditionType = val;
  1124. },
  1125. /* 保存编辑 */
  1126. save() {
  1127. // *** 新增判断
  1128. // let flag = this.$refs.baseInfoRefs.quantityCalculation();
  1129. // if (!flag) return;
  1130. // ***
  1131. if (this.form.qualityIdList.length == 0) {
  1132. this.$message.error('请选择质检人');
  1133. return;
  1134. }
  1135. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1136. if (!valid) {
  1137. return false;
  1138. }
  1139. // this.loading = true;
  1140. let URL =
  1141. this.type == 'add' ? save : this.type == 'edit' ? update : '';
  1142. this.form.qualityTimeStart = this.qualityTimeStart;
  1143. this.form.qualityId = this.form.qualityIdList.join(',');
  1144. delete this.form['qualityTimeEnd'];
  1145. let params = {
  1146. ...this.form,
  1147. sampleList: this.sampleList,
  1148. planTemplateList: this.schemeList,
  1149. templateList: this.schemeList,
  1150. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1151. qualityInventoryList: this.inventoryList
  1152. };
  1153. URL(params)
  1154. .then((msg) => {
  1155. this.loading = false;
  1156. this.$message.success(msg);
  1157. this.cancel();
  1158. this.$emit('done');
  1159. })
  1160. .catch((e) => {
  1161. this.loading = false;
  1162. });
  1163. });
  1164. },
  1165. update() {
  1166. this.loading = true;
  1167. this.form['status'] = 1;
  1168. update({ ...this.form })
  1169. .then((msg) => {
  1170. this.loading = false;
  1171. this.$message.success(msg);
  1172. this.$emit('done');
  1173. })
  1174. .catch((e) => {
  1175. this.loading = false;
  1176. });
  1177. },
  1178. restForm() {
  1179. this.form = { ...this.defaultForm() };
  1180. this.$nextTick(() => {
  1181. this.$refs.baseInfoRefs.$refs.form1.clearValidate();
  1182. });
  1183. },
  1184. cancel() {
  1185. finishPageTab();
  1186. this.$router.go(-1);
  1187. },
  1188. setSchemeList(list) {
  1189. this.schemeList = list;
  1190. },
  1191. handleDetail(index, row, type) {
  1192. if (!this.sampleList[index] || !this.schemeList) {
  1193. return;
  1194. }
  1195. const selectedData = [];
  1196. selectedData.push(this.sampleList[index]);
  1197. if (this.schemeList.length != 0) {
  1198. this.sampleList.forEach((item) => {
  1199. if (item.qualitySampleTemplateList.length == 0) {
  1200. item.qualitySampleTemplateList.push(...this.schemeList);
  1201. }
  1202. });
  1203. }
  1204. console.log(selectedData, 'selectedData');
  1205. this.$refs.detailRef.openDia(
  1206. index,
  1207. row,
  1208. type,
  1209. selectedData,
  1210. null,
  1211. this.schemeList.toolList
  1212. );
  1213. },
  1214. sampleListChange(sampleList) {
  1215. this.$set(this, 'sampleList', sampleList);
  1216. // this.sampleList = sampleList;
  1217. },
  1218. inputWeight(row, index) {
  1219. // 计算所有样本的总重量
  1220. console.log(this.sampleList);
  1221. const pNum = this.sampleList.reduce((sum, item) => {
  1222. return sum + Number(item.weight || 0);
  1223. }, 0);
  1224. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  1225. },
  1226. handleDispose(data) {
  1227. // return
  1228. this.rowData = data;
  1229. this.sampleDisposeVisble = true;
  1230. // if (!this.sampleList[index]) {
  1231. // return;
  1232. // }
  1233. // this.sampleList[index].sampleDate = this.getNowTimes();
  1234. // this.sampleList[index].disposeTime = this.getNowTimes();
  1235. // console.log(index, row, type, this.qualityType);
  1236. // this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
  1237. },
  1238. // 报工
  1239. handleReporting(index, row) {
  1240. if (this.form.qualityIdList.length == 0) {
  1241. this.$message.error('请选择质检人');
  1242. return;
  1243. }
  1244. if (this.form.qualityMode == 2 && !this.form.qualityResults) {
  1245. this.$refs.baseInfoRefs.toggleExpand2();
  1246. this.$message.error('请选择质检结果');
  1247. return;
  1248. }
  1249. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1250. if (!valid) return false;
  1251. this.loading = true;
  1252. if (this.qualityType == 2 && this.isReportProcessProduce) {
  1253. for (let i = 0; i < this.sampleList.length; i++) {
  1254. const disposalStatus = this.sampleList[i].disposalStatus;
  1255. if (disposalStatus == null) {
  1256. this.loading = false;
  1257. this.$refs.tabsRef.tabsChange('2');
  1258. this.$message.error('请完成以下样品处置!');
  1259. return;
  1260. }
  1261. }
  1262. }
  1263. for (let i = 0; i < this.sampleList.length; i++) {
  1264. const qualityStatus = this.sampleList[i].qualityStatus;
  1265. if (qualityStatus == '2') {
  1266. this.loading = false;
  1267. this.$refs.tabsRef.tabsChange('2');
  1268. this.$message.error('请完成以下样品质检!');
  1269. return;
  1270. }
  1271. }
  1272. // this.form.qualityTimeEnd = new Date(this.getNowTime());
  1273. // this.form.qualityTimeStart = new Date(this.qualityTimeStart);
  1274. this.form.qualityTimeEnd = this.getNowTime();
  1275. this.form.qualityTimeStart = this.qualityTimeStart;
  1276. this.form.qualityId = this.form.qualityIdList.join(',');
  1277. // if (this.form.qualityMode == 1) {
  1278. // this.form.qualityResults = '';
  1279. // }
  1280. let params = {
  1281. ...this.form,
  1282. sampleList: this.sampleList,
  1283. planTemplateList: this.schemeList,
  1284. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1285. qualityInventoryList: this.inventoryList
  1286. };
  1287. exeReportWork(params)
  1288. .then((msg) => {
  1289. this.loading = false;
  1290. this.$message.success(msg);
  1291. this.cancel();
  1292. this.$emit('done');
  1293. })
  1294. .catch((e) => {
  1295. this.loading = false;
  1296. });
  1297. });
  1298. },
  1299. // 处理确认事件
  1300. handleDisposeConfirm(data, index) {
  1301. if (index == undefined) {
  1302. this.sampleList.forEach((obj) => {
  1303. obj.disposeType = data.disposeType;
  1304. obj.sampleDate = data.sampleDate;
  1305. obj.sampleCondition = data.sampleCondition;
  1306. obj.producerManufacturer = data.producerManufacturer;
  1307. obj.samplePlace = data.samplePlace;
  1308. obj.sampleRemark = data.sampleRemark;
  1309. obj.depotId = data.depotId;
  1310. obj.depotName = data.depotName;
  1311. });
  1312. } else {
  1313. this.$set(this.sampleList, index, data);
  1314. }
  1315. },
  1316. //确认质检
  1317. handleConfirm(list, index) {
  1318. // 检查有效性
  1319. // for (const item of list) {
  1320. // for (const child of item.qualitySampleTemplateList) {
  1321. //
  1322. // console.log(child, 'child')
  1323. // if (!child.qualityResultContent || !child.qualityResults) {
  1324. // this.$message.error('请完善报工内容!');
  1325. // return;
  1326. // }
  1327. // }
  1328. // }
  1329. list.forEach((item) => {
  1330. if (item.qualitySampleTemplateList.length == 1) {
  1331. if (
  1332. item.qualitySampleTemplateList.some(
  1333. (child) => child.qualityResults === 3
  1334. )
  1335. ) {
  1336. // 如果质检项只有一条而且结果为让步接收那么整个就是让步接收
  1337. item.isValid = false;
  1338. item.qualityResults = 3;
  1339. } else if (
  1340. item.qualitySampleTemplateList.some(
  1341. (child) => child.qualityResults === 2
  1342. )
  1343. ) {
  1344. item.isValid = false;
  1345. item.qualityResults = 2;
  1346. } else {
  1347. item.isValid = true;
  1348. item.qualityResults = 1;
  1349. }
  1350. } else {
  1351. if (
  1352. item.qualitySampleTemplateList.some(
  1353. (child) => child.qualityResults === 2
  1354. )
  1355. ) {
  1356. item.isValid = false;
  1357. item.qualityResults = 2;
  1358. } else {
  1359. item.isValid = true;
  1360. item.qualityResults = 1;
  1361. }
  1362. }
  1363. item.qualityStatus = 1;
  1364. });
  1365. if (index != null) {
  1366. this.$set(this.sampleList, index, list[0]);
  1367. // this.$set(this.sampleList, index, list[0]);
  1368. if (this.form.qualityMode == 1 && this.form.isUnpack == 2) {
  1369. this.activeName = '2';
  1370. this.countQualityResults();
  1371. return;
  1372. }
  1373. } else {
  1374. this.$set(this, 'sampleList', list);
  1375. // console.log(this.sampleList, 'this.sampleList');
  1376. // return
  1377. // this.sampleList = list;
  1378. this.calculate(this.sampleList);
  1379. console.log(this.sampleList, 'this.sampleList');
  1380. }
  1381. this.activeName = '2';
  1382. // *** 选完批量质检调用
  1383. // this.countQualityResults();
  1384. this.$refs.baseInfoRefs.quantityCalculation(
  1385. 'noQualifiedNumber',
  1386. 'noSetSampleList'
  1387. );
  1388. console.log('质检没有 2');
  1389. },
  1390. // 批量质检
  1391. batchQuality(index, row, type) {
  1392. // if (this.form.sampleList.qualitySampleTemplateList.length == 0) {
  1393. // this.form.sampleList.forEach((item, index) => {
  1394. // this.$set(
  1395. // this.form.sampleList[index],
  1396. // 'qualitySampleTemplateList',
  1397. // this.form.templateList
  1398. // );
  1399. // });
  1400. // }
  1401. if (this.sampleList.length == 0) {
  1402. this.$message.error('样品清单不能为空');
  1403. return;
  1404. }
  1405. if (this.schemeList.length != 0) {
  1406. this.sampleList.forEach((item, index) => {
  1407. if (item.qualitySampleTemplateList.length == 0) {
  1408. let arr = JSON.parse(JSON.stringify(this.schemeList));
  1409. arr.forEach((el) => {
  1410. el.qualityResults = item.qualityResults;
  1411. });
  1412. this.$set(
  1413. this.sampleList[index],
  1414. 'qualitySampleTemplateList',
  1415. arr
  1416. );
  1417. }
  1418. });
  1419. }
  1420. console.log(this.sampleList, 'dsds');
  1421. this.$refs.detailRef.openDia(
  1422. null,
  1423. null,
  1424. 'report',
  1425. this.sampleList,
  1426. null,
  1427. this.schemeList.toolList
  1428. );
  1429. },
  1430. // 批量处置
  1431. batchDispose() {
  1432. if (this.sampleList && this.sampleList.length) {
  1433. this.sampleDisposeVisble = true;
  1434. return;
  1435. }
  1436. this.$message('当前没有样品清单可以处置');
  1437. // this.$refs.disposeRef.openDispose(
  1438. // null,
  1439. // null,
  1440. // 'dispose',
  1441. // this.qualityType
  1442. // );
  1443. },
  1444. //全检,检验标准改变时,重新获取样品列表
  1445. async changeInspectionStandardsModel(val) {
  1446. const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
  1447. if (sData.length > 0) {
  1448. for (let i = 0; i < sData.length; i++) {
  1449. this.$set(sData[i], 'qualityStatus', 2);
  1450. }
  1451. }
  1452. this.form.inspectionStandards = val;
  1453. this.form.sampleNumber = '';
  1454. this.$refs.tabsRef.tableSelClear();
  1455. this.sampleList = [];
  1456. this.$refs.tabsRef.tabsChange('1');
  1457. //检验标准 2计重 1计量
  1458. if (this.form.inspectionStandards == 2 && this.form.qualityMode == 1) {
  1459. for (let i = 0; i < sData.length; i++) {
  1460. let qualitySampleTemplateList = [];
  1461. if (
  1462. sData[i].qualitySampleTemplateList == undefined ||
  1463. sData[i].qualitySampleTemplateList == null ||
  1464. sData[i].qualitySampleTemplateList.length == 0
  1465. ) {
  1466. qualitySampleTemplateList = JSON.parse(
  1467. JSON.stringify(this.schemeList)
  1468. );
  1469. } else {
  1470. qualitySampleTemplateList = sData[i].qualitySampleTemplateList;
  1471. }
  1472. this.sampleList.push({
  1473. ...sData[i],
  1474. sampleCode: await this.getSampleCode(),
  1475. qualitySampleTemplateList
  1476. });
  1477. }
  1478. } else if (
  1479. this.form.inspectionStandards == 1 &&
  1480. this.form.qualityMode == 1
  1481. ) {
  1482. this.getProSamList(sData);
  1483. }
  1484. this.calculate(this.sampleList);
  1485. },
  1486. //从来源数组取样到目标数组
  1487. async getNewFullSampleList(
  1488. sampleCount,
  1489. sampleQuantity,
  1490. sampleUnit,
  1491. specifications
  1492. ) {
  1493. const sourceArray = this.selectedList;
  1494. // 检查单位是否匹配
  1495. const isUnitMismatch =
  1496. sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
  1497. // 创建副本并计算初始可取样数量
  1498. const items = sourceArray.map((item) => ({
  1499. ...item,
  1500. remainingQuantity: isUnitMismatch
  1501. ? Infinity
  1502. : item['measureQuantity'], // 剩余可取样数量
  1503. maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
  1504. }));
  1505. const result = [];
  1506. let remainingCount = sampleCount;
  1507. let count = Math.ceil(remainingCount);
  1508. const codeList = await this.batchCodes(count);
  1509. let codeIdx = 0;
  1510. // 尽可能均匀地从各条目取样
  1511. while (remainingCount > 0) {
  1512. // 按剩余可取样比例排序
  1513. items.sort(
  1514. (a, b) =>
  1515. b.remainingQuantity / b['measureQuantity'] -
  1516. a.remainingQuantity / a['measureQuantity']
  1517. );
  1518. let distributed = false;
  1519. for (const item of items) {
  1520. // let values = remainingCount > 1 ? 1 : remainingCount;
  1521. if (
  1522. !isUnitMismatch ||
  1523. (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
  1524. ) {
  1525. let qualitySampleTemplateList = [];
  1526. if (
  1527. item.qualitySampleTemplateList == undefined ||
  1528. item.qualitySampleTemplateList == null ||
  1529. item.qualitySampleTemplateList.length == 0
  1530. ) {
  1531. qualitySampleTemplateList = JSON.parse(
  1532. JSON.stringify(this.schemeList)
  1533. );
  1534. } else {
  1535. qualitySampleTemplateList = item.qualitySampleTemplateList;
  1536. }
  1537. // 添加到结果数组
  1538. // let sampleCode = await this.getSampleCode();
  1539. let sampleCode = codeList[codeIdx];
  1540. if (
  1541. this.form.conditionType == 1 &&
  1542. this.form.inspectionStandards == 1
  1543. ) {
  1544. result.push({
  1545. ...item,
  1546. // measureQuantity: values,
  1547. measureQuantity: 1,
  1548. sampleCode,
  1549. qualitySampleTemplateList
  1550. });
  1551. } else if (
  1552. this.form.conditionType == 2 &&
  1553. (this.form.inspectionStandards == 1 ||
  1554. this.form.inspectionStandards == 2)
  1555. ) {
  1556. let weight = (item.weight / item.maxPossible).toFixed(2);
  1557. result.push({
  1558. ...item,
  1559. measureQuantity: sampleQuantity,
  1560. measureUnit: sampleUnit,
  1561. sampleCode,
  1562. weight,
  1563. qualitySampleTemplateList
  1564. });
  1565. }
  1566. // 更新剩余数量
  1567. if (!isUnitMismatch) {
  1568. item.remainingQuantity -= sampleQuantity;
  1569. }
  1570. remainingCount = (remainingCount - 1).toFixed(2);
  1571. codeIdx++;
  1572. distributed = true;
  1573. }
  1574. }
  1575. // 如果没有分配任何取样
  1576. if (!distributed) {
  1577. break;
  1578. }
  1579. }
  1580. // 判断是不是取整样
  1581. if (
  1582. this.form.conditionType == 1 &&
  1583. specifications &&
  1584. specifications.id
  1585. ) {
  1586. result.map((el) => {
  1587. el.measureQuantity =
  1588. el.measureQuantity * specifications.packageCellTotal;
  1589. el.weight = this.formatNumber(
  1590. el.measureQuantity,
  1591. el.weightProportion
  1592. );
  1593. });
  1594. }
  1595. this.sampleList = result;
  1596. if (this.sampleList.length > sampleCount) {
  1597. this.sampleList = this.sampleList.splice(0, sampleCount);
  1598. }
  1599. this.form.sampleNumber = this.sampleList.length;
  1600. this.calculate(this.sampleList);
  1601. },
  1602. // 小数点数据判断
  1603. formatNumber(a, b, maxDecimals = 4) {
  1604. if (a == 0 || b == 0 || !a || !b) {
  1605. return 0;
  1606. }
  1607. // 计算乘积
  1608. const product = a * b;
  1609. // 转换为固定小数位数,然后转换为数字以去除末尾零
  1610. const rounded = Number(product.toFixed(maxDecimals));
  1611. // 转换为字符串检查是否需要显示小数部分
  1612. const str = rounded.toString();
  1613. // 如果包含小数点
  1614. if (str.indexOf('.') !== -1) {
  1615. // 移除末尾的零和小数点(如果后面没有数字了)
  1616. return str.replace(/\.?0+$/, '');
  1617. }
  1618. return str;
  1619. },
  1620. validateWeight(measureQ, sampleCount) {
  1621. let totalMaxPossible = 0;
  1622. this.selectedList.forEach((item) => {
  1623. totalMaxPossible += item.measureQuantity / measureQ;
  1624. });
  1625. if (totalMaxPossible < sampleCount) {
  1626. // this.formData.portion = totalMaxPossible;
  1627. this.$message.info(`最大取样条数为${totalMaxPossible}`);
  1628. return false;
  1629. }
  1630. let totalWeight = this.selectedList.reduce(
  1631. (sum, item) => sum + item.weight,
  1632. 0
  1633. );
  1634. const weightUnit = this.selectedList[0].weightUnit;
  1635. if (weightUnit === 'G') totalWeight /= 1000;
  1636. if (measureQ * sampleCount > totalWeight) {
  1637. this.$message.info('取样计量重量不能大于总计量重量');
  1638. return false;
  1639. }
  1640. const invalidItem = this.selectedList.find((item) => {
  1641. const weight =
  1642. item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
  1643. return weight < measureQ;
  1644. });
  1645. if (invalidItem) {
  1646. this.$message.info('勾选条目重量小于取样重量');
  1647. return false;
  1648. }
  1649. return true;
  1650. },
  1651. isStandard1OrWeightSample() {
  1652. return (
  1653. this.form.inspectionStandards === 1 ||
  1654. (this.form.inspectionStandards === 2 && this.form.conditionType == 2)
  1655. );
  1656. },
  1657. validateMeasureQuantity(measureQ, unit, sampleCount) {
  1658. if (this.form.conditionType == 2 && measureQ <= 0) {
  1659. this.$message.info('取样计量数量必须大于0');
  1660. return false;
  1661. }
  1662. const totalQuantity = this.selectedList.reduce(
  1663. (sum, item) => sum + item.measureQuantity,
  1664. 0
  1665. );
  1666. if (
  1667. (this.selectedList[0].measureUnit === unit ||
  1668. this.form.conditionType == 1) &&
  1669. measureQ * sampleCount > totalQuantity
  1670. ) {
  1671. this.$message.info('取样计量数量不能大于总计量数量');
  1672. return false;
  1673. }
  1674. const invalidItem = this.selectedList.find(
  1675. (item) => item.measureQuantity < measureQ
  1676. );
  1677. if (invalidItem) {
  1678. this.$message.info('条目计量数量小于取样计量数量');
  1679. return false;
  1680. }
  1681. return true;
  1682. },
  1683. isWeightStandardFullSample() {
  1684. return (
  1685. this.form.inspectionStandards === 2 && this.form.conditionType == 1
  1686. );
  1687. },
  1688. // 抽检取整样 校验
  1689. validateSampleCount(sampleCount, specifications) {
  1690. // 新增校验 ***
  1691. let isFlag = this.validateSampleQuantity(sampleCount, specifications);
  1692. if (!isFlag) {
  1693. return false;
  1694. }
  1695. // ***
  1696. const chooseNumber = this.selectedList.reduce((acc, pro) => {
  1697. return pro.measureQuantity ? acc + Number(pro.measureQuantity) : acc;
  1698. }, 0);
  1699. const invalidItem = chooseNumber < sampleCount;
  1700. // console.log(this.selectedList, 'this.selectedList');
  1701. // const invalidItem = this.selectedList.find(
  1702. // (item) => item.measureQuantity < sampleCount
  1703. // );
  1704. if (invalidItem) {
  1705. this.$message.info('所选的条目计量数量小于取样计量数量');
  1706. return false;
  1707. }
  1708. // ***
  1709. return true;
  1710. },
  1711. async handleWeightFullSample(sampleCount, specifications) {
  1712. const dataList = [];
  1713. let currentNum = sampleCount - this.selectedList.length;
  1714. let currentNum1 = sampleCount;
  1715. for (const item of this.selectedList) {
  1716. const qualitySampleTemplateList = item.qualitySampleTemplateList
  1717. ?.length
  1718. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  1719. : JSON.parse(
  1720. JSON.stringify(
  1721. this.schemeList.map((item) => {
  1722. item['qualityResults'] = 1;
  1723. return item;
  1724. })
  1725. )
  1726. );
  1727. if (sampleCount >= this.selectedList.length) {
  1728. dataList.push({
  1729. ...item,
  1730. measureQuantity: 1, //作为计量数量
  1731. sampleCode: await this.getSampleCode(),
  1732. qualitySampleTemplateList
  1733. });
  1734. } else {
  1735. if (dataList.length < sampleCount) {
  1736. dataList.push({
  1737. ...item,
  1738. measureQuantity: currentNum1 > 1 ? 1 : currentNum1, //作为计量数量
  1739. sampleCode: await this.getSampleCode(),
  1740. qualitySampleTemplateList
  1741. });
  1742. currentNum1 -= 1;
  1743. }
  1744. }
  1745. }
  1746. if (sampleCount > this.selectedList.length) {
  1747. dataList.forEach((item) => {
  1748. if (currentNum > 0) {
  1749. let data = this.selectedList.find((val) => val.id == item.id);
  1750. item['measureQuantity'] =
  1751. data.measureQuantity - 1 - currentNum > 0
  1752. ? currentNum + 1
  1753. : data.measureQuantity;
  1754. currentNum = currentNum - (data.measureQuantity - 1);
  1755. }
  1756. });
  1757. }
  1758. // 更改 从新计算 样品清单 取整样 数据
  1759. if (specifications && specifications.id) {
  1760. // let proportion = (obj.weight / obj.measureQuantity).toFixed(2);
  1761. dataList.map((el) => {
  1762. el.measureQuantity =
  1763. el.measureQuantity * specifications.packageCellTotal;
  1764. el.weight = this.formatNumber(
  1765. el.measureQuantity,
  1766. el.weightProportion
  1767. );
  1768. });
  1769. }
  1770. // 更改
  1771. this.sampleList = dataList;
  1772. this.calculate(this.sampleList);
  1773. this.sampleNumber = this.sampleList.length;
  1774. },
  1775. // 批量生成编码 4444444 getCodeList
  1776. async batchCodes(count) {
  1777. if (count <= 0) return;
  1778. let params = { count };
  1779. const res = await getCodeList('sample_code', params);
  1780. return res;
  1781. },
  1782. //计算合格率
  1783. countQualityResults() {
  1784. console.log(321);
  1785. let sampleList = this.sampleList; //样品清单
  1786. let sampleNumber = this.form.total; //样品总数
  1787. // let qualifiedNumber = sampleList.filter(item => item.qualityResults == 1 || item.qualityResults == 3).length;
  1788. // let noQualifiedNumber = sampleList.filter(
  1789. // (item) => item.qualityResults == 2
  1790. // ).length;
  1791. let noQualifiedNumber = sampleList.reduce((acc, pro) => {
  1792. // console.log(acc, pro);
  1793. // if (pro.qualityResults == 2) {
  1794. // return acc + Number(pro.measureQuantity);
  1795. // }
  1796. return pro.qualityResults == 2
  1797. ? acc + Number(pro.measureQuantity)
  1798. : acc;
  1799. }, 0);
  1800. let qualifiedNumber = sampleNumber - noQualifiedNumber; //不合格数
  1801. let qualificationRate = (
  1802. (qualifiedNumber / sampleNumber) *
  1803. 100
  1804. ).toFixed(2); //合格率
  1805. let noQualificationRate = (
  1806. (noQualifiedNumber / sampleNumber) *
  1807. 100
  1808. ).toFixed(2); //不合格率
  1809. this.$refs.baseInfoRefs.updateQualificationRate(
  1810. qualifiedNumber,
  1811. noQualifiedNumber,
  1812. qualificationRate,
  1813. noQualificationRate
  1814. );
  1815. this.calculate(this.sampleList);
  1816. },
  1817. closeDispose() {
  1818. this.rowData = null;
  1819. this.sampleDisposeVisble = false;
  1820. // this.rowData = null;
  1821. }
  1822. }
  1823. };
  1824. </script>
  1825. <style lang="scss" scoped></style>