edit.vue 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469
  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. });
  590. this.form.sampleNoQualificationRate =
  591. (
  592. (this.form.sampleNoQualifiedNumber / this.form.sampleQuantity) *
  593. 100
  594. ).toFixed(2) + '%';
  595. this.form.sampleQualificationRate =
  596. (
  597. (this.form.sampleQualifiedNumber / this.form.sampleQuantity) *
  598. 100
  599. ).toFixed(2) + '%';
  600. this.quantityAssignment();
  601. },
  602. //合格与不合格数变化处理逻辑
  603. quantityCalculation(val) {
  604. this.$refs.tabsRef.setSampleList(val, this.form.total);
  605. },
  606. setInspectionResults(list) {
  607. this.$nextTick(() => {
  608. let qualityResults = this.form.qualityResults;
  609. let showArrange = this.$refs.baseInfoRefs.showArrange;
  610. if (
  611. showArrange == '1' ||
  612. (showArrange == '2' && this.form.qualityMode != '2')
  613. ) {
  614. return;
  615. }
  616. if (qualityResults == null || qualityResults == undefined) {
  617. for (let i = 0; i < list.length; i++) {
  618. let el = list[i];
  619. if (el.qualityResults == 2) {
  620. this.$set(this.form, 'qualityResults', 2);
  621. return;
  622. }
  623. }
  624. this.$set(this.form, 'qualityResults', 1);
  625. // this.$set(this.form, 'status', 1);
  626. console.log(list, 'list');
  627. console.log(this.form.qualityResults, '检测结果');
  628. }
  629. });
  630. },
  631. inputValue(key, totalKey) {
  632. if (totalKey == 'sampleQualifiedNumber') {
  633. if (
  634. Number(this.form.retainedSampleQuantity || 0) +
  635. Number(this.form.lossNumber || 0) >
  636. this.form.sampleQualifiedNumber
  637. ) {
  638. this.$message.error('留样合格数与损耗合格数之和不能大于样品合格数');
  639. this.form[key] = 0;
  640. }
  641. } else {
  642. if (
  643. Number(this.form.retainedSampleUnqualified) +
  644. Number(this.form.lossNumberUnqualified) >
  645. this.form.sampleNoQualifiedNumber
  646. ) {
  647. this.$message.error(
  648. '留样不合格数与损耗不合格数之和不能大于样品不合格数'
  649. );
  650. this.form[key] = 0;
  651. }
  652. }
  653. if (this.form[key] < this.getSampleQuantityYp(key)) {
  654. this.form[key] = this.getSampleQuantityYp(key) || 0;
  655. }
  656. },
  657. //
  658. calculate(list) {
  659. if (list.length == 0) {
  660. this.form.sampleQuantity = 0;
  661. this.form.sampleWeight = 0;
  662. }
  663. let sampleQuantity = 0; // 样品数量
  664. let sampleWeight = 0; // 样品重量
  665. let sampleQualifiedNumber = 0; // 样品合格数
  666. let sampleNoQualifiedNumber = 0; // 样品不合格数
  667. list.forEach((el) => {
  668. sampleQuantity += el.measureQuantity - 0;
  669. sampleWeight += el.weight - 0;
  670. if (el.qualityResults != 2) {
  671. sampleQualifiedNumber += el.measureQuantity - 0;
  672. } else {
  673. sampleNoQualifiedNumber += el.measureQuantity - 0;
  674. }
  675. });
  676. // 计算合格率和不合格率(百分比形式)
  677. let sampleQualificationRate = '';
  678. let sampleNoQualificationRate = '';
  679. if (
  680. (sampleQualifiedNumber || sampleQualifiedNumber == 0) &&
  681. sampleQuantity !== 0
  682. ) {
  683. sampleQualificationRate =
  684. ((sampleQualifiedNumber / sampleQuantity) * 100).toFixed(2) || '';
  685. sampleNoQualificationRate =
  686. ((sampleNoQualifiedNumber / sampleQuantity) * 100).toFixed(2) || '';
  687. }
  688. if (sampleQualificationRate || sampleQualificationRate == '0.00') {
  689. if (isNaN(sampleQualificationRate)) {
  690. sampleQualificationRate = '0%';
  691. } else {
  692. sampleQualificationRate = sampleQualificationRate + '%';
  693. }
  694. }
  695. if (sampleNoQualificationRate || sampleNoQualificationRate == '0.00') {
  696. if (isNaN(sampleNoQualificationRate)) {
  697. sampleNoQualificationRate = '0%';
  698. } else {
  699. sampleNoQualificationRate = sampleNoQualificationRate + '%';
  700. }
  701. }
  702. // let resultsTotal = this.form.total - sampleQuantity;
  703. // if (sampleQuantity == sampleQualifiedNumber) {
  704. // // this.$set(this.form, 'qualifiedNumber', resultsTotal);
  705. // // this.$set(this.form, 'noQualifiedNumber', 0);
  706. // this.$set(this.form, 'qualificationRate', '100%');
  707. // this.$set(this.form, 'noQualificationRate', '0');
  708. // this.$set(this.form, 'qualityResults', 1);
  709. // } else {
  710. // // this.$set(this.form, 'noQualifiedNumber', resultsTotal);
  711. // // this.$set(this.form, 'qualifiedNumber', 0);
  712. // this.$set(this.form, 'qualificationRate', '0');
  713. // this.$set(this.form, 'noQualificationRate', '100%');
  714. // this.$set(this.form, 'qualityResults', 2);
  715. // }
  716. // this.$nextTick(() => {
  717. let showArrange = this.$refs.baseInfoRefs?.showArrange;
  718. if (
  719. showArrange != '1' ||
  720. (showArrange == '2' && this.form.qualityMode == '2')
  721. ) {
  722. if (sampleQuantity == sampleQualifiedNumber) {
  723. this.$set(this.form, 'qualificationRate', '100%');
  724. this.$set(this.form, 'noQualificationRate', '0');
  725. this.$set(this.form, 'qualityResults', 1);
  726. //样品数量和样品合格数相等 默认合格率100% 不合格率0% 检测结果合格
  727. this.$set(this.form, 'qualifiedNumber', this.form.total);
  728. this.$set(this.form, 'noQualifiedNumber', 0);
  729. } else {
  730. this.$set(this.form, 'qualificationRate', '0');
  731. this.$set(this.form, 'noQualificationRate', '100%');
  732. this.$set(this.form, 'qualityResults', 2);
  733. }
  734. }
  735. // });
  736. // this.$set(this.form, 'resultsTotal', resultsTotal);
  737. console.log(sampleQualificationRate, 'sampleQualificationRate');
  738. this.$set(
  739. this.form,
  740. 'sampleQualificationRate',
  741. sampleQualificationRate
  742. );
  743. this.$set(
  744. this.form,
  745. 'sampleNoQualificationRate',
  746. sampleNoQualificationRate
  747. );
  748. this.$set(this.form, 'sampleQuantity', sampleQuantity);
  749. this.$set(this.form, 'sampleWeight', sampleWeight);
  750. this.$set(this.form, 'sampleQualifiedNumber', sampleQualifiedNumber);
  751. this.$set(
  752. this.form,
  753. 'sampleNoQualifiedNumber',
  754. sampleNoQualifiedNumber
  755. );
  756. // 数量赋值
  757. console.log(this.form, 'this.form');
  758. this.quantityAssignment();
  759. },
  760. // 计算合格数不合格数
  761. quantityAssignment() {
  762. let showArrange = this.$refs.baseInfoRefs?.showArrange;
  763. let noQualifiedNumber = 0;
  764. let qualifiedNumber = 0;
  765. let data = this.form;
  766. let total = data.total - 0;
  767. if (this.form.qualityResults == 2) {
  768. noQualifiedNumber = total - (data.sampleQualifiedNumber - 0);
  769. qualifiedNumber = total - noQualifiedNumber;
  770. } else {
  771. qualifiedNumber = total - (data.sampleNoQualifiedNumber - 0);
  772. noQualifiedNumber = total - qualifiedNumber;
  773. }
  774. this.$set(this.form, 'qualifiedNumber', qualifiedNumber);
  775. this.$set(this.form, 'noQualifiedNumber', noQualifiedNumber);
  776. if (
  777. showArrange != '1' ||
  778. (showArrange == '2' && this.form.qualityMode == '2')
  779. ) {
  780. return;
  781. }
  782. this.$set(
  783. this.form,
  784. 'qualificationRate',
  785. ((qualifiedNumber / total) * 100).toFixed(2) + '%'
  786. );
  787. this.$set(
  788. this.form,
  789. 'noQualificationRate',
  790. ((noQualifiedNumber / total) * 100).toFixed(2) + '%'
  791. );
  792. },
  793. //切换检验方式
  794. changeModel(val, flag) {
  795. this.$refs.tabsRef.tableSelClear();
  796. this.sampleList = [];
  797. this.$refs.tabsRef.tabsChange('1');
  798. this.$refs.tabsRef.tabsConditionType(null);
  799. this.form.qualityMode = val;
  800. //检验方式 全检
  801. if (this.form.qualityMode == 1) {
  802. this.activeName = '2';
  803. this.form.sampleNumber = '';
  804. this.changeGetSampleList(this.inventoryList);
  805. } else {
  806. this.activeName = '1';
  807. if (!flag) {
  808. this.sampleList = [];
  809. }
  810. }
  811. this.calculate([]);
  812. },
  813. //根据类型判断样品清单现实列表数据
  814. async getProSamList(list) {
  815. //生产检验
  816. if (this.qualityType == 2) {
  817. if (this.form.qualityMode != null) {
  818. const ProductSampleList = [];
  819. for (const oldItem of list) {
  820. const count = oldItem.measureQuantity;
  821. const newMeasureQuantity = oldItem.measureQuantity / count;
  822. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  823. // 遍历新数组设置 qualityResults 默认值
  824. this.schemeList.forEach((item) => {
  825. if (typeof item === 'object' && item !== null) {
  826. item.qualityResults = 1; // 设置默认值
  827. }
  828. delete item.id;
  829. });
  830. delete oldItem.id;
  831. if (
  832. oldItem.qualitySampleTemplateList == undefined ||
  833. oldItem.qualitySampleTemplateList == null ||
  834. oldItem.qualitySampleTemplateList.length == 0
  835. ) {
  836. oldItem.qualitySampleTemplateList = JSON.parse(
  837. JSON.stringify(this.schemeList)
  838. );
  839. for (let i = 0; i < count; i++) {
  840. ProductSampleList.push({
  841. ...oldItem,
  842. measureQuantity: newMeasureQuantity,
  843. weight: newWeight,
  844. sampleCode: await this.getSampleCode(),
  845. qualitySampleTemplateList: JSON.parse(
  846. JSON.stringify(this.schemeList)
  847. )
  848. });
  849. }
  850. this.sampleList = ProductSampleList;
  851. this.calculate(this.sampleList);
  852. const pNum = ProductSampleList.reduce((sum, item) => {
  853. return sum + Number(item.weight || 0);
  854. }, 0);
  855. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  856. } else {
  857. for (let i = 0; i < count; i++) {
  858. ProductSampleList.push({
  859. ...oldItem,
  860. measureQuantity: newMeasureQuantity,
  861. weight: newWeight,
  862. sampleCode: await this.getSampleCode(),
  863. qualitySampleTemplateList: JSON.parse(
  864. JSON.stringify(oldItem.qualitySampleTemplateList)
  865. )
  866. });
  867. }
  868. this.sampleList = ProductSampleList;
  869. this.calculate(this.sampleList);
  870. const pNum = ProductSampleList.reduce((sum, item) => {
  871. return sum + Number(item.weight || 0);
  872. }, 0);
  873. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  874. }
  875. }
  876. }
  877. } else {
  878. // this.sampleList = list;
  879. this.sampleList = this.addStatus;
  880. }
  881. },
  882. // 创建计量数量为1的样品清单函数,用于计数类型的
  883. async createSampleList(list) {
  884. if (this.form.qualityMode != null) {
  885. this.$message.closeAll();
  886. this.$message('正在生成样品清单');
  887. const ProductSampleList = [];
  888. for (const oldItem of list) {
  889. const count = oldItem.measureQuantity ? oldItem.measureQuantity : 1;
  890. const newMeasureQuantity = oldItem.measureQuantity / count;
  891. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  892. // 遍历新数组设置 qualityResults 默认值
  893. this.schemeList.forEach((item) => {
  894. if (typeof item === 'object' && item !== null) {
  895. item.qualityResults = 1; // 设置默认值
  896. }
  897. delete item.id;
  898. });
  899. delete oldItem.id;
  900. if (
  901. oldItem.qualitySampleTemplateList == undefined ||
  902. oldItem.qualitySampleTemplateList == null ||
  903. oldItem.qualitySampleTemplateList.length == 0
  904. ) {
  905. oldItem.qualitySampleTemplateList = JSON.parse(
  906. JSON.stringify(this.schemeList)
  907. );
  908. for (let i = 0; i < count; i++) {
  909. ProductSampleList.push({
  910. ...oldItem,
  911. measureQuantity: newMeasureQuantity,
  912. weight: newWeight,
  913. sampleCode: await this.getSampleCode(),
  914. qualitySampleTemplateList: JSON.parse(
  915. JSON.stringify(this.schemeList)
  916. )
  917. });
  918. }
  919. this.sampleList = ProductSampleList;
  920. this.calculate(this.sampleList);
  921. const pNum = ProductSampleList.reduce((sum, item) => {
  922. return sum + Number(item.weight || 0);
  923. }, 0);
  924. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  925. } else {
  926. for (let i = 0; i < count; i++) {
  927. ProductSampleList.push({
  928. ...oldItem,
  929. measureQuantity: newMeasureQuantity,
  930. weight: newWeight,
  931. sampleCode: await this.getSampleCode(),
  932. qualitySampleTemplateList: JSON.parse(
  933. JSON.stringify(oldItem.qualitySampleTemplateList)
  934. )
  935. });
  936. }
  937. this.sampleList = ProductSampleList;
  938. this.calculate(this.sampleList);
  939. const pNum = ProductSampleList.reduce((sum, item) => {
  940. return sum + Number(item.weight || 0);
  941. }, 0);
  942. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  943. }
  944. }
  945. }
  946. },
  947. // 全检计量计重的样品清单函数
  948. async updatePackingList(list, sampleCount) {
  949. // for (let i = 0; i < list.length; i++) {
  950. // list[i].sampleCode = await this.getSampleCode();
  951. // }
  952. const dataList = [];
  953. let currentNum = sampleCount - list.length;
  954. let currentNum1 = sampleCount;
  955. // console.log(this.selectedList);
  956. let count = list ? list.length : 0;
  957. const codeList = await this.batchCodes(count);
  958. for (const [index, item] of list.entries()) {
  959. const qualitySampleTemplateList = item.qualitySampleTemplateList
  960. ?.length
  961. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  962. : JSON.parse(
  963. JSON.stringify(
  964. this.schemeList.map((item) => {
  965. item['qualityResults'] = 1;
  966. return item;
  967. })
  968. )
  969. );
  970. if (sampleCount >= list.length) {
  971. dataList.push({
  972. ...item,
  973. measureQuantity: item.measureQuantity, //作为计量数量
  974. // sampleCode: await this.getSampleCode(),
  975. sampleCode: codeList[index],
  976. qualitySampleTemplateList
  977. });
  978. }
  979. }
  980. this.sampleList = dataList;
  981. this.calculate(this.sampleList);
  982. this.sampleNumber = this.sampleList.length;
  983. },
  984. //检测项报工
  985. inspectionProjectReport({ index, list }) {
  986. this.$nextTick(() => {
  987. // if (this.form.taskMonadInfo) {
  988. // delete this.form.taskMonadInfo.remainingSampleCount;
  989. // }
  990. this.$refs.inspectionProjectReportRef.open(
  991. {
  992. workData: {
  993. qualityWorkOrderCode: this.form.code,
  994. qualityWorkOrderName: this.form.name,
  995. qualityWorkOrderId: this.form.id,
  996. sourceCode: this.form.sourceCode,
  997. qualityType: this.form.qualityType,
  998. qualityMode: this.form.qualityMode,
  999. productCode: this.form.productCode,
  1000. productName: this.form.productName,
  1001. batchNo: this.form.batchNo,
  1002. specification: this.form.specification,
  1003. brandNo: this.form.brandNo,
  1004. produceTaskName: this.form.produceTaskName,
  1005. total: this.form.total,
  1006. hours: this.form.hours,
  1007. accessory: this.form.accessory,
  1008. qualityNames: this.form.qualityNames,
  1009. qualityTimeEnd: this.form.qualityTimeEnd,
  1010. workSampleCount: this.form.sampleQuantity,
  1011. // remainingSampleCount: this.form.remainingSampleCount,
  1012. measureUnit: this.sampleList[0]?.measureUnit
  1013. },
  1014. row: this.form.taskMonadInfo || {},
  1015. list
  1016. },
  1017. 'report'
  1018. );
  1019. });
  1020. },
  1021. //检测项报工回调
  1022. inspectionProjectReportSuccess({ data, tableData }) {
  1023. this.schemeList = [
  1024. ...tableData,
  1025. ...this.schemeList.filter((item) => item.correlationId)
  1026. ];
  1027. data.type = 2;
  1028. // this.form.remainingSampleCount =
  1029. // data.remainingSampleCount - data.sampleQuantity;
  1030. this.form.taskMonadInfo = data;
  1031. this.form.hours = data.hours;
  1032. this.getSampleQuantity();
  1033. console.log(this.schemeList, 'this.schemeList');
  1034. },
  1035. // 切换检验方式为全检后生成样品
  1036. changeGetSampleList(list) {
  1037. this.$message.closeAll();
  1038. this.$message('正在生成样品清单');
  1039. // // 计量类型1是数量,2是重量
  1040. // if (this.form.inspectionStandards == 1) {
  1041. // this.createSampleList(list);
  1042. // }
  1043. // if (this.form.inspectionStandards == 2) {
  1044. // this.updatePackingList(list, this.form.total);
  1045. // // this.handleWeightFullSample(this.form.total);
  1046. // }
  1047. this.updatePackingList(list, this.form.total);
  1048. },
  1049. //输入取样数量
  1050. changeNumber(val) {
  1051. if (this.form.qualityMode !== 2) {
  1052. return;
  1053. }
  1054. if (val <= 0) {
  1055. this.$refs.showPackingListTable.clearSelection();
  1056. return;
  1057. }
  1058. if (this.qualityType == 2) {
  1059. //生产检验的抽检逻辑
  1060. if (val > this.packingList[0].measureQuantity) {
  1061. this.$message.warning('取样数量不能大于来源清单的计量数量!');
  1062. return;
  1063. }
  1064. const ProductSampleList = [];
  1065. this.packingList.forEach((oldItem) => {
  1066. const count = oldItem.measureQuantity;
  1067. const newMeasureQuantity = oldItem.measureQuantity / count;
  1068. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  1069. delete oldItem.id;
  1070. // 遍历新数组设置 qualityResults 默认值
  1071. this.schemeList.forEach((item) => {
  1072. if (typeof item === 'object' && item !== null) {
  1073. item.qualityResults = 1; // 设置默认值
  1074. }
  1075. delete item.id;
  1076. });
  1077. for (let i = 0; i < val; i++) {
  1078. ProductSampleList.push({
  1079. ...oldItem,
  1080. measureQuantity: newMeasureQuantity,
  1081. weight: newWeight,
  1082. qualitySampleTemplateList: JSON.parse(
  1083. JSON.stringify(this.schemeList)
  1084. )
  1085. });
  1086. }
  1087. });
  1088. this.sampleList = ProductSampleList;
  1089. this.calculate(this.sampleList);
  1090. const pNum = ProductSampleList.reduce((sum, item) => {
  1091. return sum + Number(item.weight || 0);
  1092. }, 0);
  1093. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  1094. } else {
  1095. if (val > this.packingList.length) {
  1096. this.$message.warning('取样数量不能大于物料明细总数!');
  1097. return;
  1098. }
  1099. const rows = this.packingList.slice(0, val);
  1100. rows.forEach((row) => {
  1101. this.$refs.showPackingListTable.toggleRowSelection(row);
  1102. });
  1103. }
  1104. },
  1105. getNowDate() {
  1106. let date = new Date(),
  1107. obj = {
  1108. year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
  1109. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  1110. strDate: date.getDate(), // 获取当前日(1-31)
  1111. hour: date.getHours(), //获取当前小时(0 ~ 23)
  1112. minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
  1113. second: date.getSeconds() //获取当前秒数(0 ~ 59)
  1114. };
  1115. Object.keys(obj).forEach((key) => {
  1116. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  1117. });
  1118. return obj;
  1119. },
  1120. //来源清单勾选事件
  1121. handleSelectionChange1(selection) {
  1122. if (this.form.qualityMode === 2) {
  1123. this.selectedList = selection;
  1124. this.activeName = '1';
  1125. if (this.schemeList.length == 0) {
  1126. for (let i = 0; i < selection.length; i++) {
  1127. this.$set(selection[i], 'qualityStatus', 2);
  1128. // 遍历新数组设置 qualityResults 默认值
  1129. this.schemeList.forEach((item) => {
  1130. if (typeof item === 'object' && item !== null) {
  1131. item.qualityResults = 1; // 设置默认值
  1132. }
  1133. delete item.id;
  1134. });
  1135. this.$set(
  1136. selection[i],
  1137. 'qualitySampleTemplateList',
  1138. JSON.parse(JSON.stringify(this.schemeList))
  1139. );
  1140. }
  1141. }
  1142. // this.sampleList = selection;
  1143. //赋值取样数量
  1144. this.form.sampleNumber = selection.length;
  1145. }
  1146. },
  1147. async open() {
  1148. this.type = this.$route.query.type;
  1149. this.qualityType = this.$route.query.qualityType;
  1150. this.title =
  1151. this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
  1152. if (this.type == 'add') {
  1153. const code = await getCode('quality_work_order_code');
  1154. this.form.code = code;
  1155. } else {
  1156. if (
  1157. this.$route.query.qualityTimeStart != '' ||
  1158. this.$route.query.qualityTimeStart != null ||
  1159. this.$route.query.qualityTimeStart != undefined
  1160. ) {
  1161. this.qualityTimeStart = this.getNowTime();
  1162. }
  1163. }
  1164. },
  1165. getNowTime() {
  1166. const nowDate = this.getNowDate();
  1167. return (
  1168. nowDate.year +
  1169. '-' +
  1170. nowDate.month +
  1171. '-' +
  1172. nowDate.strDate +
  1173. ' ' +
  1174. nowDate.hour +
  1175. ':' +
  1176. nowDate.minute +
  1177. ':' +
  1178. nowDate.second
  1179. );
  1180. },
  1181. getNowTimes() {
  1182. const nowDate = this.getNowDate();
  1183. return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate;
  1184. },
  1185. async getDetail() {
  1186. await getById(this.$route.query.id).then((res) => {
  1187. if (res.data.jobList?.length == 1) {
  1188. res.data.executeJobId = res.data.jobList[0].id;
  1189. res.data.executeJobName = res.data.jobList[0].name;
  1190. }
  1191. this.form = res.data;
  1192. console.log(this.form, 'this.form');
  1193. this.form.executeUserIdList = this.form.executeUserId
  1194. ? this.form.executeUserId.split(',')
  1195. : [];
  1196. this.form.qualityIdList = this.form.qualityId
  1197. ? this.form.qualityId.split(',')
  1198. : [];
  1199. this.productId = res.data.productId || '';
  1200. this.statusType = this.form.status == 1 ? true : false;
  1201. this.isReportProcessProduce =
  1202. this.form.isReportProcessProduce == 1 ? true : false;
  1203. this.tabTaskId =
  1204. this.categoryParamList[0] && this.categoryParamList[0].id;
  1205. if (this.form.assignType == 1) {
  1206. this.form.executeUserIdList = [this.$store.state.user.info.userId];
  1207. this.form.executeUserName = this.$store.state.user.info.name;
  1208. }
  1209. //宇信
  1210. if (this.$store.state.user.info.clientEnvironmentId == 10) {
  1211. //客户:5#和6#默认是重油公司7#默认是红山 2008389016775864321==7#
  1212. if (this.form.productLineId == '2008389016775864321') {
  1213. this.form.contactId =
  1214. this.form.contactId || '2008562263580520449';
  1215. this.form.contactName =
  1216. this.form.contactName || '克拉玛依红山油田有限责任公司';
  1217. } else {
  1218. this.form.contactId =
  1219. this.form.contactId || '2008383566202318850';
  1220. this.form.contactName =
  1221. this.form.contactName || '中国石油新疆油田分公司(重油公司)';
  1222. }
  1223. }
  1224. if (this.form.groupId) {
  1225. this.$nextTick(() => {
  1226. this.$refs.baseInfoRefs?.getUserList({
  1227. groupId: this.form.groupId
  1228. });
  1229. });
  1230. }
  1231. if (this.form.produceRoutingId) {
  1232. this.$nextTick(() => {
  1233. this.$refs.baseInfoRefs?.getTaskList();
  1234. });
  1235. }
  1236. });
  1237. // await this.queryQualityInventory()
  1238. // 检测方案
  1239. await this.queryQualityTempleContent();
  1240. // 样品清单
  1241. await this.queryQualitySamplContent();
  1242. // 来源清单
  1243. await this.getQueryQualityInventory();
  1244. console.log(this.form.recordingMethod, 'this.form.recordingMethod');
  1245. if (this.form.recordingMethod != 1) {
  1246. [
  1247. 'retainedSampleQuantity',
  1248. 'retainedSampleUnqualified',
  1249. 'lossNumber',
  1250. 'lossNumberUnqualified'
  1251. ].forEach((key) => {
  1252. this.form[key] =
  1253. this.form[key] || this.getSampleQuantityYp(key) || 0;
  1254. });
  1255. } else {
  1256. this.getSampleQuantity();
  1257. }
  1258. // this.getSampleQuantityYp()
  1259. },
  1260. // getNewData(val) {
  1261. // console.log(val, '清单列表')
  1262. // this.packingList = val
  1263. // },
  1264. // async queryQualityInventory() {
  1265. // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
  1266. // console.log(res, '清单列表');
  1267. // this.packingList = res;
  1268. // },
  1269. changeSamUnit(val) {
  1270. this.$set(this.form, 'sampleMeasureUnit', val);
  1271. },
  1272. async handleSample1(val, data) {
  1273. this.sampleList = [];
  1274. if (this.selectedList == undefined || this.selectedList.length == 0) {
  1275. this.activeName = '1';
  1276. this.$message.warning('请先选择样品!');
  1277. return;
  1278. }
  1279. if (val == 1) {
  1280. this.activeName = '2';
  1281. if (this.form.isUnpack == 1) {
  1282. for (let i = 0; i < this.selectedList.length; i++) {
  1283. for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
  1284. // 不拆计算每个重量
  1285. let newWeight = parseFloat(
  1286. (
  1287. this.selectedList[i].weight /
  1288. this.selectedList[i].measureQuantity
  1289. ).toFixed(4)
  1290. );
  1291. if (
  1292. this.selectedList[i].qualitySampleTemplateList == undefined ||
  1293. this.selectedList[i].qualitySampleTemplateList == null ||
  1294. this.selectedList[i].qualitySampleTemplateList.length == 0
  1295. ) {
  1296. this.sampleList.push({
  1297. ...this.selectedList[i],
  1298. sampleCode: await this.getSampleCode(),
  1299. measureQuantity: 1,
  1300. qualitySampleTemplateList: JSON.parse(
  1301. JSON.stringify(this.schemeList)
  1302. ),
  1303. weight: newWeight || 0
  1304. });
  1305. } else {
  1306. this.sampleList.push({
  1307. ...this.selectedList[i],
  1308. sampleCode: await this.getSampleCode(),
  1309. measureQuantity: 1,
  1310. qualitySampleTemplateList: JSON.parse(
  1311. JSON.stringify(
  1312. this.selectedList[i].qualitySampleTemplateList
  1313. )
  1314. ),
  1315. weight: newWeight || 0
  1316. });
  1317. }
  1318. }
  1319. }
  1320. } else if (this.form.isUnpack == 2) {
  1321. // 不拆计算每个重量
  1322. let newWeight = parseFloat(
  1323. (
  1324. this.selectedList[0].weight /
  1325. this.selectedList[0].measureQuantity
  1326. ).toFixed(4)
  1327. );
  1328. for (let i = 0; i < this.selectedList[0].measureQuantity; i++) {
  1329. if (
  1330. this.selectedList[0].qualitySampleTemplateList == undefined ||
  1331. this.selectedList[0].qualitySampleTemplateList == null ||
  1332. this.selectedList[0].qualitySampleTemplateList.length == 0
  1333. ) {
  1334. this.sampleList.push({
  1335. ...this.selectedList[0],
  1336. sampleCode: await this.getSampleCode(),
  1337. measureQuantity: 1,
  1338. qualitySampleTemplateList: JSON.parse(
  1339. JSON.stringify(this.schemeList)
  1340. ),
  1341. weight: newWeight || 0
  1342. });
  1343. } else {
  1344. this.sampleList.push({
  1345. ...this.selectedList[0],
  1346. sampleCode: await this.getSampleCode(),
  1347. measureQuantity: 1,
  1348. qualitySampleTemplateList: JSON.parse(
  1349. JSON.stringify(
  1350. this.selectedList[0].qualitySampleTemplateList
  1351. )
  1352. ),
  1353. weight: newWeight || 0
  1354. });
  1355. }
  1356. }
  1357. }
  1358. //取整样=勾选数据
  1359. // this.sampleList = this.selectedList;
  1360. this.$message.success('取样成功!');
  1361. } else if (val == 2) {
  1362. console.log(data, 'datadatadatadataxiaoyang');
  1363. }
  1364. this.calculate(this.sampleList);
  1365. },
  1366. async handleSampleSubmit(data, specifications) {
  1367. this.sampleList = [];
  1368. if (!this.selectedList || this.selectedList.length == 0) {
  1369. this.$message.warning('请先选择样品!');
  1370. return;
  1371. }
  1372. const measureQ = data.measureQ || 1;
  1373. const unit = data.sampleUnit;
  1374. const sampleCount = Number(data.portion);
  1375. try {
  1376. if (this.isStandard1OrWeightSample()) {
  1377. // 新增校验 数量 取整样 ***
  1378. if (this.form.conditionType == 1) {
  1379. let isFlag = this.validateSampleQuantity(
  1380. sampleCount,
  1381. specifications
  1382. );
  1383. if (!isFlag) return;
  1384. }
  1385. // ***
  1386. //抽检计量整样小样或者抽检计重小样
  1387. if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
  1388. return; //取样数量验证
  1389. if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
  1390. return; // 若计量单位为重量,还需验证总重量是否足够
  1391. await this.getNewFullSampleList(
  1392. Math.ceil(sampleCount),
  1393. // sampleCount,
  1394. measureQ,
  1395. unit,
  1396. specifications
  1397. );
  1398. // 这里是取整样 非数量
  1399. } else if (this.isWeightStandardFullSample()) {
  1400. console.log('这里是取整样 吗');
  1401. //抽检取计重取整样
  1402. if (!this.validateSampleCount(sampleCount, specifications)) return;
  1403. await this.handleWeightFullSample(sampleCount, specifications);
  1404. }
  1405. this.activeName = '2';
  1406. this.$refs.tabsRef.tabsChange('2');
  1407. } catch (error) {
  1408. console.error('取样处理失败:', error);
  1409. this.$message.error('取样处理失败');
  1410. }
  1411. this.calculate(this.sampleList);
  1412. },
  1413. // 当计量类型 是数量的时候 取整样 校验
  1414. validateSampleQuantity(sampleCount, specifications) {
  1415. let packingUnit = this.selectedList[0].packingUnit?.trim() || '';
  1416. let totalS = 0;
  1417. let labelKey =
  1418. packingUnit == specifications.conversionUnit.trim()
  1419. ? 'packingQuantity'
  1420. : 'measureQuantity';
  1421. let labelName = labelKey == 'packingQuantity' ? '包装数量' : '计量数量';
  1422. totalS = this.selectedList.reduce(
  1423. (total, el) => total + el[labelKey],
  1424. 0
  1425. );
  1426. if (sampleCount > totalS) {
  1427. this.$message.info(
  1428. `所填的条目数量不能超过所选${labelName}总和${totalS}`
  1429. );
  1430. return false;
  1431. }
  1432. return true;
  1433. },
  1434. //获取样品编码
  1435. async getSampleCode() {
  1436. return await getCode('sample_code');
  1437. },
  1438. async getNewSampleList(measureQ, unit, nums) {
  1439. this.sampleList = [];
  1440. if (!this.selectedList || this.selectedList.length == 0) {
  1441. this.$message.warning('请先选择来源清单!');
  1442. return;
  1443. }
  1444. this.activeName = '2';
  1445. this.$refs.tabsRef.tabsChange('2');
  1446. if (this.form.isUnpack == 1) {
  1447. // 1 拆包 2 不拆
  1448. let measureQuantity = 1;
  1449. if (this.form.conditionType == 2) {
  1450. measureQuantity = measureQ;
  1451. }
  1452. for (let i = 0; i < this.selectedList.length; i++) {
  1453. if (
  1454. this.selectedList[i].qualitySampleTemplateList == undefined ||
  1455. this.selectedList[i].qualitySampleTemplateList == null ||
  1456. this.selectedList[i].qualitySampleTemplateList.length == 0
  1457. ) {
  1458. this.sampleList.push({
  1459. ...this.selectedList[i],
  1460. sampleCode: await this.getSampleCode(),
  1461. measureQuantity: measureQuantity,
  1462. qualitySampleTemplateList: JSON.parse(
  1463. JSON.stringify(this.schemeList)
  1464. ),
  1465. measureUnit: unit
  1466. });
  1467. } else {
  1468. this.sampleList.push({
  1469. ...this.selectedList[i],
  1470. sampleCode: await this.getSampleCode(),
  1471. measureQuantity: measureQuantity,
  1472. qualitySampleTemplateList: JSON.parse(
  1473. JSON.stringify(this.selectedList[i].qualitySampleTemplateList)
  1474. ),
  1475. measureUnit: unit
  1476. });
  1477. }
  1478. }
  1479. } else if (this.form.isUnpack == 2) {
  1480. if (this.form.conditionType == 1) {
  1481. measureQ = 1;
  1482. }
  1483. // 不拆计算每个重量
  1484. let newWeight = parseFloat(
  1485. (
  1486. this.selectedList[0].weight / this.selectedList[0].measureQuantity
  1487. ).toFixed(4)
  1488. );
  1489. for (let i = 0; i < nums; i++) {
  1490. if (
  1491. this.selectedList[0].qualitySampleTemplateList == undefined ||
  1492. this.selectedList[0].qualitySampleTemplateList == null ||
  1493. this.selectedList[0].qualitySampleTemplateList.length == 0
  1494. ) {
  1495. this.sampleList.push({
  1496. ...this.selectedList[0],
  1497. sampleCode: await this.getSampleCode(),
  1498. measureQuantity: measureQ,
  1499. qualitySampleTemplateList: JSON.parse(
  1500. JSON.stringify(this.schemeList)
  1501. ),
  1502. measureUnit: unit,
  1503. weight: newWeight || 0
  1504. });
  1505. } else {
  1506. this.sampleList.push({
  1507. ...this.selectedList[0],
  1508. sampleCode: await this.getSampleCode(),
  1509. measureQuantity: measureQ,
  1510. qualitySampleTemplateList: JSON.parse(
  1511. JSON.stringify(this.selectedList[0].qualitySampleTemplateList)
  1512. ),
  1513. measureUnit: unit,
  1514. weight: newWeight || 0
  1515. });
  1516. // this.sampleList.push({
  1517. // ...this.selectedList[0],
  1518. // sampleCode: await this.getSampleCode(),
  1519. // measureQuantity: measureQ,
  1520. // measureUnit: unit,
  1521. // weight: newWeight || 0,
  1522. // });
  1523. }
  1524. }
  1525. }
  1526. // this.sampleList = this.selectedList.map(oldItem => {
  1527. // const newItem = JSON.parse(JSON.stringify(oldItem));
  1528. // newItem.measureQuantity = measureQ;
  1529. // newItem.measureUnit = unit;
  1530. // return newItem;
  1531. // });
  1532. this.calculate(this.sampleList);
  1533. this.$refs.tabsRef.tabsChange('2');
  1534. },
  1535. async getQueryQualityInventory() {
  1536. const res = await queryQualityInventory({
  1537. qualityWorkerId: this.$route.query.id,
  1538. size: -1
  1539. });
  1540. if (res.list.length > 0) {
  1541. this.inventoryList = res.list;
  1542. }
  1543. },
  1544. async queryQualitySamplContent() {
  1545. const res = await queryQualitySamplContent({
  1546. qualityWorkerId: this.$route.query.id,
  1547. size: 1000
  1548. });
  1549. let addStatus = res.list.map((item) => {
  1550. item.isValid = true;
  1551. item.status = item.status || 1;
  1552. item.qualityStatus = 1;
  1553. // item.disposeTime = item.disposeTime
  1554. // ? item.disposeTime.split(' ')[0]
  1555. // : null;
  1556. item.sampleDate = item.sampleDate
  1557. ? item.sampleDate.split(' ')[0]
  1558. : null;
  1559. return {
  1560. ...item
  1561. };
  1562. });
  1563. if (addStatus.length > 0) {
  1564. this.sampleList = addStatus;
  1565. // this.calculate(this.sampleList);
  1566. this.addStatus = addStatus;
  1567. } else {
  1568. this.getProSamList(this.packingList);
  1569. }
  1570. if (this.form.recordingMethod != 1) {
  1571. this.$nextTick(() => {
  1572. this.countQualityResults();
  1573. });
  1574. }
  1575. },
  1576. async queryQualityTempleContent() {
  1577. const res = await queryQualityTempleContent({
  1578. qualityWorkerId: this.$route.query.id,
  1579. page: 1,
  1580. size: 10000
  1581. });
  1582. this.schemeList = res.list;
  1583. },
  1584. // 取样
  1585. getConditionType(val) {
  1586. this.form.conditionType = val;
  1587. },
  1588. /* 保存编辑 */
  1589. save() {
  1590. // *** 新增判断
  1591. // let flag = this.$refs.baseInfoRefs.quantityCalculation();
  1592. // if (!flag) return;
  1593. // ***
  1594. if (this.form.qualityIdList.length == 0) {
  1595. this.$message.error('请选择检测人');
  1596. return;
  1597. }
  1598. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1599. if (!valid) {
  1600. return false;
  1601. }
  1602. // this.loading = true;
  1603. let URL =
  1604. this.type == 'add' ? save : this.type == 'edit' ? update : '';
  1605. this.form.qualityTimeStart = this.qualityTimeStart;
  1606. this.form.qualityId = this.form.qualityIdList.toString();
  1607. delete this.form['qualityTimeEnd'];
  1608. this.form.executeUserId = this.form.executeUserIdList.toString();
  1609. this.form.isUpdate = 1;
  1610. this.schemeList.forEach((item) => {
  1611. if (item.executionMethod != 2 || this.form.recordingMethod != 1) {
  1612. item.experiment = null;
  1613. }
  1614. });
  1615. let params = {
  1616. ...this.form,
  1617. sampleList: this.sampleList,
  1618. planTemplateList: this.schemeList,
  1619. templateList: this.schemeList,
  1620. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1621. qualityInventoryList: this.inventoryList
  1622. };
  1623. console.log(params, 'params');
  1624. URL(params)
  1625. .then((msg) => {
  1626. this.loading = false;
  1627. this.$message.success(msg);
  1628. this.cancel();
  1629. this.$emit('done');
  1630. })
  1631. .catch((e) => {
  1632. this.loading = false;
  1633. });
  1634. });
  1635. },
  1636. update() {
  1637. this.loading = true;
  1638. this.form['status'] = 1;
  1639. update({ ...this.form })
  1640. .then((msg) => {
  1641. this.loading = false;
  1642. this.$message.success(msg);
  1643. this.$emit('done');
  1644. })
  1645. .catch((e) => {
  1646. this.loading = false;
  1647. });
  1648. },
  1649. setSchemeListChange() {
  1650. this.form.qualityTimeStart = this.qualityTimeStart;
  1651. this.form.qualityId = this.form.qualityIdList.join(',');
  1652. delete this.form['qualityTimeEnd'];
  1653. let params = {
  1654. ...this.form,
  1655. sampleList: this.sampleList,
  1656. planTemplateList: this.schemeList,
  1657. templateList: this.schemeList,
  1658. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1659. qualityInventoryList: this.inventoryList
  1660. };
  1661. this.loading = true;
  1662. update(params)
  1663. .then((msg) => {
  1664. this.loading = false;
  1665. this.getDetail();
  1666. })
  1667. .catch((e) => {
  1668. this.loading = false;
  1669. });
  1670. },
  1671. restForm() {
  1672. this.form = { ...this.defaultForm() };
  1673. this.$nextTick(() => {
  1674. this.$refs.baseInfoRefs.$refs.form1.clearValidate();
  1675. });
  1676. },
  1677. cancel() {
  1678. finishPageTab();
  1679. this.$router.go(-1);
  1680. },
  1681. setSchemeList(list) {
  1682. this.schemeList = list;
  1683. },
  1684. handleDetail(index, row, type) {
  1685. if (!this.sampleList[index] || !this.schemeList) {
  1686. return;
  1687. }
  1688. const selectedData = [];
  1689. selectedData.push(this.sampleList[index]);
  1690. if (this.schemeList.length != 0) {
  1691. this.sampleList.forEach((item) => {
  1692. if (item.qualitySampleTemplateList.length == 0) {
  1693. item.qualitySampleTemplateList.push(...this.schemeList);
  1694. }
  1695. });
  1696. }
  1697. console.log(selectedData, 'selectedData');
  1698. this.$refs.detailRef.openDia(
  1699. index,
  1700. row,
  1701. type,
  1702. selectedData,
  1703. null,
  1704. this.schemeList.toolList
  1705. );
  1706. },
  1707. sampleListChange(sampleList) {
  1708. this.$set(this, 'sampleList', sampleList);
  1709. // this.sampleList = sampleList;
  1710. },
  1711. inputWeight(row, index) {
  1712. // 计算所有样本的总重量
  1713. console.log(this.sampleList);
  1714. const pNum = this.sampleList.reduce((sum, item) => {
  1715. return sum + Number(item.weight || 0);
  1716. }, 0);
  1717. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  1718. },
  1719. handleDispose(data) {
  1720. // return
  1721. this.rowData = data;
  1722. this.sampleDisposeVisble = true;
  1723. // if (!this.sampleList[index]) {
  1724. // return;
  1725. // }
  1726. // this.sampleList[index].sampleDate = this.getNowTimes();
  1727. // this.sampleList[index].disposeTime = this.getNowTimes();
  1728. // console.log(index, row, type, this.qualityType);
  1729. // this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
  1730. },
  1731. // 报工
  1732. handleReporting(index, row) {
  1733. if (this.form.qualityIdList.length == 0) {
  1734. this.$message.error('请选择检测人');
  1735. return;
  1736. }
  1737. if (this.form.qualityMode == 2 && !this.form.qualityResults) {
  1738. this.$refs.baseInfoRefs.toggleExpand2();
  1739. this.$message.error('请选择检测结果');
  1740. return;
  1741. }
  1742. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1743. if (!valid) return false;
  1744. //单样全部
  1745. console.log(this.form.recordingMethod, 'this.form.recordingMethod');
  1746. if (this.form.recordingMethod == 2) {
  1747. if (this.qualityType == 2 && this.isReportProcessProduce) {
  1748. for (let i = 0; i < this.sampleList.length; i++) {
  1749. const disposalStatus = this.sampleList[i].disposalStatus;
  1750. if (disposalStatus == null) {
  1751. this.loading = false;
  1752. this.$refs.tabsRef.tabsChange('2');
  1753. this.$message.error('请完成以下样品处置!');
  1754. return;
  1755. }
  1756. }
  1757. }
  1758. for (let i = 0; i < this.sampleList.length; i++) {
  1759. const status = this.sampleList[i].status;
  1760. if (status != '1') {
  1761. this.loading = false;
  1762. this.$refs.tabsRef.tabsChange('2');
  1763. this.$message.error('请完成以下样品检测!');
  1764. return;
  1765. }
  1766. }
  1767. } else {
  1768. let is = false;
  1769. this.schemeList.forEach((item) => {
  1770. if (item.status != 1) {
  1771. is = true;
  1772. }
  1773. });
  1774. if (is) {
  1775. this.$message.error('有未完成检测项检测,请检查!');
  1776. return;
  1777. }
  1778. if (!this.schemeList.length) {
  1779. this.$message.error('检测方案不能为空,请检查!');
  1780. return;
  1781. }
  1782. }
  1783. this.form.qualityTimeEnd = this.getNowTime();
  1784. this.form.qualityTimeStart = this.qualityTimeStart;
  1785. this.form.qualityId = this.form.qualityIdList.toString();
  1786. this.form.executeUserIdList = this.form.executeUserIdList || [];
  1787. if (
  1788. !this.form.executeUserIdList.find(
  1789. (item) => item == this.$store.state.user.info.userId
  1790. )
  1791. ) {
  1792. this.form.executeUserIdList.push(
  1793. this.$store.state.user.info.userId
  1794. );
  1795. this.form.executeUserName =
  1796. this.form.executeUserIdList.length > 1
  1797. ? this.form.executeUserName +
  1798. ',' +
  1799. this.$store.state.user.info.name
  1800. : this.$store.state.user.info.name;
  1801. }
  1802. this.form.executeUserId = this.form.executeUserIdList.toString();
  1803. // this.form.qualityIdList = [];
  1804. this.schemeList.forEach((item) => {
  1805. if (item.executionMethod != 2 || this.form.recordingMethod != 1) {
  1806. item.experiment = null;
  1807. }
  1808. });
  1809. let params = {
  1810. ...this.form,
  1811. sampleList: this.sampleList,
  1812. planTemplateList: this.schemeList,
  1813. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  1814. qualityInventoryList: this.inventoryList
  1815. };
  1816. this.loading = true;
  1817. exeReportWork(params)
  1818. .then((msg) => {
  1819. this.loading = false;
  1820. this.$message.success(msg);
  1821. this.cancel();
  1822. this.$emit('done');
  1823. })
  1824. .catch((e) => {
  1825. this.loading = false;
  1826. });
  1827. });
  1828. },
  1829. // 处理确认事件
  1830. handleDisposeConfirm(data, index) {
  1831. if (index == undefined) {
  1832. this.sampleList.forEach((obj) => {
  1833. obj.disposeType = data.disposeType;
  1834. obj.sampleDate = data.sampleDate;
  1835. obj.sampleCondition = data.sampleCondition;
  1836. obj.producerManufacturer = data.producerManufacturer;
  1837. obj.samplePlace = data.samplePlace;
  1838. obj.sampleRemark = data.sampleRemark;
  1839. obj.depotId = data.depotId;
  1840. obj.depotName = data.depotName;
  1841. });
  1842. } else {
  1843. this.$set(this.sampleList, index, data);
  1844. }
  1845. },
  1846. //确认检测
  1847. handleConfirm(list, index) {
  1848. let qualityResults = '';
  1849. list.forEach((item) => {
  1850. if (item.correlationId) {
  1851. return;
  1852. }
  1853. if (item.qualitySampleTemplateList.length == 1) {
  1854. if (
  1855. item.qualitySampleTemplateList.some(
  1856. (child) => child.qualityResults === 3
  1857. )
  1858. ) {
  1859. // 如果检测项只有一条而且结果为让步接收那么整个就是让步接收
  1860. item.isValid = false;
  1861. item.qualityResults = 3;
  1862. } else if (
  1863. item.qualitySampleTemplateList.some(
  1864. (child) => child.qualityResults === 2
  1865. )
  1866. ) {
  1867. item.isValid = false;
  1868. item.qualityResults = 2;
  1869. } else {
  1870. item.isValid = true;
  1871. item.qualityResults = 1;
  1872. }
  1873. } else {
  1874. if (
  1875. item.qualitySampleTemplateList.some(
  1876. (child) => child.qualityResults === 2
  1877. )
  1878. ) {
  1879. item.isValid = false;
  1880. item.qualityResults = 2;
  1881. } else {
  1882. item.isValid = true;
  1883. item.qualityResults = 1;
  1884. }
  1885. }
  1886. item.qualityStatus = 1;
  1887. qualityResults = item.qualityResults;
  1888. });
  1889. if (index != null) {
  1890. this.$set(this.sampleList, index, list[0]);
  1891. // this.$set(this.sampleList, index, list[0]);
  1892. // if (this.form.qualityMode == 1 && this.form.isUnpack == 2) {
  1893. // this.activeName = '2';
  1894. // this.countQualityResults();
  1895. // return;
  1896. // }
  1897. this.countQualityResults();
  1898. } else {
  1899. this.$set(this, 'sampleList', list);
  1900. // console.log(this.sampleList, 'this.sampleList');
  1901. // return
  1902. // this.sampleList = list;
  1903. this.calculate(this.sampleList);
  1904. console.log(this.sampleList, 'this.sampleList');
  1905. }
  1906. this.activeName = '2';
  1907. if (this.$store.state.user.info.clientEnvironmentId == 10) {
  1908. this.$refs.baseInfoRefs.setQualityResults(qualityResults);
  1909. }
  1910. // *** 选完批量检测调用
  1911. // this.countQualityResults();
  1912. // this.$refs.baseInfoRefs.quantityCalculation(
  1913. // 'noQualifiedNumber',
  1914. // 'noSetSampleList'
  1915. // );
  1916. console.log('检测没有 2');
  1917. },
  1918. // 批量检测
  1919. batchQuality(index, row, type) {
  1920. if (this.sampleList.length == 0) {
  1921. this.$message.error('样品清单不能为空');
  1922. return;
  1923. }
  1924. if (this.form.recordingMethod == 1) {
  1925. this.inspectionProjectReport({
  1926. index: -1,
  1927. list: this.schemeList.filter((item) => !item.correlationId)
  1928. });
  1929. return;
  1930. }
  1931. if (this.schemeList.length != 0) {
  1932. this.sampleList.forEach((item, index) => {
  1933. if (item.qualitySampleTemplateList.length == 0) {
  1934. let arr = JSON.parse(JSON.stringify(this.schemeList));
  1935. arr.forEach((el) => {
  1936. el.qualityResults = item.qualityResults;
  1937. });
  1938. this.$set(
  1939. this.sampleList[index],
  1940. 'qualitySampleTemplateList',
  1941. arr
  1942. );
  1943. }
  1944. });
  1945. }
  1946. console.log(this.sampleList, 'dsds');
  1947. this.$refs.detailRef.openDia(
  1948. null,
  1949. null,
  1950. 'report',
  1951. this.sampleList,
  1952. null,
  1953. this.schemeList.toolList
  1954. );
  1955. },
  1956. // 批量处置
  1957. batchDispose() {
  1958. if (this.sampleList && this.sampleList.length) {
  1959. this.sampleDisposeVisble = true;
  1960. return;
  1961. }
  1962. this.$message('当前没有样品清单可以处置');
  1963. // this.$refs.disposeRef.openDispose(
  1964. // null,
  1965. // null,
  1966. // 'dispose',
  1967. // this.qualityType
  1968. // );
  1969. },
  1970. //全检,检验标准改变时,重新获取样品列表
  1971. async changeInspectionStandardsModel(val) {
  1972. const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
  1973. if (sData.length > 0) {
  1974. for (let i = 0; i < sData.length; i++) {
  1975. this.$set(sData[i], 'qualityStatus', 2);
  1976. }
  1977. }
  1978. this.form.inspectionStandards = val;
  1979. this.form.sampleNumber = '';
  1980. this.$refs.tabsRef.tableSelClear();
  1981. this.sampleList = [];
  1982. this.$refs.tabsRef.tabsChange('1');
  1983. //检验标准 2计重 1计量
  1984. if (
  1985. [2, 3, 4, 5].includes(this.form.inspectionStandards) &&
  1986. this.form.qualityMode == 1
  1987. ) {
  1988. for (let i = 0; i < sData.length; i++) {
  1989. let qualitySampleTemplateList = [];
  1990. if (
  1991. sData[i].qualitySampleTemplateList == undefined ||
  1992. sData[i].qualitySampleTemplateList == null ||
  1993. sData[i].qualitySampleTemplateList.length == 0
  1994. ) {
  1995. qualitySampleTemplateList = JSON.parse(
  1996. JSON.stringify(this.schemeList)
  1997. );
  1998. } else {
  1999. qualitySampleTemplateList = sData[i].qualitySampleTemplateList;
  2000. }
  2001. this.sampleList.push({
  2002. ...sData[i],
  2003. sampleCode: await this.getSampleCode(),
  2004. qualitySampleTemplateList
  2005. });
  2006. }
  2007. } else if (
  2008. this.form.inspectionStandards == 1 &&
  2009. this.form.qualityMode == 1
  2010. ) {
  2011. this.getProSamList(sData);
  2012. }
  2013. this.calculate(this.sampleList);
  2014. },
  2015. //从来源数组取样到目标数组
  2016. async getNewFullSampleList(
  2017. sampleCount,
  2018. sampleQuantity,
  2019. sampleUnit,
  2020. specifications
  2021. ) {
  2022. const sourceArray = this.selectedList;
  2023. // 检查单位是否匹配
  2024. const isUnitMismatch =
  2025. sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
  2026. // 创建副本并计算初始可取样数量
  2027. const items = sourceArray.map((item) => ({
  2028. ...item,
  2029. remainingQuantity: isUnitMismatch
  2030. ? Infinity
  2031. : item['measureQuantity'], // 剩余可取样数量
  2032. maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
  2033. }));
  2034. const result = [];
  2035. let remainingCount = sampleCount;
  2036. let count = Math.ceil(remainingCount);
  2037. const codeList = await this.batchCodes(count);
  2038. let codeIdx = 0;
  2039. // 尽可能均匀地从各条目取样
  2040. while (remainingCount > 0) {
  2041. // 按剩余可取样比例排序
  2042. items.sort(
  2043. (a, b) =>
  2044. b.remainingQuantity / b['measureQuantity'] -
  2045. a.remainingQuantity / a['measureQuantity']
  2046. );
  2047. let distributed = false;
  2048. for (const item of items) {
  2049. // let values = remainingCount > 1 ? 1 : remainingCount;
  2050. if (
  2051. !isUnitMismatch ||
  2052. (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
  2053. ) {
  2054. let qualitySampleTemplateList = [];
  2055. if (
  2056. item.qualitySampleTemplateList == undefined ||
  2057. item.qualitySampleTemplateList == null ||
  2058. item.qualitySampleTemplateList.length == 0
  2059. ) {
  2060. qualitySampleTemplateList = JSON.parse(
  2061. JSON.stringify(this.schemeList)
  2062. );
  2063. } else {
  2064. qualitySampleTemplateList = item.qualitySampleTemplateList;
  2065. }
  2066. // 添加到结果数组
  2067. // let sampleCode = await this.getSampleCode();
  2068. let sampleCode = codeList[codeIdx];
  2069. if (
  2070. this.form.conditionType == 1 &&
  2071. this.form.inspectionStandards == 1
  2072. ) {
  2073. result.push({
  2074. ...item,
  2075. // measureQuantity: values,
  2076. measureQuantity: 1,
  2077. sampleCode,
  2078. qualitySampleTemplateList
  2079. });
  2080. } else if (this.form.conditionType == 2) {
  2081. let weight = (item.weight / item.maxPossible).toFixed(2);
  2082. result.push({
  2083. ...item,
  2084. measureQuantity: sampleQuantity,
  2085. measureUnit: sampleUnit,
  2086. sampleCode,
  2087. weight,
  2088. qualitySampleTemplateList
  2089. });
  2090. }
  2091. // 更新剩余数量
  2092. if (!isUnitMismatch) {
  2093. item.remainingQuantity -= sampleQuantity;
  2094. }
  2095. remainingCount = (remainingCount - 1).toFixed(2);
  2096. codeIdx++;
  2097. distributed = true;
  2098. }
  2099. }
  2100. // 如果没有分配任何取样
  2101. if (!distributed) {
  2102. break;
  2103. }
  2104. }
  2105. // 判断是不是取整样
  2106. if (
  2107. this.form.conditionType == 1 &&
  2108. specifications &&
  2109. specifications.id
  2110. ) {
  2111. result.map((el) => {
  2112. el.measureQuantity =
  2113. el.measureQuantity * specifications.packageCellTotal;
  2114. el.weight = this.formatNumber(
  2115. el.measureQuantity,
  2116. el.weightProportion
  2117. );
  2118. });
  2119. }
  2120. this.sampleList = result;
  2121. if (this.sampleList.length > sampleCount) {
  2122. this.sampleList = this.sampleList.splice(0, sampleCount);
  2123. }
  2124. this.form.sampleNumber = this.sampleList.length;
  2125. this.calculate(this.sampleList);
  2126. },
  2127. // 小数点数据判断
  2128. formatNumber(a, b, maxDecimals = 4) {
  2129. if (a == 0 || b == 0 || !a || !b) {
  2130. return 0;
  2131. }
  2132. // 计算乘积
  2133. const product = a * b;
  2134. // 转换为固定小数位数,然后转换为数字以去除末尾零
  2135. const rounded = Number(product.toFixed(maxDecimals));
  2136. // 转换为字符串检查是否需要显示小数部分
  2137. const str = rounded.toString();
  2138. // 如果包含小数点
  2139. if (str.indexOf('.') !== -1) {
  2140. // 移除末尾的零和小数点(如果后面没有数字了)
  2141. return str.replace(/\.?0+$/, '');
  2142. }
  2143. return str;
  2144. },
  2145. validateWeight(measureQ, sampleCount) {
  2146. let totalMaxPossible = 0;
  2147. this.selectedList.forEach((item) => {
  2148. totalMaxPossible += item.measureQuantity / measureQ;
  2149. });
  2150. if (totalMaxPossible < sampleCount) {
  2151. // this.formData.portion = totalMaxPossible;
  2152. this.$message.info(`最大取样条数为${totalMaxPossible}`);
  2153. return false;
  2154. }
  2155. let totalWeight = this.selectedList.reduce(
  2156. (sum, item) => sum + item.weight,
  2157. 0
  2158. );
  2159. const weightUnit = this.selectedList[0].weightUnit;
  2160. if (weightUnit === 'G') totalWeight /= 1000;
  2161. if (measureQ * sampleCount > totalWeight) {
  2162. this.$message.info('取样计量重量不能大于总计量重量');
  2163. return false;
  2164. }
  2165. const invalidItem = this.selectedList.find((item) => {
  2166. const weight =
  2167. item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
  2168. return weight < measureQ;
  2169. });
  2170. if (invalidItem) {
  2171. this.$message.info('勾选条目重量小于取样重量');
  2172. return false;
  2173. }
  2174. return true;
  2175. },
  2176. isStandard1OrWeightSample() {
  2177. return (
  2178. this.form.inspectionStandards === 1 ||
  2179. ([2, 3, 4, 5].includes(this.form.inspectionStandards) &&
  2180. this.form.conditionType == 2)
  2181. );
  2182. },
  2183. validateMeasureQuantity(measureQ, unit, sampleCount) {
  2184. if (this.form.conditionType == 2 && measureQ <= 0) {
  2185. this.$message.info('取样计量数量必须大于0');
  2186. return false;
  2187. }
  2188. const totalQuantity = this.selectedList.reduce(
  2189. (sum, item) => sum + item.measureQuantity,
  2190. 0
  2191. );
  2192. if (
  2193. (this.selectedList[0].measureUnit === unit ||
  2194. this.form.conditionType == 1) &&
  2195. measureQ * sampleCount > totalQuantity
  2196. ) {
  2197. this.$message.info('取样计量数量不能大于总计量数量');
  2198. return false;
  2199. }
  2200. const invalidItem = this.selectedList.find(
  2201. (item) => item.measureQuantity < measureQ
  2202. );
  2203. if (invalidItem) {
  2204. this.$message.info('条目计量数量小于取样计量数量');
  2205. return false;
  2206. }
  2207. return true;
  2208. },
  2209. isWeightStandardFullSample() {
  2210. return (
  2211. [2, 3, 4, 5].includes(this.form.inspectionStandards) &&
  2212. this.form.conditionType == 1
  2213. );
  2214. },
  2215. // 抽检取整样 校验
  2216. validateSampleCount(sampleCount, specifications) {
  2217. // 新增校验 ***
  2218. let isFlag = this.validateSampleQuantity(sampleCount, specifications);
  2219. if (!isFlag) {
  2220. return false;
  2221. }
  2222. // ***
  2223. const chooseNumber = this.selectedList.reduce((acc, pro) => {
  2224. return pro.measureQuantity ? acc + Number(pro.measureQuantity) : acc;
  2225. }, 0);
  2226. const invalidItem = chooseNumber < sampleCount;
  2227. // console.log(this.selectedList, 'this.selectedList');
  2228. // const invalidItem = this.selectedList.find(
  2229. // (item) => item.measureQuantity < sampleCount
  2230. // );
  2231. if (invalidItem) {
  2232. this.$message.info('所选的条目计量数量小于取样计量数量');
  2233. return false;
  2234. }
  2235. // ***
  2236. return true;
  2237. },
  2238. async handleWeightFullSample(sampleCount, specifications) {
  2239. const dataList = [];
  2240. let currentNum = sampleCount - this.selectedList.length;
  2241. let currentNum1 = sampleCount;
  2242. for (const item of this.selectedList) {
  2243. const qualitySampleTemplateList = item.qualitySampleTemplateList
  2244. ?.length
  2245. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  2246. : JSON.parse(
  2247. JSON.stringify(
  2248. this.schemeList.map((item) => {
  2249. item['qualityResults'] = 1;
  2250. return item;
  2251. })
  2252. )
  2253. );
  2254. if (sampleCount >= this.selectedList.length) {
  2255. dataList.push({
  2256. ...item,
  2257. measureQuantity: 1, //作为计量数量
  2258. sampleCode: await this.getSampleCode(),
  2259. qualitySampleTemplateList
  2260. });
  2261. } else {
  2262. if (dataList.length < sampleCount) {
  2263. dataList.push({
  2264. ...item,
  2265. measureQuantity: currentNum1 > 1 ? 1 : currentNum1, //作为计量数量
  2266. sampleCode: await this.getSampleCode(),
  2267. qualitySampleTemplateList
  2268. });
  2269. currentNum1 -= 1;
  2270. }
  2271. }
  2272. }
  2273. if (sampleCount > this.selectedList.length) {
  2274. dataList.forEach((item) => {
  2275. if (currentNum > 0) {
  2276. let data = this.selectedList.find((val) => val.id == item.id);
  2277. item['measureQuantity'] =
  2278. data.measureQuantity - 1 - currentNum > 0
  2279. ? currentNum + 1
  2280. : data.measureQuantity;
  2281. currentNum = currentNum - (data.measureQuantity - 1);
  2282. }
  2283. });
  2284. }
  2285. // 更改 从新计算 样品清单 取整样 数据
  2286. if (specifications && specifications.id) {
  2287. // let proportion = (obj.weight / obj.measureQuantity).toFixed(2);
  2288. dataList.map((el) => {
  2289. el.measureQuantity =
  2290. el.measureQuantity * specifications.packageCellTotal;
  2291. el.weight = this.formatNumber(
  2292. el.measureQuantity,
  2293. el.weightProportion
  2294. );
  2295. });
  2296. }
  2297. // 更改
  2298. this.sampleList = dataList;
  2299. this.calculate(this.sampleList);
  2300. this.sampleNumber = this.sampleList.length;
  2301. },
  2302. // 批量生成编码 4444444 getCodeList
  2303. async batchCodes(count) {
  2304. if (count <= 0) return;
  2305. let params = { count };
  2306. const res = await getCodeList('sample_code', params);
  2307. return res;
  2308. },
  2309. //计算合格率
  2310. countQualityResults() {
  2311. console.log(321);
  2312. let sampleList = this.sampleList; //样品清单
  2313. let sampleNumber = this.form.total; //样品总数
  2314. // let qualifiedNumber = sampleList.filter(item => item.qualityResults == 1 || item.qualityResults == 3).length;
  2315. // let noQualifiedNumber = sampleList.filter(
  2316. // (item) => item.qualityResults == 2
  2317. // ).length;
  2318. let noQualifiedNumber = sampleList.reduce((acc, pro) => {
  2319. // console.log(acc, pro);
  2320. // if (pro.qualityResults == 2) {
  2321. // return acc + Number(pro.measureQuantity);
  2322. // }
  2323. return pro.qualityResults == 2
  2324. ? acc + Number(pro.measureQuantity)
  2325. : acc;
  2326. }, 0);
  2327. let qualifiedNumber = sampleNumber - noQualifiedNumber; //不合格数
  2328. let qualificationRate = (
  2329. (qualifiedNumber / sampleNumber) *
  2330. 100
  2331. ).toFixed(2); //合格率
  2332. let noQualificationRate = (
  2333. (noQualifiedNumber / sampleNumber) *
  2334. 100
  2335. ).toFixed(2); //不合格率
  2336. this.$refs.baseInfoRefs.updateQualificationRate(
  2337. qualifiedNumber,
  2338. noQualifiedNumber,
  2339. qualificationRate,
  2340. noQualificationRate
  2341. );
  2342. this.calculate(this.sampleList);
  2343. },
  2344. closeDispose() {
  2345. this.rowData = null;
  2346. this.sampleDisposeVisble = false;
  2347. // this.rowData = null;
  2348. }
  2349. }
  2350. };
  2351. </script>
  2352. <style lang="scss" scoped></style>