|
|
@@ -4,8 +4,9 @@
|
|
|
:close-on-press-escape="false" append-to-body width="80%" :maxable="true">
|
|
|
<header-title title="基本信息"></header-title>
|
|
|
<base-info ref="baseInfoRefs" v-if="baseForm" :form="baseForm" :btnType="btnType" @resetTable="resetTable"
|
|
|
- @changeModel="changeModel" @getList="getList" @table2="table2" :packingLists="packingList"
|
|
|
- @getCategoryInfo="getCategoryInfo"></base-info>
|
|
|
+ @changeModel="changeModel" @getList="getList" @table2="table2" @getInspectionStandards="getInspectionStandards" :packingLists="packingList"
|
|
|
+ @getCategoryInfo="getCategoryInfo" @changeProductNumberModel="changeProductNumberModel"
|
|
|
+ @changesStokledgerNumberModal="changesStokledgerNumberModal" @getQualityTemplate="getQualityTemplate"></base-info>
|
|
|
<el-row>
|
|
|
<header-title title="质检内容"></header-title>
|
|
|
|
|
|
@@ -30,7 +31,7 @@
|
|
|
<el-col :span="6" v-if="conditionType == 2">
|
|
|
<el-form-item prop="number" label-width="0" style="margin-bottom: 0;">
|
|
|
<el-input v-model="formData.number" placeholder="请输入" size="mini"
|
|
|
- @change="handleInputNumber"></el-input>
|
|
|
+ ></el-input>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
<el-col :span="6" v-if="conditionType == 2">
|
|
|
@@ -42,22 +43,22 @@
|
|
|
</el-col>
|
|
|
<el-col :span="8" v-if="conditionType == 2">
|
|
|
<el-form-item prop="portion" label="数量" style="margin: 0;">
|
|
|
- <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"
|
|
|
+ <el-input v-model="formData.portion" placeholder="请输入" size="mini"
|
|
|
clearable></el-input>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="24" v-if="conditionType == 1 && !isCheck">
|
|
|
+ <el-col :span="24" v-if="conditionType == 1">
|
|
|
<el-form-item prop="portion" label="数量" style="margin: 0;">
|
|
|
- <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"
|
|
|
+ <el-input v-model="formData.portion" placeholder="请输入" size="mini"
|
|
|
clearable></el-input>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="4" style="text-align: right;" v-if="conditionType == 1 && !isCheck">
|
|
|
- <el-button type="primary" size="mini" @click="handleSampleSubmit"
|
|
|
+ <el-col :span="4" style="text-align: right;" v-if="conditionType == 1">
|
|
|
+ <el-button type="primary" size="mini" @click="handleExtractFull"
|
|
|
style="margin-right: 12px;">确认</el-button>
|
|
|
</el-col>
|
|
|
<el-col :span="4" style="text-align: right;" v-if="conditionType == 2">
|
|
|
- <el-button type="primary" size="mini" @click="handleSampleSubmit"
|
|
|
+ <el-button type="primary" size="mini" @click="handleExtractFull"
|
|
|
style="margin-right: 12px;">确认</el-button>
|
|
|
</el-col>
|
|
|
</el-form>
|
|
|
@@ -279,11 +280,12 @@ export default {
|
|
|
]
|
|
|
|
|
|
},
|
|
|
- isConsumable: '',
|
|
|
+ isConsumable: '',//0 单件 1批量
|
|
|
netWeight: '',// 净重
|
|
|
conditionType: null,
|
|
|
|
|
|
- sampleListCode: ''
|
|
|
+ sampleListCode: '',
|
|
|
+ productItem: {}, //产品信息
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -384,6 +386,58 @@ export default {
|
|
|
},
|
|
|
created() { },
|
|
|
methods: {
|
|
|
+ //成品检验类型,计划来源主数据,修改数量生成来源清单
|
|
|
+ changeProductNumberModel(num) {
|
|
|
+ this.$refs.table12.setData([])
|
|
|
+ let nums = Number(num)
|
|
|
+ let p = this.productItem
|
|
|
+ console.log(p, 'productItem')
|
|
|
+ let list = []
|
|
|
+ if (this.isConsumable == 0) {
|
|
|
+ for (let i = 0; i < nums; i++) {
|
|
|
+ let obj = {
|
|
|
+ id:p.id,
|
|
|
+ categoryCode: p.code, //编码
|
|
|
+ categoryName: p.name, //名称
|
|
|
+ measureQuantity: 1, //计量数量
|
|
|
+ measureUnit: p.measuringUnit, //计量单位
|
|
|
+ weightUnit: p.weightUnit, //重量单位
|
|
|
+ weight:p.netWeight, //重量
|
|
|
+ }
|
|
|
+ list.push(obj)
|
|
|
+ }
|
|
|
+ } else if (this.isConsumable == 1) {
|
|
|
+ let obj = {
|
|
|
+ id:p.id,
|
|
|
+ categoryCode: p.code, //编码
|
|
|
+ categoryName: p.name, //名称
|
|
|
+ measureQuantity: nums, //计量数量
|
|
|
+ measureUnit: p.measuringUnit, //计量单位
|
|
|
+ weightUnit: p.weightUnit, //重量单位
|
|
|
+ weight: p.netWeight * nums, //重量
|
|
|
+ }
|
|
|
+ list.push(obj)
|
|
|
+ }
|
|
|
+ this.$refs.table12.setData(list)
|
|
|
+ },
|
|
|
+
|
|
|
+ //成品类型检验类型,计划来源库存台账, 生成来源清单
|
|
|
+ changesStokledgerNumberModal(val, dimension) {
|
|
|
+ this.$refs.table12.setData([])
|
|
|
+ if (dimension == 3) return this.$refs.table12.setData(val)
|
|
|
+ let num = Number(val[0].outboundNum)
|
|
|
+ let list = []
|
|
|
+ for (let i = 0; i < num; i++) {
|
|
|
+ list.push({...val[0], id: i + 1, packingQuantity:null, measureQuantity: 1 });
|
|
|
+ }
|
|
|
+ this.$refs.table12.setData(list)
|
|
|
+ },
|
|
|
+
|
|
|
+ //获取基本信息中计量方式
|
|
|
+ getInspectionStandards(data) {
|
|
|
+ this.baseForm.inspectionStandards = data;
|
|
|
+ this.handleSampleList()
|
|
|
+ },
|
|
|
async datasource({ page, limit, where }) {
|
|
|
const res = await getInventoryListByPlanId({ ...where, page, limit });
|
|
|
// if (res.list.length > 1) {
|
|
|
@@ -418,7 +472,7 @@ export default {
|
|
|
},
|
|
|
async inspectionTemplateSuccess(select){
|
|
|
let data= await getQualityTemplateByIds({templateIds:select.map(item=>item.id)})
|
|
|
- this.schemeList.push(...data)
|
|
|
+ this.schemeList.push(...data)
|
|
|
},
|
|
|
async handleEditOrDetail(row) {
|
|
|
console.log('row====', row);
|
|
|
@@ -493,6 +547,7 @@ export default {
|
|
|
this.schemePagination.total = this.schemeList.length;
|
|
|
},
|
|
|
async getList(receiveNo, productCode, productCategoryId, productCategoryName, categoryid, batchNo, supplierName, supplierMark) {
|
|
|
+
|
|
|
//通过来源和产品 获取来料清单
|
|
|
await this.getGoodsList(receiveNo, productCode, null, productCategoryId, productCategoryName, categoryid, batchNo, supplierName, supplierMark);
|
|
|
|
|
|
@@ -569,8 +624,8 @@ export default {
|
|
|
},
|
|
|
async handleSampleList() {
|
|
|
let packingList = this.$refs.table12.getData();
|
|
|
- //全检时
|
|
|
- if (this.baseForm.qualityMode == 1) {
|
|
|
+ //全检时 计量时
|
|
|
+ if (this.baseForm.qualityMode == 1 && this.baseForm.inspectionStandards == 1) {
|
|
|
this.sampleList = [];
|
|
|
console.log(this.baseForm, '---isUnpack---')
|
|
|
await this.handleUnpackCase(packingList);
|
|
|
@@ -589,10 +644,21 @@ export default {
|
|
|
// await this.updatePackingList(packingList);
|
|
|
// }
|
|
|
// }
|
|
|
+ //全检 计重时
|
|
|
+ } else if (this.baseForm.qualityMode == 1 && this.baseForm.inspectionStandards == 2) {
|
|
|
+ this.sampleList = [];
|
|
|
+ this.getFullInspectionWeight(packingList);
|
|
|
} else {
|
|
|
this.sampleList = [];
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
+ //全检 计重时生成样品清单
|
|
|
+ async getFullInspectionWeight(packingList) {
|
|
|
+ this.updatePackingList(packingList);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
//拆包处理样品清单数据
|
|
|
async handleUnpackCase(packingList) {
|
|
|
const num = Number(this.baseForm.productNumber || 0);
|
|
|
@@ -604,6 +670,8 @@ export default {
|
|
|
async getSampleCode() {
|
|
|
return await getCode('sample_code');
|
|
|
},
|
|
|
+
|
|
|
+ //更新样品清单数据
|
|
|
async updatePackingList(list) {
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
list[i].sampleCode = await this.getSampleCode();
|
|
|
@@ -613,6 +681,8 @@ export default {
|
|
|
this.samplePagination.currentPage = 1;
|
|
|
this.samplePagination.total = list.length;
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
async getUnpackSamList(list, num) {
|
|
|
console.log('拆包getUnpackSamList')
|
|
|
let data = [];
|
|
|
@@ -648,13 +718,11 @@ export default {
|
|
|
|
|
|
},
|
|
|
async getQualityTemplate(productCode, ids) {
|
|
|
-
|
|
|
await getQualityTemplateList({
|
|
|
productCode: productCode,
|
|
|
qualityQlanId: ids,
|
|
|
}).then((res) => {
|
|
|
if (Object.keys(res).length === 0) {
|
|
|
- this.$message.error('请确认该物品是否配置质检方案!');
|
|
|
return;
|
|
|
}
|
|
|
this.baseForm.sampleProportion = res.checkProportion;
|
|
|
@@ -703,6 +771,7 @@ export default {
|
|
|
this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
|
|
|
} else if (this.conditionType == 1) {
|
|
|
this.baseForm.sampleNumber = this.formData.portion;
|
|
|
+ this.formData.number = 0;
|
|
|
}
|
|
|
},
|
|
|
//取样方式选择
|
|
|
@@ -711,63 +780,61 @@ export default {
|
|
|
this.conditionType = val;
|
|
|
//清空样品清单列表
|
|
|
this.sampleList = []
|
|
|
- const dataS = this.$refs.table12.getData();
|
|
|
+ // const dataS = this.$refs.table12.getData();
|
|
|
//取整样
|
|
|
- if (val == 1) {
|
|
|
- if (this.selectedList.length == 0) {
|
|
|
- this.$message.warning('请先选择样品!');
|
|
|
- } else {
|
|
|
- if (this.isCheck) {
|
|
|
- for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
- for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
|
|
|
- // this.selectedList[i].sampleCode = await this.getSampleCode();
|
|
|
- this.sampleList.push({
|
|
|
- ...this.selectedList[i],
|
|
|
- sampleCode: await this.getSampleCode(),
|
|
|
- measureQuantity: 1,
|
|
|
- weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
- let forNum = 0;
|
|
|
- if (this.formData.portion != null && this.formData.portion != '') {
|
|
|
- forNum = this.formData.portion;
|
|
|
- } else {
|
|
|
- forNum = this.selectedList[i].measureQuantity;
|
|
|
- }
|
|
|
- for (let j = 0; j < forNum; j++) {
|
|
|
- // this.selectedList[i].sampleCode = await this.getSampleCode();
|
|
|
- this.sampleList.push({
|
|
|
- ...this.selectedList[i],
|
|
|
- sampleCode: await this.getSampleCode(),
|
|
|
- measureQuantity: 1,
|
|
|
- weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ // if (val == 1) {
|
|
|
+ // if (this.selectedList.length == 0) {
|
|
|
+ // this.$message.warning('请先选择样品!');
|
|
|
+ // } else {
|
|
|
+ // if (this.isCheck) {
|
|
|
+ // for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
+ // for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
|
|
|
+ // // this.selectedList[i].sampleCode = await this.getSampleCode();
|
|
|
+ // this.sampleList.push({
|
|
|
+ // ...this.selectedList[i],
|
|
|
+ // sampleCode: await this.getSampleCode(),
|
|
|
+ // measureQuantity: 1,
|
|
|
+ // weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
+ // let forNum = 0;
|
|
|
+ // if (this.formData.portion != null && this.formData.portion != '') {
|
|
|
+ // forNum = this.formData.portion;
|
|
|
+ // } else {
|
|
|
+ // forNum = this.selectedList[i].measureQuantity;
|
|
|
+ // }
|
|
|
+ // for (let j = 0; j < forNum; j++) {
|
|
|
+ // // this.selectedList[i].sampleCode = await this.getSampleCode();
|
|
|
+ // this.sampleList.push({
|
|
|
+ // ...this.selectedList[i],
|
|
|
+ // sampleCode: await this.getSampleCode(),
|
|
|
+ // measureQuantity: 1,
|
|
|
+ // weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
- // this.sampleList = this.selectedList;
|
|
|
- this.formData.portion = this.sampleList.length;
|
|
|
- this.activeName = '2';
|
|
|
- this.$message.success('取样成功!');
|
|
|
- }
|
|
|
- } else if (val == 2) {
|
|
|
- this.formData.sampleUnit = dataS[0].measureUnit;
|
|
|
+ // }
|
|
|
+ // this.formData.portion = this.sampleList.length;
|
|
|
+ // this.activeName = '2';
|
|
|
+ // this.$message.success('取样成功!');
|
|
|
+ // }
|
|
|
+ // } else if (val == 2) {
|
|
|
+ // this.formData.sampleUnit = dataS[0].measureUnit;
|
|
|
|
|
|
- // this.$refs.table12.clearSelection();
|
|
|
- //小样
|
|
|
- if (this.selectedList.length == 0) {
|
|
|
- this.$message.warning('请先选择样品!');
|
|
|
- } else {
|
|
|
- if (this.formData.number == null || this.formData.sampleUnit == '') {
|
|
|
- this.$message.warning('请先选择取样的数量和单位!');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // this.$refs.table12.clearSelection();
|
|
|
+ // //小样
|
|
|
+ // if (this.selectedList.length == 0) {
|
|
|
+ // this.$message.warning('请先选择样品!');
|
|
|
+ // } else {
|
|
|
+ // if (this.formData.number == null || this.formData.sampleUnit == '') {
|
|
|
+ // this.$message.warning('请先选择取样的数量和单位!');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
},
|
|
|
|
|
|
handleInputNumber(val) {
|
|
|
@@ -781,6 +848,8 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
+ // 整样输入框事件
|
|
|
handleInput(val) {
|
|
|
if (val == 0 || val == '' || val == null) {
|
|
|
this.$refs.table12.clearSelection();
|
|
|
@@ -832,13 +901,159 @@ export default {
|
|
|
},
|
|
|
getCategoryInfo(val) {
|
|
|
// this.baseForm.isUnpack = val.categoryWms.isUnpack;
|
|
|
-
|
|
|
+ console.log(val, '产品信息')
|
|
|
this.isConsumable = val.category.isConsumable;
|
|
|
this.netWeight = val.category.netWeight;
|
|
|
+ this.productItem = val.category; //产品信息
|
|
|
},
|
|
|
changeSamUnit(val) {
|
|
|
this.$refs.baseInfoRefs.getsampleMeasureUnit(val);
|
|
|
},
|
|
|
+
|
|
|
+ //整样确认按钮-样品列表右上角确认按钮
|
|
|
+ // handleExtractFull() {
|
|
|
+ // this.$refs.ruleForm.validate((valid) => {
|
|
|
+ // if (valid) {
|
|
|
+ // if (!this.selectedList || this.selectedList.length == 0) {
|
|
|
+ // this.$message.warning('请先选择样品!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // this.sampleList = []
|
|
|
+ // //取样条数
|
|
|
+ // let safePortion = Number(this.formData.portion);
|
|
|
+ // //计量数量
|
|
|
+ // let measureQ = this.formData.number || 1;
|
|
|
+ // //计量单位
|
|
|
+ // let unit = this.formData.sampleUnit;
|
|
|
+ // //抽检计量整样小样或者抽检计重小样
|
|
|
+ // if ((this.baseForm.inspectionStandards === 1) || (this.baseForm.inspectionStandards === 2 && this.conditionType == 2)) {
|
|
|
+ // if (this.conditionType == 2) {
|
|
|
+ // if (measureQ <= 0) {
|
|
|
+ // this.$message.info('取样计量数量必须大于0');
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // 计算总计量数量
|
|
|
+ // const totalQuantity = this.selectedList.reduce((sum, item) => sum + item['measureQuantity'], 0);
|
|
|
+ // // 验证取样总量不超过总计量数量,只有计量单位相同才进行验证
|
|
|
+ // if (this.selectedList[0].measureUnit == unit || this.conditionType == 1) {
|
|
|
+ // if (measureQ * safePortion > totalQuantity) {
|
|
|
+ // this.$message.info('取样计量数量不能大于总计量数量');
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // // 验证每条数据的计量数量都大于等于取样计量数量
|
|
|
+ // for (const item of this.selectedList) {
|
|
|
+ // if (item['measureQuantity'] < measureQ) {
|
|
|
+ // this.$message.info(`条目计量数量小于取样计量数量`);
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (unit === 'KG') {
|
|
|
+ // let totalMaxPossible = 0;
|
|
|
+ // this.selectedList.map(item => {
|
|
|
+ // const maxPossible = item['measureQuantity'] / measureQ;
|
|
|
+ // totalMaxPossible += maxPossible;});
|
|
|
+ // if (totalMaxPossible < safePortion) {
|
|
|
+ // this.formData.portion = totalMaxPossible;
|
|
|
+ // return this.$message.info(`最大取样条数为${totalMaxPossible}`);
|
|
|
+ // }
|
|
|
+ // // 计算总重量
|
|
|
+ // let totalWeight = this.selectedList.reduce((sum, item) => sum + item['weight'], 0);
|
|
|
+ // let weightUnit = this.selectedList[0].weightUnit;
|
|
|
+ // if (weightUnit === 'G') {
|
|
|
+ // totalWeight = totalWeight / 1000
|
|
|
+ // }
|
|
|
+ // if (measureQ * safePortion > totalWeight) {
|
|
|
+ // this.$message.info('取样计量重量不能大于总计量重量');
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // for (const item of this.selectedList) {
|
|
|
+ // let weight = weightUnit === 'G' ? item.weight / 1000 : item.weight
|
|
|
+ // if (weight < measureQ) {
|
|
|
+ // this.$message.info(`勾选条目重量小于取样重量`);
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // this.getNewFullSampleList(Math.ceil(safePortion), measureQ, unit);
|
|
|
+ // //抽检计重整样
|
|
|
+ // } else if (this.baseForm.inspectionStandards === 2 && this.conditionType == 1) {
|
|
|
+ // for (const item of this.selectedList) {
|
|
|
+ // if (item['measureQuantity'] < safePortion) {
|
|
|
+ // this.$message.info(`所选的条目计量数量小于取样计量数量`);
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // let list = [];
|
|
|
+ // for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
+ // list.push({
|
|
|
+ // ...this.selectedList[i],
|
|
|
+ // measureQuantity: safePortion, //作为计量数量
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // this.updatePackingList(list);
|
|
|
+ // }
|
|
|
+ // this.activeName = '2'
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ //从来源数组取样到目标数组
|
|
|
+ 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 && remainingCount > 0 ) || item.remainingQuantity >= sampleQuantity && remainingCount > 0) {
|
|
|
+ // 添加到结果数组
|
|
|
+ let sampleCode = await this.getSampleCode()
|
|
|
+ if (this.conditionType == 1 && this.baseForm.inspectionStandards == 1) {
|
|
|
+ result.push({ ...item,measureQuantity: 1, sampleCode});
|
|
|
+ } else if (this.conditionType == 2 && (this.baseForm.inspectionStandards == 1 || this.baseForm.inspectionStandards == 2)) {
|
|
|
+ let weight = (item.weight / item.maxPossible).toFixed(2);
|
|
|
+ result.push({ ...item, measureQuantity: sampleQuantity, measureUnit: sampleUnit, sampleCode, weight})
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新剩余数量
|
|
|
+ if (!isUnitMismatch) {
|
|
|
+ item.remainingQuantity -= sampleQuantity;
|
|
|
+ }
|
|
|
+ remainingCount--;
|
|
|
+ distributed = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有分配任何取样
|
|
|
+ if (!distributed) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.sampleList = result;
|
|
|
+ this.baseForm.sampleNumber = this.sampleList.length;
|
|
|
+ this.changeSamUnit(sampleUnit)
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
//抽样确认按钮事件-样品列表右上角确认按钮
|
|
|
handleSampleSubmit() {
|
|
|
this.$refs.ruleForm.validate((valid) => {
|
|
|
@@ -848,9 +1063,9 @@ export default {
|
|
|
let measureQ = this.formData.number;
|
|
|
let unit = this.formData.sampleUnit;
|
|
|
let nums = Number(this.formData.portion);
|
|
|
-
|
|
|
+
|
|
|
console.log(measureQ, unit, nums, 'measureQ, unit, nums')
|
|
|
- this.getNewSampleList(measureQ, unit, nums)
|
|
|
+ this.getNewFullSampleList(nums,measureQ, unit)
|
|
|
// if (this.conditionType == 1) {
|
|
|
// this.sampleList = this.selectedList
|
|
|
// } else {
|
|
|
@@ -865,51 +1080,46 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
//更新计量数量、单位后重新生成样品列表数据
|
|
|
- async getNewSampleList(measureQ, unit, nums) {
|
|
|
- this.sampleList = [];
|
|
|
- if (!this.selectedList || this.selectedList.length == 0) {
|
|
|
- this.$message.warning('请先选择样品!');
|
|
|
- return;
|
|
|
- }
|
|
|
+ // async getNewSampleList(measureQ, unit, nums) {
|
|
|
+ // this.sampleList = [];
|
|
|
+ // if (!this.selectedList || this.selectedList.length == 0) {
|
|
|
+ // this.$message.warning('请先选择样品!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
|
|
|
- if (!this.isCheck) {
|
|
|
- let measureQuantity = 1;
|
|
|
- if (this.conditionType == 2) {
|
|
|
- measureQuantity = this.formData.number;
|
|
|
- }
|
|
|
- for (let i = 0; i < nums; i++) {
|
|
|
- this.sampleList.push({
|
|
|
- ...this.selectedList[0],
|
|
|
- sampleCode: await this.getSampleCode(),
|
|
|
- measureQuantity: measureQuantity,
|
|
|
- measureUnit: unit,
|
|
|
- weight: this.netWeight || 0
|
|
|
- });
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (this.conditionType == 1) {
|
|
|
- measureQ = 1;
|
|
|
- }
|
|
|
- for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
- this.sampleList.push({
|
|
|
- ...this.selectedList[i],
|
|
|
- sampleCode: await this.getSampleCode(),
|
|
|
- measureQuantity: measureQ,
|
|
|
- measureUnit: unit,
|
|
|
- weight: this.netWeight || 0
|
|
|
- });
|
|
|
- }
|
|
|
+ // if (!this.isCheck) {
|
|
|
+ // let measureQuantity = 1;
|
|
|
+ // if (this.conditionType == 2) {
|
|
|
+ // measureQuantity = this.formData.number;
|
|
|
+ // }
|
|
|
+ // for (let i = 0; i < nums; i++) {
|
|
|
+ // this.sampleList.push({
|
|
|
+ // ...this.selectedList[0],
|
|
|
+ // sampleCode: await this.getSampleCode(),
|
|
|
+ // measureQuantity: measureQuantity,
|
|
|
+ // measureUnit: unit,
|
|
|
+ // weight: this.netWeight || 0
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // if (this.conditionType == 1) {
|
|
|
+ // measureQ = 1;
|
|
|
+ // }
|
|
|
+ // for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
+ // this.sampleList.push({
|
|
|
+ // ...this.selectedList[i],
|
|
|
+ // sampleCode: await this.getSampleCode(),
|
|
|
+ // measureQuantity: measureQ,
|
|
|
+ // measureUnit: unit,
|
|
|
+ // weight: this.netWeight || 0
|
|
|
+ // });
|
|
|
+ // }
|
|
|
|
|
|
- }
|
|
|
- // this.sampleList = this.selectedList.map(async oldItem => {
|
|
|
- // const newItem = JSON.parse(JSON.stringify(oldItem));
|
|
|
- // newItem.sampleCode = await this.getSampleCode();
|
|
|
- // newItem.measureQuantity = measureQ;
|
|
|
- // newItem.measureUnit = unit;
|
|
|
- // return newItem;
|
|
|
- // });
|
|
|
- },
|
|
|
+ // }
|
|
|
+ // },
|
|
|
//监听类型变化
|
|
|
resetTable() {
|
|
|
this.$nextTick(() => {
|
|
|
@@ -1046,7 +1256,124 @@ export default {
|
|
|
} else {
|
|
|
this.sampleList = [];
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ //确定按钮
|
|
|
+ handleExtractFull() {
|
|
|
+ this.$refs.ruleForm.validate(async (valid) => {
|
|
|
+ if (!valid || !this.validateSelection()) return;
|
|
|
+
|
|
|
+ this.sampleList = [];
|
|
|
+ const sampleCount = Number(this.formData.portion);
|
|
|
+ const measureQ = this.formData.number || 1;
|
|
|
+ const unit = this.formData.sampleUnit;
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (this.isStandard1OrWeightSample()) {//抽检计量整样小样或者抽检计重小样
|
|
|
+ if (!this.validateMeasureQuantity(measureQ, unit, sampleCount)) return;
|
|
|
+ if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount)) return; // 若计量单位为重量,还需验证总重量是否足够
|
|
|
+
|
|
|
+ await this.getNewFullSampleList(Math.ceil(sampleCount), measureQ, unit);
|
|
|
+ } else if (this.isWeightStandardFullSample()) { //抽检取计重取整样
|
|
|
+ if (!this.validateSampleCount(sampleCount)) return;
|
|
|
+ await this.handleWeightFullSample(sampleCount);
|
|
|
+ }
|
|
|
+ this.activeName = '2';
|
|
|
+ } catch (error) {
|
|
|
+ console.error('取样处理失败:', error);
|
|
|
+ this.$message.error('取样处理失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
+ validateSelection() {
|
|
|
+ if (!this.selectedList?.length) {
|
|
|
+ this.$message.warning('请先选择样品!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
+ isStandard1OrWeightSample() {
|
|
|
+ return (this.baseForm.inspectionStandards === 1) ||
|
|
|
+ (this.baseForm.inspectionStandards === 2 && this.conditionType == 2);
|
|
|
+ },
|
|
|
+
|
|
|
+ isWeightStandardFullSample() {
|
|
|
+ return this.baseForm.inspectionStandards === 2 && this.conditionType == 1;
|
|
|
+ },
|
|
|
+
|
|
|
+ validateMeasureQuantity(measureQ, unit, sampleCount) {
|
|
|
+ if (this.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.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;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ validateSampleCount(sampleCount) {
|
|
|
+ const invalidItem = this.selectedList.find(item => item.measureQuantity < sampleCount);
|
|
|
+ if (invalidItem) {
|
|
|
+ this.$message.info('所选的条目计量数量小于取样计量数量');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
+ async handleWeightFullSample(sampleCount) {
|
|
|
+ const list = this.selectedList.map(item => ({
|
|
|
+ ...item,
|
|
|
+ measureQuantity: sampleCount
|
|
|
+ }));
|
|
|
+ await this.updatePackingList(list);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
</script>
|