edit.vue 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899
  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. },
  419. //切换检验方式
  420. changeModel(val, flag) {
  421. this.$refs.tabsRef.tableSelClear();
  422. this.sampleList = [];
  423. this.$refs.tabsRef.tabsChange('1');
  424. this.$refs.tabsRef.tabsConditionType(null);
  425. this.form.qualityMode = val;
  426. //检验方式 全检
  427. if (this.form.qualityMode == 1) {
  428. this.activeName = '2';
  429. this.form.sampleNumber = '';
  430. this.changeGetSampleList(this.inventoryList);
  431. } else {
  432. this.activeName = '1';
  433. if (!flag) {
  434. this.sampleList = [];
  435. }
  436. }
  437. this.calculate([]);
  438. },
  439. //根据类型判断样品清单现实列表数据
  440. async getProSamList(list) {
  441. //生产检验
  442. if (this.qualityType == 2) {
  443. if (this.form.qualityMode != null) {
  444. const ProductSampleList = [];
  445. for (const oldItem of list) {
  446. const count = oldItem.measureQuantity;
  447. const newMeasureQuantity = oldItem.measureQuantity / count;
  448. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  449. // 遍历新数组设置 qualityResults 默认值
  450. this.schemeList.forEach((item) => {
  451. if (typeof item === 'object' && item !== null) {
  452. item.qualityResults = 1; // 设置默认值
  453. }
  454. delete item.id;
  455. });
  456. delete oldItem.id;
  457. if (
  458. oldItem.qualitySampleTemplateList == undefined ||
  459. oldItem.qualitySampleTemplateList == null ||
  460. oldItem.qualitySampleTemplateList.length == 0
  461. ) {
  462. oldItem.qualitySampleTemplateList = JSON.parse(
  463. JSON.stringify(this.schemeList)
  464. );
  465. for (let i = 0; i < count; i++) {
  466. ProductSampleList.push({
  467. ...oldItem,
  468. measureQuantity: newMeasureQuantity,
  469. weight: newWeight,
  470. sampleCode: await this.getSampleCode(),
  471. qualitySampleTemplateList: JSON.parse(
  472. JSON.stringify(this.schemeList)
  473. )
  474. });
  475. }
  476. this.sampleList = ProductSampleList;
  477. this.calculate(this.sampleList);
  478. const pNum = ProductSampleList.reduce((sum, item) => {
  479. return sum + Number(item.weight || 0);
  480. }, 0);
  481. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  482. } else {
  483. for (let i = 0; i < count; i++) {
  484. ProductSampleList.push({
  485. ...oldItem,
  486. measureQuantity: newMeasureQuantity,
  487. weight: newWeight,
  488. sampleCode: await this.getSampleCode(),
  489. qualitySampleTemplateList: JSON.parse(
  490. JSON.stringify(oldItem.qualitySampleTemplateList)
  491. )
  492. });
  493. }
  494. this.sampleList = ProductSampleList;
  495. this.calculate(this.sampleList);
  496. const pNum = ProductSampleList.reduce((sum, item) => {
  497. return sum + Number(item.weight || 0);
  498. }, 0);
  499. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  500. }
  501. }
  502. }
  503. } else {
  504. // this.sampleList = list;
  505. this.sampleList = this.addStatus;
  506. }
  507. },
  508. // 创建计量数量为1的样品清单函数,用于计数类型的
  509. async createSampleList(list) {
  510. if (this.form.qualityMode != null) {
  511. this.$message.closeAll();
  512. this.$message('正在生成样品清单');
  513. const ProductSampleList = [];
  514. for (const oldItem of list) {
  515. const count = oldItem.measureQuantity ? oldItem.measureQuantity : 1;
  516. const newMeasureQuantity = oldItem.measureQuantity / count;
  517. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  518. // 遍历新数组设置 qualityResults 默认值
  519. this.schemeList.forEach((item) => {
  520. if (typeof item === 'object' && item !== null) {
  521. item.qualityResults = 1; // 设置默认值
  522. }
  523. delete item.id;
  524. });
  525. delete oldItem.id;
  526. if (
  527. oldItem.qualitySampleTemplateList == undefined ||
  528. oldItem.qualitySampleTemplateList == null ||
  529. oldItem.qualitySampleTemplateList.length == 0
  530. ) {
  531. oldItem.qualitySampleTemplateList = JSON.parse(
  532. JSON.stringify(this.schemeList)
  533. );
  534. for (let i = 0; i < count; i++) {
  535. ProductSampleList.push({
  536. ...oldItem,
  537. measureQuantity: newMeasureQuantity,
  538. weight: newWeight,
  539. sampleCode: await this.getSampleCode(),
  540. qualitySampleTemplateList: JSON.parse(
  541. JSON.stringify(this.schemeList)
  542. )
  543. });
  544. }
  545. this.sampleList = ProductSampleList;
  546. this.calculate(this.sampleList);
  547. const pNum = ProductSampleList.reduce((sum, item) => {
  548. return sum + Number(item.weight || 0);
  549. }, 0);
  550. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  551. } else {
  552. for (let i = 0; i < count; i++) {
  553. ProductSampleList.push({
  554. ...oldItem,
  555. measureQuantity: newMeasureQuantity,
  556. weight: newWeight,
  557. sampleCode: await this.getSampleCode(),
  558. qualitySampleTemplateList: JSON.parse(
  559. JSON.stringify(oldItem.qualitySampleTemplateList)
  560. )
  561. });
  562. }
  563. this.sampleList = ProductSampleList;
  564. this.calculate(this.sampleList);
  565. const pNum = ProductSampleList.reduce((sum, item) => {
  566. return sum + Number(item.weight || 0);
  567. }, 0);
  568. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  569. }
  570. }
  571. }
  572. },
  573. // 全检计量计重的样品清单函数
  574. async updatePackingList(list, sampleCount) {
  575. // for (let i = 0; i < list.length; i++) {
  576. // list[i].sampleCode = await this.getSampleCode();
  577. // }
  578. const dataList = [];
  579. let currentNum = sampleCount - list.length;
  580. let currentNum1 = sampleCount;
  581. // console.log(this.selectedList);
  582. let count = list ? list.length : 0;
  583. const codeList = await this.batchCodes(count);
  584. for (const [index, item] of list.entries()) {
  585. const qualitySampleTemplateList = item.qualitySampleTemplateList
  586. ?.length
  587. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  588. : JSON.parse(
  589. JSON.stringify(
  590. this.schemeList.map((item) => {
  591. item['qualityResults'] = 1;
  592. return item;
  593. })
  594. )
  595. );
  596. if (sampleCount >= list.length) {
  597. dataList.push({
  598. ...item,
  599. measureQuantity: item.measureQuantity, //作为计量数量
  600. // sampleCode: await this.getSampleCode(),
  601. sampleCode: codeList[index],
  602. qualitySampleTemplateList
  603. });
  604. }
  605. }
  606. this.sampleList = dataList;
  607. this.calculate(this.sampleList);
  608. this.sampleNumber = this.sampleList.length;
  609. },
  610. // 切换检验方式为全检后生成样品
  611. changeGetSampleList(list) {
  612. this.$message.closeAll();
  613. this.$message('正在生成样品清单');
  614. // // 计量类型1是数量,2是重量
  615. // if (this.form.inspectionStandards == 1) {
  616. // this.createSampleList(list);
  617. // }
  618. // if (this.form.inspectionStandards == 2) {
  619. // this.updatePackingList(list, this.form.total);
  620. // // this.handleWeightFullSample(this.form.total);
  621. // }
  622. this.updatePackingList(list, this.form.total);
  623. },
  624. //输入取样数量
  625. changeNumber(val) {
  626. if (this.form.qualityMode !== 2) {
  627. return;
  628. }
  629. if (val <= 0) {
  630. this.$refs.showPackingListTable.clearSelection();
  631. return;
  632. }
  633. if (this.qualityType == 2) {
  634. //生产检验的抽检逻辑
  635. if (val > this.packingList[0].measureQuantity) {
  636. this.$message.warning('取样数量不能大于来源清单的计量数量!');
  637. return;
  638. }
  639. const ProductSampleList = [];
  640. this.packingList.forEach((oldItem) => {
  641. const count = oldItem.measureQuantity;
  642. const newMeasureQuantity = oldItem.measureQuantity / count;
  643. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  644. delete oldItem.id;
  645. // 遍历新数组设置 qualityResults 默认值
  646. this.schemeList.forEach((item) => {
  647. if (typeof item === 'object' && item !== null) {
  648. item.qualityResults = 1; // 设置默认值
  649. }
  650. delete item.id;
  651. });
  652. for (let i = 0; i < val; i++) {
  653. ProductSampleList.push({
  654. ...oldItem,
  655. measureQuantity: newMeasureQuantity,
  656. weight: newWeight,
  657. qualitySampleTemplateList: JSON.parse(
  658. JSON.stringify(this.schemeList)
  659. )
  660. });
  661. }
  662. });
  663. this.sampleList = ProductSampleList;
  664. this.calculate(this.sampleList);
  665. const pNum = ProductSampleList.reduce((sum, item) => {
  666. return sum + Number(item.weight || 0);
  667. }, 0);
  668. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  669. } else {
  670. if (val > this.packingList.length) {
  671. this.$message.warning('取样数量不能大于物料明细总数!');
  672. return;
  673. }
  674. const rows = this.packingList.slice(0, val);
  675. rows.forEach((row) => {
  676. this.$refs.showPackingListTable.toggleRowSelection(row);
  677. });
  678. }
  679. },
  680. getNowDate() {
  681. let date = new Date(),
  682. obj = {
  683. year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
  684. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  685. strDate: date.getDate(), // 获取当前日(1-31)
  686. hour: date.getHours(), //获取当前小时(0 ~ 23)
  687. minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
  688. second: date.getSeconds() //获取当前秒数(0 ~ 59)
  689. };
  690. Object.keys(obj).forEach((key) => {
  691. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  692. });
  693. return obj;
  694. },
  695. //来源清单勾选事件
  696. handleSelectionChange1(selection) {
  697. if (this.form.qualityMode === 2) {
  698. this.selectedList = selection;
  699. this.activeName = '1';
  700. if (this.schemeList.length == 0) {
  701. for (let i = 0; i < selection.length; i++) {
  702. this.$set(selection[i], 'qualityStatus', 2);
  703. // 遍历新数组设置 qualityResults 默认值
  704. this.schemeList.forEach((item) => {
  705. if (typeof item === 'object' && item !== null) {
  706. item.qualityResults = 1; // 设置默认值
  707. }
  708. delete item.id;
  709. });
  710. this.$set(
  711. selection[i],
  712. 'qualitySampleTemplateList',
  713. JSON.parse(JSON.stringify(this.schemeList))
  714. );
  715. }
  716. }
  717. // this.sampleList = selection;
  718. //赋值取样数量
  719. this.form.sampleNumber = selection.length;
  720. }
  721. },
  722. async open() {
  723. this.type = this.$route.query.type;
  724. this.qualityType = this.$route.query.qualityType;
  725. this.title =
  726. this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
  727. if (this.type == 'add') {
  728. const code = await getCode('quality_work_order_code');
  729. this.form.code = code;
  730. } else {
  731. if (
  732. this.$route.query.qualityTimeStart != '' ||
  733. this.$route.query.qualityTimeStart != null ||
  734. this.$route.query.qualityTimeStart != undefined
  735. ) {
  736. this.qualityTimeStart = this.getNowTime();
  737. }
  738. }
  739. },
  740. getNowTime() {
  741. const nowDate = this.getNowDate();
  742. return (
  743. nowDate.year +
  744. '-' +
  745. nowDate.month +
  746. '-' +
  747. nowDate.strDate +
  748. ' ' +
  749. nowDate.hour +
  750. ':' +
  751. nowDate.minute +
  752. ':' +
  753. nowDate.second
  754. );
  755. },
  756. getNowTimes() {
  757. const nowDate = this.getNowDate();
  758. return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate;
  759. },
  760. async getDetail() {
  761. getById(this.$route.query.id).then((res) => {
  762. this.form = res.data;
  763. console.log(this.form, 'this.form');
  764. this.form.qualityIdList = this.form.qualityId
  765. ? this.form.qualityId.split(',')
  766. : [];
  767. this.productId = res.data.productId || '';
  768. this.statusType = this.form.status == 1 ? true : false;
  769. this.isReportProcessProduce =
  770. this.form.isReportProcessProduce == 1 ? true : false;
  771. this.tabTaskId =
  772. this.categoryParamList[0] && this.categoryParamList[0].id;
  773. if (this.form.groupId) {
  774. this.$nextTick(() => {
  775. this.$refs.baseInfoRefs?.getUserList({
  776. groupId: this.form.groupId
  777. });
  778. });
  779. }
  780. if (this.form.produceRoutingId) {
  781. this.$nextTick(() => {
  782. this.$refs.baseInfoRefs?.getTaskList();
  783. });
  784. }
  785. });
  786. // await this.queryQualityInventory()
  787. // 质检方案
  788. await this.queryQualityTempleContent();
  789. // 样品清单
  790. await this.queryQualitySamplContent();
  791. // 来源清单
  792. await this.getQueryQualityInventory();
  793. },
  794. // getNewData(val) {
  795. // console.log(val, '清单列表')
  796. // this.packingList = val
  797. // },
  798. // async queryQualityInventory() {
  799. // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
  800. // console.log(res, '清单列表');
  801. // this.packingList = res;
  802. // },
  803. changeSamUnit(val) {
  804. this.$set(this.form, 'sampleMeasureUnit', val);
  805. },
  806. async handleSample1(val, data) {
  807. this.sampleList = [];
  808. if (this.selectedList == undefined || this.selectedList.length == 0) {
  809. this.activeName = '1';
  810. this.$message.warning('请先选择样品!');
  811. return;
  812. }
  813. if (val == 1) {
  814. this.activeName = '2';
  815. if (this.form.isUnpack == 1) {
  816. for (let i = 0; i < this.selectedList.length; i++) {
  817. for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
  818. // 不拆计算每个重量
  819. let newWeight = parseFloat(
  820. (
  821. this.selectedList[i].weight /
  822. this.selectedList[i].measureQuantity
  823. ).toFixed(4)
  824. );
  825. if (
  826. this.selectedList[i].qualitySampleTemplateList == undefined ||
  827. this.selectedList[i].qualitySampleTemplateList == null ||
  828. this.selectedList[i].qualitySampleTemplateList.length == 0
  829. ) {
  830. this.sampleList.push({
  831. ...this.selectedList[i],
  832. sampleCode: await this.getSampleCode(),
  833. measureQuantity: 1,
  834. qualitySampleTemplateList: JSON.parse(
  835. JSON.stringify(this.schemeList)
  836. ),
  837. weight: newWeight || 0
  838. });
  839. } else {
  840. this.sampleList.push({
  841. ...this.selectedList[i],
  842. sampleCode: await this.getSampleCode(),
  843. measureQuantity: 1,
  844. qualitySampleTemplateList: JSON.parse(
  845. JSON.stringify(
  846. this.selectedList[i].qualitySampleTemplateList
  847. )
  848. ),
  849. weight: newWeight || 0
  850. });
  851. }
  852. }
  853. }
  854. } else if (this.form.isUnpack == 2) {
  855. // 不拆计算每个重量
  856. let newWeight = parseFloat(
  857. (
  858. this.selectedList[0].weight /
  859. this.selectedList[0].measureQuantity
  860. ).toFixed(4)
  861. );
  862. for (let i = 0; i < this.selectedList[0].measureQuantity; i++) {
  863. if (
  864. this.selectedList[0].qualitySampleTemplateList == undefined ||
  865. this.selectedList[0].qualitySampleTemplateList == null ||
  866. this.selectedList[0].qualitySampleTemplateList.length == 0
  867. ) {
  868. this.sampleList.push({
  869. ...this.selectedList[0],
  870. sampleCode: await this.getSampleCode(),
  871. measureQuantity: 1,
  872. qualitySampleTemplateList: JSON.parse(
  873. JSON.stringify(this.schemeList)
  874. ),
  875. weight: newWeight || 0
  876. });
  877. } else {
  878. this.sampleList.push({
  879. ...this.selectedList[0],
  880. sampleCode: await this.getSampleCode(),
  881. measureQuantity: 1,
  882. qualitySampleTemplateList: JSON.parse(
  883. JSON.stringify(
  884. this.selectedList[0].qualitySampleTemplateList
  885. )
  886. ),
  887. weight: newWeight || 0
  888. });
  889. }
  890. }
  891. }
  892. //取整样=勾选数据
  893. // this.sampleList = this.selectedList;
  894. this.$message.success('取样成功!');
  895. } else if (val == 2) {
  896. console.log(data, 'datadatadatadataxiaoyang');
  897. }
  898. this.calculate(this.sampleList);
  899. },
  900. async handleSampleSubmit(data, specifications) {
  901. this.sampleList = [];
  902. if (!this.selectedList || this.selectedList.length == 0) {
  903. this.$message.warning('请先选择样品!');
  904. return;
  905. }
  906. const measureQ = data.measureQ || 1;
  907. const unit = data.sampleUnit;
  908. const sampleCount = Number(data.portion);
  909. try {
  910. if (this.isStandard1OrWeightSample()) {
  911. // 新增校验 数量 取整样 ***
  912. if (this.form.conditionType == 1) {
  913. let isFlag = this.validateSampleQuantity(
  914. sampleCount,
  915. specifications
  916. );
  917. if (!isFlag) return;
  918. }
  919. // ***
  920. //抽检计量整样小样或者抽检计重小样
  921. if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
  922. return; //取样数量验证
  923. if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
  924. return; // 若计量单位为重量,还需验证总重量是否足够
  925. await this.getNewFullSampleList(
  926. Math.ceil(sampleCount),
  927. // sampleCount,
  928. measureQ,
  929. unit,
  930. specifications
  931. );
  932. // 这里是取整样 非数量
  933. } else if (this.isWeightStandardFullSample()) {
  934. console.log('这里是取整样 吗');
  935. //抽检取计重取整样
  936. if (!this.validateSampleCount(sampleCount, specifications)) return;
  937. await this.handleWeightFullSample(sampleCount, specifications);
  938. }
  939. this.activeName = '2';
  940. this.$refs.tabsRef.tabsChange('2');
  941. } catch (error) {
  942. console.error('取样处理失败:', error);
  943. this.$message.error('取样处理失败');
  944. }
  945. this.calculate(this.sampleList);
  946. },
  947. // 当计量类型 是数量的时候 取整样 校验
  948. validateSampleQuantity(sampleCount, specifications) {
  949. let packingUnit = this.selectedList[0].packingUnit?.trim() || '';
  950. let totalS = 0;
  951. let labelKey =
  952. packingUnit == specifications.conversionUnit.trim()
  953. ? 'packingQuantity'
  954. : 'measureQuantity';
  955. let labelName = labelKey == 'packingQuantity' ? '包装数量' : '计量数量';
  956. totalS = this.selectedList.reduce(
  957. (total, el) => total + el[labelKey],
  958. 0
  959. );
  960. if (sampleCount > totalS) {
  961. this.$message.info(
  962. `所填的条目数量不能超过所选${labelName}总和${totalS}`
  963. );
  964. return false;
  965. }
  966. return true;
  967. },
  968. //获取样品编码
  969. async getSampleCode() {
  970. return await getCode('sample_code');
  971. },
  972. async getNewSampleList(measureQ, unit, nums) {
  973. this.sampleList = [];
  974. if (!this.selectedList || this.selectedList.length == 0) {
  975. this.$message.warning('请先选择来源清单!');
  976. return;
  977. }
  978. this.activeName = '2';
  979. this.$refs.tabsRef.tabsChange('2');
  980. if (this.form.isUnpack == 1) {
  981. // 1 拆包 2 不拆
  982. let measureQuantity = 1;
  983. if (this.form.conditionType == 2) {
  984. measureQuantity = measureQ;
  985. }
  986. for (let i = 0; i < this.selectedList.length; i++) {
  987. if (
  988. this.selectedList[i].qualitySampleTemplateList == undefined ||
  989. this.selectedList[i].qualitySampleTemplateList == null ||
  990. this.selectedList[i].qualitySampleTemplateList.length == 0
  991. ) {
  992. this.sampleList.push({
  993. ...this.selectedList[i],
  994. sampleCode: await this.getSampleCode(),
  995. measureQuantity: measureQuantity,
  996. qualitySampleTemplateList: JSON.parse(
  997. JSON.stringify(this.schemeList)
  998. ),
  999. measureUnit: unit
  1000. });
  1001. } else {
  1002. this.sampleList.push({
  1003. ...this.selectedList[i],
  1004. sampleCode: await this.getSampleCode(),
  1005. measureQuantity: measureQuantity,
  1006. qualitySampleTemplateList: JSON.parse(
  1007. JSON.stringify(this.selectedList[i].qualitySampleTemplateList)
  1008. ),
  1009. measureUnit: unit
  1010. });
  1011. }
  1012. }
  1013. } else if (this.form.isUnpack == 2) {
  1014. if (this.form.conditionType == 1) {
  1015. measureQ = 1;
  1016. }
  1017. // 不拆计算每个重量
  1018. let newWeight = parseFloat(
  1019. (
  1020. this.selectedList[0].weight / this.selectedList[0].measureQuantity
  1021. ).toFixed(4)
  1022. );
  1023. for (let i = 0; i < nums; i++) {
  1024. if (
  1025. this.selectedList[0].qualitySampleTemplateList == undefined ||
  1026. this.selectedList[0].qualitySampleTemplateList == null ||
  1027. this.selectedList[0].qualitySampleTemplateList.length == 0
  1028. ) {
  1029. this.sampleList.push({
  1030. ...this.selectedList[0],
  1031. sampleCode: await this.getSampleCode(),
  1032. measureQuantity: measureQ,
  1033. qualitySampleTemplateList: JSON.parse(
  1034. JSON.stringify(this.schemeList)
  1035. ),
  1036. measureUnit: unit,
  1037. weight: newWeight || 0
  1038. });
  1039. } else {
  1040. this.sampleList.push({
  1041. ...this.selectedList[0],
  1042. sampleCode: await this.getSampleCode(),
  1043. measureQuantity: measureQ,
  1044. qualitySampleTemplateList: JSON.parse(
  1045. JSON.stringify(this.selectedList[0].qualitySampleTemplateList)
  1046. ),
  1047. measureUnit: unit,
  1048. weight: newWeight || 0
  1049. });
  1050. // this.sampleList.push({
  1051. // ...this.selectedList[0],
  1052. // sampleCode: await this.getSampleCode(),
  1053. // measureQuantity: measureQ,
  1054. // measureUnit: unit,
  1055. // weight: newWeight || 0,
  1056. // });
  1057. }
  1058. }
  1059. }
  1060. // this.sampleList = this.selectedList.map(oldItem => {
  1061. // const newItem = JSON.parse(JSON.stringify(oldItem));
  1062. // newItem.measureQuantity = measureQ;
  1063. // newItem.measureUnit = unit;
  1064. // return newItem;
  1065. // });
  1066. this.calculate(this.sampleList);
  1067. this.$refs.tabsRef.tabsChange('2');
  1068. },
  1069. async getQueryQualityInventory() {
  1070. const res = await queryQualityInventory({
  1071. qualityWorkerId: this.$route.query.id,
  1072. size: -1
  1073. });
  1074. if (res.list.length > 0) {
  1075. this.inventoryList = res.list;
  1076. }
  1077. },
  1078. async queryQualitySamplContent() {
  1079. const res = await queryQualitySamplContent({
  1080. qualityWorkerId: this.$route.query.id,
  1081. size: 1000
  1082. });
  1083. let addStatus = res.list.map((item) => {
  1084. item.isValid = true;
  1085. // item.disposeTime = item.disposeTime
  1086. // ? item.disposeTime.split(' ')[0]
  1087. // : null;
  1088. item.sampleDate = item.sampleDate
  1089. ? item.sampleDate.split(' ')[0]
  1090. : null;
  1091. return {
  1092. ...item
  1093. };
  1094. });
  1095. if (addStatus.length > 0) {
  1096. this.sampleList = addStatus;
  1097. // this.calculate(this.sampleList);
  1098. this.addStatus = addStatus;
  1099. } else {
  1100. this.getProSamList(this.packingList);
  1101. }
  1102. },
  1103. async queryQualityTempleContent() {
  1104. const res = await queryQualityTempleContent({
  1105. qualityWorkerId: this.$route.query.id,
  1106. page: 1,
  1107. size: 10000
  1108. });
  1109. this.schemeList = res.list;
  1110. },
  1111. // 取样
  1112. getConditionType(val) {
  1113. this.form.conditionType = val;
  1114. },
  1115. /* 保存编辑 */
  1116. save() {
  1117. // *** 新增判断
  1118. // let flag = this.$refs.baseInfoRefs.quantityCalculation();
  1119. // if (!flag) return;
  1120. // ***
  1121. if (this.form.qualityIdList.length == 0) {
  1122. this.$message.error('请选择质检人');
  1123. return;
  1124. }
  1125. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1126. if (!valid) {
  1127. return false;
  1128. }
  1129. // this.loading = true;
  1130. let URL =
  1131. this.type == 'add' ? save : this.type == 'edit' ? update : '';
  1132. this.form.qualityTimeStart = this.qualityTimeStart;
  1133. this.form.qualityId = this.form.qualityIdList.join(',');
  1134. delete this.form['qualityTimeEnd'];
  1135. let params = {
  1136. ...this.form,
  1137. sampleList: this.sampleList,
  1138. planTemplateList: this.schemeList,
  1139. templateList: this.schemeList,
  1140. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1141. qualityInventoryList: this.inventoryList
  1142. };
  1143. URL(params)
  1144. .then((msg) => {
  1145. this.loading = false;
  1146. this.$message.success(msg);
  1147. this.cancel();
  1148. this.$emit('done');
  1149. })
  1150. .catch((e) => {
  1151. this.loading = false;
  1152. });
  1153. });
  1154. },
  1155. update() {
  1156. this.loading = true;
  1157. this.form['status'] = 1;
  1158. update({ ...this.form })
  1159. .then((msg) => {
  1160. this.loading = false;
  1161. this.$message.success(msg);
  1162. this.$emit('done');
  1163. })
  1164. .catch((e) => {
  1165. this.loading = false;
  1166. });
  1167. },
  1168. restForm() {
  1169. this.form = { ...this.defaultForm() };
  1170. this.$nextTick(() => {
  1171. this.$refs.baseInfoRefs.$refs.form1.clearValidate();
  1172. });
  1173. },
  1174. cancel() {
  1175. finishPageTab();
  1176. this.$router.go(-1);
  1177. },
  1178. setSchemeList(list) {
  1179. this.schemeList = list;
  1180. },
  1181. handleDetail(index, row, type) {
  1182. if (!this.sampleList[index] || !this.schemeList) {
  1183. return;
  1184. }
  1185. const selectedData = [];
  1186. selectedData.push(this.sampleList[index]);
  1187. if (this.schemeList.length != 0) {
  1188. this.sampleList.forEach((item) => {
  1189. if (item.qualitySampleTemplateList.length == 0) {
  1190. item.qualitySampleTemplateList.push(...this.schemeList);
  1191. }
  1192. });
  1193. }
  1194. this.$refs.detailRef.openDia(
  1195. index,
  1196. row,
  1197. type,
  1198. selectedData,
  1199. null,
  1200. this.schemeList.toolList
  1201. );
  1202. },
  1203. sampleListChange(sampleList) {
  1204. this.sampleList = sampleList;
  1205. },
  1206. inputWeight(row, index) {
  1207. // 计算所有样本的总重量
  1208. console.log(this.sampleList);
  1209. const pNum = this.sampleList.reduce((sum, item) => {
  1210. return sum + Number(item.weight || 0);
  1211. }, 0);
  1212. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  1213. },
  1214. handleDispose(data) {
  1215. // return
  1216. this.rowData = data;
  1217. this.sampleDisposeVisble = true;
  1218. // if (!this.sampleList[index]) {
  1219. // return;
  1220. // }
  1221. // this.sampleList[index].sampleDate = this.getNowTimes();
  1222. // this.sampleList[index].disposeTime = this.getNowTimes();
  1223. // console.log(index, row, type, this.qualityType);
  1224. // this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
  1225. },
  1226. // 报工
  1227. handleReporting(index, row) {
  1228. if (this.form.qualityIdList.length == 0) {
  1229. this.$message.error('请选择质检人');
  1230. return;
  1231. }
  1232. if (this.form.qualityMode == 2 && !this.form.qualityResults) {
  1233. this.$refs.baseInfoRefs.toggleExpand2();
  1234. this.$message.error('请选择质检结果');
  1235. return;
  1236. }
  1237. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1238. if (!valid) return false;
  1239. this.loading = true;
  1240. if (this.qualityType == 2 && this.isReportProcessProduce) {
  1241. for (let i = 0; i < this.sampleList.length; i++) {
  1242. const disposalStatus = this.sampleList[i].disposalStatus;
  1243. if (disposalStatus == null) {
  1244. this.loading = false;
  1245. this.$refs.tabsRef.tabsChange('2');
  1246. this.$message.error('请完成以下样品处置!');
  1247. return;
  1248. }
  1249. }
  1250. }
  1251. for (let i = 0; i < this.sampleList.length; i++) {
  1252. const qualityStatus = this.sampleList[i].qualityStatus;
  1253. if (qualityStatus == '2') {
  1254. this.loading = false;
  1255. this.$refs.tabsRef.tabsChange('2');
  1256. this.$message.error('请完成以下样品质检!');
  1257. return;
  1258. }
  1259. }
  1260. // this.form.qualityTimeEnd = new Date(this.getNowTime());
  1261. // this.form.qualityTimeStart = new Date(this.qualityTimeStart);
  1262. this.form.qualityTimeEnd = this.getNowTime();
  1263. this.form.qualityTimeStart = this.qualityTimeStart;
  1264. this.form.qualityId = this.form.qualityIdList.join(',');
  1265. // if (this.form.qualityMode == 1) {
  1266. // this.form.qualityResults = '';
  1267. // }
  1268. let params = {
  1269. ...this.form,
  1270. sampleList: this.sampleList,
  1271. planTemplateList: this.schemeList,
  1272. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1273. qualityInventoryList: this.inventoryList
  1274. };
  1275. exeReportWork(params)
  1276. .then((msg) => {
  1277. this.loading = false;
  1278. this.$message.success(msg);
  1279. this.cancel();
  1280. this.$emit('done');
  1281. })
  1282. .catch((e) => {
  1283. this.loading = false;
  1284. });
  1285. });
  1286. },
  1287. // 处理确认事件
  1288. handleDisposeConfirm(data, index) {
  1289. if (index == undefined) {
  1290. this.sampleList.forEach((obj) => {
  1291. obj.disposeType = data.disposeType;
  1292. obj.sampleDate = data.sampleDate;
  1293. obj.sampleCondition = data.sampleCondition;
  1294. obj.producerManufacturer = data.producerManufacturer;
  1295. obj.samplePlace = data.samplePlace;
  1296. obj.sampleRemark = data.sampleRemark;
  1297. obj.depotId = data.depotId;
  1298. obj.depotName = data.depotName;
  1299. });
  1300. } else {
  1301. this.$set(this.sampleList, index, data);
  1302. }
  1303. },
  1304. //确认质检
  1305. handleConfirm(list, index) {
  1306. // 检查有效性
  1307. // for (const item of list) {
  1308. // for (const child of item.qualitySampleTemplateList) {
  1309. //
  1310. // console.log(child, 'child')
  1311. // if (!child.qualityResultContent || !child.qualityResults) {
  1312. // this.$message.error('请完善报工内容!');
  1313. // return;
  1314. // }
  1315. // }
  1316. // }
  1317. list.forEach((item) => {
  1318. if (item.qualitySampleTemplateList.length == 1) {
  1319. if (
  1320. item.qualitySampleTemplateList.some(
  1321. (child) => child.qualityResults === 3
  1322. )
  1323. ) {
  1324. // 如果质检项只有一条而且结果为让步接收那么整个就是让步接收
  1325. item.isValid = false;
  1326. item.qualityResults = 3;
  1327. } else if (
  1328. item.qualitySampleTemplateList.some(
  1329. (child) => child.qualityResults === 2
  1330. )
  1331. ) {
  1332. item.isValid = false;
  1333. item.qualityResults = 2;
  1334. } else {
  1335. item.isValid = true;
  1336. item.qualityResults = 1;
  1337. }
  1338. } else {
  1339. 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. }
  1351. item.qualityStatus = 1;
  1352. });
  1353. if (index != null) {
  1354. this.$set(this.sampleList, index, list[0]);
  1355. // this.$set(this.sampleList, index, list[0]);
  1356. if (this.form.qualityMode == 1 && this.form.isUnpack == 2) {
  1357. this.activeName = '2';
  1358. this.countQualityResults();
  1359. return;
  1360. }
  1361. } else {
  1362. // this.$set(this.sampleList, null, list);
  1363. this.sampleList = list;
  1364. this.calculate(this.sampleList);
  1365. }
  1366. this.activeName = '2';
  1367. // *** 选完批量质检调用
  1368. // this.countQualityResults();
  1369. this.$refs.baseInfoRefs.quantityCalculation('noQualifiedNumber');
  1370. console.log('质检没有 2');
  1371. },
  1372. // 批量质检
  1373. batchQuality(index, row, type) {
  1374. // if (this.form.sampleList.qualitySampleTemplateList.length == 0) {
  1375. // this.form.sampleList.forEach((item, index) => {
  1376. // this.$set(
  1377. // this.form.sampleList[index],
  1378. // 'qualitySampleTemplateList',
  1379. // this.form.templateList
  1380. // );
  1381. // });
  1382. // }
  1383. if (this.sampleList.length == 0) {
  1384. this.$message.error('样品清单不能为空');
  1385. return;
  1386. }
  1387. if (this.schemeList.length != 0) {
  1388. this.sampleList.forEach((item) => {
  1389. if (item.qualitySampleTemplateList.length == 0) {
  1390. item.qualitySampleTemplateList.push(...this.schemeList);
  1391. }
  1392. });
  1393. }
  1394. this.$refs.detailRef.openDia(
  1395. null,
  1396. null,
  1397. 'report',
  1398. this.sampleList,
  1399. null,
  1400. this.schemeList.toolList
  1401. );
  1402. },
  1403. // 批量处置
  1404. batchDispose() {
  1405. if (this.sampleList && this.sampleList.length) {
  1406. this.sampleDisposeVisble = true;
  1407. return;
  1408. }
  1409. this.$message('当前没有样品清单可以处置');
  1410. // this.$refs.disposeRef.openDispose(
  1411. // null,
  1412. // null,
  1413. // 'dispose',
  1414. // this.qualityType
  1415. // );
  1416. },
  1417. //全检,检验标准改变时,重新获取样品列表
  1418. async changeInspectionStandardsModel(val) {
  1419. const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
  1420. if (sData.length > 0) {
  1421. for (let i = 0; i < sData.length; i++) {
  1422. this.$set(sData[i], 'qualityStatus', 2);
  1423. }
  1424. }
  1425. this.form.inspectionStandards = val;
  1426. this.form.sampleNumber = '';
  1427. this.$refs.tabsRef.tableSelClear();
  1428. this.sampleList = [];
  1429. this.$refs.tabsRef.tabsChange('1');
  1430. //检验标准 2计重 1计量
  1431. if (this.form.inspectionStandards == 2 && this.form.qualityMode == 1) {
  1432. for (let i = 0; i < sData.length; i++) {
  1433. let qualitySampleTemplateList = [];
  1434. if (
  1435. sData[i].qualitySampleTemplateList == undefined ||
  1436. sData[i].qualitySampleTemplateList == null ||
  1437. sData[i].qualitySampleTemplateList.length == 0
  1438. ) {
  1439. qualitySampleTemplateList = JSON.parse(
  1440. JSON.stringify(this.schemeList)
  1441. );
  1442. } else {
  1443. qualitySampleTemplateList = sData[i].qualitySampleTemplateList;
  1444. }
  1445. this.sampleList.push({
  1446. ...sData[i],
  1447. sampleCode: await this.getSampleCode(),
  1448. qualitySampleTemplateList
  1449. });
  1450. }
  1451. } else if (
  1452. this.form.inspectionStandards == 1 &&
  1453. this.form.qualityMode == 1
  1454. ) {
  1455. this.getProSamList(sData);
  1456. }
  1457. this.calculate(this.sampleList);
  1458. },
  1459. //从来源数组取样到目标数组
  1460. async getNewFullSampleList(
  1461. sampleCount,
  1462. sampleQuantity,
  1463. sampleUnit,
  1464. specifications
  1465. ) {
  1466. const sourceArray = this.selectedList;
  1467. // 检查单位是否匹配
  1468. const isUnitMismatch =
  1469. sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
  1470. // 创建副本并计算初始可取样数量
  1471. const items = sourceArray.map((item) => ({
  1472. ...item,
  1473. remainingQuantity: isUnitMismatch
  1474. ? Infinity
  1475. : item['measureQuantity'], // 剩余可取样数量
  1476. maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
  1477. }));
  1478. const result = [];
  1479. let remainingCount = sampleCount;
  1480. let count = Math.ceil(remainingCount);
  1481. const codeList = await this.batchCodes(count);
  1482. let codeIdx = 0;
  1483. // 尽可能均匀地从各条目取样
  1484. while (remainingCount > 0) {
  1485. // 按剩余可取样比例排序
  1486. items.sort(
  1487. (a, b) =>
  1488. b.remainingQuantity / b['measureQuantity'] -
  1489. a.remainingQuantity / a['measureQuantity']
  1490. );
  1491. let distributed = false;
  1492. for (const item of items) {
  1493. // let values = remainingCount > 1 ? 1 : remainingCount;
  1494. if (
  1495. !isUnitMismatch ||
  1496. (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
  1497. ) {
  1498. let qualitySampleTemplateList = [];
  1499. if (
  1500. item.qualitySampleTemplateList == undefined ||
  1501. item.qualitySampleTemplateList == null ||
  1502. item.qualitySampleTemplateList.length == 0
  1503. ) {
  1504. qualitySampleTemplateList = JSON.parse(
  1505. JSON.stringify(this.schemeList)
  1506. );
  1507. } else {
  1508. qualitySampleTemplateList = item.qualitySampleTemplateList;
  1509. }
  1510. // 添加到结果数组
  1511. // let sampleCode = await this.getSampleCode();
  1512. let sampleCode = codeList[codeIdx];
  1513. if (
  1514. this.form.conditionType == 1 &&
  1515. this.form.inspectionStandards == 1
  1516. ) {
  1517. result.push({
  1518. ...item,
  1519. // measureQuantity: values,
  1520. measureQuantity: 1,
  1521. sampleCode,
  1522. qualitySampleTemplateList
  1523. });
  1524. } else if (
  1525. this.form.conditionType == 2 &&
  1526. (this.form.inspectionStandards == 1 ||
  1527. this.form.inspectionStandards == 2)
  1528. ) {
  1529. let weight = (item.weight / item.maxPossible).toFixed(2);
  1530. result.push({
  1531. ...item,
  1532. measureQuantity: sampleQuantity,
  1533. measureUnit: sampleUnit,
  1534. sampleCode,
  1535. weight,
  1536. qualitySampleTemplateList
  1537. });
  1538. }
  1539. // 更新剩余数量
  1540. if (!isUnitMismatch) {
  1541. item.remainingQuantity -= sampleQuantity;
  1542. }
  1543. remainingCount = (remainingCount - 1).toFixed(2);
  1544. codeIdx++;
  1545. distributed = true;
  1546. }
  1547. }
  1548. // 如果没有分配任何取样
  1549. if (!distributed) {
  1550. break;
  1551. }
  1552. }
  1553. // 判断是不是取整样
  1554. if (
  1555. this.form.conditionType == 1 &&
  1556. specifications &&
  1557. specifications.id
  1558. ) {
  1559. result.map((el) => {
  1560. el.measureQuantity =
  1561. el.measureQuantity * specifications.packageCellTotal;
  1562. el.weight = this.formatNumber(
  1563. el.measureQuantity,
  1564. el.weightProportion
  1565. );
  1566. });
  1567. }
  1568. this.sampleList = result;
  1569. if (this.sampleList.length > sampleCount) {
  1570. this.sampleList = this.sampleList.splice(0, sampleCount);
  1571. }
  1572. this.form.sampleNumber = this.sampleList.length;
  1573. this.calculate(this.sampleList);
  1574. },
  1575. // 小数点数据判断
  1576. formatNumber(a, b, maxDecimals = 4) {
  1577. if (a == 0 || b == 0 || !a || !b) {
  1578. return 0;
  1579. }
  1580. // 计算乘积
  1581. const product = a * b;
  1582. // 转换为固定小数位数,然后转换为数字以去除末尾零
  1583. const rounded = Number(product.toFixed(maxDecimals));
  1584. // 转换为字符串检查是否需要显示小数部分
  1585. const str = rounded.toString();
  1586. // 如果包含小数点
  1587. if (str.indexOf('.') !== -1) {
  1588. // 移除末尾的零和小数点(如果后面没有数字了)
  1589. return str.replace(/\.?0+$/, '');
  1590. }
  1591. return str;
  1592. },
  1593. validateWeight(measureQ, sampleCount) {
  1594. let totalMaxPossible = 0;
  1595. this.selectedList.forEach((item) => {
  1596. totalMaxPossible += item.measureQuantity / measureQ;
  1597. });
  1598. if (totalMaxPossible < sampleCount) {
  1599. // this.formData.portion = totalMaxPossible;
  1600. this.$message.info(`最大取样条数为${totalMaxPossible}`);
  1601. return false;
  1602. }
  1603. let totalWeight = this.selectedList.reduce(
  1604. (sum, item) => sum + item.weight,
  1605. 0
  1606. );
  1607. const weightUnit = this.selectedList[0].weightUnit;
  1608. if (weightUnit === 'G') totalWeight /= 1000;
  1609. if (measureQ * sampleCount > totalWeight) {
  1610. this.$message.info('取样计量重量不能大于总计量重量');
  1611. return false;
  1612. }
  1613. const invalidItem = this.selectedList.find((item) => {
  1614. const weight =
  1615. item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
  1616. return weight < measureQ;
  1617. });
  1618. if (invalidItem) {
  1619. this.$message.info('勾选条目重量小于取样重量');
  1620. return false;
  1621. }
  1622. return true;
  1623. },
  1624. isStandard1OrWeightSample() {
  1625. return (
  1626. this.form.inspectionStandards === 1 ||
  1627. (this.form.inspectionStandards === 2 && this.form.conditionType == 2)
  1628. );
  1629. },
  1630. validateMeasureQuantity(measureQ, unit, sampleCount) {
  1631. if (this.form.conditionType == 2 && measureQ <= 0) {
  1632. this.$message.info('取样计量数量必须大于0');
  1633. return false;
  1634. }
  1635. const totalQuantity = this.selectedList.reduce(
  1636. (sum, item) => sum + item.measureQuantity,
  1637. 0
  1638. );
  1639. if (
  1640. (this.selectedList[0].measureUnit === unit ||
  1641. this.form.conditionType == 1) &&
  1642. measureQ * sampleCount > totalQuantity
  1643. ) {
  1644. this.$message.info('取样计量数量不能大于总计量数量');
  1645. return false;
  1646. }
  1647. const invalidItem = this.selectedList.find(
  1648. (item) => item.measureQuantity < measureQ
  1649. );
  1650. if (invalidItem) {
  1651. this.$message.info('条目计量数量小于取样计量数量');
  1652. return false;
  1653. }
  1654. return true;
  1655. },
  1656. isWeightStandardFullSample() {
  1657. return (
  1658. this.form.inspectionStandards === 2 && this.form.conditionType == 1
  1659. );
  1660. },
  1661. // 抽检取整样 校验
  1662. validateSampleCount(sampleCount, specifications) {
  1663. // 新增校验 ***
  1664. let isFlag = this.validateSampleQuantity(sampleCount, specifications);
  1665. if (!isFlag) {
  1666. return false;
  1667. }
  1668. // ***
  1669. const chooseNumber = this.selectedList.reduce((acc, pro) => {
  1670. return pro.measureQuantity ? acc + Number(pro.measureQuantity) : acc;
  1671. }, 0);
  1672. const invalidItem = chooseNumber < sampleCount;
  1673. // console.log(this.selectedList, 'this.selectedList');
  1674. // const invalidItem = this.selectedList.find(
  1675. // (item) => item.measureQuantity < sampleCount
  1676. // );
  1677. if (invalidItem) {
  1678. this.$message.info('所选的条目计量数量小于取样计量数量');
  1679. return false;
  1680. }
  1681. // ***
  1682. return true;
  1683. },
  1684. async handleWeightFullSample(sampleCount, specifications) {
  1685. const dataList = [];
  1686. let currentNum = sampleCount - this.selectedList.length;
  1687. let currentNum1 = sampleCount;
  1688. for (const item of this.selectedList) {
  1689. const qualitySampleTemplateList = item.qualitySampleTemplateList
  1690. ?.length
  1691. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  1692. : JSON.parse(
  1693. JSON.stringify(
  1694. this.schemeList.map((item) => {
  1695. item['qualityResults'] = 1;
  1696. return item;
  1697. })
  1698. )
  1699. );
  1700. if (sampleCount >= this.selectedList.length) {
  1701. dataList.push({
  1702. ...item,
  1703. measureQuantity: 1, //作为计量数量
  1704. sampleCode: await this.getSampleCode(),
  1705. qualitySampleTemplateList
  1706. });
  1707. } else {
  1708. if (dataList.length < sampleCount) {
  1709. dataList.push({
  1710. ...item,
  1711. measureQuantity: currentNum1 > 1 ? 1 : currentNum1, //作为计量数量
  1712. sampleCode: await this.getSampleCode(),
  1713. qualitySampleTemplateList
  1714. });
  1715. currentNum1 -= 1;
  1716. }
  1717. }
  1718. }
  1719. if (sampleCount > this.selectedList.length) {
  1720. dataList.forEach((item) => {
  1721. if (currentNum > 0) {
  1722. let data = this.selectedList.find((val) => val.id == item.id);
  1723. item['measureQuantity'] =
  1724. data.measureQuantity - 1 - currentNum > 0
  1725. ? currentNum + 1
  1726. : data.measureQuantity;
  1727. currentNum = currentNum - (data.measureQuantity - 1);
  1728. }
  1729. });
  1730. }
  1731. // 更改 从新计算 样品清单 取整样 数据
  1732. if (specifications && specifications.id) {
  1733. // let proportion = (obj.weight / obj.measureQuantity).toFixed(2);
  1734. dataList.map((el) => {
  1735. el.measureQuantity =
  1736. el.measureQuantity * specifications.packageCellTotal;
  1737. el.weight = this.formatNumber(
  1738. el.measureQuantity,
  1739. el.weightProportion
  1740. );
  1741. });
  1742. }
  1743. // 更改
  1744. this.sampleList = dataList;
  1745. this.calculate(this.sampleList);
  1746. this.sampleNumber = this.sampleList.length;
  1747. },
  1748. // 批量生成编码 4444444 getCodeList
  1749. async batchCodes(count) {
  1750. if (count <= 0) return;
  1751. let params = { count };
  1752. const res = await getCodeList('sample_code', params);
  1753. return res;
  1754. },
  1755. //计算合格率
  1756. countQualityResults() {
  1757. console.log(321);
  1758. let sampleList = this.sampleList; //样品清单
  1759. let sampleNumber = this.form.total; //样品总数
  1760. // let qualifiedNumber = sampleList.filter(item => item.qualityResults == 1 || item.qualityResults == 3).length;
  1761. // let noQualifiedNumber = sampleList.filter(
  1762. // (item) => item.qualityResults == 2
  1763. // ).length;
  1764. let noQualifiedNumber = sampleList.reduce((acc, pro) => {
  1765. // console.log(acc, pro);
  1766. // if (pro.qualityResults == 2) {
  1767. // return acc + Number(pro.measureQuantity);
  1768. // }
  1769. return pro.qualityResults == 2
  1770. ? acc + Number(pro.measureQuantity)
  1771. : acc;
  1772. }, 0);
  1773. let qualifiedNumber = sampleNumber - noQualifiedNumber; //不合格数
  1774. let qualificationRate = (
  1775. (qualifiedNumber / sampleNumber) *
  1776. 100
  1777. ).toFixed(2); //合格率
  1778. let noQualificationRate = (
  1779. (noQualifiedNumber / sampleNumber) *
  1780. 100
  1781. ).toFixed(2); //不合格率
  1782. this.$refs.baseInfoRefs.updateQualificationRate(
  1783. qualifiedNumber,
  1784. noQualifiedNumber,
  1785. qualificationRate,
  1786. noQualificationRate
  1787. );
  1788. this.calculate(this.sampleList);
  1789. },
  1790. closeDispose() {
  1791. this.rowData = null;
  1792. this.sampleDisposeVisble = false;
  1793. // this.rowData = null;
  1794. }
  1795. }
  1796. };
  1797. </script>
  1798. <style lang="scss" scoped></style>