<template>
  <el-form
    ref="selectSubjectForm"
    v-loading="btnLoading"
    :model="form"
    size="small"
    :rules="rules"
    label-width="110px"
    :inline="true"
  >
    <div class="base-dialog-body">
      <el-form-item
        :label="$t('trials:trials-panel:form:ParticipateEvaluation')"
        prop="IsJoinEvaluation"
      >
        <el-radio-group v-model="form.IsJoinEvaluation">
          <el-radio v-for="item of $d.YesOrNo" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
    </div>
    <div
      class="base-dialog-footer"
      style="text-align:right;margin-top:10px;"
    >
      <el-form-item>
        <!-- 取消 -->
        <el-button
          :disabled="btnLoading"
          size="small"
          type="primary"
          @click="close"
        >
          {{ $t('common:button:cancel') }}
        </el-button>
        <!-- 保存 -->
        <el-button
          size="small"
          type="primary"
          :loading="btnLoading"
          @click="save"
        >
          {{ $t('common:button:save') }}
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>

<script>
import { batchAddOrUpdateSubjectCriteriaEvaluation } from '@/api/trials/subject'
export default {
  name: 'AddOrUpdateClinicalData',
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      btnLoading: false,
      form: {
        Id: null,
        SubjectId: null,
        TrialReadingCriterionId: null,
        IsJoinEvaluation: null
      },
      rules: {
        IsJoinEvaluation: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: ['blur'] }],
      },
    }
  },
  mounted() {
    this.form = Object.assign(this.form, this.data)
  },
  methods: {
    save() {
      this.$refs['selectSubjectForm'].validate(valid => {
        if (!valid) return
        this.btnLoading = true
        var params = [this.form]
        batchAddOrUpdateSubjectCriteriaEvaluation(params).then(res => {
          this.$emit('getList')
          this.$emit('close')
          this.btnLoading = false
        }).catch(() => {
          this.btnLoading = false
        })
      })

    },
    close() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>

</style>
