promise.js 2.38 KB
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
import App from '../../utils/api.js'
Page({
    data:{
        isselect:false
    },
    onShow:function(){
        this.alert=this.selectComponent('#confirmalert');
    },
    login:function(){
        this.getsellerlist();
    },
	getsellerlist(){
		App.Seller.GetSystemByOpenid({openid:this.data.openid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				if(json.data.auth==0){
					wx.navigateTo({             //无商家
					    url:'l_info'
					})
				}else{
					if(json.data.length==1){
						wx.redirectTo({
						    url:'../me/s_index?sellerid='+json.data[0].seller.id
						})
					}else{
						wx.reLaunch({
							url:'../currency/c_store'
						})
					}
				}
				
			}
		})
	},
    //重新调起授权后,想接口获取信息
    login_start(iv,encryptedData){
        console.log(iv,encryptedData)
        var that=this;
        wx.login({
            //获取code
            success: (login_res)=>{
                console.log('cc',login_res.code)
                var data = {
                    code: login_res.code,
                    appid: 'wx418f1d7cdeda26c1',
                    iv:iv,
                    encryptedData:encryptedData
                }
				App.Wechat.WxLogin(data).then((json)=>{
					if(json.ret==200){
						console.log(json);
						if(json.data && json.data.openid){
							this.setData({
								openid:json.data.openid
							})
							util.cache('openid',json.data.openid)
						}
						this.getsellerlist();
					}
				})
            }
        })

    },
    select:function(){
        this.setData({
            isselect:!this.data.isselect
        })
    },
    getuserinfo:function(e){
        console.log(e)
        if(e.detail && e.detail.errMsg=='getUserInfo:ok'){
            this.setData({
                username:e.detail.userInfo.nickName
            })
            wx.setStorageSync('nickname',e.detail.userInfo.nickName)
            var iv=e.detail.iv;
            var encryptedData=e.detail.encryptedData;
            this.login_start(iv,encryptedData)
        }else{
            this.alert.show('需要授权才能继续访问');
        }
    },
    reject:function(){
        let len=getCurrentPages().length;
        wx.navigateBack({
            delta: len
        })
    },
    lookagree:function(){
        wx.navigateTo({
            url:'agreement'
        })
    }
})