pyt
9 天以前 6e48606ee4721482f2f754b21f462704fff7ccbc
laboratory/src/views/dataManagement/confirmation-sheet/components/add-test-item.vue
@@ -49,6 +49,10 @@
    dialogVisible: {
      type: Boolean,
      default: false
    },
    editData: {
      type: Object,
      default: () => null
    }
  },
  data() {
@@ -59,7 +63,9 @@
        termType: 1,
        termMethodCode: '',
        termMethod: '',
        sampleRequire: ''
        sampleRequire: '',
        status: 1,
        testId: ''
      },
      rules: {
        termCode: [
@@ -83,17 +89,48 @@
      }
    }
  },
  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: ''
      }
    }
  }
}