修改猪栏卡片和猪舍时列表不折叠
This commit is contained in:
@@ -49,7 +49,7 @@ export default {
|
||||
},
|
||||
penData: {
|
||||
type: Object,
|
||||
default: () => ({}) // 改为非必需,并提供默认值
|
||||
required: true
|
||||
},
|
||||
isEdit: {
|
||||
type: Boolean,
|
||||
@@ -90,6 +90,9 @@ export default {
|
||||
const handleClose = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
nextTick(() => {
|
||||
formRef.value?.resetFields();
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
@@ -98,14 +101,15 @@ export default {
|
||||
if (valid) {
|
||||
loading.value = true;
|
||||
try {
|
||||
let response;
|
||||
if (props.isEdit) {
|
||||
const { id, ...updateData } = formData;
|
||||
await updatePen(id, updateData);
|
||||
response = await updatePen(id, updateData);
|
||||
} else {
|
||||
const { id, status, ...createData } = formData;
|
||||
await createPen(createData);
|
||||
response = await createPen(createData);
|
||||
}
|
||||
emit('success');
|
||||
emit('success', response.data);
|
||||
handleClose();
|
||||
} catch (error) {
|
||||
ElMessage.error((props.isEdit ? '更新' : '创建') + '猪栏失败: ' + (error.message || '未知错误'));
|
||||
@@ -118,23 +122,15 @@ export default {
|
||||
|
||||
watch(() => props.visible, (newVal) => {
|
||||
if (newVal) {
|
||||
// 重置表单以适应新数据
|
||||
Object.assign(formData, initialFormData());
|
||||
if (props.isEdit && props.penData) {
|
||||
// 编辑模式:填充数据
|
||||
Object.assign(formData, props.penData);
|
||||
} else if (props.penData) {
|
||||
// 添加模式:只设置 house_id
|
||||
formData.house_id = props.penData.house_id;
|
||||
}
|
||||
nextTick(() => {
|
||||
formRef.value?.clearValidate();
|
||||
});
|
||||
} else {
|
||||
// 对话框关闭时重置表单
|
||||
nextTick(() => {
|
||||
formRef.value?.resetFields();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -88,12 +88,13 @@ export default {
|
||||
loading.value = true;
|
||||
try {
|
||||
const submitData = { name: formData.name, description: formData.description };
|
||||
let response;
|
||||
if (props.isEdit) {
|
||||
await updatePigHouse(formData.id, submitData);
|
||||
response = await updatePigHouse(formData.id, submitData);
|
||||
} else {
|
||||
await createPigHouse(submitData);
|
||||
response = await createPigHouse(submitData);
|
||||
}
|
||||
emit('success');
|
||||
emit('success', response.data);
|
||||
handleClose();
|
||||
} catch (error) {
|
||||
ElMessage.error((props.isEdit ? '更新' : '创建') + '猪舍失败: ' + (error.message || '未知错误'));
|
||||
|
||||
Reference in New Issue
Block a user