/* eslint-disable */
<template>
  <el-form>
    <div class="base-dialog-body">
      <el-table
        v-loading="loading"
        :data="list"
        stripe
        height="100"
        style="min-height: 400px;"
        @selection-change="handleSelectChange"
      >
        <el-table-column :selectable="selectable" type="selection" align="left" width="45" />
        <!-- 中心编号 -->
        <el-table-column
          prop="TrialSiteCode"
          :label="$t('trials:grouptConsistencyAnalysis:table:siteCode')"
          min-width="100"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 受试者编号 -->
        <el-table-column
          prop="SubjectCode"
          :label="$t('trials:grouptConsistencyAnalysis:table:subjectCode')"
          min-width="120"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 符合规则访视数 -->
        <el-table-column
          prop="ValidVisitCount"
          :label="$t('trials:grouptConsistencyAnalysis:table:validVisitCount')"
          min-width="160"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 是否受到退回影响 -->
        <el-table-column
          prop="IsReReadingOrBackInfluenceAnalysis"
          :label="$t('trials:grouptConsistencyAnalysis:table:backImpact')"
          min-width="160"
          sortable="custom"
          show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="!scope.row.IsReReadingOrBackInfluenceAnalysis" type="danger">{{ $fd('YesOrNo', scope.row.IsReReadingOrBackInfluenceAnalysis) }}</el-tag>
            <el-tag v-if="scope.row.IsReReadingOrBackInfluenceAnalysis" type="primary">{{ $fd('YesOrNo', scope.row.IsReReadingOrBackInfluenceAnalysis) }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize" @pagination="getList" />
    </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('trials:grouptConsistencyAnalysis:button:create')}}
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>
<script>
import { getDoctorSelfConsistentRuleSubjectList, confirmGenerateSelfConsistentTask, getDoctorConsistentRuleSubjectList, confirmGenerateConsistentTask } from '@/api/trials/reading'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'
const searchDataDefault = () => {
  return {
    PageIndex: 1,
    PageSize: 20,
    Asc: true,
    SortField: '',
    TrialId: null,
    TaskConsistentRuleId: null
  }
}
export default {
  name: 'TrialsNotice',
  components: { BaseContainer, Pagination },
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
  },
  data() {
    return {
      searchData: searchDataDefault(),
      list: [],
      total: 0,
      loading: false,
      trialId: this.$route.query.trialId,
      SelectList: [],
      btnLoading: false
    }
  },
  mounted() {
    this.searchData.TaskConsistentRuleId = this.data.Id
    this.searchData.DoctorUserId = this.data.AnalysisDoctorUser.UserId
    this.getList()
  },
  methods: {
    selectable(row) {
      if (row.IsHaveGeneratedTask) {
        return false
      } else {
        return true
      }
    },
    handleSelectChange(e) {
      this.SelectList = e
    },
    save () {
      if (this.SelectList.length === 0) {
        // '请选择要生成的受试者'
        this.$alert(this.$t('trials:grouptConsistencyAnalysis:message:msg1'))
        return
      }
      this.btnLoading = true
      this.loading = true
      var params = {
        TaskConsistentRuleId: this.searchData.TaskConsistentRuleId,
        SubejctIdList: this.SelectList.map(v => v.SubjectId),
        DoctorUserId: this.searchData.DoctorUserId
      }
      confirmGenerateSelfConsistentTask(params).then(res => {
        this.loading = false
        this.btnLoading = false
        this.$message.success(this.$t('common:message:savedSuccessfully'))
        this.$emit('getList')
        this.close()
      }).catch(() => {
        this.loading = false
        this.btnLoading = false
      })
    },
    getList() {
      this.searchData.TrialId = this.$route.query.trialId
      this.loading = true
      getDoctorSelfConsistentRuleSubjectList(this.searchData).then(res => {
        this.loading = false
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    close() { this.$emit('close') },
    // 排序
    handleSortChange(column) {
      if (column.order === 'ascending') {
        this.searchData.Asc = true
      } else {
        this.searchData.Asc = false
      }
      this.searchData.SortField = column.prop
      this.searchData.PageIndex = 1
      this.getList()
    }
  }
}
</script>
