<template>
  <div style="height: 100%;">
    <van-nav-bar :title="'填写' + Tit" left-text="" left-arrow @click-left="routerBak" />
    <header class="performanceList">
      <div>请选择记录"{{ Tit }}"的考核指标</div>
    </header>
    <scroller ref="work_bench_scroller" class="all">
      <div style="padding-bottom:1.5rem;">
        <van-empty description="暂无绩效考核数据" v-if="backlogList.length == 0" />
        <div v-else v-for="(item, index) in backlogList" :key="index">
          <template v-if="item.index.length > 0">
            <div class="backlog_list_tit">{{ item.name }}</div>
            <div v-for="(arr, keys) in item.index" :key="keys" class="backlog_list">
              <van-cell :title="arr.name + '（' + arr.weight + '%）'" @click="openPlanPath(arr)" is-link class="apListt">
                <template>
                  <span class="num" v-if="returnNum(arr) > 0">{{ returnNum(arr) }}</span>
                </template>
              </van-cell>
            </div>
          </template>
        </div>
      </div>
    </scroller>
  </div>
</template>

<script>
export default {
  data() {
    return {
      Tit: '',
      knowFrom: '',
      backlogList: [],
      packId: 0, //记录id
      assessID: 0, //记录人
      recordMemberIds: []
    };
  },
  methods: {
    // 返回上一页
    routerBak() {
      this.$route_back();
    },
    returnNum(item) {
      if (this.knowFrom == 'action') {
        //执行计划
        return item.schedule.length;
      } else if (this.knowFrom == 'admnin') {
        //管理记录
        return item.mamage_record.length;
      }
    },
    openPlanPath(apList) {
      let data = {
        know: this.knowFrom,
        apList: JSON.stringify(apList),
        packId: this.packId,
        assessID: this.assessID
      };
      this.$setCache('actionplanDetails', data);
      this.$router.push({ name: 'actionplanDetails' });
    },
    //获取指定人员上级列表
    getSuperiors(employee_id){
      return this.$axiosUser('get', 'api/pro/employee/superior', {employee_id:employee_id,platform:'3'}).then(res=>{
        return res.data.data.list
      })
    },
    async init() {
      let query = this.$getCache('actionplanList');
      this.knowFrom = query.know;
      this.packId = query.packId; //记录id
      this.assessID = query.assessID; //记录人
      this.recordMemberIds = query.recordMemberIds ? query.recordMemberIds : []; //管理记录人ID
      if (this.knowFrom == 'action') {
        //执行计划
        this.Tit = '执行计划';
      } else if (this.knowFrom == 'admnin') {
        //管理记录
        this.Tit = '管理记录';
      }
      let apList = JSON.parse(query.apList);
      apList.forEach((item, keys) => {
        item.index.forEach((arr, index) => {
          arr.planIndex = [keys, index]; //当打开执行计划时的下标
          arr.isOperation = true;
        });
      });
      // 当有管理记录人时过滤数据
      let isFiltration = true; //是否需要过滤数据源
      if (this.recordMemberIds.length > 0) {
        let superior_list=await this.getSuperiors(this.assessID);
        superior_list.some(item => {
          // 判断被考核人的上级是否包含登录者
          if (item.id == this.$userInfo().id) {
            isFiltration = false;
            return true;
          }
        });
        if (this.$userInfo().is_per_manager) {
          // 如果是绩效管理员也可以操作
          isFiltration = true;
        }
        if (this.$getPermis(3)) {
          // 如果是子管理员并且管理范围权限为“全公司”
          isFiltration = false;
        }
        if (isFiltration) {
          let actionPlanList = JSON.parse(JSON.stringify(apList));
          actionPlanList.forEach((item, index) => {
            item.index.forEach(item2 => {
              item2.isOperation = false;
              if (item2.record_ids.indexOf(this.$userInfo().id) >= 0) {
                item2.isOperation = true;
              }
            });
          });
          this.backlogList = actionPlanList;
        } else {
          this.backlogList = apList;
        }
      } else {
        this.backlogList = apList;
      }
    }
  },
  activated() {
    this.init();
  }
};
</script>

<style scoped lang="less">
.num {
  color: #fff;
  text-align: center;
  border-radius: 25px;
  padding: 0 5px;
  width: 0.8rem;
  background-color: #2686ff;
}
.all {
  height: calc(100% - 1.74rem) !important;
  position: relative !important;
  background-color: #f5f7fa;
}
header {
  padding: 0.2rem;
  background-color: #fff;
  padding-left: 0.3rem;
  font-size: 0.26rem;
  z-index: 1;
}
.backlog_list_tit {
  background-color: #f5f7fa;
  padding: 0.2rem 0 0.2rem 0.3rem;
  font-size: 0.28rem;
}
.backlog_list {
  border-bottom: red;
  /deep/ .apListt {
    border-bottom: 1px solid #f1f1f1;
  }
  /deep/ .apListt span {
    font-size: 0.27rem;
  }
}

/deep/ .van-cell__value {
  width: 1rem;
  flex: none;
}
</style>
