<template>
  <div class="contradiction-div">
    <Modal v-model="showFamily" width="1000" title="评分历史列表">
      <Table stripe :columns="columns" :data="familyList">
        <template slot-scope="{ row, index }" slot="doStatus">
          <div v-if="row.doStatus === '0'">待评</div>
          <div v-else-if="row.doStatus === '1'">已评</div>
          <div v-else-if="row.doStatus === '2'">超期未评</div>
          <div v-else-if="row.doStatus === '3'">超期已评</div>
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <Button v-if="canShowVisit(row)" type="info" size="small" style="margin-right: 5px" @click="showRatingList(row)"  :disabled="(row.canClick == '1' || row.doStatus == '2')?false:true ">评分</Button>
          <Button type="info" size="small" style="margin-right: 5px" @click="showRatingInfo(row)">详情</Button>
        </template>
      </Table>
      <Page
        class="page_style"
        :total="params.totalRecord"
        :current="params.pageNo"
        :page-size="params.pageSize"
        @on-change="changePageNo"
        show-total
        show-sizer
        @on-page-size-change="size"
      />
    </Modal>
  </div>
</template>

<script>
import { selectRatingHistoryList, getVisitButtonPower } from '@/api/peopleInfo.js'
export default {
  name: 'ratingHistoryList',
  props: {
    peopleInfo: Object
  },
  data () {
    return {
      showFamily: false,
      columns: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '评分人员', key: 'ratingPersonnel', minWidth: 100, align: 'center' },
        { title: '评分部门', key: 'ratingCompany', minWidth: 100, align: 'center' },
        {
          title: '风险等级',
          key: 'ratingTypeName',
          align: 'center',
          width: '90'
        },
        {
          title: '分数',
          key: 'rating',
          align: 'center',
          width: '90'
        },
        {
          title: '评分时间',
          key: 'ratingTime',
          align: 'center',
          width: '150'
        },
        {
          title: '评分开始日期',
          key: 'planStartData',
          align: 'center',
          width: '120'
        },
        {
          title: '评分截止日期',
          key: 'planEndData',
          align: 'center',
          width: '120'
        },
        {
          title: '评分临期日期',
          key: 'overdueDate',
          align: 'center',
          width: '120'
        },
        { title: '评分状态', slot: 'doStatus', minWidth: 100, align: 'center', fixed: 'right' },
        { title: '操作', slot: 'action', minWidth: 140, align: 'center', fixed: 'right' }
      ],
      familyList: [],
      params: {
        pageNo: 1,
        pageSize: 10,
        totalRecord: 0
      },
      visitButtonPower: {},
      severUserInfo: {}
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
  },
  methods: {
    fetchVisitButtonPower () {
      const payload = {}
      return getVisitButtonPower(payload).then((ret) => {
        if (ret && ret.data && ret.data.errcode === 0) {
          this.visitButtonPower = ret.data.data || {}
        } else {
          this.visitButtonPower = {}
        }
      }).catch(() => { this.visitButtonPower = {} })
    },
    canShowVisit (row) {
      const isAdmin = (this.severUserInfo.loginName === 'admin')
      const power = this.visitButtonPower || {}
      const type = String(row.ratingDictType || '')
      if (isAdmin) return true
      if (row.dualMark === '1') return false
      if (type === '2') return !!power['rucs_rating']
      if (type === '3') return !!power['psmd_rating']
      if (type === '6') return !!power['km_rating']
      return false
    },
    init () {
      this.params.pageNo = 1
      this.params.pageSize = 10
      this.showFamily = true
      this.fetchVisitButtonPower()
      this.getEventList()
    },
    getEventList () {
      this.params.ratingDictType = this.peopleInfo.sysType
      this.params.keyPersonId = this.peopleInfo.id
      selectRatingHistoryList(this.params).then(ret => {
        if (ret.data.errcode === 0) {
          this.params.totalRecord = ret.data.data.totalRecord
          this.familyList = ret.data.data.results
          this.tableLoading = false
        } else {
          this.$Notice.error({ title: '查询失败！', desc: ret.data.errmsg })
        }
      })
    },
    size (pageSize) {
      this.params.pageSize = pageSize
      this.changePageNo(1)
    },
    changePageNo (pageNo) {
      this.params.pageNo = pageNo
      this.init(this.params)
    },
    showRatingList (row) {
      this.$router.push({
        name: 'keyPersonRatingDetails',
        params: {
          id: row.keyPersonId,
          ratingDictType: this.peopleInfo.sysType,
          historyId: row.historyId,
          summaryId: row.summaryId,
          isHide: true
        }
      })
    },
    showRatingInfo (row) {
      this.$router.push({
        name: 'keyPersonRatingDetails',
        params: {
          id: row.keyPersonId,
          ratingDictType: this.peopleInfo.sysType,
          historyId: row.historyId,
          summaryId: row.summaryId,
          isHide: false
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
  .contradiction-div {
    padding: 10px;
  }
  .renyuan-item-box{
    margin-bottom: 16px;
  }
  /deep/ .ivu-card-bordered{
    border: 2px solid #EEEEEE;
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
</style>
