var app = getApp() var that; var typeArr = []; Page({ data: { date: app.globalData.month, minuteIndex: 0,//条件选择 minuteArray: [ { id: 0, name: '总分' }, { id: 1, name: '加班' }, { id: 2, name: '迟到' }, ], showDate: false,//是否显示时间组件 selectDateVal: '本月', showStaff: false,//显示员工选择 staffVal: '员工', types: [],//积分分类 typesIndex: '0', showRuleTwo: false, ruleVal: "规则分类", page: 1, popupCx: '', }, onLoad(e) { console.log(e); that = this; var userData = app.globalData.userData; typeArr = [{ id: 0, name: '全部' }]; var arr = typeArr.concat(app.globalData.types); arr = app.globalData.arrRemoveObj(arr, arr[1]); dd.setNavigationBar({ title: "积分事件" }); if (e.month||e.employee_ids) { var typesIndex = "0"; if (e.type) { if(arr){ arr.map((item, index) => { if (item.code == e.type) { typesIndex = index } }) } } this.setData({ date: e.month? e.month:app.globalData.month, typesIndex: typesIndex, employee_ids:e.employee_ids ? e.employee_ids:[userData.id], staffVal:e.userName ? e.userName:userData.name, selectDateVal: e.month == app.globalData.month ? '本月' : '月', defaultDate: { type: '1', date: e.month }, }) } }, onShow() { typeArr = [{ id: 0, name: '全部' }]; if (app.globalData.userData) { var arr = typeArr.concat(app.globalData.types); arr = app.globalData.arrRemoveObj(arr, arr[1]); if (arr) { that.setData({ types: arr }) } if (that.data.page == 1) { that.getData(); } } else { app.login(app.globalData.corpId, function (is) { if (is) { var arr = typeArr.concat(app.globalData.types); arr = app.globalData.arrRemoveObj(arr, arr[1]); if (arr) { that.setData({ types: arr }) } if (that.data.page == 1) { that.getData(); } } else { dd.reLaunch({ url: '../noJurisdiction/noJurisdiction' }) } }) } }, getData(is) { var data = { page: that.data.page, page_size: 20, rule_id: that.data.rule_id, pt_id: that.data.types.length > 0 ? that.data.types[that.data.typesIndex].id : '2', employee_ids: that.data.employee_ids } if (that.data.date_type == 2) { data.start_day = that.data.dateObj[0]; data.end_day = that.data.dateObj[1]; } else { data.month = that.data.dateObj || that.data.date; } app.$get('api/integral/statistics/integral', data).then((res) => { var data = res.data.data.list; data.map((item) => { item.ptObj = app.getTypesItem(item.pt_id); }) if (is) { if (data.length == 0) { this.setData({ isData: true }) return; } var list = that.data.list; this.setData({ list: list.concat(data) }) } else { this.setData({ list: [] }); this.setData({ list: data, isData: false }) } }) }, //上啦加载 onScrollToLower() { if (!that.data.isData) { this.setData({ page: ++that.data.page }) this.getData(true); } }, //打开兴趣 openDetail(e) { var item = e.target.dataset.item; dd.navigateTo({ url: '../prizeBuckleDetail/prizeBuckleDetail?id=' + item.id }) }, //显示规则组件 selectRule() { this.setData({ popupCx: 'container__mask', showRuleTwo: true }) }, //显示选择时间组件 selectDate() { this.setData({ popupCx: 'container__mask', showDate: true }) }, //显示选择员工 selectStaff() { this.setData({ popupCx: 'container__mask', showStaff: true }) }, //选择时间 onConfirmDate(data) { that.setData({ defaultDate: data, dateObj: data.date, date_type: data.type == 1 ? 3 : data.type, page: 1, selectDateVal: data.type == 1 ? (data.date == that.data.date ? '本月' : '月') : '日', }) this.getData(); }, //关闭弹窗 onClose() { this.setData({ showDate: false, showStaff: false, showRuleTwo: false, popupCx: '' }) }, //选择积分分类 bingIntegralType(e) { this.setData({ typesIndex: e.detail.value, page: 1 }); this.getData(); }, //选择员工 onConfirmStaff(data) { if (!data) { this.setData({ staffVal: '员工', employee_ids: '', page: 1 }) this.getData(); return false; } if (data.length > 0) { if (data.length > 1) { var str = ""; var arr = []; data.forEach((item) => { str += item.name + ',' arr.push(item.id); }) var employee_ids = arr.join(','); this.setData({ staffVal: str.substring(0, str.length - 1), employee_ids: employee_ids, page: 1 }) } else { this.setData({ staffVal: data[0].name, employee_ids: [data[0].id], page: 1 }) } } else { this.setData({ staffVal: '员工', employee_ids: [], page: 1 }) } this.getData(); }, //选择规则 onConfirmRule(e) { this.setData({ rule_id: e.id ? e.id : '', page: 1, ruleVal: e.name }) this.getData(); }, });