<template>

  <el-form
    ref="closeQCForm"
    v-loading="loading"
    :model="form"
    size="small"
    label-width="120px"
  >
    <div class="base-dialog-body">
      <!-- 关闭原因 -->
      <el-form-item
        :label="$t('trials:medicalFeedback:label:closeReasonEnum')"
        prop="MedicalDialogCloseEnum"
        :rules="[
          { required: true, message: $t('common:ruleMessage:select')},
        ]"
      >
        <el-radio-group v-model="form.MedicalDialogCloseEnum">

          <el-radio
            v-for="item of $d.MedicalDialogCloseEnum"
            v-show="item.value!==3"
            :key="item.id"
            :label="item.value"
          >
            {{ item.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 其他原因说明 -->
      <el-form-item
        v-if="form.MedicalDialogCloseEnum === 2"
        :label="$t('trials:medicalFeedback:label:closereasonRemarks')"
        prop="DialogCloseReason"
        :rules="[
          { required: true, message: $t('common:ruleMessage:specify')},
        ]"
      >
        <el-input
          v-model="form.DialogCloseReason"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          :placeholder="$t('common:ruleMessage:specify')"
        />
      </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 size="small" type="primary" @click="handleClose">
          {{ $t('common:button:cancel') }}
        </el-button>
        <el-button size="small" type="primary" @click="handleSave">
          {{ $t('common:button:save') }}
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>
<script>
import { closedMedicalReviewDialog } from '@/api/trials'
export default {
  name: 'CloseQC',
  props: {
    taskMedicalReviewId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      form: {
        MedicalDialogCloseEnum: null,
        DialogCloseReason: ''
      },
      loading: false
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    handleSave() {
      this.$refs['closeQCForm'].validate((valid) => {
        if (!valid) return
        this.loading = true
        this.form.TaskMedicalReviewId = this.taskMedicalReviewId
        this.form.IsClosedDialog = true
        closedMedicalReviewDialog(this.form)
          .then(res => {
            this.loading = false
            if (res.IsSuccess) {
              // 关闭成功!
              this.$message.success(this.$t('trials:qcQuality:message:closedSuccessfully'))
              this.$emit('close')
              this.$emit('refresh')
            }
          }).catch(() => {
            this.loading = false
          })
      })
    }
  }
}
</script>
