<template>
  <el-form
    ref="pdForm"
    v-loading="loading"
    :model="form"
    label-width="120px"
    size="small"
    :rules="rules"
    class="audit-form"
  >
    <div class="base-dialog-body">
      <!-- 是否PD -->
      <el-form-item
        :label="$t('trials:auditRecord:table:isPDConfirm')"
        prop="IsPDConfirm"
      >
        <el-radio-group
          v-model="form.IsPDConfirm"
        >
          <el-radio
            v-for="item of $d.YesOrNo"
            :key="`IsPDConfirm${item.value}`"
            :label="item.value"
          >
            {{ item.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 阅片结果 -->
      <el-form-item
        :label="$t('trials:auditRecord:table:readingResult')"
      >
        <el-button type="text" @click="handleView">{{ $t('common:button:view') }}</el-button>
      </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"
        >
          {{ rowData.IsPDConfirm!==null?$t('trials:pendingReview:button:modify'):$t('trials:pendingReview:button:confirm') }}
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>
<script>
import { pIAuditTaskEnrollOrPD } from '@/api/reading'
export default {
  name: 'PdFrom',
  props: {
    rowData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      form: {
        VisitTaskId: '',
        IsPDConfirm: null
      },
      rules: {
        IsPDConfirm: [
          { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
        ]
      },
      loading: false
    }
  },
  mounted() {
    this.form.VisitTaskId = this.rowData.Id
    this.form.IsPDConfirm = this.rowData.IsPDConfirm
  },
  methods: {
    // 更新qc问题配置信息
    handleSave() {
      this.$refs.pdForm.validate(valid => {
        if (!valid) return
        this.loading = true
        pIAuditTaskEnrollOrPD(this.form).then(res => {
          this.loading = false
          if (res.IsSuccess) {
            // 关闭弹窗并刷新
            this.$emit('close')
            this.$emit('getList')
            this.$message.success(this.$t('common:message:savedSuccessfully'))
          }
        }).catch(() => { this.loading = false })
      })
    },
    handleClose() {
      this.$emit('close')
    },
    handleView() {
      this.$emit('viewReaingResult')
    }
  }
}
</script>
