import _ from '../../commons/js/commons' const app = getApp() Component({ //组件的属性列表 properties: { isShow: { type: Boolean, value: false }, userInfo:{ type: Object, value:"" }, //是否显示授权用户信息 isShowProfile: { type: Boolean, value: true }, //是否强制显示授权用户信息 isForceProfile: { type: Boolean, value:false }, title:{ type: String, value: '' }, cancelbtn:{ type: String, value: '' }, submitbtn:{ type: String, value: '' }, tip:{ type: String, value: '' }, type:{ type: String, value: '' }, zindex: { type: Number, value: 10 }, //专题模式登录样式 mode:{ type: String, value: '' }, modeDate:{ type: Object, value:"" }, }, //组件的初始数据 data: { isRunning:false, userCurrInfo:"", isBindMobile:false }, lifetimes: { attached: function () { // 在组件实例进入页面节点树时执行 if (this.data.type == "mobile") { if (!this.data.userInfo){ _.apiQuery.getUserInfo("",false).then(res => { this.setData({ userCurrInfo: res }) }) }else{ this.setData({ userCurrInfo: this.data.userInfo }) } } if (this.data.type == "userinfo") { _.userManager.isAuthUserInfo().then(re => { if (re) { this.setData({ isShowProfile:false }) }else{ this.setData({ isShowProfile:true }) } }) } }, detached: function () { // 在组件实例被从页面节点树移除时执行 this.setData({ isBindMobile:false, isShow:false }) }, }, /** * 组件的方法列表 */ methods: { //catchtap emptyfunc(){}, //授权用户信息 getUserProfile(){ let that = this if(!!that.data.isRunning) return; that.setData({ isRunning:true }); wx.getUserProfile({ desc:'获取你的昵称、头像、地区及性别',//不写不弹提示框 success:function(res){ let params = {}; params['userInfo'] = res.userInfo; _.apiQuery.putUserInfo(params).then(res => { that.setData({ isRunning:false }); that.successEvent() _.eventBus.emit("isShowProfile",false) }) }, fail:function(err){ that.setData({ isRunning:false }); wx.showToast({ title: '您拒绝授权,将无法进行更多操作!', icon: 'none', duration: 2000 }); } }) }, //授权手机号码 getPhoneNumber(e) { if (e.detail.errMsg && e.detail.errMsg.indexOf('ok') > -1){ let that = this; _.apiQuery.authUserPhone(e).then(res=>{ _.apiQuery.getUserInfo() this.setData({ isBindMobile: true }) }) }else{ app.printErrorClient('failGetPhoneNumber',['用户拒绝授权手机号码:'+JSON.stringify(e)]) } }, onShow:function () { this.setData({ isShow: true }); this.triggerEvent('onShow', { type: this.data.type }); }, onClose: function () { this.setData({ isShow: false }); this.triggerEvent('onClose', { type: this.data.type }); if(this.data.type=="mobile" && this.data.isBindMobile){ this.setData({ isBindMobile:false }) this.successEvent() } }, //成功回调方法 successEvent(){ this.triggerEvent('onSuccess', { type: this.data.type }); }, } })