var app = getApp();
var that;
import { returnStr, setCache, getCache, _debounce, getRole } from '../../../utils/util'
Page({
  data: {
    Tit: '',
    knowFrom: '',
    backlogList: [],
    packId: 0, //记录id
    assessID: 0, //记录人
    recordMemberIds: []
  },
  onLoad() {
    that = this;
  },
  onShow() {
    this.setData({
      query: getCache('actionplanList')
    })
    this.init()
  },
  openPlanPath(e) {
    let apList=e.target.dataset.item
    let data = {
      know: this.data.knowFrom,
      apList: JSON.stringify(apList),
      packId: this.data.packId,
      assessID: this.data.assessID
    };
    setCache('actionplanDetails', data);
    dd.navigateTo({
      url: `../actionplanDetails/actionplanDetails?`
    })
  },
  init() {
    let query = this.data.query;
    this.setData({
      knowFrom: query.know,
      Tit:query.know=='action'? '执行计划':'管理记录',
      packId: query.packId,
      assessID: query.assessID,
      recordMemberIds: query.recordMemberIds ? query.recordMemberIds : [],
    })
    if (this.data.knowFrom == 'action') {
      //执行计划
      dd.setNavigationBar({ title: "执行计划" });
    } else if (this.data.knowFrom == 'admnin') {
      //管理记录
      dd.setNavigationBar({ title: "管理记录" });
    }
    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.data.recordMemberIds.length > 0) {
      // this.$getEmployeeAll()[this.assessID].employee_detail.superior_list.some(item => {
      //   // 判断被考核人的上级是否包含登录者
      //   if (item.id == this.$getUserData_jx().id) {
      //     isFiltration = false;
      //     return true;
      //   }
      // });
      if (app.globalData.userData.is_creator == 1) {
        // 如果是创始人也可以操作
        isFiltration = false;
      }
      if (app.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(app.globalData.userData.id) >= 0) {
              item2.isOperation = true;
            }
          });
        });
        this.setData({
          backlogList: actionPlanList
        })
      } else {
        this.setData({
          backlogList: apList
        })
      }
    } else {
      this.setData({
        backlogList: apList
      })
    }
  }
});
