var app = getApp() var that; var socket = null; var setTime; Page({ data: { date: app.globalData.month, activeIndex: 1, keyword: '', page: 1, isBh: false,//是否显示驳回弹窗 textArea: "", disabled: false, isPl:false, objectArray: [{id:'[1,2]',name: '全部'},{ id: '[1]',name: '通过'},{id: '[2]', name: '不通过'}], arrIndex: 0, isAll: true, minuteIndex: 0,//条件选择 minuteArray: [ { id: 1, name: '待复核' }, { id: 2, name: '已复核' }, ], // 长连接结果 results: [], //提交的返回结果集合 isResult: false, percentage: 0, resultList: [],//要发送数据的集合 resultIndex: 0, isShowError: false, popupCx: '', config: {}, showStaff: false,//显示员工选择 staffVal: '人员', isOpen:false, }, onLoad() { that = this; dd.setNavigationBar({ title: "复核" }); app.globalData.socketApi.sendData({},this.onmessageWS,true); }, onShow() { if (app.globalData.userData) { that.refreshData(); } else { app.login(app.globalData.corpId, function (is) { if (is) { that.refreshData(); } else { dd.reLaunch({ url: '../../noJurisdiction/noJurisdiction' }) } },function(){}) } }, onUnload (){ // app.globalData.socketApi.closewebsocket(); }, //选择员工 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(); }, //显示选择员工 selectStaff() { this.setData({ popupCx: 'container__mask', showStaff: true }) }, //关闭弹窗 onClose() { this.setData({ showStaff: false, popupCx: '' }) }, openPl(){ this.setData({ isPl: !that.data.isPl }) }, // 通过 openTg() { let that = this; let selectIds = []; this.data.dataList.forEach(item => { if(item.checked){ selectIds.push({ type:'event_check', action:'agree', event_id:item.id, point:item.point, remark:item.remark, name:item.employee_name, pt_id:item.pt_id }); } }) if (selectIds.length == 0) { app.globalData.showToast("请先选择复核单"); return false } dd.confirm({ title: '批量通过', content: `已选中${selectIds.length}条复核单,确认全部通过?`, confirmButtonText: '确定', cancelButtonText: '取消', success: (result) => { if (result.confirm) { that.webSocket(selectIds,true); } }, }); }, selectAll() { let dataList = this.data.dataList.map((item,index) => { item.checked= false; if(index<50){ item.checked = this.data.isAll; } return item; }) this.setData({ dataList: dataList, isAll:!this.data.isAll, }) }, //选择规则分类 bindKeyInput(e) { this.setData({ keyword: e.detail.value, page: 1, isVal: e.detail.value ? true : false, }); this.getData(); }, bindObjPickerChange(e) { this.setData({ arrIndex: e.detail.value, page: 1, isPl:false, }) this.getData(); }, //当在详情返回时刷新列表,但你请求接口 refreshData(id) { if (this.data.page == 1) { dd.hideLoading(); that.getData(); } else { if (id) {//当page不为一并下一页返回上一页不执行onshow() var arr = this.data.dataList; arr.forEach((element, index) => { if (element.id == id) { arr.splice(index, 1); } }); this.setData({ dataList: arr }) } } }, bindTextAreaBlur(e) { this.setData({ textArea: e.detail.value }); }, confirmBh() { if (that.data.textArea == '') { app.globalData.showToast("请输入不通过原因"); return; } let noData={ type:'event_check', action:'disagree', event_id:that.data.bhItem.id, comment:that.data.textArea, } this.setData({ disabled: true }); this.webSocket(noData) }, closeBh() { this.setData({ isBh: false, textArea: '' }) }, openBh(e) { var item = e.target.dataset.item; var index = e.target.dataset.index; if(index=='1'){ let data={ type:'event_check', action:'agree', event_id:item.id, point:item.point } this.webSocket(data) }else{ this.setData({ isBh: true, bhItem: item }) } }, webSocket(data,is) { if(!this.data.isOpen){ app.globalData.showToast("正在连接服务器,请稍侯..."); return false; } let resultList=is? data:[data]; this.setData({ resultList:resultList, resultIndex: 0, percentage: 0, results: [], isResult:resultList.length!=1, }) this.opneWebSocket() }, opneWebSocket() { let wsData = this.data.resultList; if (wsData[this.data.resultIndex]) { // setTime = setTimeout(() => { // dd.alert({ // title: '温馨提示', // content: '网络异常,请检查网络', // buttonText: '我知道了', // success: () => { // clearTimeout(setTime); // app.globalData.socketApi.closewebsocket(); // that.closeTc(); // }, // }); // }, 15000) app.globalData.socketApi.sendData(wsData[this.data.resultIndex],this.onmessageWS,true); } }, onmessageWS(e) { if(e.type=='auth'){ that.setData({ isOpen:true }) } // 因为作用域问题,这个函数不能使用this if (e.type == 'event_check') { // clearTimeout(setTime); if(that.data.resultList.length==1){ //单条 if(e.code==1){ app.globalData.showToast("提交成功"); that.setData({ disabled: false, isBh: false, textArea: '', }); that.refreshData(e.result.task.msg.event_id); return false; }else{ that.setData({ disabled: false, }); app.globalData.showToast(e.msg) return false; } } let user; if(e.code==1){ user={ name:e.result.task.msg.name, point:e.result.task.msg.point, remark:e.result.task.msg.remark, pt_id:e.result.task.msg.pt_id, msg:'提交成功' } }else{ let item = that.data.resultList[that.data.resultIndex]; user={ name:item.name, point:item.point, remark:item.remark, pt_id:item.pt_id, msg:e.msg } } let results=that.data.results results.unshift(user); that.setData({ results: results, resultIndex: that.data.resultIndex + 1 }) that.opneWebSocket(); // 进度条 let lng = that.data.resultList.length; that.setData({ percentage: that.data.percentage + Math.floor(100 / lng), }) if (lng == that.data.results.length) { that.setData({ percentage: 100, }) } } if (e.type == 'error') { clearTimeout(setTime); that.setData({ isShowError: true, }) } }, closeTc() { this.setData({ results: [], //提交的返回结果集合 isResult: false, percentage: 0, resultList: [],//要发送数据的集合 resultIndex: 0, isBh: false,//是否显示驳回弹窗 isShowError: false, textArea: '', page: 1, }) app.globalData.socketApi.closewebsocket(); this.getData(); }, activeItem(e) { this.setData({ minuteIndex: e.detail.value, page: 1, dataList: [], isPl:false, }) this.getData(); }, onReset() { this.setData({ keyword: '', isVal: false, page: 1, }) this.getData(); }, openDetail(e) { var item = e.target.dataset.item; if(this.data.isPl){ let num=0; this.data.dataList.map(e=>{ if(e.checked){ num++ } }) let dataList = this.data.dataList.map(e => { if(item.id==e.id){ if(num>=50&&!e.checked){ app.globalData.showToast('最多只能选择50条'); }else{ e.checked = !e.checked; } } return e; }) this.setData({ dataList: dataList, }) return false } dd.navigateTo({ url: '../reviewDetail/reviewDetail?id=' + item.id }) }, getData(type) { let dc_status=that.data.minuteIndex==0? "[0]":'[1,2]'; if(that.data.minuteIndex=="1"){ if(that.data.arrIndex==0){ dc_status='[1,2]' }else if(that.data.arrIndex==1){ dc_status='[1]' }else{ dc_status='[2]' } } let data={ dc_status:dc_status, page: that.data.page, order_key:that.data.minuteIndex=='0'? 'create_time':'update_time', page_size: 20, keyword: that.data.keyword, employee_ids:this.data.employee_ids } app.$get("api/integral/statistics/integral",data).then((res) => { var list = res.data.data.list || []; list.forEach(element => { element.checked = false if (element.pt_id) { element.pt_name = app.getTypesItem(element.pt_id).name } }); if(that.data.page==1){ this.setData({ dataList:[] }) } var dataList = that.data.dataList || []; if (type == '2') { this.setData({ dataList: dataList.concat(list), isData: list.length < 20 }) } else { this.setData({ dataList: list, isData: false }) } }) }, //上啦加载 onScrollToLower() { if (!that.data.isData) { this.setData({ page: ++that.data.page }) this.getData("2"); } }, });