edit.vue 35 KB

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