<template>
  <div style="height: 100%;" :class="{ bg_fff: skeletonLoad }">
    <van-nav-bar title="待办事项" left-text="" left-arrow @click-left="routerBack" />
    <VanSkeleton :skeLoad="skeletonLoad">
      <template>
        <van-tabs v-model="type" @change="changeTab">
          <van-tab title="待处理" name="noEntering"></van-tab>
          <van-tab title="已处理" name="entering"></van-tab>
        </van-tabs>

        <header class="flex-box-ce">
          <div class="flex-1">
            当前待办：
            <span v-if="commission > 0" style="color: #e42000; font-size: .29rem;">{{ commission }}条</span>
          </div>
          <div class="selector" @click="selectPfTIme">
            <span>{{ selectPftiText }}</span>
            <van-icon name="arrow-down" />
          </div>
        </header>

        <scroller v-if="type == 'noEntering'" ref="work_bench_scroller" class="all" :on-refresh="refresh" :on-infinite="infinite" noDataText="我也是有底线的" :list="noEnteringList">
          <template v-if="noEnteringList && noEnteringList.length > 0">
            <div class="list-item" v-for="(item, index) in noEnteringList" :key="index" @click="goHandlePage(item.reviewId, item.reviewIndicatorId, item.taskId, 'entering')">

              <div class="flex-box-ce" style="justify-content: space-between;">
                <div class="flex-box-ce">
                  <userImage :id="item.userInfo.id" :user_name="item.userInfo.name" fontSize="0.28" width="0.6rem" height="0.6rem" style="margin-right: 0.08rem;"></userImage>
                  <div style="font-size: 0.28rem; font-weight: 500; margin-right: 0.14rem;">{{item.employeeName}}</div>
                </div>
                <div style="font-size: 0.28rem; " class="fontColorC">{{ item.reviewTitle }}</div>
              </div>

              <div style="line-height: 0.6rem; font-size: 0.3rem; margin-bottom: 0.1rem;">指标：{{ item.title }} </div>

              <div class="flex-box-ce" style="justify-content: space-between; margin-bottom: 0.1rem;">
                <div class="node-type">
                  {{ item.nodeType | formatNodeType }}
                </div>
                <div class="btn">去处理</div>
              </div>

            </div>
          </template>
          <van-empty v-else description="暂无绩效考核数据" />
          <div style="height: 0.5rem;"></div>
        </scroller>

        <scroller v-if="type == 'entering'" ref="work_bench_scroller2" class="all" :on-refresh="refresh2" :on-infinite="infinite2" noDataText="我也是有底线的" :list="enteringList">
          <template v-if="enteringList && enteringList.length > 0">
            <div class="list-item" v-for="(item, index) in enteringList" :key="index" @click="goHandlePage(item.reviewId, item.reviewIndicatorId, item.taskId, 'noEntering')">
              <div class="flex-box-ce" style="justify-content: space-between;">
                <div class="flex-box-ce">
                  <userImage :id="item.userInfo.id" :user_name="item.userInfo.name" fontSize="0.28" width="0.6rem" height="0.6rem" style="margin-right: 0.08rem;"></userImage>
                  <div style="font-size: 0.28rem; font-weight: 500; margin-right: 0.14rem;">{{item.employeeName}}</div>
                </div>
                <div style="font-size: 0.28rem; " class="fontColorC">{{ item.reviewTitle }}</div>
              </div>
              
              <div style="line-height: 0.6rem; font-size: 0.3rem; margin-bottom: 0.1rem;">指标：{{ item.title }} </div>
              
              <div class="flex-box-ce" style="justify-content: space-between; margin-bottom: 0.1rem;">
                <div class="node-type">
                  {{ item.nodeType | formatNodeType }}
                </div>
                <div class="btn">查看详情</div>
              </div>
            </div>
          </template>

          <van-empty description="暂无绩效考核数据" v-if="enteringList.length == 0" />
          <div style="height: 0.5rem;"></div>
        </scroller>

      </template>
    </VanSkeleton>

    <van-dialog v-model="selectpfdlg" title="" width="300" :show-confirm-button="false" closeOnClickOverlay>
      <van-radio-group v-model="doSthForData.type">
        <van-radio
          v-for="(item, index) in selectpfList"
          :key="index"
          :name="item.value"
          @click="clickpfTime(item)"
          style="margin:.3rem 0 .3rem .4rem;font-size:.3rem"
          icon-size="16px"
        >
          <span style="margin-left:.3rem">{{ item.label }}</span>
        </van-radio>
      </van-radio-group>
    </van-dialog>
  </div>
