/* eslint-disable */
<template>
  <el-form
    ref="taskAllocationRuleDataForm"
    v-loading="loading"
    :model="form"
    size="small"
    :rules="rules"
    label-width="170px"
  >
    <!-- 访视数 -->
    <el-form-item  :label="$t('trials:medicalAuditSetting:label:DefaultQSLang')" prop="LanguageType">
      <el-radio-group
        v-model="form.LanguageType"
      >
        <el-radio :label="0">
          中文
        </el-radio>
        <el-radio :label="1">
          English
        </el-radio>
      </el-radio-group>
    </el-form-item>
    <div v-if="otherInfo.LanguageType === null"></div>
    <div v-else-if="otherInfo.LanguageType === form.LanguageType" style="color:#f66;font-size: 12px;padding-left: 170px;"><span class="el-icon-warning"></span>{{ $t('trials:medicalAuditSetting:tap:message1') }}</div>
    <div v-else style="color:#f66;font-size: 12px;padding-left: 170px;"><span class="el-icon-warning"></span>{{ $t('trials:medicalAuditSetting:tap:message2') }}</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-dialog
      v-if="isSiteCodeHistory"
      :title="$t('trials:consistencyAnalysis:dialog:isSiteCodeHistory')"
      :visible.sync="isSiteCodeHistory"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
      custom-class="base-dialog-wrapper"
    >
      <el-table
        v-loading="loading"
        :data="list"
        stripe
        min-height="300"
      >
        <el-table-column
          show-overflow-tooltip
          width="80"
        >
          <template slot-scope="scope">
            {{scope.$index + 1}}
          </template>
        </el-table-column>
        <el-table-column
          prop="VirtualSiteCode"
          :label="$t('trials:consistencyAnalysis:siteTable:VirtualSiteCode')"
          show-overflow-tooltip
          min-width="120"
        >
        </el-table-column>
        <el-table-column
          prop="Creatime"
          :label="$t('trials:consistencyAnalysis:siteTable:Creatime')"
          show-overflow-tooltip
          sortable="custom"
        >
        </el-table-column>
      </el-table>
    </el-dialog>
  </el-form>
</template>
<script>
import { addDefaultQuestions } from '@/api/trials'

export default {
  name: 'VirtualCenter',
  props: {
    trialReadingCriterionId: {
      type: String,
      default() {
        return ''
      }
    },
    otherInfo: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      form: {
        TrialId: this.$route.query.trialId,
        TrialReadingCriterionId: this.trialReadingCriterionId,
        LanguageType: 0
      },
      rules: {
        LanguageType: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' }],
      },
      loading: false,
      btnLoading: false,
      isSiteCodeHistory: false,
      list: []
    }
  },
  mounted() {
    if (this.otherInfo.LanguageType === null) {
      this.form.LanguageType = this.$i18n.locale === 'zh' ? 0 : 1
    } else {
      this.form.LanguageType = this.otherInfo.LanguageType
    }
  },
  methods: {
    save() {
      this.$refs.taskAllocationRuleDataForm.validate(valid => {
        if (!valid) return
        this.btnLoading = true
        this.loading = true
        addDefaultQuestions(this.form).then(res => {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.btnLoading = false
          this.loading = false
          this.$emit('getList')
          this.$emit('close')
        })
      })
    },
    close() { this.$emit('close') }
  }
}
</script>
<style lang="scss" scoped>
</style>
