/* eslint-disable */
<template>
  <el-form
    ref="taskAllocationRuleDataForm"
    v-loading="loading"
    :model="form"
    size="small"
    :rules="rules"
    label-width="170px"
    @submit.native.prevent
  >
    <div class="base-dialog-body" style="position: relative;padding-top: 20px">
      <!-- 访视数 -->
      <el-form-item :label="$t('trials:consistencyAnalysisRule:table:nowSiteCode')">
        <div style="display:flex;align-items:center;justify-content: space-between;">
          <span>{{ OtherInfo.VitrualSiteCode }}</span>
          <el-button @click="openSiteCodeHistory" type="text">{{$t('trials:consistencyAnalysisRule:table:SiteCodeHistory')}}</el-button>
        </div>
      </el-form-item>
      <!-- 虚拟中心编号 -->
      <el-form-item  :label="$t('trials:consistencyAnalysisRule:table:siteCode')" prop="VirtualSiteCode">
        <el-input v-model="form.VirtualSiteCode" maxlength="10" style="width: 140px;" @input="(v)=>(form.VirtualSiteCode = v.replace(/[^\a-\z\A-\Z0-9]/g, ''))"/>
      </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-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
        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 { updateTrialVirtualSiteCode, getUpdateVirtualSiteCodeList } from '@/api/trials'

export default {
  name: 'VirtualCenter',
  props: {
    OtherInfo: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      form: {
        TrialId: this.$route.query.trialId,
        VirtualSiteCode: '',
      },
      rules: {
        VirtualSiteCode: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' }],
      },
      loading: false,
      btnLoading: false,
      isSiteCodeHistory: false,
      list: []
    }
  },
  mounted() {
  },
  methods: {
    openSiteCodeHistory() {
      this.isSiteCodeHistory = true
      getUpdateVirtualSiteCodeList({
        trialId: this.$route.query.trialId
      }).then(res => {
        this.list = res.Result
      })
    },
    save() {
      this.$refs.taskAllocationRuleDataForm.validate(valid => {
        if (!valid) return
        this.btnLoading = true
        this.loading = true
        updateTrialVirtualSiteCode(this.form).then(res => {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.btnLoading = false
          this.loading = false
          this.$emit('getList')
          this.$emit('close')
        }).catch(() => {
          this.loading = false
          this.btnLoading = false
        })
      })
    },
    close() { this.$emit('close') }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .base-dialog-wrapper .el-dialog__body{
  padding-bottom: 30px;
}
</style>
