| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400 |
- <template>
- <div class="ele-body">
- <el-card shadow="never">
- <header-title title="基本信息">
- <el-button @click="cancel">返回</el-button>
- <el-button
- type="primary"
- @click="save"
- :loading="loading"
- v-if="type != 'detail'"
- >保存</el-button
- >
- <el-button
- type="primary"
- @click="handleReporting"
- :loading="loading"
- v-if="type != 'detail'"
- >报工完成</el-button
- >
- </header-title>
- <base-info
- ref="baseInfoRefs"
- v-if="form"
- :form="form"
- :btnType="type"
- :qualityType1="qualityType"
- @changeModel="changeModel"
- @changeNumber="changeNumber"
- @changeInspectionStandardsModel="changeInspectionStandardsModel"
- ></base-info>
- <quality-content-tabs
- ref="tabsRef"
- :type="type"
- :ids="this.$route.query.id"
- :sample-list="sampleList"
- :activeName="activeName"
- :scheme-list="schemeList"
- :loading="loading"
- :form="form"
- :status="statusType"
- @handleSelectionChange="handleSelectionChange1"
- @batch-quality="batchQuality"
- @batch-dispose="batchDispose"
- @handleDetail="handleDetail"
- @inputWeight="inputWeight"
- @handleDispose="handleDispose"
- @changeSamUnit="changeSamUnit"
- @handleSample1="handleSample1"
- @handleSampleSubmit="handleSampleSubmit"
- @getConditionType="getConditionType"
- @countQualityResults="countQualityResults"
- />
- </el-card>
- <sampleListDialog
- ref="detailRef"
- @handleConfirm="handleConfirm"
- @handleDispose="handleDispose"
- ></sampleListDialog>
- <sampleDisposeDialog
- v-if="sampleDisposeVisble"
- :sampleDisposeVisble.sync="sampleDisposeVisble"
- ref="disposeRef"
- @handleDisposeConfirm="handleDisposeConfirm"
- :rowData="rowData"
- @close="closeDispose"
- @handleDispose="handleDispose"
- ></sampleDisposeDialog>
- </div>
- </template>
- <script>
- import baseInfo from './components/baseInfo.vue';
- // import QualityContentTabs from './components/QualityContentTabs.vue';
- import QualityContentTabs from './components/newQualityContentTabs.vue';
- import { getCode } from '@/api/login';
- import {
- save,
- update,
- getById,
- exeReportWork,
- queryQualitySamplContent,
- queryQualityTempleContent,
- queryQualityInventory
- } from '@/api/inspectionWork';
- import dictMixins from '@/mixins/dictMixins';
- // import term from './term';
- import sampleListDialog from './components/sampleListDialog.vue';
- import sampleDisposeDialog from './components/sampleDisposeDialog.vue';
- import { finishPageTab } from '@/utils/page-tab-util';
- export default {
- components: {
- baseInfo,
- QualityContentTabs,
- sampleListDialog,
- sampleDisposeDialog
- },
- mixins: [dictMixins],
- data() {
- const defaultForm = function () {
- return {
- code: '',
- qualityType: null,
- qualityModeproduceRoutingId: '',
- produceRoutingName: '',
- produceTaskId: '',
- produceTaskName: '',
- productName: '',
- productCode: '',
- batchNo: '',
- specification: '',
- modelType: '',
- brandNo: '',
- total: '',
- qualifiedNumber: '',
- noQualifiedNumber: '',
- groupId: '',
- groupName: '',
- qualityId: '',
- qualityName: '',
- qualityTime: '',
- hours: '',
- qualificationRate: '',
- noQualificationRate: '',
- totalWeight: '',
- sampleNumber: '',
- imgUrl: [],
- qualityTimeStart: '',
- qualityTimeEnd: '',
- sampleMeasureUnit: '',
- conditionType: null
- };
- };
- return {
- rowData: null,
- defaultForm,
- sampleDisposeVisble: false,
- // 表单数据
- form: { ...defaultForm() },
- voList: [],
- // 表单验证规则
- categoryParamList: [],
- type: '',
- title: '',
- loading: false,
- tabTaskId: null,
- // activeName: '2',
- packingList: [],
- // 样品清单,处置,批量处置,批量质检,质检的操作
- sampleList: [],
- schemeList: [],
- inventoryList: [],
- activeName: '1',
- isValid: true,
- isStatus: true,
- SampleListbyReportList: [],
- qualityTimeStart: '',
- isReportProcessProduce: false,
- addStatus: [],
- statusType: false
- };
- },
- watch: {
- '$route.query.id': {
- handler(id) {
- if (id) {
- this.getDetail();
- } else {
- this.form = { ...defaultForm() };
- }
- }
- }
- },
- created() {
- this.open();
- if (this.$route.query.id) {
- this.getDetail();
- }
- },
- methods: {
- //切换检验方式
- changeModel(val, flag) {
- console.log('切换检验方式');
-
- this.$refs.tabsRef.tableSelClear();
- this.sampleList = [];
- this.$refs.tabsRef.tabsChange('1');
- this.$refs.tabsRef.tabsConditionType(null);
- this.form.qualityMode = val;
- //检验方式 全检
- if (this.form.qualityMode == 1) {
- this.activeName = '2';
- this.form.sampleNumber = '';
- const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
- if (sData.length == 0) {
- for (let i = 0; i < sData.length; i++) {
- this.$set(sData[i], 'qualityStatus', 2);
- }
- }
- console.log(
- this.$refs.tabsRef.$refs.sourceTable.getData(),
- 'packingList'
- );
- this.getProSamList(sData);
- } else {
- this.activeName = '1';
- if (!flag) {
- this.sampleList = [];
- }
- }
- },
- //根据类型判断样品清单现实列表数据
- async getProSamList(list) {
- //生产检验
- if (this.qualityType == 2) {
- if (this.form.qualityMode != null) {
- const ProductSampleList = [];
- console.log(list, 'list');
- for (const oldItem of list) {
- const count = oldItem.measureQuantity;
- const newMeasureQuantity = oldItem.measureQuantity / count;
- const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
- console.log(typeof oldItem.qualitySampleTemplateList, 'ssssss');
- // 遍历新数组设置 qualityResults 默认值
- this.schemeList.forEach((item) => {
- if (typeof item === 'object' && item !== null) {
- item.qualityResults = 1; // 设置默认值
- }
- delete item.id;
- });
- console.log(oldItem, 'oldItem');
- console.log(count, newMeasureQuantity, newWeight);
- delete oldItem.id;
- if (
- oldItem.qualitySampleTemplateList == undefined ||
- oldItem.qualitySampleTemplateList == null ||
- oldItem.qualitySampleTemplateList.length == 0
- ) {
- oldItem.qualitySampleTemplateList = JSON.parse(
- JSON.stringify(this.schemeList)
- );
- for (let i = 0; i < count; i++) {
- ProductSampleList.push({
- ...oldItem,
- measureQuantity: newMeasureQuantity,
- weight: newWeight,
- sampleCode: await this.getSampleCode(),
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.schemeList)
- )
- });
- }
- console.log(ProductSampleList, 'ProductSampleList');
- this.sampleList = ProductSampleList;
- const pNum = ProductSampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- } else {
- for (let i = 0; i < count; i++) {
- ProductSampleList.push({
- ...oldItem,
- measureQuantity: newMeasureQuantity,
- weight: newWeight,
- sampleCode: await this.getSampleCode(),
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(oldItem.qualitySampleTemplateList)
- )
- });
- }
- console.log(ProductSampleList, 'ProductSampleList');
- this.sampleList = ProductSampleList;
- const pNum = ProductSampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- }
- }
- }
- } else {
- // this.sampleList = list;
- this.sampleList = this.addStatus;
- }
- },
- //输入取样数量
- changeNumber(val) {
- if (this.form.qualityMode !== 2) {
- return;
- }
- if (val <= 0) {
- this.$refs.showPackingListTable.clearSelection();
- return;
- }
- if (this.qualityType == 2) {
- //生产检验的抽检逻辑
- if (val > this.packingList[0].measureQuantity) {
- this.$message.warning('取样数量不能大于来源清单的计量数量!');
- return;
- }
- const ProductSampleList = [];
- this.packingList.forEach((oldItem) => {
- const count = oldItem.measureQuantity;
- const newMeasureQuantity = oldItem.measureQuantity / count;
- const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
- console.log(count, newMeasureQuantity, newWeight);
- delete oldItem.id;
- // 遍历新数组设置 qualityResults 默认值
- this.schemeList.forEach((item) => {
- if (typeof item === 'object' && item !== null) {
- item.qualityResults = 1; // 设置默认值
- }
- delete item.id;
- });
- for (let i = 0; i < val; i++) {
- ProductSampleList.push({
- ...oldItem,
- measureQuantity: newMeasureQuantity,
- weight: newWeight,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.schemeList)
- )
- });
- }
- });
- this.sampleList = ProductSampleList;
- const pNum = ProductSampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- } else {
- if (val > this.packingList.length) {
- this.$message.warning('取样数量不能大于物料明细总数!');
- return;
- }
- const rows = this.packingList.slice(0, val);
- rows.forEach((row) => {
- this.$refs.showPackingListTable.toggleRowSelection(row);
- });
- }
- },
- getNowDate() {
- let date = new Date(),
- obj = {
- year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
- month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
- strDate: date.getDate(), // 获取当前日(1-31)
- hour: date.getHours(), //获取当前小时(0 ~ 23)
- minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
- second: date.getSeconds() //获取当前秒数(0 ~ 59)
- };
- Object.keys(obj).forEach((key) => {
- if (obj[key] < 10) obj[key] = `0${obj[key]}`;
- });
- return obj;
- },
- //来源清单勾选事件
- handleSelectionChange1(selection) {
- if (this.form.qualityMode === 2) {
- this.selectedList = selection;
- this.activeName = '1';
- if (this.schemeList.length == 0) {
- for (let i = 0; i < selection.length; i++) {
- this.$set(selection[i], 'qualityStatus', 2);
- // 遍历新数组设置 qualityResults 默认值
- this.schemeList.forEach((item) => {
- if (typeof item === 'object' && item !== null) {
- item.qualityResults = 1; // 设置默认值
- }
- delete item.id;
- });
- this.$set(
- selection[i],
- 'qualitySampleTemplateList',
- JSON.parse(JSON.stringify(this.schemeList))
- );
- }
- }
- // this.sampleList = selection;
- //赋值取样数量
- this.form.sampleNumber = selection.length;
- }
- },
- async open() {
- this.type = this.$route.query.type;
- this.qualityType = this.$route.query.qualityType;
- this.title =
- this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
- if (this.type == 'add') {
- const code = await getCode('quality_work_order_code');
- this.form.code = code;
- } else {
- if (
- this.$route.query.qualityTimeStart != '' ||
- this.$route.query.qualityTimeStart != null ||
- this.$route.query.qualityTimeStart != undefined
- ) {
- this.qualityTimeStart = this.getNowTime();
- }
- }
- },
- getNowTime() {
- const nowDate = this.getNowDate();
- return (
- nowDate.year +
- '-' +
- nowDate.month +
- '-' +
- nowDate.strDate +
- ' ' +
- nowDate.hour +
- ':' +
- nowDate.minute +
- ':' +
- nowDate.second
- );
- },
- getNowTimes() {
- const nowDate = this.getNowDate();
- return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate;
- },
- async getDetail() {
- getById(this.$route.query.id).then((res) => {
- this.form = res.data;
- this.statusType = this.form.status == 1 ? true : false;
- this.isReportProcessProduce =
- this.form.isReportProcessProduce == 1 ? true : false;
- this.tabTaskId =
- this.categoryParamList[0] && this.categoryParamList[0].id;
- if (this.form.groupId) {
- this.$nextTick(() => {
- this.$refs.baseInfoRefs?.getUserList({
- groupId: this.form.groupId
- });
- });
- }
- if (this.form.produceRoutingId) {
- this.$nextTick(() => {
- this.$refs.baseInfoRefs?.getTaskList();
- });
- }
- });
- // await this.queryQualityInventory()
- // 质检方案
- await this.queryQualityTempleContent();
- await this.queryQualitySamplContent();
- // 来源清单
- await this.getQueryQualityInventory();
- },
- // getNewData(val) {
- // console.log(val, '清单列表')
- // this.packingList = val
- // },
- // async queryQualityInventory() {
- // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
- // console.log(res, '清单列表');
- // this.packingList = res;
- // },
- changeSamUnit(val) {
- this.$set(this.form, 'sampleMeasureUnit', val);
- },
- async handleSample1(val, data) {
- this.sampleList = [];
- if (this.selectedList == undefined || this.selectedList.length == 0) {
- this.activeName = '1';
- this.$message.warning('请先选择样品!');
- return;
- }
- if (val == 1) {
- this.activeName = '2';
- if (this.form.isUnpack == 1) {
- for (let i = 0; i < this.selectedList.length; i++) {
- for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
- // 不拆计算每个重量
- let newWeight = parseFloat(
- (
- this.selectedList[i].weight /
- this.selectedList[i].measureQuantity
- ).toFixed(4)
- );
- if (
- this.selectedList[i].qualitySampleTemplateList == undefined ||
- this.selectedList[i].qualitySampleTemplateList == null ||
- this.selectedList[i].qualitySampleTemplateList.length == 0
- ) {
- this.sampleList.push({
- ...this.selectedList[i],
- sampleCode: await this.getSampleCode(),
- measureQuantity: 1,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.schemeList)
- ),
- weight: newWeight || 0
- });
- } else {
- this.sampleList.push({
- ...this.selectedList[i],
- sampleCode: await this.getSampleCode(),
- measureQuantity: 1,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(
- this.selectedList[i].qualitySampleTemplateList
- )
- ),
- weight: newWeight || 0
- });
- }
- }
- }
- } else if (this.form.isUnpack == 2) {
- // 不拆计算每个重量
- let newWeight = parseFloat(
- (
- this.selectedList[0].weight /
- this.selectedList[0].measureQuantity
- ).toFixed(4)
- );
- for (let i = 0; i < this.selectedList[0].measureQuantity; i++) {
- if (
- this.selectedList[0].qualitySampleTemplateList == undefined ||
- this.selectedList[0].qualitySampleTemplateList == null ||
- this.selectedList[0].qualitySampleTemplateList.length == 0
- ) {
- this.sampleList.push({
- ...this.selectedList[0],
- sampleCode: await this.getSampleCode(),
- measureQuantity: 1,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.schemeList)
- ),
- weight: newWeight || 0
- });
- } else {
- this.sampleList.push({
- ...this.selectedList[0],
- sampleCode: await this.getSampleCode(),
- measureQuantity: 1,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(
- this.selectedList[0].qualitySampleTemplateList
- )
- ),
- weight: newWeight || 0
- });
- }
- }
- }
- //取整样=勾选数据
- // this.sampleList = this.selectedList;
- this.$message.success('取样成功!');
- } else if (val == 2) {
- console.log(data, 'datadatadatadataxiaoyang');
- }
- },
- async handleSampleSubmit(data) {
- console.log(data, 'data123确认');
- this.sampleList = [];
- if (!this.selectedList || this.selectedList.length == 0) {
- this.$message.warning('请先选择样品!');
- return;
- }
- const measureQ = data.measureQ || 1;
- const unit = data.sampleUnit;
- const sampleCount = Number(data.portion);
- console.log(measureQ, '计量数量');
- console.log(unit, '所选单位');
- console.log(sampleCount, '数量');
- try {
- if (this.isStandard1OrWeightSample()) {
- //抽检计量整样小样或者抽检计重小样
- if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
- return; //取样数量验证
- if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
- return; // 若计量单位为重量,还需验证总重量是否足够
- console.log(1111111111111);
- await this.getNewFullSampleList(
- Math.ceil(sampleCount),
- measureQ,
- unit
- );
- } else if (this.isWeightStandardFullSample()) {
- //抽检取计重取整样
- if (!this.validateSampleCount(sampleCount)) return;
- console.log(222222222222222222);
- await this.handleWeightFullSample(sampleCount);
- }
- this.activeName = '2';
- this.$refs.tabsRef.tabsChange('2');
- } catch (error) {
- console.error('取样处理失败:', error);
- this.$message.error('取样处理失败');
- }
- },
- //获取样品编码
- async getSampleCode() {
- return await getCode('sample_code');
- },
- async getNewSampleList(measureQ, unit, nums) {
- this.sampleList = [];
- console.log(this.selectedList, 'this.selectedList');
- if (!this.selectedList || this.selectedList.length == 0) {
- this.$message.warning('请先选择来源清单!');
- return;
- }
- this.activeName = '2';
- this.$refs.tabsRef.tabsChange('2');
- if (this.form.isUnpack == 1) {
- // 1 拆包 2 不拆
- let measureQuantity = 1;
- if (this.form.conditionType == 2) {
- measureQuantity = measureQ;
- }
- for (let i = 0; i < this.selectedList.length; i++) {
- if (
- this.selectedList[i].qualitySampleTemplateList == undefined ||
- this.selectedList[i].qualitySampleTemplateList == null ||
- this.selectedList[i].qualitySampleTemplateList.length == 0
- ) {
- this.sampleList.push({
- ...this.selectedList[i],
- sampleCode: await this.getSampleCode(),
- measureQuantity: measureQuantity,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.schemeList)
- ),
- measureUnit: unit
- });
- } else {
- this.sampleList.push({
- ...this.selectedList[i],
- sampleCode: await this.getSampleCode(),
- measureQuantity: measureQuantity,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.selectedList[i].qualitySampleTemplateList)
- ),
- measureUnit: unit
- });
- }
- }
- } else if (this.form.isUnpack == 2) {
- if (this.form.conditionType == 1) {
- measureQ = 1;
- }
- // 不拆计算每个重量
- let newWeight = parseFloat(
- (
- this.selectedList[0].weight / this.selectedList[0].measureQuantity
- ).toFixed(4)
- );
- for (let i = 0; i < nums; i++) {
- if (
- this.selectedList[0].qualitySampleTemplateList == undefined ||
- this.selectedList[0].qualitySampleTemplateList == null ||
- this.selectedList[0].qualitySampleTemplateList.length == 0
- ) {
- this.sampleList.push({
- ...this.selectedList[0],
- sampleCode: await this.getSampleCode(),
- measureQuantity: measureQ,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.schemeList)
- ),
- measureUnit: unit,
- weight: newWeight || 0
- });
- } else {
- this.sampleList.push({
- ...this.selectedList[0],
- sampleCode: await this.getSampleCode(),
- measureQuantity: measureQ,
- qualitySampleTemplateList: JSON.parse(
- JSON.stringify(this.selectedList[0].qualitySampleTemplateList)
- ),
- measureUnit: unit,
- weight: newWeight || 0
- });
- // this.sampleList.push({
- // ...this.selectedList[0],
- // sampleCode: await this.getSampleCode(),
- // measureQuantity: measureQ,
- // measureUnit: unit,
- // weight: newWeight || 0,
- // });
- }
- }
- }
- // this.sampleList = this.selectedList.map(oldItem => {
- // const newItem = JSON.parse(JSON.stringify(oldItem));
- // newItem.measureQuantity = measureQ;
- // newItem.measureUnit = unit;
- // return newItem;
- // });
- this.$refs.tabsRef.tabsChange('2');
- },
- async getQueryQualityInventory() {
- const res = await queryQualityInventory({
- qualityWorkerId: this.$route.query.id,
- size: -1
- });
- if (res.list.length > 0) {
- this.inventoryList = res.list;
- }
- },
- async queryQualitySamplContent() {
- const res = await queryQualitySamplContent({
- qualityWorkerId: this.$route.query.id,
- size: 1000
- });
- let addStatus = res.list.map((item) => {
- item.isValid = true;
- // item.disposeTime = item.disposeTime
- // ? item.disposeTime.split(' ')[0]
- // : null;
- item.sampleDate = item.sampleDate
- ? item.sampleDate.split(' ')[0]
- : null;
- return {
- ...item
- };
- });
- console.log(addStatus, '样品清单12123123');
- if (addStatus.length > 0) {
- this.sampleList = addStatus;
- this.addStatus = addStatus;
- } else {
- this.getProSamList(this.packingList);
- }
- },
- async queryQualityTempleContent() {
- const res = await queryQualityTempleContent({
- qualityWorkerId: this.$route.query.id
- });
- console.log(res, '质检方案');
- this.schemeList = res.list;
- },
- // 取样
- getConditionType(val) {
- console.log(val, '------取样的回调');
- this.form.conditionType = val;
- },
- /* 保存编辑 */
- save() {
- // *** 新增判断
- let flag = this.$refs.baseInfoRefs.quantityCalculation();
- if (!flag) return;
- // ***
- this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
- if (!valid) {
- return false;
- }
- // this.loading = true;
- let URL =
- this.type == 'add' ? save : this.type == 'edit' ? update : '';
- this.form.qualityTimeStart = this.qualityTimeStart;
- delete this.form['qualityTimeEnd'];
- console.log(this.sampleList);
- // return
-
- let params = {
- ...this.form,
- sampleList: this.sampleList,
- planTemplateList: this.schemeList,
- templateList: this.schemeList,
- // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
- qualityInventoryList: this.inventoryList
- };
- console.log(params, 'params ----');
- URL(params)
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.cancel();
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- });
- });
- },
- update() {
- this.loading = true;
- this.form['status'] = 1;
- update({ ...this.form })
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- });
- },
- restForm() {
- this.form = { ...this.defaultForm() };
- this.$nextTick(() => {
- this.$refs.baseInfoRefs.$refs.form1.clearValidate();
- });
- },
- cancel() {
- finishPageTab();
- this.$router.go(-1);
- },
- handleDetail(index, row, type) {
- if (!this.sampleList[index] || !this.schemeList) {
- return;
- }
- const selectedData = [];
- selectedData.push(this.sampleList[index]);
- this.$refs.detailRef.openDia(
- index,
- row,
- type,
- selectedData,
- null,
- this.schemeList.toolList
- );
- },
- inputWeight(row, index) {
- console.log(row, index, '输入重量');
- // 计算所有样本的总重量
- const pNum = this.sampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- },
- handleDispose(data) {
- console.log(data);
- // return
- this.rowData = data;
- this.sampleDisposeVisble = true;
- // if (!this.sampleList[index]) {
- // return;
- // }
- // this.sampleList[index].sampleDate = this.getNowTimes();
- // this.sampleList[index].disposeTime = this.getNowTimes();
- // console.log(index, row, type, this.qualityType);
- // this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
- },
- // 报工
- handleReporting(index, row) {
- if (this.form.qualityMode == 2 && !this.form.qualityResults) {
- this.$refs.baseInfoRefs.toggleExpand2();
- this.$message.error('请选择质检结果');
- return;
- }
- this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
- if (!valid) return false;
- this.loading = true;
- if (this.qualityType == 2 && this.isReportProcessProduce) {
- for (let i = 0; i < this.sampleList.length; i++) {
- const disposalStatus = this.sampleList[i].disposalStatus;
- if (disposalStatus == null) {
- this.loading = false;
- this.$refs.tabsRef.tabsChange('2');
- this.$message.error('请完成以下样品处置!');
- return;
- }
- }
- }
- for (let i = 0; i < this.sampleList.length; i++) {
- const qualityStatus = this.sampleList[i].qualityStatus;
- if (qualityStatus == '2') {
- this.loading = false;
- this.$refs.tabsRef.tabsChange('2');
- this.$message.error('请完成以下样品质检!');
- return;
- }
- }
- // this.form.qualityTimeEnd = new Date(this.getNowTime());
- // this.form.qualityTimeStart = new Date(this.qualityTimeStart);
- this.form.qualityTimeEnd = this.getNowTime();
- this.form.qualityTimeStart = this.qualityTimeStart;
- console.log(this.form.qualityTimeStart, this.form.qualityTimeEnd);
- // if (this.form.qualityMode == 1) {
- // this.form.qualityResults = '';
- // }
- let params = {
- ...this.form,
- sampleList: this.sampleList,
- planTemplateList: this.schemeList,
- // qualityInventoryList: this.$refs.tabsRef.$refs.sourceTable.getData()
- qualityInventoryList: this.inventoryList
- };
- console.log(params, 'params');
- exeReportWork(params)
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.cancel();
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- });
- });
- },
- // 处理确认事件
- handleDisposeConfirm(data, index) {
- console.log(data, index, '确认处置事件');
- console.log(this.sampleList);
- if (index == undefined) {
- this.sampleList.forEach((obj) => {
- obj.disposeType = data.disposeType;
- obj.sampleDate = data.sampleDate;
- obj.sampleCondition = data.sampleCondition;
- obj.producerManufacturer = data.producerManufacturer;
- obj.samplePlace = data.samplePlace;
- obj.sampleRemark = data.sampleRemark;
- obj.depotId = data.depotId;
- obj.depotName = data.depotName;
- });
- } else {
- this.$set(this.sampleList, index, data);
- }
- console.log(this.sampleList);
- },
- //确认质检
- handleConfirm(list, index) {
- console.log(list);
- // 检查有效性
- // for (const item of list) {
- // for (const child of item.qualitySampleTemplateList) {
- //
- // console.log(child, 'child')
- // if (!child.qualityResultContent || !child.qualityResults) {
- // this.$message.error('请完善报工内容!');
- // return;
- // }
- // }
- // }
- console.log(list, 'listlistlistlist');
- list.forEach((item) => {
- if (item.qualitySampleTemplateList.length == 1) {
- if (
- item.qualitySampleTemplateList.some(
- (child) => child.qualityResults === 3
- )
- ) {
- // 如果质检项只有一条而且结果为让步接收那么整个就是让步接收
- item.isValid = false;
- item.qualityResults = 3;
- } else if (
- item.qualitySampleTemplateList.some(
- (child) => child.qualityResults === 2
- )
- ) {
- item.isValid = false;
- item.qualityResults = 2;
- } else {
- item.isValid = true;
- item.qualityResults = 1;
- }
- } else {
- if (
- item.qualitySampleTemplateList.some(
- (child) => child.qualityResults === 2
- )
- ) {
- item.isValid = false;
- item.qualityResults = 2;
- } else {
- item.isValid = true;
- item.qualityResults = 1;
- }
- }
- item.qualityStatus = 1;
- });
- if (index != null) {
- this.$set(this.sampleList, index, list[0]);
- } else {
- this.$set(this.sampleList, null, list);
- }
- this.activeName = '2';
- console.log(this.sampleList, '222表');
- // *** 选完批量质检调用
- this.countQualityResults();
- },
- // 批量质检
- batchQuality(index, row, type) {
- this.$refs.detailRef.openDia(
- null,
- null,
- 'report',
- this.sampleList,
- null,
- this.schemeList.toolList
- );
- },
- // 批量处置
- batchDispose() {
- if (this.sampleList && this.sampleList.length) {
- this.sampleDisposeVisble = true;
- return;
- }
- this.$message('当前没有样品清单可以处置');
- // this.$refs.disposeRef.openDispose(
- // null,
- // null,
- // 'dispose',
- // this.qualityType
- // );
- },
- //全检,检验标准改变时,重新获取样品列表
- async changeInspectionStandardsModel(val) {
- const sData = this.$refs.tabsRef.$refs.sourceTable.getData();
- if (sData.length > 0) {
- for (let i = 0; i < sData.length; i++) {
- this.$set(sData[i], 'qualityStatus', 2);
- }
- }
- this.form.inspectionStandards = val;
- this.form.sampleNumber = '';
- this.$refs.tabsRef.tableSelClear();
- this.sampleList = [];
- this.$refs.tabsRef.tabsChange('1');
- //检验标准 2计重 1计量
- if (this.form.inspectionStandards == 2 && this.form.qualityMode == 1) {
- for (let i = 0; i < sData.length; i++) {
- let qualitySampleTemplateList = [];
- if (
- sData[i].qualitySampleTemplateList == undefined ||
- sData[i].qualitySampleTemplateList == null ||
- sData[i].qualitySampleTemplateList.length == 0
- ) {
- qualitySampleTemplateList = JSON.parse(
- JSON.stringify(this.schemeList)
- );
- } else {
- qualitySampleTemplateList = sData[i].qualitySampleTemplateList;
- }
- this.sampleList.push({
- ...sData[i],
- sampleCode: await this.getSampleCode(),
- qualitySampleTemplateList
- });
- }
- } else if (
- this.form.inspectionStandards == 1 &&
- this.form.qualityMode == 1
- ) {
- this.getProSamList(sData);
- }
- },
- //从来源数组取样到目标数组
- async getNewFullSampleList(sampleCount, sampleQuantity, sampleUnit) {
- const sourceArray = this.selectedList;
- // 检查单位是否匹配
- const isUnitMismatch =
- sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
- // 创建副本并计算初始可取样数量
- const items = sourceArray.map((item) => ({
- ...item,
- remainingQuantity: isUnitMismatch
- ? Infinity
- : item['measureQuantity'], // 剩余可取样数量
- maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
- }));
- const result = [];
- let remainingCount = sampleCount;
- // 尽可能均匀地从各条目取样
- while (remainingCount > 0) {
- // 按剩余可取样比例排序
- items.sort(
- (a, b) =>
- b.remainingQuantity / b['measureQuantity'] -
- a.remainingQuantity / a['measureQuantity']
- );
- let distributed = false;
- for (const item of items) {
- if (
- !isUnitMismatch ||
- (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
- ) {
- let qualitySampleTemplateList = [];
- if (
- item.qualitySampleTemplateList == undefined ||
- item.qualitySampleTemplateList == null ||
- item.qualitySampleTemplateList.length == 0
- ) {
- qualitySampleTemplateList = JSON.parse(
- JSON.stringify(this.schemeList)
- );
- } else {
- qualitySampleTemplateList = item.qualitySampleTemplateList;
- }
- // 添加到结果数组
- let sampleCode = await this.getSampleCode();
- if (
- this.form.conditionType == 1 &&
- this.form.inspectionStandards == 1
- ) {
- result.push({
- ...item,
- measureQuantity: 1,
- sampleCode,
- qualitySampleTemplateList
- });
- } else if (
- this.form.conditionType == 2 &&
- (this.form.inspectionStandards == 1 ||
- this.form.inspectionStandards == 2)
- ) {
- let weight = (item.weight / item.maxPossible).toFixed(2);
- result.push({
- ...item,
- measureQuantity: sampleQuantity,
- measureUnit: sampleUnit,
- sampleCode,
- weight,
- qualitySampleTemplateList
- });
- }
- // 更新剩余数量
- if (!isUnitMismatch) {
- item.remainingQuantity -= sampleQuantity;
- }
- remainingCount--;
- distributed = true;
- }
- }
- // 如果没有分配任何取样
- if (!distributed) {
- break;
- }
- }
- this.sampleList = result;
- if (this.sampleList.length > sampleCount) {
- this.sampleList = this.sampleList.splice(0, sampleCount);
- }
- this.form.sampleNumber = this.sampleList.length;
- },
- validateWeight(measureQ, sampleCount) {
- let totalMaxPossible = 0;
- this.selectedList.forEach((item) => {
- totalMaxPossible += item.measureQuantity / measureQ;
- });
- if (totalMaxPossible < sampleCount) {
- // this.formData.portion = totalMaxPossible;
- this.$message.info(`最大取样条数为${totalMaxPossible}`);
- return false;
- }
- let totalWeight = this.selectedList.reduce(
- (sum, item) => sum + item.weight,
- 0
- );
- const weightUnit = this.selectedList[0].weightUnit;
- if (weightUnit === 'G') totalWeight /= 1000;
- if (measureQ * sampleCount > totalWeight) {
- this.$message.info('取样计量重量不能大于总计量重量');
- return false;
- }
- const invalidItem = this.selectedList.find((item) => {
- const weight =
- item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
- return weight < measureQ;
- });
- if (invalidItem) {
- this.$message.info('勾选条目重量小于取样重量');
- return false;
- }
- return true;
- },
- isStandard1OrWeightSample() {
- return (
- this.form.inspectionStandards === 1 ||
- (this.form.inspectionStandards === 2 && this.form.conditionType == 2)
- );
- },
- validateMeasureQuantity(measureQ, unit, sampleCount) {
- if (this.form.conditionType == 2 && measureQ <= 0) {
- this.$message.info('取样计量数量必须大于0');
- return false;
- }
- const totalQuantity = this.selectedList.reduce(
- (sum, item) => sum + item.measureQuantity,
- 0
- );
- if (
- (this.selectedList[0].measureUnit === unit ||
- this.form.conditionType == 1) &&
- measureQ * sampleCount > totalQuantity
- ) {
- this.$message.info('取样计量数量不能大于总计量数量');
- return false;
- }
- const invalidItem = this.selectedList.find(
- (item) => item.measureQuantity < measureQ
- );
- if (invalidItem) {
- this.$message.info('条目计量数量小于取样计量数量');
- return false;
- }
- return true;
- },
- isWeightStandardFullSample() {
- return (
- this.form.inspectionStandards === 2 && this.form.conditionType == 1
- );
- },
- validateSampleCount(sampleCount) {
- const chooseNumber = this.selectedList.reduce((acc, pro) => {
- return pro.measureQuantity ? acc + Number(pro.measureQuantity) : acc;
- }, 0);
- const invalidItem = chooseNumber < sampleCount;
- // console.log(this.selectedList, 'this.selectedList');
- // const invalidItem = this.selectedList.find(
- // (item) => item.measureQuantity < sampleCount
- // );
- if (invalidItem) {
- this.$message.info('所选的条目计量数量小于取样计量数量');
- return false;
- }
- return true;
- },
- async handleWeightFullSample(sampleCount) {
- const dataList = [];
- let currentNum = sampleCount - this.selectedList.length;
- let currentNum1 = sampleCount;
- for (const item of this.selectedList) {
- const qualitySampleTemplateList = item.qualitySampleTemplateList
- ?.length
- ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
- : JSON.parse(
- JSON.stringify(
- this.schemeList.map((item) => {
- item['qualityResults'] = 1;
- return item;
- })
- )
- );
- if (sampleCount >= this.selectedList.length) {
- dataList.push({
- ...item,
- measureQuantity: 1, //作为计量数量
- sampleCode: await this.getSampleCode(),
- qualitySampleTemplateList
- });
- } else {
- if (dataList.length < sampleCount) {
- dataList.push({
- ...item,
- measureQuantity: currentNum1 > 1 ? 1 : currentNum1, //作为计量数量
- sampleCode: await this.getSampleCode(),
- qualitySampleTemplateList
- });
- currentNum1 -= 1;
- }
- }
- }
- if (sampleCount > this.selectedList.length) {
- dataList.forEach((item) => {
- if (currentNum > 0) {
- let data = this.selectedList.find((val) => val.id == item.id);
- item['measureQuantity'] =
- data.measureQuantity - 1 - currentNum > 0
- ? currentNum + 1
- : data.measureQuantity;
- currentNum = currentNum - (data.measureQuantity - 1);
- }
- });
- }
- this.sampleList = dataList;
- this.sampleNumber = this.sampleList.length;
- },
- //计算合格率
- countQualityResults() {
- let sampleList = this.sampleList; //样品清单
- let sampleNumber = this.form.total; //样品总数
- console.log(sampleList, sampleNumber, '=====');
- // let qualifiedNumber = sampleList.filter(item => item.qualityResults == 1 || item.qualityResults == 3).length;
- // let noQualifiedNumber = sampleList.filter(
- // (item) => item.qualityResults == 2
- // ).length;
- let noQualifiedNumber = sampleList.reduce((acc, pro) => {
- // console.log(acc, pro);
- // if (pro.qualityResults == 2) {
- // return acc + Number(pro.measureQuantity);
- // }
- return pro.qualityResults == 2
- ? acc + Number(pro.measureQuantity)
- : acc;
- }, 0);
- console.log(noQualifiedNumber, 'noQualifiedNumber');
- let qualifiedNumber = sampleNumber - noQualifiedNumber; //不合格数
- let qualificationRate = (
- (qualifiedNumber / sampleNumber) *
- 100
- ).toFixed(2); //合格率
- let noQualificationRate = (
- (noQualifiedNumber / sampleNumber) *
- 100
- ).toFixed(2); //不合格率
- this.$refs.baseInfoRefs.updateQualificationRate(
- qualifiedNumber,
- noQualifiedNumber,
- qualificationRate,
- noQualificationRate
- );
- },
- closeDispose() {
- this.rowData = null;
- this.sampleDisposeVisble = false;
- // this.rowData = null;
- }
- }
- };
- </script>
- <style lang="scss" scoped></style>
|