import carhelp from '@/utils/mixin.js'
import * as API_WeiXin from '@/apis/weixin.js'

import {
	getUrlParam,
	getAlipayRedirectURI,
 
} from '@/utils'
var checkOpenId = true; //是否需要获取openId
var openId = carhelp.getOpenIdALI();

var app = {
	init: function() {
		 
		if (!openId) {
			this.getOpenId();
		} 
		
		
	},
	
	getOpenId() {
		
		const code = getUrlParam('auth_code');
		var openId= carhelp.getOpenIdALI()
		
		if (!openId) {
			if (!code) {
				
				var authUrl = document.URL//.replace('pages/parking/search', 'pages/parking/auth');
				window.location.href = getAlipayRedirectURI(process.car.VUE_APP_ALIAPPID, authUrl );
			} else {
				
				API_WeiXin.getDataByCodeALI(code).then(response => {
					
					carhelp.setOpenIdALI(response.data.openid)
					 location.reload();
				}).catch(error => {
					console.log(error);
				});
			}
		}
	}
}
module.exports = app
