edit.vue 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <header-title title="基本信息">
  5. <el-button @click="cancel">返回</el-button>
  6. <el-button
  7. type="primary"
  8. @click="save"
  9. :loading="loading"
  10. v-if="type != 'detail'"
  11. >保存</el-button
  12. >
  13. <el-button
  14. type="primary"
  15. @click="handleReporting"
  16. :loading="loading"
  17. v-if="type != 'detail'"
  18. >报工完成</el-button
  19. >
  20. </header-title>
  21. <base-info
  22. ref="baseInfoRefs"
  23. v-if="form"
  24. :form="form"
  25. :btnType="type"
  26. :qualityType1="qualityType"
  27. @changeModel="changeModel"
  28. @changeNumber="changeNumber"
  29. @changeInspectionStandardsModel="changeInspectionStandardsModel"
  30. ></base-info>
  31. <quality-content-tabs
  32. ref="tabsRef"
  33. :type="type"
  34. :ids="this.$route.query.id"
  35. :sample-list="sampleList"
  36. :activeName="activeName"
  37. :scheme-list="schemeList"
  38. :loading="loading"
  39. :form="form"
  40. @handleSelectionChange="handleSelectionChange1"
  41. @batch-quality="batchQuality"
  42. @batch-dispose="batchDispose"
  43. @handleDetail="handleDetail"
  44. @inputWeight="inputWeight"
  45. @handleDispose="handleDispose"
  46. @changeSamUnit="changeSamUnit"
  47. @handleSample1="handleSample1"
  48. @handleSampleSubmit="handleSampleSubmit"
  49. @getConditionType="getConditionType"
  50. @countQualityResults="countQualityResults"
  51. />
  52. </el-card>
  53. <sampleListDialog
  54. ref="detailRef"
  55. @handleConfirm="handleConfirm"
  56. @handleDispose="handleDispose"
  57. ></sampleListDialog>
  58. <sampleDisposeDialog
  59. ref="disposeRef"
  60. @handleDisposeConfirm="handleDisposeConfirm"
  61. ></sampleDisposeDialog>
  62. </div>
  63. </template>
  64. <script>
  65. import baseInfo from './components/baseInfo.vue';
  66. // import QualityContentTabs from './components/QualityContentTabs.vue';
  67. import QualityContentTabs from './components/newQualityContentTabs.vue';
  68. import { getCode } from '@/api/login';
  69. import {
  70. save,
  71. update,
  72. getById,
  73. exeReportWork,
  74. queryQualitySamplContent,
  75. queryQualityTempleContent,
  76. queryQualityInventory
  77. } from '@/api/inspectionWork';
  78. import dictMixins from '@/mixins/dictMixins';
  79. // import term from './term';
  80. import sampleListDialog from './components/sampleListDialog.vue';
  81. import sampleDisposeDialog from './components/sampleDisposeDialog.vue';
  82. import { finishPageTab } from '@/utils/page-tab-util';
  83. export default {
  84. components: {
  85. baseInfo,
  86. QualityContentTabs,
  87. sampleListDialog,
  88. sampleDisposeDialog
  89. },
  90. mixins: [dictMixins],
  91. data() {
  92. const defaultForm = function () {
  93. return {
  94. code: '',
  95. qualityType: null,
  96. qualityModeproduceRoutingId: '',
  97. produceRoutingName: '',
  98. produceTaskId: '',
  99. produceTaskName: '',
  100. productName: '',
  101. productCode: '',
  102. batchNo: '',
  103. specification: '',
  104. modelType: '',
  105. brandNo: '',
  106. total: '',
  107. qualifiedNumber: '',
  108. noQualifiedNumber: '',
  109. groupId: '',
  110. groupName: '',
  111. qualityId: '',
  112. qualityName: '',
  113. qualityTime: '',
  114. hours: '',
  115. qualificationRate: '',
  116. noQualificationRate: '',
  117. totalWeight: '',
  118. sampleNumber: '',
  119. imgUrl: [],
  120. qualityTimeStart: '',
  121. qualityTimeEnd: '',
  122. sampleMeasureUnit: '',
  123. conditionType: null
  124. };
  125. };
  126. return {
  127. defaultForm,
  128. // 表单数据
  129. form: { ...defaultForm() },
  130. voList: [],
  131. // 表单验证规则
  132. categoryParamList: [],
  133. type: '',
  134. title: '',
  135. loading: false,
  136. tabTaskId: null,
  137. // activeName: '2',
  138. packingList: [],
  139. sampleList: [],
  140. schemeList: [],
  141. inventoryList: [],
  142. activeName: '1',
  143. isValid: true,
  144. isStatus: true,
  145. SampleListbyReportList: [],
  146. qualityTimeStart: '',
  147. isReportProcessProduce: false,
  148. addStatus: []
  149. };
  150. },
  151. watch: {
  152. '$route.query.id': {
  153. handler(id) {
  154. if (id) {
  155. this.getDetail();
  156. } else {
  157. this.form = { ...defaultForm() };
  158. }
  159. }
  160. }
  161. },
  162. created() {
  163. this.open();
  164. if (this.$route.query.id) {
  165. this.getDetail();
  166. }
  167. },
  168. methods: {
  169. //切换检验方式
  170. changeModel(val, flag) {
  171. this.$refs.tabsRef.tableSelClear();
  172. this.sampleList = [];
  173. this.$refs.tabsRef.tabsChange('1');
  174. this.$refs.tabsRef.tabsConditionType(null);
  175. this.form.qualityMode = val;
  176. //检验方式 全检
  177. if (this.form.qualityMode == 1) {
  178. this.activeName = '2';
  179. this.form.sampleNumber = '';
  180. const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
  181. if (sData.length == 0) {
  182. for (let i = 0; i < sData.length; i++) {
  183. this.$set(sData[i], 'qualityStatus', 2);
  184. }
  185. }
  186. console.log(
  187. this.$refs.tabsRef.$refs.sourceTable.getData(),
  188. 'packingList'
  189. );
  190. this.getProSamList(sData);
  191. } else {
  192. this.activeName = '1';
  193. if (!flag) {
  194. this.sampleList = [];
  195. }
  196. }
  197. },
  198. //根据类型判断样品清单现实列表数据
  199. async getProSamList(list) {
  200. //生产检验
  201. if (this.qualityType == 2) {
  202. if (this.form.qualityMode != null) {
  203. const ProductSampleList = [];
  204. console.log(list, 'list');
  205. for (const oldItem of list) {
  206. const count = oldItem.measureQuantity;
  207. const newMeasureQuantity = oldItem.measureQuantity / count;
  208. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  209. console.log(typeof oldItem.qualitySampleTemplateList, 'ssssss');
  210. // 遍历新数组设置 qualityResults 默认值
  211. this.schemeList.forEach((item) => {
  212. if (typeof item === 'object' && item !== null) {
  213. item.qualityResults = 1; // 设置默认值
  214. }
  215. delete item.id;
  216. });
  217. console.log(oldItem, 'oldItem');
  218. console.log(count, newMeasureQuantity, newWeight);
  219. delete oldItem.id;
  220. if (
  221. oldItem.qualitySampleTemplateList == undefined ||
  222. oldItem.qualitySampleTemplateList == null ||
  223. oldItem.qualitySampleTemplateList.length == 0
  224. ) {
  225. oldItem.qualitySampleTemplateList = JSON.parse(
  226. JSON.stringify(this.schemeList)
  227. );
  228. for (let i = 0; i < count; i++) {
  229. ProductSampleList.push({
  230. ...oldItem,
  231. measureQuantity: newMeasureQuantity,
  232. weight: newWeight,
  233. sampleCode: await this.getSampleCode(),
  234. qualitySampleTemplateList: JSON.parse(
  235. JSON.stringify(this.schemeList)
  236. )
  237. });
  238. }
  239. console.log(ProductSampleList, 'ProductSampleList');
  240. this.sampleList = ProductSampleList;
  241. const pNum = ProductSampleList.reduce((sum, item) => {
  242. return sum + Number(item.weight || 0);
  243. }, 0);
  244. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  245. } else {
  246. for (let i = 0; i < count; i++) {
  247. ProductSampleList.push({
  248. ...oldItem,
  249. measureQuantity: newMeasureQuantity,
  250. weight: newWeight,
  251. sampleCode: await this.getSampleCode(),
  252. qualitySampleTemplateList: JSON.parse(
  253. JSON.stringify(oldItem.qualitySampleTemplateList)
  254. )
  255. });
  256. }
  257. console.log(ProductSampleList, 'ProductSampleList');
  258. this.sampleList = ProductSampleList;
  259. const pNum = ProductSampleList.reduce((sum, item) => {
  260. return sum + Number(item.weight || 0);
  261. }, 0);
  262. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  263. }
  264. }
  265. }
  266. } else {
  267. // this.sampleList = list;
  268. this.sampleList = this.addStatus;
  269. }
  270. },
  271. //输入取样数量
  272. changeNumber(val) {
  273. if (this.form.qualityMode !== 2) {
  274. return;
  275. }
  276. if (val <= 0) {
  277. this.$refs.showPackingListTable.clearSelection();
  278. return;
  279. }
  280. if (this.qualityType == 2) {
  281. //生产检验的抽检逻辑
  282. if (val > this.packingList[0].measureQuantity) {
  283. this.$message.warning('取样数量不能大于来源清单的计量数量!');
  284. return;
  285. }
  286. const ProductSampleList = [];
  287. this.packingList.forEach((oldItem) => {
  288. const count = oldItem.measureQuantity;
  289. const newMeasureQuantity = oldItem.measureQuantity / count;
  290. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  291. console.log(count, newMeasureQuantity, newWeight);
  292. delete oldItem.id;
  293. // 遍历新数组设置 qualityResults 默认值
  294. this.schemeList.forEach((item) => {
  295. if (typeof item === 'object' && item !== null) {
  296. item.qualityResults = 1; // 设置默认值
  297. }
  298. delete item.id;
  299. });
  300. for (let i = 0; i < val; i++) {
  301. ProductSampleList.push({
  302. ...oldItem,
  303. measureQuantity: newMeasureQuantity,
  304. weight: newWeight,
  305. qualitySampleTemplateList: JSON.parse(
  306. JSON.stringify(this.schemeList)
  307. )
  308. });
  309. }
  310. });
  311. this.sampleList = ProductSampleList;
  312. const pNum = ProductSampleList.reduce((sum, item) => {
  313. return sum + Number(item.weight || 0);
  314. }, 0);
  315. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  316. } else {
  317. if (val > this.packingList.length) {
  318. this.$message.warning('取样数量不能大于物料明细总数!');
  319. return;
  320. }
  321. const rows = this.packingList.slice(0, val);
  322. rows.forEach((row) => {
  323. this.$refs.showPackingListTable.toggleRowSelection(row);
  324. });
  325. }
  326. },
  327. getNowDate() {
  328. let date = new Date(),
  329. obj = {
  330. year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
  331. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  332. strDate: date.getDate(), // 获取当前日(1-31)
  333. hour: date.getHours(), //获取当前小时(0 ~ 23)
  334. minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
  335. second: date.getSeconds() //获取当前秒数(0 ~ 59)
  336. };
  337. Object.keys(obj).forEach((key) => {
  338. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  339. });
  340. return obj;
  341. },
  342. //来源清单勾选事件
  343. handleSelectionChange1(selection) {
  344. if (this.form.qualityMode === 2) {
  345. this.selectedList = selection;
  346. this.activeName = '1';
  347. if (this.schemeList.length == 0) {
  348. for (let i = 0; i < selection.length; i++) {
  349. this.$set(selection[i], 'qualityStatus', 2);
  350. // 遍历新数组设置 qualityResults 默认值
  351. this.schemeList.forEach((item) => {
  352. if (typeof item === 'object' && item !== null) {
  353. item.qualityResults = 1; // 设置默认值
  354. }
  355. delete item.id;
  356. });
  357. this.$set(
  358. selection[i],
  359. 'qualitySampleTemplateList',
  360. JSON.parse(JSON.stringify(this.schemeList))
  361. );
  362. }
  363. }
  364. // this.sampleList = selection;
  365. //赋值取样数量
  366. this.form.sampleNumber = selection.length;
  367. }
  368. },
  369. async open() {
  370. this.type = this.$route.query.type;
  371. this.qualityType = this.$route.query.qualityType;
  372. this.title =
  373. this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
  374. if (this.type == 'add') {
  375. const code = await getCode('quality_work_order_code');
  376. this.form.code = code;
  377. } else {
  378. if (
  379. this.$route.query.qualityTimeStart != '' ||
  380. this.$route.query.qualityTimeStart != null ||
  381. this.$route.query.qualityTimeStart != undefined
  382. ) {
  383. this.qualityTimeStart = this.getNowTime();
  384. }
  385. }
  386. },
  387. getNowTime() {
  388. const nowDate = this.getNowDate();
  389. return (
  390. nowDate.year +
  391. '-' +
  392. nowDate.month +
  393. '-' +
  394. nowDate.strDate +
  395. ' ' +
  396. nowDate.hour +
  397. ':' +
  398. nowDate.minute +
  399. ':' +
  400. nowDate.second
  401. );
  402. },
  403. getNowTimes() {
  404. const nowDate = this.getNowDate();
  405. return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate;
  406. },
  407. async getDetail() {
  408. getById(this.$route.query.id).then((res) => {
  409. this.form = res.data;
  410. this.isReportProcessProduce =
  411. this.form.isReportProcessProduce == 1 ? true : false;
  412. this.tabTaskId =
  413. this.categoryParamList[0] && this.categoryParamList[0].id;
  414. if (this.form.groupId) {
  415. this.$nextTick(() => {
  416. this.$refs.baseInfoRefs?.getUserList({
  417. groupId: this.form.groupId
  418. });
  419. });
  420. }
  421. if (this.form.produceRoutingId) {
  422. this.$nextTick(() => {
  423. this.$refs.baseInfoRefs?.getTaskList();
  424. });
  425. }
  426. });
  427. // await this.queryQualityInventory()
  428. await this.queryQualityTempleContent();
  429. await this.queryQualitySamplContent();
  430. await this.getQueryQualityInventory();
  431. },
  432. // getNewData(val) {
  433. // console.log(val, '清单列表')
  434. // this.packingList = val
  435. // },
  436. // async queryQualityInventory() {
  437. // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
  438. // console.log(res, '清单列表');
  439. // this.packingList = res;
  440. // },
  441. changeSamUnit(val) {
  442. this.$set(this.form, 'sampleMeasureUnit', val);
  443. },
  444. async handleSample1(val, data) {
  445. this.sampleList = [];
  446. if (this.selectedList == undefined || this.selectedList.length == 0) {
  447. this.activeName = '1';
  448. this.$message.warning('请先选择样品!');
  449. return;
  450. }
  451. if (val == 1) {
  452. this.activeName = '2';
  453. if (this.form.isUnpack == 1) {
  454. for (let i = 0; i < this.selectedList.length; i++) {
  455. for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
  456. // 不拆计算每个重量
  457. let newWeight = parseFloat(
  458. (
  459. this.selectedList[i].weight /
  460. this.selectedList[i].measureQuantity
  461. ).toFixed(4)
  462. );
  463. if (
  464. this.selectedList[i].qualitySampleTemplateList == undefined ||
  465. this.selectedList[i].qualitySampleTemplateList == null ||
  466. this.selectedList[i].qualitySampleTemplateList.length == 0
  467. ) {
  468. this.sampleList.push({
  469. ...this.selectedList[i],
  470. sampleCode: await this.getSampleCode(),
  471. measureQuantity: 1,
  472. qualitySampleTemplateList: JSON.parse(
  473. JSON.stringify(this.schemeList)
  474. ),
  475. weight: newWeight || 0
  476. });
  477. } else {
  478. this.sampleList.push({
  479. ...this.selectedList[i],
  480. sampleCode: await this.getSampleCode(),
  481. measureQuantity: 1,
  482. qualitySampleTemplateList: JSON.parse(
  483. JSON.stringify(
  484. this.selectedList[i].qualitySampleTemplateList
  485. )
  486. ),
  487. weight: newWeight || 0
  488. });
  489. }
  490. }
  491. }
  492. } else if (this.form.isUnpack == 2) {
  493. // 不拆计算每个重量
  494. let newWeight = parseFloat(
  495. (
  496. this.selectedList[0].weight /
  497. this.selectedList[0].measureQuantity
  498. ).toFixed(4)
  499. );
  500. for (let i = 0; i < this.selectedList[0].measureQuantity; i++) {
  501. if (
  502. this.selectedList[0].qualitySampleTemplateList == undefined ||
  503. this.selectedList[0].qualitySampleTemplateList == null ||
  504. this.selectedList[0].qualitySampleTemplateList.length == 0
  505. ) {
  506. this.sampleList.push({
  507. ...this.selectedList[0],
  508. sampleCode: await this.getSampleCode(),
  509. measureQuantity: 1,
  510. qualitySampleTemplateList: JSON.parse(
  511. JSON.stringify(this.schemeList)
  512. ),
  513. weight: newWeight || 0
  514. });
  515. } else {
  516. this.sampleList.push({
  517. ...this.selectedList[0],
  518. sampleCode: await this.getSampleCode(),
  519. measureQuantity: 1,
  520. qualitySampleTemplateList: JSON.parse(
  521. JSON.stringify(
  522. this.selectedList[0].qualitySampleTemplateList
  523. )
  524. ),
  525. weight: newWeight || 0
  526. });
  527. }
  528. }
  529. }
  530. //取整样=勾选数据
  531. // this.sampleList = this.selectedList;
  532. this.$message.success('取样成功!');
  533. } else if (val == 2) {
  534. console.log(data, 'datadatadatadataxiaoyang');
  535. }
  536. },
  537. async handleSampleSubmit(data) {
  538. console.log(data, 'data123确认');
  539. this.sampleList = [];
  540. if (!this.selectedList || this.selectedList.length == 0) {
  541. this.$message.warning('请先选择样品!');
  542. return;
  543. }
  544. const measureQ = data.measureQ || 1;
  545. const unit = data.sampleUnit;
  546. const sampleCount = Number(data.portion);
  547. console.log(measureQ, '计量数量');
  548. console.log(unit, '所选单位');
  549. console.log(sampleCount, '数量');
  550. try {
  551. if (this.isStandard1OrWeightSample()) {
  552. //抽检计量整样小样或者抽检计重小样
  553. if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
  554. return; //取样数量验证
  555. if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
  556. return; // 若计量单位为重量,还需验证总重量是否足够
  557. await this.getNewFullSampleList(
  558. Math.ceil(sampleCount),
  559. measureQ,
  560. unit
  561. );
  562. } else if (this.isWeightStandardFullSample()) {
  563. //抽检取计重取整样
  564. if (!this.validateSampleCount(sampleCount)) return;
  565. await this.handleWeightFullSample(sampleCount);
  566. }
  567. this.activeName = '2';
  568. } catch (error) {
  569. console.error('取样处理失败:', error);
  570. this.$message.error('取样处理失败');
  571. }
  572. },
  573. //获取样品编码
  574. async getSampleCode() {
  575. return await getCode('sample_code');
  576. },
  577. async getNewSampleList(measureQ, unit, nums) {
  578. this.sampleList = [];
  579. console.log(this.selectedList, 'this.selectedList');
  580. if (!this.selectedList || this.selectedList.length == 0) {
  581. this.$message.warning('请先选择来源清单!');
  582. return;
  583. }
  584. this.activeName = '2';
  585. if (this.form.isUnpack == 1) {
  586. // 1 拆包 2 不拆
  587. let measureQuantity = 1;
  588. if (this.form.conditionType == 2) {
  589. measureQuantity = measureQ;
  590. }
  591. for (let i = 0; i < this.selectedList.length; i++) {
  592. if (
  593. this.selectedList[i].qualitySampleTemplateList == undefined ||
  594. this.selectedList[i].qualitySampleTemplateList == null ||
  595. this.selectedList[i].qualitySampleTemplateList.length == 0
  596. ) {
  597. this.sampleList.push({
  598. ...this.selectedList[i],
  599. sampleCode: await this.getSampleCode(),
  600. measureQuantity: measureQuantity,
  601. qualitySampleTemplateList: JSON.parse(
  602. JSON.stringify(this.schemeList)
  603. ),
  604. measureUnit: unit
  605. });
  606. } else {
  607. this.sampleList.push({
  608. ...this.selectedList[i],
  609. sampleCode: await this.getSampleCode(),
  610. measureQuantity: measureQuantity,
  611. qualitySampleTemplateList: JSON.parse(
  612. JSON.stringify(this.selectedList[i].qualitySampleTemplateList)
  613. ),
  614. measureUnit: unit
  615. });
  616. }
  617. }
  618. } else if (this.form.isUnpack == 2) {
  619. if (this.form.conditionType == 1) {
  620. measureQ = 1;
  621. }
  622. // 不拆计算每个重量
  623. let newWeight = parseFloat(
  624. (
  625. this.selectedList[0].weight / this.selectedList[0].measureQuantity
  626. ).toFixed(4)
  627. );
  628. for (let i = 0; i < nums; i++) {
  629. if (
  630. this.selectedList[0].qualitySampleTemplateList == undefined ||
  631. this.selectedList[0].qualitySampleTemplateList == null ||
  632. this.selectedList[0].qualitySampleTemplateList.length == 0
  633. ) {
  634. this.sampleList.push({
  635. ...this.selectedList[0],
  636. sampleCode: await this.getSampleCode(),
  637. measureQuantity: measureQ,
  638. qualitySampleTemplateList: JSON.parse(
  639. JSON.stringify(this.schemeList)
  640. ),
  641. measureUnit: unit,
  642. weight: newWeight || 0
  643. });
  644. } else {
  645. this.sampleList.push({
  646. ...this.selectedList[0],
  647. sampleCode: await this.getSampleCode(),
  648. measureQuantity: measureQ,
  649. qualitySampleTemplateList: JSON.parse(
  650. JSON.stringify(this.selectedList[0].qualitySampleTemplateList)
  651. ),
  652. measureUnit: unit,
  653. weight: newWeight || 0
  654. });
  655. // this.sampleList.push({
  656. // ...this.selectedList[0],
  657. // sampleCode: await this.getSampleCode(),
  658. // measureQuantity: measureQ,
  659. // measureUnit: unit,
  660. // weight: newWeight || 0,
  661. // });
  662. }
  663. }
  664. }
  665. // this.sampleList = this.selectedList.map(oldItem => {
  666. // const newItem = JSON.parse(JSON.stringify(oldItem));
  667. // newItem.measureQuantity = measureQ;
  668. // newItem.measureUnit = unit;
  669. // return newItem;
  670. // });
  671. this.$refs.tabsRef.tabsChange('2');
  672. },
  673. async getQueryQualityInventory() {
  674. const res = await queryQualityInventory({
  675. qualityWorkerId: this.$route.query.id,
  676. size: -1
  677. });
  678. if (res.list.length > 0) {
  679. this.inventoryList = res.list;
  680. }
  681. },
  682. async queryQualitySamplContent() {
  683. const res = await queryQualitySamplContent({
  684. qualityWorkerId: this.$route.query.id,
  685. size: 1000
  686. });
  687. let addStatus = res.list.map((item) => {
  688. item.isValid = true;
  689. item.disposeTime = item.disposeTime
  690. ? item.disposeTime.split(' ')[0]
  691. : null;
  692. item.sampleDate = item.sampleDate
  693. ? item.sampleDate.split(' ')[0]
  694. : null;
  695. return {
  696. ...item
  697. };
  698. });
  699. console.log(addStatus, '样品清单12123123');
  700. if (addStatus.length > 0) {
  701. this.sampleList = addStatus;
  702. this.addStatus = addStatus;
  703. } else {
  704. this.getProSamList(this.packingList);
  705. }
  706. },
  707. async queryQualityTempleContent() {
  708. const res = await queryQualityTempleContent({
  709. qualityWorkerId: this.$route.query.id
  710. });
  711. console.log(res, '质检方案');
  712. this.schemeList = res.list;
  713. },
  714. getConditionType(val) {
  715. this.form.conditionType = val;
  716. },
  717. /* 保存编辑 */
  718. save() {
  719. // *** 新增判断
  720. let flag = this.$refs.baseInfoRefs.quantityCalculation();
  721. if (!flag) return;
  722. // ***
  723. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  724. if (!valid) {
  725. return false;
  726. }
  727. // this.loading = true;
  728. let URL =
  729. this.type == 'add' ? save : this.type == 'edit' ? update : '';
  730. this.form.qualityTimeStart = new Date(this.qualityTimeStart);
  731. delete this.form['qualityTimeEnd'];
  732. let params = {
  733. ...this.form,
  734. sampleList: this.sampleList,
  735. planTemplateList: this.schemeList,
  736. templateList: this.schemeList,
  737. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  738. qualityInventoryList: this.inventoryList
  739. };
  740. console.log(params, 'params ----');
  741. URL(params)
  742. .then((msg) => {
  743. this.loading = false;
  744. this.$message.success(msg);
  745. this.cancel();
  746. this.$emit('done');
  747. })
  748. .catch((e) => {
  749. this.loading = false;
  750. });
  751. });
  752. },
  753. update() {
  754. this.loading = true;
  755. this.form['status'] = 1;
  756. update({ ...this.form })
  757. .then((msg) => {
  758. this.loading = false;
  759. this.$message.success(msg);
  760. this.$emit('done');
  761. })
  762. .catch((e) => {
  763. this.loading = false;
  764. });
  765. },
  766. restForm() {
  767. this.form = { ...this.defaultForm() };
  768. this.$nextTick(() => {
  769. this.$refs.baseInfoRefs.$refs.form1.clearValidate();
  770. });
  771. },
  772. cancel() {
  773. finishPageTab();
  774. this.$router.go(-1);
  775. },
  776. handleDetail(index, row, type) {
  777. if (!this.sampleList[index] || !this.schemeList) {
  778. return;
  779. }
  780. const selectedData = [];
  781. selectedData.push(this.sampleList[index]);
  782. this.$refs.detailRef.openDia(
  783. index,
  784. row,
  785. type,
  786. selectedData,
  787. null,
  788. this.schemeList.toolList
  789. );
  790. },
  791. inputWeight(row, index) {
  792. console.log(row, index, '输入重量');
  793. // 计算所有样本的总重量
  794. const pNum = this.sampleList.reduce((sum, item) => {
  795. return sum + Number(item.weight || 0);
  796. }, 0);
  797. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  798. },
  799. handleDispose(index, row, type) {
  800. if (!this.sampleList[index]) {
  801. return;
  802. }
  803. this.sampleList[index].sampleDate = this.getNowTimes();
  804. this.sampleList[index].disposeTime = this.getNowTimes();
  805. console.log(index, row, type, this.qualityType);
  806. this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
  807. },
  808. // 报工
  809. handleReporting(index, row) {
  810. if (this.form.qualityMode == 2 && !this.form.qualityResults) {
  811. this.$refs.baseInfoRefs.toggleExpand2();
  812. this.$message.error('请选择质检结果');
  813. return;
  814. }
  815. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  816. if (!valid) return false;
  817. this.loading = true;
  818. if (this.qualityType == 2 && this.isReportProcessProduce) {
  819. for (let i = 0; i < this.sampleList.length; i++) {
  820. const disposalStatus = this.sampleList[i].disposalStatus;
  821. if (disposalStatus == null) {
  822. this.loading = false;
  823. this.$refs.tabsRef.tabsChange('2');
  824. this.$message.error('请完成以下样品处置!');
  825. return;
  826. }
  827. }
  828. }
  829. for (let i = 0; i < this.sampleList.length; i++) {
  830. const qualityStatus = this.sampleList[i].qualityStatus;
  831. if (qualityStatus == '2') {
  832. this.loading = false;
  833. this.$refs.tabsRef.tabsChange('2');
  834. this.$message.error('请完成以下样品质检!');
  835. return;
  836. }
  837. }
  838. this.form.qualityTimeEnd = new Date(this.getNowTime());
  839. this.form.qualityTimeStart = new Date(this.qualityTimeStart);
  840. // if (this.form.qualityMode == 1) {
  841. // this.form.qualityResults = '';
  842. // }
  843. let params = {
  844. ...this.form,
  845. sampleList: this.sampleList,
  846. planTemplateList: this.schemeList,
  847. // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
  848. qualityInventoryList: this.inventoryList
  849. };
  850. console.log(params, 'params');
  851. exeReportWork(params)
  852. .then((msg) => {
  853. this.loading = false;
  854. this.$message.success(msg);
  855. this.cancel();
  856. this.$emit('done');
  857. })
  858. .catch((e) => {
  859. this.loading = false;
  860. });
  861. });
  862. },
  863. // 处理确认事件
  864. handleDisposeConfirm(data, index) {
  865. console.log(data, index, '确认处置事件');
  866. if (index != null) {
  867. this.$set(this.sampleList, index, data);
  868. } else {
  869. this.sampleList.forEach((obj) => {
  870. obj.disposalStatus = data.disposalStatus;
  871. obj.sampleDate = data.sampleDate;
  872. obj.disposeTime = data.disposeTime;
  873. obj.sampleCondition = data.sampleCondition;
  874. obj.producerManufacturer = data.producerManufacturer;
  875. obj.samplePlace = data.samplePlace;
  876. obj.sampleRemark = data.sampleRemark;
  877. });
  878. }
  879. },
  880. //确认质检
  881. handleConfirm(list, index) {
  882. console.log(list);
  883. // 检查有效性
  884. // for (const item of list) {
  885. // for (const child of item.qualitySampleTemplateList) {
  886. //
  887. // console.log(child, 'child')
  888. // if (!child.qualityResultContent || !child.qualityResults) {
  889. // this.$message.error('请完善报工内容!');
  890. // return;
  891. // }
  892. // }
  893. // }
  894. console.log(list, 'listlistlistlist');
  895. list.forEach((item) => {
  896. if (item.qualitySampleTemplateList.length == 1) {
  897. if (
  898. item.qualitySampleTemplateList.some(
  899. (child) => child.qualityResults === 3
  900. )
  901. ) {
  902. // 如果质检项只有一条而且结果为让步接收那么整个就是让步接收
  903. item.isValid = false;
  904. item.qualityResults = 3;
  905. } else if (
  906. item.qualitySampleTemplateList.some(
  907. (child) => child.qualityResults === 2
  908. )
  909. ) {
  910. item.isValid = false;
  911. item.qualityResults = 2;
  912. } else {
  913. item.isValid = true;
  914. item.qualityResults = 1;
  915. }
  916. } else {
  917. if (
  918. item.qualitySampleTemplateList.some(
  919. (child) => child.qualityResults === 2
  920. )
  921. ) {
  922. item.isValid = false;
  923. item.qualityResults = 2;
  924. } else {
  925. item.isValid = true;
  926. item.qualityResults = 1;
  927. }
  928. }
  929. item.qualityStatus = 1;
  930. });
  931. if (index != null) {
  932. this.$set(this.sampleList, index, list[0]);
  933. } else {
  934. this.$set(this.sampleList, null, list);
  935. }
  936. this.activeName = '2';
  937. console.log(this.sampleList, '222表');
  938. // *** 选完批量质检调用
  939. this.countQualityResults();
  940. },
  941. // 批量质检
  942. batchQuality(index, row, type) {
  943. this.$refs.detailRef.openDia(
  944. null,
  945. null,
  946. 'report',
  947. this.sampleList,
  948. null,
  949. this.schemeList.toolList
  950. );
  951. },
  952. // 批量处置
  953. batchDispose() {
  954. this.$refs.disposeRef.openDispose(
  955. null,
  956. null,
  957. 'dispose',
  958. this.qualityType
  959. );
  960. },
  961. //全检,检验标准改变时,重新获取样品列表
  962. async changeInspectionStandardsModel(val) {
  963. const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
  964. if (sData.length > 0) {
  965. for (let i = 0; i < sData.length; i++) {
  966. this.$set(sData[i], 'qualityStatus', 2);
  967. }
  968. }
  969. this.form.inspectionStandards = val;
  970. this.form.sampleNumber = '';
  971. this.$refs.tabsRef.tableSelClear();
  972. this.sampleList = [];
  973. this.$refs.tabsRef.tabsChange('1');
  974. //检验标准 2计重 1计量
  975. if (this.form.inspectionStandards == 2 && this.form.qualityMode == 1) {
  976. for (let i = 0; i < sData.length; i++) {
  977. let qualitySampleTemplateList = [];
  978. if (
  979. sData[i].qualitySampleTemplateList == undefined ||
  980. sData[i].qualitySampleTemplateList == null ||
  981. sData[i].qualitySampleTemplateList.length == 0
  982. ) {
  983. qualitySampleTemplateList = JSON.parse(
  984. JSON.stringify(this.schemeList)
  985. );
  986. } else {
  987. qualitySampleTemplateList = sData[i].qualitySampleTemplateList;
  988. }
  989. this.sampleList.push({
  990. ...sData[i],
  991. sampleCode: await this.getSampleCode(),
  992. qualitySampleTemplateList
  993. });
  994. }
  995. } else if (
  996. this.form.inspectionStandards == 1 &&
  997. this.form.qualityMode == 1
  998. ) {
  999. this.getProSamList(sData);
  1000. }
  1001. },
  1002. //从来源数组取样到目标数组
  1003. async getNewFullSampleList(sampleCount, sampleQuantity, sampleUnit) {
  1004. const sourceArray = this.selectedList;
  1005. // 检查单位是否匹配
  1006. const isUnitMismatch =
  1007. sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
  1008. // 创建副本并计算初始可取样数量
  1009. const items = sourceArray.map((item) => ({
  1010. ...item,
  1011. remainingQuantity: isUnitMismatch
  1012. ? Infinity
  1013. : item['measureQuantity'], // 剩余可取样数量
  1014. maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
  1015. }));
  1016. const result = [];
  1017. let remainingCount = sampleCount;
  1018. // 尽可能均匀地从各条目取样
  1019. while (remainingCount > 0) {
  1020. // 按剩余可取样比例排序
  1021. items.sort(
  1022. (a, b) =>
  1023. b.remainingQuantity / b['measureQuantity'] -
  1024. a.remainingQuantity / a['measureQuantity']
  1025. );
  1026. let distributed = false;
  1027. for (const item of items) {
  1028. if (
  1029. !isUnitMismatch ||
  1030. (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
  1031. ) {
  1032. let qualitySampleTemplateList = [];
  1033. if (
  1034. item.qualitySampleTemplateList == undefined ||
  1035. item.qualitySampleTemplateList == null ||
  1036. item.qualitySampleTemplateList.length == 0
  1037. ) {
  1038. qualitySampleTemplateList = JSON.parse(
  1039. JSON.stringify(this.schemeList)
  1040. );
  1041. } else {
  1042. qualitySampleTemplateList = item.qualitySampleTemplateList;
  1043. }
  1044. // 添加到结果数组
  1045. let sampleCode = await this.getSampleCode();
  1046. if (
  1047. this.form.conditionType == 1 &&
  1048. this.form.inspectionStandards == 1
  1049. ) {
  1050. result.push({
  1051. ...item,
  1052. measureQuantity: 1,
  1053. sampleCode,
  1054. qualitySampleTemplateList
  1055. });
  1056. } else if (
  1057. this.form.conditionType == 2 &&
  1058. (this.form.inspectionStandards == 1 ||
  1059. this.form.inspectionStandards == 2)
  1060. ) {
  1061. let weight = (item.weight / item.maxPossible).toFixed(2);
  1062. result.push({
  1063. ...item,
  1064. measureQuantity: sampleQuantity,
  1065. measureUnit: sampleUnit,
  1066. sampleCode,
  1067. weight,
  1068. qualitySampleTemplateList
  1069. });
  1070. }
  1071. // 更新剩余数量
  1072. if (!isUnitMismatch) {
  1073. item.remainingQuantity -= sampleQuantity;
  1074. }
  1075. remainingCount--;
  1076. distributed = true;
  1077. }
  1078. }
  1079. // 如果没有分配任何取样
  1080. if (!distributed) {
  1081. break;
  1082. }
  1083. }
  1084. this.sampleList = result;
  1085. if (this.sampleList.length > sampleCount) {
  1086. this.sampleList = this.sampleList.splice(0, sampleCount);
  1087. }
  1088. this.form.sampleNumber = this.sampleList.length;
  1089. },
  1090. validateWeight(measureQ, sampleCount) {
  1091. let totalMaxPossible = 0;
  1092. this.selectedList.forEach((item) => {
  1093. totalMaxPossible += item.measureQuantity / measureQ;
  1094. });
  1095. if (totalMaxPossible < sampleCount) {
  1096. // this.formData.portion = totalMaxPossible;
  1097. this.$message.info(`最大取样条数为${totalMaxPossible}`);
  1098. return false;
  1099. }
  1100. let totalWeight = this.selectedList.reduce(
  1101. (sum, item) => sum + item.weight,
  1102. 0
  1103. );
  1104. const weightUnit = this.selectedList[0].weightUnit;
  1105. if (weightUnit === 'G') totalWeight /= 1000;
  1106. if (measureQ * sampleCount > totalWeight) {
  1107. this.$message.info('取样计量重量不能大于总计量重量');
  1108. return false;
  1109. }
  1110. const invalidItem = this.selectedList.find((item) => {
  1111. const weight =
  1112. item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
  1113. return weight < measureQ;
  1114. });
  1115. if (invalidItem) {
  1116. this.$message.info('勾选条目重量小于取样重量');
  1117. return false;
  1118. }
  1119. return true;
  1120. },
  1121. isStandard1OrWeightSample() {
  1122. return (
  1123. this.form.inspectionStandards === 1 ||
  1124. (this.form.inspectionStandards === 2 && this.form.conditionType == 2)
  1125. );
  1126. },
  1127. validateMeasureQuantity(measureQ, unit, sampleCount) {
  1128. if (this.form.conditionType == 2 && measureQ <= 0) {
  1129. this.$message.info('取样计量数量必须大于0');
  1130. return false;
  1131. }
  1132. const totalQuantity = this.selectedList.reduce(
  1133. (sum, item) => sum + item.measureQuantity,
  1134. 0
  1135. );
  1136. if (
  1137. (this.selectedList[0].measureUnit === unit ||
  1138. this.form.conditionType == 1) &&
  1139. measureQ * sampleCount > totalQuantity
  1140. ) {
  1141. this.$message.info('取样计量数量不能大于总计量数量');
  1142. return false;
  1143. }
  1144. const invalidItem = this.selectedList.find(
  1145. (item) => item.measureQuantity < measureQ
  1146. );
  1147. if (invalidItem) {
  1148. this.$message.info('条目计量数量小于取样计量数量');
  1149. return false;
  1150. }
  1151. return true;
  1152. },
  1153. isWeightStandardFullSample() {
  1154. return (
  1155. this.form.inspectionStandards === 2 && this.form.conditionType == 1
  1156. );
  1157. },
  1158. validateSampleCount(sampleCount) {
  1159. const invalidItem = this.selectedList.find(
  1160. (item) => item.measureQuantity < sampleCount
  1161. );
  1162. if (invalidItem) {
  1163. this.$message.info('所选的条目计量数量小于取样计量数量');
  1164. return false;
  1165. }
  1166. return true;
  1167. },
  1168. async handleWeightFullSample(sampleCount) {
  1169. for (const item of this.selectedList) {
  1170. const qualitySampleTemplateList = item.qualitySampleTemplateList
  1171. ?.length
  1172. ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
  1173. : JSON.parse(JSON.stringify(this.schemeList));
  1174. this.sampleList.push({
  1175. ...item,
  1176. measureQuantity: sampleCount, //作为计量数量
  1177. sampleCode: await this.getSampleCode(),
  1178. qualitySampleTemplateList
  1179. });
  1180. }
  1181. this.sampleNumber = this.sampleList.length;
  1182. },
  1183. //计算合格率
  1184. countQualityResults() {
  1185. let sampleList = this.sampleList; //样品清单
  1186. let sampleNumber = this.form.total; //样品总数
  1187. console.log(sampleList, sampleNumber, '=====');
  1188. // let qualifiedNumber = sampleList.filter(item => item.qualityResults == 1 || item.qualityResults == 3).length;
  1189. // let noQualifiedNumber = sampleList.filter(
  1190. // (item) => item.qualityResults == 2
  1191. // ).length;
  1192. let noQualifiedNumber = sampleList.reduce((acc, pro) => {
  1193. // console.log(acc, pro);
  1194. // if (pro.qualityResults == 2) {
  1195. // return acc + Number(pro.measureQuantity);
  1196. // }
  1197. return pro.qualityResults == 2
  1198. ? acc + Number(pro.measureQuantity)
  1199. : acc;
  1200. }, 0);
  1201. console.log(noQualifiedNumber, 'noQualifiedNumber');
  1202. let qualifiedNumber = sampleNumber - noQualifiedNumber; //不合格数
  1203. let qualificationRate = (
  1204. (qualifiedNumber / sampleNumber) *
  1205. 100
  1206. ).toFixed(2); //合格率
  1207. let noQualificationRate = (
  1208. (noQualifiedNumber / sampleNumber) *
  1209. 100
  1210. ).toFixed(2); //不合格率
  1211. this.$refs.baseInfoRefs.updateQualificationRate(
  1212. qualifiedNumber,
  1213. noQualifiedNumber,
  1214. qualificationRate,
  1215. noQualificationRate
  1216. );
  1217. }
  1218. }
  1219. };
  1220. </script>
  1221. <style lang="scss" scoped></style>