<script>
	import { convertPromise } from './utils/header.js'
	import Permission from '@/js_sdk/wa-permission/permission'
	// import { SelectLocation } from "./utils/authPerission";
	export default {
		onLaunch: function() {
			const common = uni.getStorageSync("m-headers")
			if (!common) {
			        this.loadDevice();
			        this.loadNetwork();
			        // this.loadLocation();
			        this.loadUuid()
			}
			console.log('App Launch')
		},
		methods:{
			// 获取common当中的设备信息
			loadDevice: function() {
			    const that = this;
					
			    convertPromise('getSystemInfo').then(result => {
			    const deviceInfo = {
			        // token:uuidObtain,
					deviceType: result.deviceType,
			        appName: result.appName,
			        deviceId: result.deviceId,
			        device: result.osName,
					deviceName: result.platform,
			        appVersion: result.appWgtVersion,
			        osVersion: result.osVersion ? result.osVersion : result.system,
			        mobileType: result.model,
			        screenHeight: result.screenHeight,
			        screenWidth: result.screenWidth,
			        resolution: result.windowWidth + '*' + result.screenHeight
			    };
			
			    // 本地存储
			    uni.setStorage({
			        key: 'm-device-info',
			        data: JSON.stringify(deviceInfo),
			        success: function() {
			            console.log('m-device-info存储成功');
			        }
			    });
			}).catch(err => {
			    //that.toast('获取设备信息失败')
			    uni.showModal({
			        title: '"多典花"想访问您的设备信息',
			        content: '通过访问您的设备信息，提高您授信通过率。',
			        showCancel: false,
			        confirmText: '去设置',
			        success: function(res) {
			            if (res.confirm) {
			                Permission.gotoAppPermissionSetting()
			            }
			        }
			    });
			})
		},
		// 获取common当中的网络信息
		loadNetwork: function() {
			const that = this;
			convertPromise('getNetworkType').then(result => {
				const networkInfo = {
					networkStatus: result.networkType
				};
				// 网络信息存储
				uni.setStorage({
					key: 'm-network-info',
					data: JSON.stringify(networkInfo),
					success: function() {
						console.log('m-network-info存储成功');
					}
				});
			}).catch(err => {
			          that.toast('获取网络信息失败')
			})
		},
		//获取uuid
		loadUuid: function() {
					 // plus.device.uuid
			plus.device.getInfo({
			    success: function(e) {
			    const deviceInfo = {
			        token: e.uuid,
			    };
			    uni.setStorage({
			        key: 'm-load-udid',
			        data: JSON.stringify(deviceInfo),
			        success: function() {
						console.log('uuid存储成功');
			        }
			    })
			},
			fail: function(e) {
			     console.log('getDeviceInfo failed: ' + JSON.stringify(e));
			}
		 });
		},
		// 获取common当中的位置信息
		// loadLocation: function() {
		// 	const that = this;
		// 	// 苹果测试手机如果没有插入手机卡，获取定位之后会解析失败，报错
		// 	SelectLocation(() => {
		// 	    convertPromise('getLocation', {
		// 			type: 'wgs84',
		// 	         geocode: true
		// 	    }).then(result => {
		// 				const locationInfo = {
		// 				  lat: String(result.latitude),
		// 				  lng: String(result.longitude)
						  
		// 				};
		// 				uni.setStorage({
		// 				  key: 'm-location-info',
		// 				  data: JSON.stringify(locationInfo),
		// 				  success: function() {
		// 				    console.log('m-location-info存储成功');
		// 				  }
		// 				});
		// 	    }).catch(err => {
		// 	            console.log(err, '错误了')
		// 	            // that.toast('获取位置信息失败')
		// 			})
		// 	    })
		// 	}
		},
		onShow: function() {
			console.log('App Show')
		},
	
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
