var prefix = 'jp_charging_' + process.car.NODE_ENV+process.car.envjs + '_';

var app = {
	getGzDate : (key) => {
		var tdate=new Date( ).toJSON().substr(0,16).replace("T"," ")
		var date= uni.getStorageSync( prefix + "is_gz_date")
		
		if(tdate==date){
			return false
		}else{
			return  true;
		}
		
	},
	
	setGzDate : () => uni.setStorageSync(prefix + "is_gz_date", new Date( ).toJSON().substr(0,16).replace("T"," ") ),
	
	getGunIdCharge :()=>{

		var date= uni.getStorageSync( prefix + "GunId_Date_charge")
		var now=new Date().getTime()
		if(date+5*60*1000>now){
			return  uni.getStorageSync(prefix +  "GunId_Date_Show_charge")
		}else{
			return "";
		}
	},
	
	setGunIdCharge : ( value) => {
		uni.setStorageSync(prefix + "GunId_Date_Show_charge", value)
		uni.setStorageSync(prefix + "GunId_Date_charge", new Date().getTime())
		
	},
	// getGunId :()=>{
	// 	var date= uni.get( "GunId_Date")
	// 	var now=new Date().getTime()
	// 	if(date+5*60*1000<now){
	// 		return  uni.get( "GunId_Date_Show")
	// 	}else{
	// 		return "";
	// 	}
	// },
	
	// setGunId : ( value) => {
	// 	uni.setStorageSync(prefix + "GunId_Date_Show", value)
	// 	uni.setStorageSync(prefix + "GunId_Date", new Date().getTime())
		
	// },
	
	getPrefix:()=> prefix,
	get : key =>  uni.getStorageSync(prefix + key),

	set : (key, value) => uni.setStorageSync(prefix + key, value),
	remove: key =>  uni.removeStorageSync(prefix + key),
	setConfig : (value) => uni.setStorageSync(prefix + '_config_$', value),
	getConfig : () => {
		var config = uni.getStorageSync(prefix + '_config_$')
		var configure={}
		if(config){
			for(var  i in config){
				var con=config[i];
				
				if(process.car.branchParameter=="youdian"){
					
					configure[con.key]=con.valueUd
				}else{
					configure[con.key]=con.value
				}
				
				
			}
		}
		 return configure;
	},
	
	setConfigMessage : (value) => uni.setStorageSync(prefix + '_config_tips_$', value),
	getConfigMessage : () => {
		var config = uni.getStorageSync(prefix + '_config_tips_$')
		if(!config){
			config=[]
		}
		 return config;
	},
	
	logoff:()=>{
		uni.removeStorageSync(prefix + 'token_tdate')
		uni.removeStorageSync(prefix + 'token')
		uni.removeStorageSync(prefix  + 'personInfo');
		uni.removeStorageSync(prefix + 'personInfoPlus');
		uni.removeStorageSync(prefix + 'getElderModeClass');
		//uni.removeStorageSync(prefix+'wx_openId');
		
	},
	
	getPersonInfo : () => {
		 return uni.getStorageSync(prefix + 'personInfo')
	},
	getPersonInfoPlus : () => {
		 return uni.getStorageSync(prefix + 'personInfoPlus')
	},
	signOut:()=>  uni.removeStorageSync(prefix  + 'personInfo'),
	getOpenId : () =>   uni.getStorageSync(prefix + 'wx_openId'+process.car.VUE_APP_WXAPPID),
	setOpenId : (value) => uni.setStorageSync(prefix + 'wx_openId'+process.car.VUE_APP_WXAPPID, value),
	
	getOpenIdALI : () =>   uni.getStorageSync(prefix + 'ali_openId'+process.car.VUE_APP_WXAPPID),
	setOpenIdALI : (value) => uni.setStorageSync(prefix + 'ali_openId'+process.car.VUE_APP_WXAPPID, value),
	
	getUserInfo : () => {
		 return uni.getStorageSync(prefix + 'xpgj_wx_user_info')
	},

	setPersonInfo : (value) => uni.setStorageSync(prefix + 'personInfo', value),
	setPersonInfoPlus : (value) => uni.setStorageSync(prefix + 'personInfoPlus', value),
	
	setUserInfo : (value) => uni.setStorageSync(prefix + 'xpgj_wx_user_info', value),
	
	getToken : (options) => {
		//不同权限 ，不同token
		if(options&&options.jp_identity){
			return uni.getStorageSync(prefix+options.jp_identity+ '_token')
		}else{
			return uni.getStorageSync(prefix + 'token')
			
		}
	},
	setToken : (value) => {
		uni.setStorageSync(prefix + 'token', value)
		
		if(value){
			var tdate=new Date( +new Date() + 8 * 3600 * 1000 ).toJSON().substr(0,15).replace("T"," ")
			uni.setStorageSync(prefix + 'token_tdate', tdate)
		}
	}
	,
	getGetElderModeClass : () => {
		 return uni.getStorageSync(prefix + 'getElderModeClass')
	},
	setGetElderModeClass : (value) => uni.setStorageSync(prefix + 'getElderModeClass', value),
	
}

module.exports = app
