edit.vue 59 KB

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