123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- 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;i<arr.length;i++){
- let str=arr[i].split('=');
- if(str[0]=='manager'){
- flag=true;
- that.setData({
- type:1,
- root:str[1]
- })
- }
- if(str[0]=='employee'){
- flag=true;
- that.setData({
- type:0,
- root:str[1]
- })
- }
- if(str[0]=='cgi'){
- // that.setData({
- // othercompanyflag:true
- // })
- app.globalData.clientype=str[1];
- }
- if(str[0]=='r'){
- this.setData({
- recruit:str[1]
- })
- }
- }
- this.login();
- }
- },
- suretap:function(){
- let str="";
- for(let i=0;i<this.data.nowtext.length;i++){
- str+=this.data.nowtext[i].name+',';
- }
- str=str.substring(0,str.length-1);
- this.setData({
- realorg:str,
- orgshow:false,
- nowtext:[]
- })
- },
- dothis:function(){},
- setnametap:function(e){
- this.setData({
- realname:e.detail.value
- })
- },
- setphonetap:function(e){
- this.setData({
- realphone:e.detail.value
- })
- },
- radioChange(e) {
- const that=this;
- let nowidx=that.data.nowidx,nowtext=that.data.nowtext,nowid=that.data.nowid,orgarr=that.data.orgarr,nowarr=that.data.nowarr;
- let obj={};
- obj.name=nowarr[e.detail.value].title;
- obj.id=nowarr[e.detail.value].id;
- nowid=nowarr[e.detail.value].id;
- // children的长度为0是说明没有子元素,endflag=true说明上一次的
- if(that.data.endflag==true){
- nowtext[nowtext.length-1]=obj;
- }else{
- nowtext.push(obj);
- }
- if(nowarr[e.detail.value].children.length>0){
- 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;i<arr1.length;i++){
- if(arr1[i].id==cid){
- if(e.currentTarget.dataset.type==0){
- that.setData({
- nowtext:[]
- })
- let obj1={};
- obj1.name=arr1[i].title;
- obj1.id=arr1[i].id;
- nowtext=[];
- }else{
- nowtext=nowtext.slice(0,e.currentTarget.dataset.type);
- // nowtext[nowtext.length]=[];
- }
- nowid=arr1[i].id;
- }
- }
- nowarr=arr1;
- nowidx=nowtext.length-1;
- that.setData({
- nowtext:nowtext,
- nowid:nowid,
- nowarr:nowarr,
- nowidx:nowidx
- })
- },
- forfun:function(arr,idx){
- let that=this,i=0;
- for(i;i<arr.length;i++){
- if(arr[i].id==idx){
- arr2=arr;
- return arr;
- }else if(arr[i].children.length>0){
- 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 () {
- // }
- })
|