<template>
  <el-form
    ref="organForm"
    v-loading="loading"
    :model="form"
    label-width="100px"
    size="small"
    :rules="rules"
  >
    <div class="base-dialog-body">
      <el-form-item label="靶病灶" prop="TargetLesion">
        <el-select v-model="form.TargetLesion">
          <el-option
            v-for="item of $d.TargetAssessment"
            :key="item.id"
            :value="item.value"
            :label="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="非靶病灶" prop="NonTargetLesions">
        <el-select v-model="form.NonTargetLesions">
          <el-option
            v-for="item of $d.NoTargetAssessment"
            :key="item.id"
            :value="item.value"
            :label="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="新病灶" prop="NewLesion">
        <el-select v-model="form.NewLesion">
          <el-option
            v-for="item of $d.NewLesionAssessment"
            :key="item.id"
            :value="item.value"
            :label="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="整体疗效" prop="OverallEfficacy">
        <el-select v-model="form.OverallEfficacy">
          <el-option
            v-for="item of $d.OverallAssessment"
            :key="item.id"
            :value="item.value"
            :label="item.label"
          />
        </el-select>
      </el-form-item>
    </div>
    <div class="base-dialog-footer" style="text-align:right;margin-top:10px;">
      <el-form-item style="text-align:right;">
        <el-button type="primary" @click="handleCancel"> {{ $t('common:button:cancel') }}</el-button>
        <!-- Save -->
        <el-button size="small" type="primary" @click="handleSave">
          {{ $t('common:button:save') }}
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>
<script>
import { addOrUpdateTumorAssessment } from '@/api/dictionary'
export default {
  name: 'LesionTypeForm',
  props: {
    data: {
      type: Object,
      default() { return {} }
    }
  },

  data() {
    return {
      targetLesion: ['CR', 'PR', 'SD', 'PD', 'NE', 'ND'],
      nonTargetLesion: ['CR', 'NN', 'PD', 'NE', 'ND'],
      newLesion: ['是', '否', '疑似', 'NE'],
      efficacyArr: ['CR', 'PR', 'SD', 'NN', 'PD', 'NE', 'ND'],
      form: {
        Id: '',
        CriterionId: '',
        TargetLesion: '',
        NonTargetLesions: '',
        NewLesion: '',
        OverallEfficacy: ''
      },
      rules: {
        TargetLesion: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] }],
        NonTargetLesions: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] }],
        NewLesion: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] }],
        OverallEfficacy: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] }]
      },

      loading: false
    }
  },
  mounted() {
    this.initForm()
  },
  methods: {
    // 保存
    handleSave() {
      this.$refs.organForm.validate(valid => {
        if (!valid) return

        this.loading = true
        addOrUpdateTumorAssessment(this.form).then(res => {
          this.loading = false
          this.$emit('close')
          this.$emit('getList')
          if (this.form.Id) {
            this.$message.success(this.$t('common:message:savedSuccessfully'))
          } else {
            this.$message.success(this.$t('common:message:addedSuccessfully'))
          }
        }).catch(() => {
          this.loading = false
        })
      })
    },
    handleCancel() {
      this.$emit('close')
    },
    initForm() {
      if (Object.keys(this.data).length > 0) {
        for (const k in this.form) {
          if (this.data.hasOwnProperty(k)) {
            this.form[k] = this.data[k]
          }
        }
      }
      this.loading = false
    }
  }
}
</script>
