diff --git a/src/views/productionManagement/shortageApplication/components/declareAdd.vue b/src/views/productionManagement/shortageApplication/components/declareAdd.vue
index b62e452..3ab3691 100644
--- a/src/views/productionManagement/shortageApplication/components/declareAdd.vue
+++ b/src/views/productionManagement/shortageApplication/components/declareAdd.vue
@@ -148,9 +148,60 @@ export default {
],
// 数组中每一项的
- reworkCode: [{ required: true, message: '请输入', trigger: ['blur', 'submit'] }],
- quantity: [{ required: true, message: '请输入', trigger: ['blur', 'submit'] }],
+ reworkCode: [
+ {
+ validator: (rule, value, callback) => {
+ // 获取当前校验的行索引
+ // rule.field 格式为 "tableData[0].reworkCode"
+ const match = rule.field.match(/tableData\[(\d+)\]/);
+ if (match) {
+ const index = parseInt(match[1]);
+ const row = this.form.tableData[index];
+
+ // 如果该行被选中 (_select 为 true),则必须填写
+ if (row && row._select) {
+ if (!value) {
+ callback(new Error('请输入返工单号'));
+ } else {
+ callback();
+ }
+ } else {
+ // 如果未选中,直接通过
+ callback();
+ }
+ } else {
+ callback();
+ }
+ },
+ trigger: ['blur', 'change'],
+ },
+ ],
+ quantity: [
+ {
+ validator: (rule, value, callback) => {
+ const match = rule.field.match(/tableData\[(\d+)\]/);
+ if (match) {
+ const index = parseInt(match[1]);
+ const row = this.form.tableData[index];
+
+ if (row && row._select) {
+ if (!value) {
+ callback(new Error('请输入数量'));
+ } else {
+ callback();
+ }
+ } else {
+ callback();
+ }
+ } else {
+ callback();
+ }
+ },
+ trigger: ['blur', 'change'],
+ },
+ ],
},
+ selectTableData: [], //选中数据
};
},
mounted() {
@@ -164,10 +215,7 @@ export default {
this.batchLoading = true;
queryBatch({ partCode: this.form.partCode })
.then(res => {
- if (res.data.data) {
- this.form.tableData.push(res.data.data);
- }
- // this.form.tableData = res.data.data || [];
+ this.form.tableData = res.data.data || [];
this.batchLoading = false;
})
.catch(err => {
@@ -181,19 +229,18 @@ export default {
},
selectChange(list, row) {
+ if (list.length > 0) {
+ list.forEach(item => {
+ item.quantity = null;
+ item.woCode = null;
+ item.reworkCode = null;
+ item.remark = null;
+ });
+ }
+ this.selectTableData = list;
row._select = !row._select;
},
- // 新增一行(直接push到表单模型的 tableData 中)
- addTable() {
- this.form.tableData.push({
- _select: false, // 选择状态
- wcId: '', // 作业中心ID
- batchNo: '', // 槽号/检查项
- preserveContent: '', // 维护内容
- });
- },
-
// 删除选中行
delTable() {
this.form.tableData = this.form.tableData.filter(row => !row._select);
@@ -212,48 +259,57 @@ export default {
submitForm() {
this.formError = '';
- // 调用单个 Form 的校验方法
- this.$refs.tableForm.validate((isValid, invalidFields) => {
- if (!isValid) {
- // 校验失败:显示提示并滚动到第一个错误字段
- this.formError = '存在未完善的字段,请检查表格中的红色提示';
+ // 1. 获取选中的行
+ const selectedRows = this.form.tableData.filter(row => row._select);
+
+ // 2. 如果没有选中任何行,提示用户
+ if (selectedRows.length === 0) {
+ this.$message.warning('请至少选择一行数据进行申报');
+ return;
+ }
+ // 3. 调用全量校验
+ // 由于我们在 validator 中已经判断了 row._select,
+ // 所以未选中的行会自动通过校验
+ this.$refs.tableForm.validate(valid => {
+ if (valid) {
+ this.saveLoading = true;
+ let query = []
+ selectedRows.forEach(row => {
+ query.push({
+ useCode: row.useCode,//领用单号
+ woCode: row.woCode,//车间订单号
+ reworkCode: row.reworkCode,//返工单号
+ partCode: row.prtno,//零件号
+ batchNo: row.splcode,//批次号
+ quaLevel: row.prtlotno,//生产标识
+ quantity: row.quantity,//数量
+ remark: row.remark,//备注
+ keeper: row.warctlr,//保管员
+ planMan: row.schemer,//计划员
+ locationNo:row.warlocno,//库位
+ })
+ })
+
+ saveDeclare({orderDeclares:query})
+ .then(res => {
+ this.$message.success('操作成功');
+ this.saveLoading = false;
+ this.closeDialog();
+ })
+ .catch(err => {
+ this.saveLoading = false;
+ });
+ } else {
+ this.formError = '选中数据存在未完善的字段,请检查表格中的红色提示';
this.$nextTick(() => {
- // 找到第一个错误字段并滚动到视图
const firstError = document.querySelector('.el-form-item.is-error');
if (firstError) {
firstError.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
});
- return;
+ return false;
}
- this.saveLoading = true;
-
- // 调用接口提交(实际项目替换)
- saveDeclare(this.form.tableData)
- .then(res => {
- this.$message.success('操作成功');
- this.saveLoading = false;
-
- this.closeDialog();
- })
- .catch(err => {
- this.saveLoading = false;
- });
- // try {
- // const res = saveDeclare(this.form.tableData);
- // if (res.code === 200) {
- // this.$message.success('操作成功');
- // this.closeDialog();
- // this.$emit('submitSuccess', submitData);
- // } else {
- // this.$message.error(res.msg || '操作失败');
- // }
-
- // } catch (err) {
- // this.$message.error(err);
- // console.error('提交失败:', err);
- // }
});
},
},
diff --git a/src/views/productionManagement/shortageApplication/index.vue b/src/views/productionManagement/shortageApplication/index.vue
index fde96a6..f421315 100644
--- a/src/views/productionManagement/shortageApplication/index.vue
+++ b/src/views/productionManagement/shortageApplication/index.vue
@@ -29,7 +29,7 @@
-
+