<template>
  <el-form
    ref="EditRPStatus"
    v-loading="loading"
    :model="form"
    size="small"
    label-width="100px"
  >
    <div class="base-dialog-body">
      <!-- 状态 -->
      <el-form-item :label="$t('trials:rpManage:table:readingStatus')" prop="IsTakeEffect">

        <el-radio-group v-model="form.IsTakeEffect" style="width:100%;">
          <el-radio v-for="item of $d.TakeEffect" :key="item.value" :label="item.value" :disabled="item.value===0">{{ 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="handleSave">
          {{ $t('common:button:save') }}
        </el-button>
      </el-form-item>
    </div>

  </el-form>
</template>
<script>
import { setReadingPeriodSetEffect } from '@/api/trials'
export default {
  name: 'EditRPStatus',
  props: {
    trialReadingCriterionId: {
      type: String,
      default: ''
    },
    data: {
      type: Object,
      default() { return {} }
    }
  },
  data() {
    return {
      loading: false,
      btnLoading: false,
      visitPlanOptions: [],
      form: {
        Id: '',
        IsTakeEffect: null
        // Remark: ''
      }
    }
  },
  mounted() {
    this.initForm()
  },
  methods: {
    async 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.form.TrialId = this.trialId
    },
    handleSave() {
      this.$refs.EditRPStatus.validate(valid => {
        if (!valid) return
        this.btnLoading = true
        this.form.TrialReadingCriterionId = this.trialReadingCriterionId
        setReadingPeriodSetEffect(this.form).then(res => {
          this.btnLoading = false
          this.$emit('getList')
          this.$emit('close')
          this.$message.success(this.$t('common:message:savedSuccessfully'))
        })
          .catch(() => {
            this.btnLoading = false
          })
      })
    },
    close() {
      this.$emit('close')
    }
  }
}
</script>
