// pageage/safetyManagement/addSafetyInspect/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { maxDate:new Date(2088,1,1).getTime(), deptName:"", userId:"", myUserId:"", nickName:"", loginName:"", projectId:"", projectName:"", procInsId:"", infoData:{}, procDefName:"", deployId:"", activeName:"", flowNodeList:[], flowNodes:[], taskId:"", procInsId:"", taskName:"", passState:true, backName:"", stopShow:false, deleteShow:false, revocationShow:false, finishTime:"", ret:"", comment:"", stopBtnShow:false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let {deployId,procInsId,procDefName,deptName,nickName,taskId,taskName,projectName,userId,finishTime,ret} = options //获取缓存数据 wx.getStorage({ key: 'userinfo', success:res=>{ this.setData({ projectId:app.globalData.projectId, projectName, procInsId, procDefName, deployId, deptName, nickName, taskId, taskName, userId, finishTime, ret, myUserId:res.data.userId, loginName:res.data.loginName, }) this.getFlowNodes(); this.getFlowRecordList(); this.getFormDatasList(); } }) }, getFlowNode(val){ let flowNodeList = this.data.flowNodeList; for(let i=0;i0){ return this.getFlowNode(flowNodeList[i].outgoingFlows[0].targetRef); } } } }, //查询工作流节点 getFlowNodes(){ let that = this; wx.request({ url: app.globalData.reqUrl + '/wechat/flowTask/readNotes/'+that.data.deployId, method:"get", data:{}, header: { "Content-Type": "application/json" }, success(res){ res = res.data if(res.code == 200){ that.setData({ flowNodeList:res.data }) if(res.data.length>0){ let list = that.data.flowNodes; list.push({id:res.data[0].id,name:res.data[0].name,state:'pass'}); that.setData({ flowNodes:list }) return that.getFlowNode(res.data[0].outgoingFlows[0].targetRef); } }else{ app.toast(res.msg); } } }) }, //查询审批日志 getFlowRecordList(){ let that = this; wx.request({ url: app.globalData.reqUrl + '/wechat/flowTask/findCommentByProcInsId', method:"get", data:{ procInsId:this.data.procInsId }, header: { "Content-Type": "application/json" }, success(res){ res = res.data if(res.code == 200){ that.setData({ flowRecordList:res.data }) let list=[]; res.data.forEach(item=>{ if(item.deleteReason){ item.deleteReason=that.getDeleteReason(item.deleteReason); } if(item.duration){ item.duration=that.getDurationDate(item.duration); } list.push(item); }) that.setData({ flowRecordList:list }) }else{ app.toast(res.msg); } } }) }, //查询审批表单参数 getFormDatasList(){ let that = this; wx.request({ url: app.globalData.reqUrl + '/wechat/flowTask/findFormDatasByProcInsId', method:"get", data:{ procInsId:this.data.procInsId }, header: { "Content-Type": "application/json" }, success(res){ res = res.data if(res.code == 200){ that.setData({ infoData:res.data, stopShow:!that.data.finishTime && that.data.userId==that.myUserId, deleteShow:!that.data.finishTime && that.data.userId==that.myUserId, revocationShow:!that.data.finishTime }) }else{ app.toast(res.msg); } } }) }, //退回 onStop(){ if(!this.data.stopBtnShow){ app.toast("请填写终止原因!") this.setData({ stopBtnShow:true }) return; }else{ if(this.data.comment==""){ app.toast("请填写终止原因!") this.setData({ stopBtnShow:true }) return; } } this.setData({ loadShow:true }) let that = this let params = { instanceId:this.data.procInsId, comment:this.data.comment, userId:this.data.myUserId, taskId:this.data.taskId } //弹出确认 wx.showModal({ title: '提示', content: '是否终止当前流程申请?', success: function (sm) { if (sm.confirm) { wx.request({ url: app.globalData.reqUrl + '/wechat/flowTask/stopProcess', method:"POST", data:params, header: { "Username": that.data.loginName, "Content-Type": "application/json" }, success(res){ that.setData({ loadShow:false }) res = res.data if(res.code == 200){ app.toast("终止流程申请成功!") if(that.data.ret=="finished"){ setTimeout(()=>{ wx.redirectTo({ url: '../finished/index', }) },200) }else{ setTimeout(()=>{ wx.redirectTo({ url: '../myProcessIns/index', }) },200) } }else{ app.toast(res.msg); } } }) } else if (sm.cancel) { that.setData({ loadShow:false }) console.log('用户点击取消'); } } }) }, //通过 onDelete(){ this.setData({ loadShow:true }) let that = this //弹出确认 wx.showModal({ title: '提示', content: '是否确认删除流程申请?', success: function (sm) { if (sm.confirm) { wx.request({ url: app.globalData.reqUrl + '/wechat/flowTask/delete/'+that.data.procInsId, method:"delete", data:{}, header: { "Username": that.data.loginName, "Content-Type": "application/json" }, success(res){ that.setData({ loadShow:false }) res = res.data if(res.code == 200){ app.toast("删除流程申请成功!") if(that.data.ret=="finished"){ setTimeout(()=>{ wx.redirectTo({ url: '../finished/index', }) },200) }else{ setTimeout(()=>{ wx.redirectTo({ url: '../myProcessIns/index', }) },200) } }else{ app.toast(res.msg); } } }) } else if (sm.cancel) { that.setData({ loadShow:false }) console.log('用户点击取消'); } } }) }, //撤回 onRevocation(){ this.setData({ loadShow:true }) let that = this let params = { procInsId: this.data.procInsId, instanceId: this.data.procInsId, taskId:this.data.taskId, userId:this.data.myUserId, assignee:this.data.nickName } //弹出确认 wx.showModal({ title: '提示', content: '是否确认撤回当前任务流程?', success: function (sm) { if (sm.confirm) { wx.request({ url: app.globalData.reqUrl + '/wechat/flowTask/revokeProcess', method:"POST", data:params, header: { "Username": that.data.loginName, "Content-Type": "application/json" }, success(res){ that.setData({ loadShow:false }) res =res.data if(res.code == 200){ app.toast("撤回流程申请成功!") if(that.data.ret=="finished"){ setTimeout(()=>{ wx.redirectTo({ url: '../finished/index', }) },200) }else{ setTimeout(()=>{ wx.redirectTo({ url: '../myProcessIns/index', }) },200) } }else{ app.toast(res.msg); } } }) } else if (sm.cancel) { that.setData({ loadShow:false }) console.log('用户点击取消'); } } }) }, // 手风琴 onChange(event) { this.setData({ activeName: event.detail, }); }, getDeleteReason(val){ val = val.replace("Change activity to ",""); let flowRecordList = this.data.flowRecordList; for(let i=0;i0){ if(days<10) days = "0"+days; if(hours<10) hours = "0"+hours; if(minutes<10) minutes = "0"+minutes; if(seconds<10) seconds = "0"+seconds; return days + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒'; } if(hours>0){ if(hours<10) hours = "0"+hours; if(minutes<10) minutes = "0"+minutes; if(seconds<10) seconds = "0"+seconds; return hours + '小时' + minutes + '分钟' + seconds + '秒'; } if(minutes>0){ if(minutes<10) minutes = "0"+minutes; if(seconds<10) seconds = "0"+seconds; return minutes + '分钟' + seconds + '秒'; } if(seconds>0){ if(seconds<10) seconds = "0"+seconds; return seconds + '秒'; } }, //选择退回节点 onSelectTargetKey(e){ this.setData({ targetKey:e.detail.id, backName:e.detail.name }) }, returnToPage: function () { /*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/ if(this.data.ret=="finished"){ wx.redirectTo({ url: '../finished/index', }) }else{ wx.redirectTo({ url: '../myProcessIns/index', }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })