edit.vue 79 KB

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