| | |
| | | dialogVisible: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | editData: { |
| | | type: Object, |
| | | default: () => null |
| | | } |
| | | }, |
| | | data() { |
| | |
| | | termType: 1, |
| | | termMethodCode: '', |
| | | termMethod: '', |
| | | sampleRequire: '' |
| | | sampleRequire: '', |
| | | status: 1, |
| | | testId: '' |
| | | }, |
| | | rules: { |
| | | termCode: [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | watch: { |
| | | dialogVisible(val) { |
| | | if (val && this.editData) { |
| | | // 编辑模式,回显数据 |
| | | this.$nextTick(() => { |
| | | this.form = { |
| | | ...this.editData, |
| | | termType: Number(this.editData.termType) // 确保termType是数字类型 |
| | | } |
| | | }) |
| | | } else if (!val) { |
| | | // 关闭对话框时重置表单 |
| | | this.resetForm() |
| | | } |
| | | } |
| | | }, |
| | | methods: { |
| | | submitForm() { |
| | | this.$refs.form.validate((valid) => { |
| | | if (valid) { |
| | | this.$emit('confirm', this.form) |
| | | // 提交前确保termType是数字类型 |
| | | const submitData = { |
| | | ...this.form, |
| | | termType: Number(this.form.termType) |
| | | } |
| | | this.$emit('confirm', submitData) |
| | | this.resetForm() |
| | | } |
| | | }) |
| | | }, |
| | | resetForm() { |
| | | this.$refs.form.resetFields() |
| | | this.form = { |
| | | termCode: '', |
| | | termName: '', |
| | | termType: 1, |
| | | termMethodCode: '', |
| | | termMethod: '', |
| | | sampleRequire: '', |
| | | status: 1, |
| | | testId: '' |
| | | } |
| | | } |
| | | } |
| | | } |