var app = getApp() var that; var typeArr = []; import { _debounce } from '../../../utils/util' Page({ data: { date: app.globalData.month, minuteIndex: 2,//条件选择 minuteArray: [ { id: -1, name: '全部' }, { id: 1, name: '已发放' }, { id: 0, name: '未发放' }, ], showDate: false,//是否显示时间组件 selectDateVal: '本月', showStaff: false,//显示员工选择 staffVal: '员工', types: [ { id: 0, name: '全部事件' }, { id: 1, name: '我奖扣的' }, ], typesIndex: '0', showRuleTwo: false, page: 1, popupCx: '', isAll:true, isShowYy:false, }, onLoad(e) { that = this; dd.setNavigationBar({ title: "发放奖票" }); let isShowYy=false; app.globalData.userData.employee_detail.role_list.forEach(item=>{ if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){ isShowYy=true; } }) this.setData({ isShowYy:isShowYy, }) }, onShow() { typeArr = [{ id: 0, name: '全部' }]; if (app.globalData.userData) { if (that.data.page == 1) { that.getData(); } } else { app.login(app.globalData.corpId, function (is) { if (that.data.page == 1) { that.getData(); } }, function () { }) } }, selectAll(e){ let list=this.data.list list.map((item) => { if(!item.has_ticket){ item.checked=this.data.isAll; } }) this.setData({ list:list, isAll:!this.data.isAll }) }, //提交 sumbit(){ let list=this.data.list let selectId=[]; list.map((item) => { if(item.checked){ selectId.push(item.id) } }) if(selectId.length==0){ app.globalData.showToast("请选择需要发放奖票的事件"); return false } dd.confirm({ title: '提示', content: '你确定发放奖票吗?', confirmButtonText: '确定', cancelButtonText: '取消', success: (result) => { if (result.confirm) { app.$post('api/integral/ticket/create',{event_ids:selectId.toString()},'application/vnd.test.v2+json').then((res) => { app.globalData.showToast("已发放"); that.setData({ page: 1 }) this.getData(); }) } }, }); }, onChange(e) { let id=e.target.dataset.item.id; let list=this.data.list list.map((item) => { if(item.id==id){ item.checked=e.detail.value; } }) this.setData({ list:list }) }, bingStatus(e){ this.setData({ minuteIndex: e.detail.value, page: 1, }); this.getData(); }, bingIntegralType(e) { this.setData({ typesIndex: e.detail.value, page: 1, }); this.getData(); }, onReset() { this.setData({ page: 1, isVal: false, keyword: '' }) this.getData(); }, bindKeyInput:_debounce(function(e){ this.setData({ page: 1, isVal: e.detail.value ? true : false, keyword: e.detail.value ? e.detail.value : '', }) this.getData(); }), getData(is) { var data = { page: that.data.page, page_size: 20, employee_ids: that.data.employee_ids, dc_status: JSON.stringify([1]), keyword:this.data.keyword, add_subtract:1, has_ticket:this.data.minuteArray[this.data.minuteIndex].id } 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; } if(this.data.isShowYy){ if(this.data.typesIndex==1){ data.recorder_id=app.globalData.userData.id } }else{ data.recorder_id=app.globalData.userData.id } 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); item.checked=false; }) 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+'&is=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, popupCx: '', }) }, //选择员工 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(); }, });