edit.vue 85 KB

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