edit.vue 74 KB

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