</template>

<script>
import Vue from 'vue';
import { mapGetters, mapState } from 'vuex';
import moment from 'moment';
import VanSkeleton from '@/performance/components/public/VanSkeleton';
import {Tab, Tabs, Search} from 'vant'
Vue.use(Tab).use(Tabs).use(Search)
export default {
  data() {
    return {
      skeletonLoad: false, // 过度骨架屏
      backlogList: [],
      commission: 0,
      doSthForData: {
        siteId: this.$userInfo().site_id,
        employeeId: this.$userInfo().id,
        page: 1, // 当期页
        pageSize: 15, // 一页多少数据
        type: 0 // 0-全部 1-确认目标 2-录入结果 3-自评 4-互评 5-评分 6-审批 7-考核面谈
      },
      theBackupList: [],
      // 分类相关
      selectpfList: [
        // 选择时间选项
        { label: '全部', value: 0 },
        { label: '确认目标', value: 1 },
        { label: '录入结果', value: 2 },
        { label: '自评', value: 3 },
        { label: '互评', value: 4 },
        { label: '评分', value: 5 },
        { label: '审批', value: 6 }
      ],
      selectpfdlg: false,
      selectPftiText: '全部', // 默认值
      pendingList: [] ,//提供给考核详情上下切换人员列表
      plcList:[],
      userInfo: this.$userInfo(),
      type:'noEntering',
      noEnteringList: [],
      enteringList:[],
      enteringList2:[],
      page: 1,
    };
  },

  computed: {
    ...mapGetters(['site_info'])
  },

  components: { VanSkeleton },

  filters: {
    formatNodeType(val) {
      // targetConfirm-确认目标 resultInput-录入结果值 scoreSelf-自评 scoreEachOther-互评 score-评分 review-审批
      if(val === 'targetConfirm') return '确认目标'
      if(val === 'resultInput') return '录入结果'
      if(val === 'scoreSelf') return '自评'
      if(val === 'scoreEachOther') return '互评'
      if(val === 'score') return '评分'
      if(val === 'review') return '审批'
    }
  },


  activated() {
    this.page = 1;
    this.doSthForData.page = 1;
    this.doSthForData.type = 0;
    this.selectPftiText = '全部'; // 默认值
    if(this.type == 'noEntering'){
      setTimeout(() => {
        this.$refs.work_bench_scroller.triggerPullToRefresh();
      }, 50);
    }else{
      setTimeout(() => {
        this.$refs.work_bench_scroller2.triggerPullToRefresh();
      }, 50);
    }
  },



  methods: {

    changeTab(name) {
      this.page = 1;
      this.doSthForData.page = 1;
      this.doSthForData.type = 0;
      this.selectPftiText = '全部'; // 默认值
      if(this.type == 'noEntering'){
        console.log("请求待处理数据")
        setTimeout(() => {
          this.$refs.work_bench_scroller.triggerPullToRefresh();
        }, 50);
      }else{
        setTimeout(() => {
          this.$refs.work_bench_scroller2.triggerPullToRefresh();
        }, 50);
      }
    },

    getNoEntering(callback) {
      let hasMore = false;
      let url = `/performance/review/job/employee/app/${this.$userInfo().site_id}/${this.$userInfo().id}`
      this.commission = 0;
      this.$axiosUser('get', url, this.doSthForData).then(res => {
        if(res.data.code == 1) {
          this.commission = res.data.data.total;
          let list = res.data.data.list;
          this.skeletonLoad = false;
          if(list && list.length > 0) {
            list.forEach(item => {
              let userInfo = this.$getEmployeeMapItem(item.employeeId)
              item.userInfo = userInfo
            })
          }

          if (this.doSthForData.page === 1) {
            this.noEnteringList = list;
          } else {
            this.noEnteringList = this.noEnteringList.concat(list);
          }
          hasMore = list.length !== 10;
          callback && callback(hasMore);
        }
      })
    },

    getEnteringList(callback) {
      let hasMore = false;
      this.commission = 0;
      let url = `/performance/review/job/employee/app/history/${this.$userInfo().site_id}/${this.$userInfo().id}`
      this.$axiosUser('get', url, this.doSthForData).then(res => {
        if(res.data.code == 1) {
          this.commission = res.data.data.total;
          let list = res.data.data.list;
          this.skeletonLoad = false;
          if(list && list.length > 0) {
            list.forEach(item => {
              let userInfo = this.$getEmployeeMapItem(item.employeeId)
              item.userInfo = userInfo
            })
          }

          if (this.doSthForData.page === 1) {
            this.enteringList = list;
          } else {
            this.enteringList = this.enteringList.concat(list);
          }
          hasMore = list.length !== 10;
          callback && callback(hasMore);
        }
      })
    },

    clickpfTime(item) {
      this.selectPftiText = item.label;
      this.doSthForData.page = 1;
      if(this.type === "noEntering") {
        setTimeout(() => {
          this.$refs.work_bench_scroller.triggerPullToRefresh();
        }, 50);
      }else {
        setTimeout(() => {
          this.$refs.work_bench_scroller2.triggerPullToRefresh();
        }, 50);
      }

      this.selectpfdlg = false;
    },

    selectPfTIme() {
      this.selectpfdlg = true;
    },

    goHandlePage(reviewId, reviewIndicatorId, taskId, type) {
      this.$router.push({ path:'/newBacklogDetails', query: { reviewId, reviewIndicatorId, taskId, type } });
    },


    // 上拉刷新
    refresh(done) {
      this.doSthForData.page = 1;
      this.getNoEntering(done);
    },

    // 下拉加载
    infinite(done) {
      this.doSthForData.page++;
      this.getNoEntering(done);
    },



    // 返回上一页
    routerBack() {
      this.$route_back();
    },

    // 上拉刷新
    refresh2(done) {
      this.doSthForData.page = 1;
      this.getEnteringList(done);
    },

    // 下拉加载
    infinite2(done) {
      this.doSthForData.page++;
      this.getEnteringList(done);
    },

  },
};
</script>

