const app=getApp(),utils=require("../../../utils/http"); let arr2=[]; Page({ /** * 页面的初始数据 */ data: { realname:"", realphone:'', orgshow:false, rootid:1, loginFlag:true, canIUseGetUserProfile: false, orgarr:[], nowarr:[], nowtext:[], nowidx:'', nowid:'', endflag:false, realorg:"", type:0,//1是管理层,0是员工 root:'', focus:false, othercompanyflag:false, recruit:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const that=this; if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } this.setData({ orgshow:false, nowarr:[], nowtext:[], nowidx:'', nowid:'', realorg:'', }) if(!!options.scene){ options=unescape(options.scene); let arr=options.split('&'); console.log(arr) let flag=false; for(let i=0;i0){ that.setData({ endflag:false }) }else{ that.setData({ endflag:true }) } if(nowarr[e.detail.value].children.length>0){ nowarr=nowarr[e.detail.value].children; } if(nowidx===''){ nowidx=0; }else{ nowidx=nowtext.length-1; } that.setData({ nowtext:nowtext, nowid:nowid, nowarr:nowarr, nowidx:nowidx }) }, changeorgtap:function(e){ const that=this; if(e.currentTarget.dataset.type==(that.data.nowtext.length-1)){ return false; } that.setData({ endflag:false }) let nowidx=that.data.nowidx,nowtext=that.data.nowtext,nowid=that.data.nowid,orgarr=that.data.orgarr,nowarr=that.data.nowarr; const cid=nowtext[e.currentTarget.dataset.type].id; that.forfun(orgarr,cid); let arr1=arr2; for(let i=0;i0){ that.forfun(arr[i].children,idx) } } }, setorgtap:function(){ const that=this; that.setData({ orgshow:true, focus:true, nowarr:this.data.orgarr }) }, closetap:function(){ const that=this; that.setData({ orgshow:false, nowarr:[], nowtext:[], nowidx:'', }) }, login:function(){ var that=this; wx.showLoading(); wx.login({ success: function (data) { if (data.errMsg == 'login:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/code2session', data: { code:data.code, share:'' }, success: function (r) { if(r.data.code=='0'){ that.orgfun(); if(r.data.user!=null&&(!!r.data.user.headimgurl&&r.data.user.headimgurl!=""||!!r.data.user.nickname&&r.data.user.nickname!=""&&r.data.user.nickname!='游客')){ if(!!r.data.user.binded&&r.data.user.binded.state!='驳回'&&r.data.user.binded.state!='离职'){ wx.reLaunch({ url: '/pages/index/index', }) } app.globalData.personMsg=r.data.user; app.globalData.use_id=r.data.user.id; app.globalData.userflag=true;//有个人信息 that.setData({ loginFlag:true }) }else{ that.setData({ loginFlag:false }) } wx.hideLoading() } } }) } } }) }, orgfun: function () { const that=this; if(!!app.globalData.personMsg.phone){ that.setData({ realphone:app.globalData.personMsg.phone }) } utils.$post({ url: app.globalData.webUrl + 'api/users/org', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ root:that.data.root }, success: function (res) { if(res.data.code=='0'){ let arr=JSON.parse(res.data.data); that.setData({ orgarr:arr, nowarr:arr }) } } }) }, getUserInfoTap:function(res){ var that=this; if(res.detail.errMsg=='getUserInfo:ok'){ utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth url: app.globalData.webUrl + 'api/users/setUserInfo', data: { encryptedData:res.detail.encryptedData, iv:res.detail.iv, rawData:res.detail.rawData, signature:res.detail.signature, }, header: { 'Authorization':'bearer '+app.globalData.token }, success: function (r) { if(r.data.code=='0'){ that.setData({ loginFlag:true }) app.globalData.userflag=true;//有个人信息 }else{ wx.showToast({ title: r.data.msg, icon: "none", duration:2000 }); } } }) } }, getUserProfile:function(){ var that=this; wx.getUserProfile({ lang:'zh_CN', desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { if(res.errMsg=="getUserProfile:ok"){ utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth url: app.globalData.webUrl + 'api/users/setUserInfo', data: { encryptedData:res.encryptedData, iv:res.iv, rawData:res.rawData, signature:res.signature, }, header: { 'Authorization':'bearer '+app.globalData.token }, success: function (r) { if(r.data.code=='0'){ that.setData({ loginFlag:true }) app.globalData.userflag=true;//有个人信息 }else{ wx.showToast({ title: r.data.msg, icon: "none", duration:2000 }); } } }) } } }) }, getPhoneNumberTap:function(res){ var that=this; if(res.detail.errMsg=='getPhoneNumber:ok'){ utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth url: app.globalData.webUrl + 'api/users/setUserMobile', data: { encryptedData:res.detail.encryptedData, iv:res.detail.iv }, header: { 'Authorization':'bearer '+app.globalData.token }, success: function (r) { if(r.data.code=='0'){ app.globalData.personMsg.phone=r.data.mobile; that.setData({ realphone:r.data.mobile }) app.globalData.phone=true; that.logintap(); }else{ wx.showToast({ title: r.data.msg, icon: "none", duration:2000 }); } } }) } }, logintap: function () { const that=this; if(!that.data.realname){ wx.showToast({ title: "姓名不能为空", icon: "none", duration: 2000 }); return false; } if(!that.data.nowid){ wx.showToast({ title: "部门不能为空", icon: "none", duration: 2000 }); return false; } utils.$post({ url: app.globalData.webUrl + 'api/users/register', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ is_manager:that.data.type, phone:that.data.realphone, name:that.data.realname, orgid:that.data.nowid, recruit:that.data.recruit }, success: function (res) { if(res.data.code=='0'){ wx.showToast({ title: res.data.msg, icon: "none", duration: 2000 }); setTimeout(function () { wx.reLaunch({ url: '/pages/index/index', }) }, 2000) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.setData({ orgshow:false, nowarr:[], nowtext:[], nowidx:'', nowid:'', realorg:'', }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })