<template>
	<view>
		<!-- <view class="profile_item ">
			<text>Country</text>
			<image src="../../static/img/right1.png" mode="" class="right_img"></image>
		</view>
		<view class="profile_item ">
			<text>Language</text>
			<image src="../../static/img/right1.png" mode="" class="right_img"></image>
		</view> -->
		<view class="profile_item " @click="gotopage(1)">
			<text>My account</text>
			<image src="../../static/img/right1.png" mode="" class="right_img"></image>
		</view>
		<view class="profile_item " @click="gotopage(2)">
			<text>Privacy policy</text>
			<image src="../../static/img/right1.png" mode="" class="right_img"></image>
		</view>
		<view class="profile_item " @click="gotopage(3)">
			<text>Legal</text>
			<image src="../../static/img/right1.png" mode="" class="right_img"></image>
		</view>
		<view class="set_button">
			<button @click="signOut">SIGN OUT</button>
		</view>
		<view class="edition">
			<view class="edition_title">DOPE PLUS</view>
			<text @click="bb">Version {{appver}}</text>
		</view>
		<!-- Download -->
		<uni-popup ref="inputDialog" type="dialog" :mask-click="false">
			<uni-popup-dialog ref="inputClose" title="Updated version" cancelText="Cancel" confirmText="Download"
				@confirm="dialogInputConfirm">
				<view>
					{{titleDow}}
				</view>
				<!-- <view style="position: absolute;right: 0px;bottom: 0%;width: 50%;height: 44px;z-index: 111;"></view> -->
			</uni-popup-dialog>
		</uni-popup>
	</view>

</template>

<script>
	import {
		defaultRequest2
	} from '../../api/index.js'
	export default {
		data() {
			return {
				appver: '',
				ver_url: '',
				titleDow: ''
			}
		},
		onShow() {
			this.getAppnum()
		},
		methods: {
			
			close() {
				this.$refs.inputDialog.close()
			},
			bb() {
				console.log();
				this.$refs.inputDialog.open()
				let data = {
					_action: 'getnewversion'
				}
				defaultRequest2(data).then(res => {
					console.log(res)
					this.titleDow = res.data.ver_text
				})
			},
			signOut() {
				let data = {
					_action: 'logout'
				}
				uni.showModal({
					title: 'Confirm SING OUT?',
					cancelText: "cancel", // 取消按钮的文字  
					confirmText: "confirm", // 确认按钮的文字  
					showCancel: true, // 是否显示取消按钮，默认为 true
					// confirmColor:'#ccc',
					// cancelColor: '#000',
					success: (res) => {
						if (res.confirm) {
							console.log('comfirm')
							defaultRequest2(data).then(res => {
								console.info(res)
								if (res.error == 0) {
									// uni.clearStorageSync()
									uni.setStorageSync('isLogin', 0)
									uni.setStorageSync('user_info', ' ')
									// uni.reLaunch({
									// 	url:'../login/index'
									// })
									uni.navigateTo({
										url: '../login/index'
									})
								}
							})

						} else {
							console.log('cancel')

						}
					}
				})

			},
			gotopage(a) {
				if (a == 1) {
					uni.navigateTo({
						url: './myProfile'
					})
				} else if (a == 2) {
					var urlStr = encodeURI("https://en.meixx.com/help/privacy.html")
					// plus.runtime.openURL(urlStr);
					uni.navigateTo({
						url: '../order/paypalWebview?src=' + urlStr
					})
				} else {
					var urlStr2 = encodeURI("https://dopeplus.com/help/Terms.html")
					// plus.runtime.openURL(urlStr);
					uni.navigateTo({
						url: '../order/paypalWebview?src=' + urlStr2
					})
				}
			},
			
			// Download
			dialogInputConfirm(e) {
				let data = {
					_action: 'getnewversion'
				}
				defaultRequest2(data).then(res => {
					console.log(res)
					this.ver_url = res.data.ver_url
					console.log(this.ver_url);
					plus.runtime.openURL(this.ver_url)
				})
			},
			getAppnum() {
				let data = {
					// _action: 'getnewversion',
					_action: 'getnewversion',
				}
				defaultRequest2(data).then(res => {
					const that = this
					console.log(res)
					res.data = that.ver_url
					if (res.error == 0) {
						let e = uni.getStorageSync('appdata')
						console.log(e)
						if (!res.data.ver_name) {
							// e.appver = '1.3.0'
							that.appver = e.appver
							uni.setStorageSync('appver', e.appver)
							uni.getStorageSync('appver', e.appver)
							that.appver = e.appver
							console.log(that.appver);
						} else {
							that.appver = res.data.ver_name
							console.log(that.appver);
						}
						uni.setStorage({
							key: that.appver,
							success: function() {
						  console.log("存储成功+++++++++++++++++++++++++++++")
							}
						})
					}
				})
			},
		},
		onLoad() {
			let that = this;
			let s = 0;
			let time = setInterval(() => {
				uni.getNetworkType({
					success: (res) => {
						console.log(res.networkType, s);
						if (res.networkType == 'none') {
							uni.showToast({
								icon: 'none',
								title: 'Please connect to the network',
								duration: 3000,
							})
						} else if (res.networkType !== 'none') {
							that.typee = 2;
							clearInterval(time);
						}
					}
				})
				s++;
			}, 1000);
			this.getAppnum()
		}
	}
</script>
<style lang="scss">
	page {
		border-top: 14.67rpx #F7F7F7 solid;
		padding-left: 26.67rpx;
		box-sizing: border-box;

	}
</style>
<style lang="scss" scoped>
	page {}

	.profile_item {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 24rpx;
		font-weight: bold;
		padding: 40rpx 0;
		padding-right: 33.33rpx;
		border-bottom: 1.33rpx #ECECEC solid;
		box-sizing: border-box;

		.right_img {
			width: 18.67rpx;
			height: 18.67rpx;
			margin-left: 20rpx;
		}

	}

	.profile_item:last-child {
		border-bottom: none;
	}

	.set_button {
		width: 686.67rpx;
		height: 73.33rpx;
		margin-top: 133.33rpx;

		button {
			background-color: #191919;
			font-size: 26.67rpx;
			color: white;
			font-weight: bold;
			height: 100%;
			line-height: 73.33rpx;
			border-radius: 0;
		}
	}

	.edition {
		position: fixed;
		bottom: 0;
		width: 100%;
		line-height: 50rpx;
		font-size: 20rpx;
		text-align: center;
		font-weight: bold;
		margin-bottom: 112rpx;

		.edition_title {
			font-size: 25.33rpx;
			margin-bottom: 16rpx;
		}
	}
</style>
