import carhelp from '@/apis/utils/mixin.js'

import * as API_WeiXin from '@/apis/weixin.js'
 
 var openId = carhelp.getOpenId();

var app = {
	init: function() {
		
		// #ifdef H5
			console.log("SIMPLE_RUN 模式，取配置固定openId  可修改SIMPLE_RUN ")
			carhelp.setOpenId(process.car.openId)
			
		// #endif
		
		// #ifdef MP-WEIXIN
			if(process.car.SIMPLE_RUN&& process.env.NODE_ENV === "development" ){
				console.log("SIMPLE_RUN 模式，取配置固定openId  可修改SIMPLE_RUN ")
				carhelp.setOpenId(process.car.openId)
				
			}else{
				if (!openId) {
					this.getOpenId()
				}
			}
			
		// #endif

	},
	 	
	getOpenId() {
		var openId = carhelp.getOpenId()
		if (!openId) {
		
			uni.login({
				provider: 'weixin',
				success: loginRes => {
					
					API_WeiXin.findAppletUserInfo(loginRes.code).then(response => {
						carhelp.setOpenId(response.data)
						//user_info 等属性 ，头像，名称，可通过授权获得  uniapp方法申请
						//carhelp.set("xpgj_wx_user_info",response.data)
						if(this.onload){
							this.onload();
						}						
					}).catch(error => {
						console.log(error);
					});
				}
			});
			
		}
	
	}

}
module.exports = app