<style scoped lang="less">
.all {
  height: calc(100% - 2.64rem) !important;
  position: relative !important;
  background-color: #f5f7fa;
}
.all2{
  height: calc(100% - 1.84rem) !important;
  position: relative !important;
  background-color: #f5f7fa;
}
header {
  padding: 0.2rem;
  background-color: #fff;
  padding-left: 0.2rem;
  font-size: 0.3rem;
  z-index: 1;
  box-sizing: border-box;
  border-bottom: 1px solid #f1f1f1;
  border-top: 1px solid #f1f1f1;
}

.backlog_list_tit {
  background-color: #f5f7fa;
  padding: 0.2rem 0 0.2rem 0.2rem;
  font-size: 0.28rem;
}
.backlog_list {
  padding: 0.32rem 0.3rem 0.32rem 0.45rem;
  box-sizing: border-box;
  span {
    font-size: 0.29rem;
  }
}

.mb-2 {
  margin-bottom: 0.2rem;
}

.list-item {
  width: 96%;
  padding: 0.2rem;
  background-color: #fff;
  box-sizing: border-box;
  font-size: 0.28rem;
  position: relative;
  margin: 0.2rem auto 0 auto;
  border-radius: 8px;
  .node-type {
    background-color: #ecf5ff;
    width: 1.3rem;
    text-align: center;
    padding: 0.05rem;
    color: #fff;
    border-radius: 6px;
    font-size: 0.3rem;
    color: #26a2ff;
    margin-right: 0.14rem;
  }

  .btn {
    padding: 0.05rem;
    border-radius: 6px;
    color: #26a2ff;
    font-size: 0.28rem;
  }
}
</style>
