edit.vue 59 KB

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