<template>
  <el-table
    v-adaptive="{bottomOffset:60}"
    v-loading="loading"
    :data="list"
    stripe
    height="100"
    :span-method="objectSpanMethod"
  >
    <el-table-column
      prop="UserType"
      label="角色"
      show-overflow-tooltip
      width="120"
      sortable="custom"
    >
      <template slot-scope="scope">
        {{$fd('UserType', scope.row.UserType)}}
      </template>
    </el-table-column>
    <el-table-column
      prop="UserName"
      label="用户名"
      show-overflow-tooltip
      width="120"
      sortable="custom"
    />
    <el-table-column
      prop="TrialSiteCode"
      label="阅片人筛选"
      show-overflow-tooltip
      sortable="custom"
    >
      <el-table-column
        prop="ReviewerSelect_SPM_ToBeApprovalCount"
        label="阅片人待审批"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="ReviewerSelect_PM_ToBeConfirmCount"
        label="阅片人待确认"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
    </el-table-column>
    <el-table-column
      label="上传影像"
      show-overflow-tooltip
      sortable="custom"
    >
      <el-table-column
        prop="ImageUpload_CRC_ToBeReUploadCount"
        label="影像待重传"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="ImageUpload_CRC_ToBeSubmitCount"
        label="加急影像待提交"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
    </el-table-column>
    <el-table-column
      label="QC"
      show-overflow-tooltip
      sortable="custom"
    >
      <el-table-column
        prop="QC_IQC_ToBeClaimedCount"
        label="QC待领取"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="QC_IQC_ToBeReviewedCount"
        label="QC审核未完成"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="QC_IQC_ToBeDealedCount"
        label="QC质疑待处理"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="QC_CRC_ToBeDealedCount"
        label="质疑待CRC处理"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
    </el-table-column>
    <el-table-column
      prop="TrialSiteCode"
      label="一致性核查"
      show-overflow-tooltip
      sortable="custom"
    >
      <el-table-column
        prop="Check_CRC_ToBeDealedCount"
        label="待CRC处理"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="Check_PM_ToBeDealedCount"
        label="待PM处理"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
    </el-table-column>
    <el-table-column
      prop="TrialSiteCode"
      label="阅片"
      show-overflow-tooltip
      sortable="custom"
    >
      <el-table-column
        prop="Reading_IR_UnReadCount"
        label="待阅"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="Reading_PM_ToBeApprovalCount"
        label="重阅待审批"
        show-overflow-tooltip
        sortable="custom"
      >
        <template slot-scope="scope">
          {{scope.row.Reading_PM_ToBeApprovalCount + scope.row.Reading_SPM_ToBeApprovalCount}}
        </template>
      </el-table-column>
    </el-table-column>
    <el-table-column
      prop="TrialSiteCode"
      label="医学审核"
      show-overflow-tooltip
      sortable="custom"
    >
      <el-table-column
        prop="TrialSiteCode"
        label="待审核"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="Medical_MIM_ToBeDealedCount"
        label="MIM待处理"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
      <el-table-column
        prop="Medical_IR_ToBeDealedCount"
        label="IR待回复"
        show-overflow-tooltip
        sortable="custom"
      >
      </el-table-column>
    </el-table-column>
  </el-table>
</template>

<script>
import { getTrialUserToBeDoneList } from '@/api/trials'
export default {
  name: "DoneList",
  props: {
    trialId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      list: [],
      UserTypeList: [],
      spanArr: [],
      pos: 0,
      loading: false
    }
  },
  methods: {
    getSpanArr(data) {
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1)
          this.pos = 0
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].UserType === data[i - 1].UserType) {
            this.spanArr[this.pos] += 1
            this.spanArr.push(0)
          } else {
            this.spanArr.push(1)
            this.pos = i
          }
        }
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    }
  },
  mounted() {
    this.loading = true
    getTrialUserToBeDoneList({
      TrialId: this.trialId
    }).then(res => {
      this.list = res.Result
      this.getSpanArr(this.list)
      this.loading = false
    })
  }
}
</script>

<style scoped>

</style>
