|
|
@@ -23,30 +23,38 @@
|
|
|
</el-dropdown-menu>
|
|
|
</el-dropdown>
|
|
|
</template>
|
|
|
- <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2 && conditionType == 2">
|
|
|
+ <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2 ">
|
|
|
<el-row>
|
|
|
<el-form ref="ruleForm" :model="formData" label-width="60px" size="mini" :rules="rules" class="flex"
|
|
|
:show-message="false">
|
|
|
- <el-col :span="6">
|
|
|
+ <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-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="6">
|
|
|
+ <el-col :span="6" v-if="conditionType == 2">
|
|
|
<el-form-item prop="sampleUnit" label-width="0" style="margin: 0;">
|
|
|
<DictSelection dictName="计量单位" clearable v-model="formData.sampleUnit" size="mini"
|
|
|
@change="changeSamUnit">
|
|
|
</DictSelection>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="8">
|
|
|
+ <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"
|
|
|
- :disabled="conditionType == 1"></el-input>
|
|
|
+ <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput" clearable></el-input>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="4" style="text-align: right;">
|
|
|
+ <el-col :span="24" v-if="conditionType == 1 && !isCheck ">
|
|
|
+ <el-form-item prop="portion" label="数量" style="margin: 0;">
|
|
|
+ <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput" 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"
|
|
|
+ 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"
|
|
|
style="margin-right: 12px;">确认</el-button>
|
|
|
</el-col>
|
|
|
@@ -232,7 +240,7 @@ export default {
|
|
|
|
|
|
activeName: '1',
|
|
|
selectedList: [],
|
|
|
- isCheck: false,
|
|
|
+ isCheck: false, // 是否拆包 false 不拆包 true 拆包
|
|
|
|
|
|
rowIds: '',
|
|
|
formData: {
|
|
|
@@ -265,6 +273,7 @@ export default {
|
|
|
|
|
|
},
|
|
|
isConsumable: '',
|
|
|
+ netWeight: '',// 净重
|
|
|
conditionType: null,
|
|
|
|
|
|
sampleListCode: ''
|
|
|
@@ -370,11 +379,11 @@ export default {
|
|
|
methods: {
|
|
|
async datasource({ page, limit, where }) {
|
|
|
const res = await getInventoryListByPlanId({ ...where, page, limit });
|
|
|
- if (res.list.length > 1) {
|
|
|
- this.isCheck = true
|
|
|
- } else {
|
|
|
- this.isCheck = false
|
|
|
- }
|
|
|
+ // if (res.list.length > 1) {
|
|
|
+ // this.isCheck = true
|
|
|
+ // } else {
|
|
|
+ // this.isCheck = false
|
|
|
+ // }
|
|
|
this.packingList = res.list;
|
|
|
return res.list;
|
|
|
},
|
|
|
@@ -428,6 +437,11 @@ export default {
|
|
|
// 如果是编辑或者详情,则查询物料清单、质检方案和样品列表
|
|
|
if (row.id) {
|
|
|
this.rowIds = row.id;
|
|
|
+ if (row.isUnpack === 1) {
|
|
|
+ this.isCheck = true
|
|
|
+ } else {
|
|
|
+ this.isCheck = false
|
|
|
+ }
|
|
|
//操作行点击时查询清单
|
|
|
// await this.getInventoryList();
|
|
|
await this.reload({ planId: row.id });
|
|
|
@@ -527,7 +541,6 @@ export default {
|
|
|
this.packingList = _arr1;
|
|
|
this.$refs.table12.setData(_arr1);//赋值
|
|
|
const _arr2 = this.$refs.table12.getData();
|
|
|
-
|
|
|
if (_arr2.length > 1) {
|
|
|
this.baseForm.productNumber = _arr2.length;
|
|
|
} else {
|
|
|
@@ -545,21 +558,22 @@ export default {
|
|
|
if (this.baseForm.qualityMode == 1) {
|
|
|
this.sampleList = [];
|
|
|
console.log(this.baseForm, '---isUnpack---')
|
|
|
- if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
|
|
|
- //拆包
|
|
|
- if (this.baseForm.isUnpack == 1) {
|
|
|
- await this.handleUnpackCase(packingList);
|
|
|
- } else if (this.baseForm.isUnpack == 0) {
|
|
|
- await this.updatePackingList(packingList);
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.log(this.isCheck, 'this.isCheck')
|
|
|
- if (!this.isCheck) {
|
|
|
- await this.handleUnpackCase(packingList);
|
|
|
- } else {
|
|
|
- await this.updatePackingList(packingList);
|
|
|
- }
|
|
|
- }
|
|
|
+ await this.handleUnpackCase(packingList);
|
|
|
+ // if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
|
|
|
+ // //拆包
|
|
|
+ // if (this.baseForm.isUnpack == 1) {
|
|
|
+ // await this.handleUnpackCase(packingList);
|
|
|
+ // } else if (this.baseForm.isUnpack == 0) {
|
|
|
+ // await this.updatePackingList(packingList);
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // console.log(this.isCheck, 'this.isCheck')
|
|
|
+ // if (!this.isCheck) {
|
|
|
+ // await this.handleUnpackCase(packingList);
|
|
|
+ // } else {
|
|
|
+ // await this.updatePackingList(packingList);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
} else {
|
|
|
this.sampleList = [];
|
|
|
}
|
|
|
@@ -591,13 +605,25 @@ export default {
|
|
|
const newMeasureQuantity = oldItem.measureQuantity / this.baseForm.productNumber;
|
|
|
const newWeight = parseFloat((oldItem.weight / this.baseForm.productNumber).toFixed(2))
|
|
|
|
|
|
+ // 将 measureQuantity 转换为数字
|
|
|
+ const measureQuantity = Number(oldItem.measureQuantity);
|
|
|
+ // 判断是否有小数部分
|
|
|
+ const hasDecimal = measureQuantity % 1 !== 0;
|
|
|
+ let roundedQuantity;
|
|
|
+ if (hasDecimal) {
|
|
|
+ // 有小数部分,向上取整
|
|
|
+ roundedQuantity = Math.ceil(measureQuantity);
|
|
|
+ } else {
|
|
|
+ roundedQuantity = measureQuantity;
|
|
|
+ }
|
|
|
+
|
|
|
delete oldItem.id;
|
|
|
|
|
|
- for (let i = 0; i < num; i++) {
|
|
|
+ for (let i = 0; i < roundedQuantity; i++) {
|
|
|
data.push({
|
|
|
...oldItem,
|
|
|
- measureQuantity: newMeasureQuantity,
|
|
|
- weight: newWeight
|
|
|
+ measureQuantity: 1,
|
|
|
+ weight: this.netWeight || 0
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
@@ -649,13 +675,19 @@ export default {
|
|
|
handleSelectionChange(selection) {
|
|
|
console.log(selection, '勾选')
|
|
|
this.selectedList = selection;
|
|
|
- this.formData.portion = selection.length;
|
|
|
- this.baseForm.sampleNumber = selection.length;
|
|
|
//如果取小样
|
|
|
if (this.conditionType == 2) {
|
|
|
+ if (this.isCheck){
|
|
|
+ this.formData.portion = selection.length;
|
|
|
+ this.baseForm.sampleNumber = selection.length;
|
|
|
+ }else{
|
|
|
+ this.baseForm.sampleNumber = this.formData.portion;
|
|
|
+ }
|
|
|
const data1 = this.$refs.table12.getData()
|
|
|
this.$set(this.formData, 'sampleUnit', data1[0]?.measureUnit);
|
|
|
this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
|
|
|
+ }else if (this.conditionType == 1){
|
|
|
+ this.baseForm.sampleNumber = this.formData.portion;
|
|
|
}
|
|
|
},
|
|
|
//取样方式选择
|
|
|
@@ -670,18 +702,48 @@ export default {
|
|
|
if (this.selectedList.length == 0) {
|
|
|
this.$message.warning('请先选择样品!');
|
|
|
} else {
|
|
|
- for (let i = 0; i < this.selectedList.length; i++) {
|
|
|
- this.selectedList[i].sampleCode = await this.getSampleCode();
|
|
|
+ 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.selectedList.length;
|
|
|
+
|
|
|
+ // 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.$refs.table12.clearSelection();
|
|
|
+ // this.$refs.table12.clearSelection();
|
|
|
//小样
|
|
|
if (this.selectedList.length == 0) {
|
|
|
this.$message.warning('请先选择样品!');
|
|
|
@@ -713,30 +775,51 @@ export default {
|
|
|
if (!packingList || packingList.length === 0) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ // 计算 packingList 中 measureQuantity 字段的总和
|
|
|
+ const measureQuantitySum = packingList.reduce((sum, item) => {
|
|
|
+ const quantity = Number(item.measureQuantity) || 0;
|
|
|
+ return sum + quantity;
|
|
|
+ }, 0);
|
|
|
const portion = Number(this.formData.portion);
|
|
|
- if (this.isCheck) {
|
|
|
- if (portion > packingList.length) {
|
|
|
- this.$message.warning('取样数量不能大于来源清单数量!');
|
|
|
- this.formData.portion = packingList.length;
|
|
|
- return;
|
|
|
+ // 清空当前选中
|
|
|
+ this.$refs.table12.clearSelection();
|
|
|
+ if (this.conditionType == 2){ // 取小样
|
|
|
+ // 确保 portion 不超过数据列表长度
|
|
|
+ const safePortion = Math.min(portion, packingList.length);
|
|
|
+ if (this.isCheck) { // 是否拆包 false 不拆包
|
|
|
+ if (portion > packingList.length) {
|
|
|
+ this.$message.warning('取样数量不能大于来源清单数量!');
|
|
|
+ this.formData.portion = packingList.length;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const maxQuantity = Number(packingList[0].measureQuantity);
|
|
|
+ if (portion > maxQuantity) {
|
|
|
+ this.$message.warning('取样数量不能大于计量数量!');
|
|
|
+ this.formData.portion = maxQuantity;
|
|
|
+ }
|
|
|
}
|
|
|
- packingList.slice(0, this.formData.portion).forEach(row => {
|
|
|
- this.$refs.table12.toggleRowSelection(row);
|
|
|
+ // 选中前 safePortion 行
|
|
|
+ packingList.slice(0, safePortion).forEach(row => {
|
|
|
+ this.$refs.table12.toggleRowSelection(row, true);
|
|
|
});
|
|
|
- } else {
|
|
|
- const maxQuantity = Number(packingList[0].measureQuantity);
|
|
|
- if (portion > maxQuantity) {
|
|
|
+ }else if (this.conditionType == 1){
|
|
|
+ // 确保 portion 不超过数据列表长度
|
|
|
+ const safePortion = Math.min(portion, measureQuantitySum);
|
|
|
+ if (portion > measureQuantitySum) {
|
|
|
this.$message.warning('取样数量不能大于计量数量!');
|
|
|
- this.formData.portion = maxQuantity;
|
|
|
- return;
|
|
|
+ this.formData.portion = measureQuantitySum;
|
|
|
}
|
|
|
+ // 选中前 safePortion 行
|
|
|
+ packingList.slice(0, safePortion).forEach(row => {
|
|
|
+ this.$refs.table12.toggleRowSelection(row, true);
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
getCategoryInfo(val) {
|
|
|
// this.baseForm.isUnpack = val.categoryWms.isUnpack;
|
|
|
|
|
|
this.isConsumable = val.category.isConsumable;
|
|
|
+ this.netWeight = val.category.netWeight;
|
|
|
},
|
|
|
changeSamUnit(val) {
|
|
|
this.$refs.baseInfoRefs.getsampleMeasureUnit(val);
|
|
|
@@ -747,35 +830,70 @@ export default {
|
|
|
if (valid) {
|
|
|
this.sampleList = []
|
|
|
this.baseForm.sampleMeasureUnit = this.formData.sampleUnit
|
|
|
+ let measureQ = this.formData.number;
|
|
|
+ let unit = this.formData.sampleUnit;
|
|
|
+ let nums = Number(this.formData.portion);
|
|
|
|
|
|
- if (this.conditionType == 1) {
|
|
|
- this.sampleList = this.selectedList
|
|
|
- } else {
|
|
|
- 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)
|
|
|
- }
|
|
|
+ console.log(measureQ, unit, nums, 'measureQ, unit, nums')
|
|
|
+ this.getNewSampleList(measureQ, unit, nums)
|
|
|
+ // if (this.conditionType == 1) {
|
|
|
+ // this.sampleList = this.selectedList
|
|
|
+ // } else {
|
|
|
+ // 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.activeName = '2'
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
//更新计量数量、单位后重新生成样品列表数据
|
|
|
- getNewSampleList(measureQ, unit, nums) {
|
|
|
+ async getNewSampleList(measureQ, unit, nums) {
|
|
|
this.sampleList = [];
|
|
|
if (!this.selectedList || this.selectedList.length == 0) {
|
|
|
this.$message.warning('请先选择样品!');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.sampleList = this.selectedList.map(oldItem => {
|
|
|
- const newItem = JSON.parse(JSON.stringify(oldItem));
|
|
|
- newItem.measureQuantity = measureQ;
|
|
|
- newItem.measureUnit = unit;
|
|
|
- return newItem;
|
|
|
- });
|
|
|
+ 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() {
|