enter.js 1.87 KB
var util = require('../../../utils/util.js')
import App from '../../../utils/api.js'
Page({
	onLoad(opt){
		if(util.cache('openid')){
			if(opt.id && opt.share){
				util.cache('lookseller',opt.id);
				wx.redirectTo({
					url:'../seller/menu?id='+opt.id
				})
			}else{
				this.setData({
				    openid:util.cache('openid')
				})
				if(util.cache('lookseller')){
					wx.redirectTo({
						url:'../seller/menu?id='+util.cache('lookseller')
					})
				}else{
					this.getsellerlist();
				}
				
			}
			
		}else{
			this.getopenid()
			
		}
		this.opt=opt;
	},
	getopenid(){
		wx.login({
		    //获取code
		    success: (login_res)=>{
		        console.log('cc',login_res.code)
		        var data = {
		            code: login_res.code,
		            appid: 'wx418f1d7cdeda26c1',
		        }
		        //获取openid
				App.Wechat.GetSellerOpenidByCode(data).then((json)=>{
					var openid = JSON.parse(json.data[0]).openid;//返回openid
					this.setData({
					    openid:openid
					})
					util.cache('openid',openid);
					if(this.opt.id && this.opt.share){
						wx.redirectTo({
							url:'../seller/menu?id='+opt.id
						})
					}else{
						this.getsellerlist();
					}
					
				})
		
		    },
			fail:(res)=>{
		        console.log('dddddd',res)
		    }
		})
	},
	getsellerlist(){
		App.Seller.GetSystemByOpenid({openid:this.data.openid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				if(json.data.auth==0){
					wx.reLaunch({
						url:'../../me/s_index'
					})
				}else{
					if(json.data.length==1){
						wx.reLaunch({
							url:'../../me/s_index?sellerid='+json.data[0].seller.id
						})
					}else{
						if(util.cache('sellerid')){
							wx.reLaunch({
								url:'../../me/s_index?sellerid='+util.cache('sellerid')
							})
						}else{
							wx.reLaunch({
								url:'../../currency/c_store'
							})
						}
						
						
					}
				}
				
			}
		})
	},
})