<template>
	<view class="page_container">
		<custom-nav-bar title="关于我们" />
		<view class="logo_area">
			<image src="@/static/images/about_logo.png" mode=""></image>
			<view>{{ appversion }}</view>
			
			<info-item @click="checkUpdate" class="check" title="检测更新" content="" />
			<info-item @click="openurl('http://baidu.com')" class="check" title="官方网站" content="" />
			<info-item @click="goto('/pages/common/article?type=article&name=coom&title=商务合作')" class="check" title="商务合作" content="" />
			<info-item @click="goto('/pages/common/article?type=article&name=contract&title=用户协议')" class="check" title="用户协议" content="" />
			<info-item @click="goto('/pages/common/article?type=article&name=privacy&title=隐私政策')" class="check" title="隐私政策" content="" />
			<info-item @click="goto('/pages/common/article?type=article&name=aboutus&title=关于我们')" class="check" title="关于我们" content="" />
			<info-item @click="clearcache" class="check" title="清除缓存" content="" />
			<info-item @click="show = true" class="check" title="上传调试日志" content="" />

			<u-modal showCancelButton :show="show" title="上传日志" @confirm="uploadLog" @cancel="show = false">
				<view class="slot-content">
					<u--input placeholder="日志数量" border="surround" v-model="line"></u--input>
				</view>
			</u-modal>
		</view>
	</view>
</template>

<script>
	import IMSDK from "openim-uniapp-polyfill";
	import {version	} from '@/common/config'
	import CustomNavBar from "@/components/CustomNavBar/index.vue";
	import {PageEvents	} from "@/constant";
	import InfoItem from "../selfInfo/InfoItem.vue";
	import {checkUpgrade} from "@/api/login.js"
	export default {
		components: {
			CustomNavBar,
			InfoItem,
		},
		data() {
			return {
				show: false,
				line: 10000,
				appversion: "",
				loading: false,
			};
		},
		onLoad() {
			this.getAppVersion();
		},
		mounted() {
			IMSDK.subscribe('uploadLogsProgress', this.uploadHandler);
		},
		beforeDestroy() {
			IMSDK.unsubscribe('uploadLogsProgress', this.uploadHandler);
		},
		methods: {
			uploadLog() {
				this.show = false
				IMSDK.asyncApi('uploadLogs',IMSDK.uuid(), {
					line: this.line,
					ex: ""
				})
				uni.showLoading({
					title: '上传中',
					mask: true,
				});
			},
			uploadHandler({data: {current,size},}) {
				console.log('uploadHandler', current, size)
				if (current >= size) {
					uni.hideLoading();
					uni.showToast({
						title: "上传成功",
						icon: "none",
					});
					return;
				}
			},
			getAppVersion() {
				let system = uni.getSystemInfoSync();
				const _this = this;
				plus.runtime.getProperty(plus.runtime.appid,(inf) => {
					console.log(inf);
					_this.appversion = inf.version
				});
			},

			checkRespHandler() {
				this.loading = false;
			},
			goto(url){
				uni.navigateTo({
					url: url,
				});
			},
			clearcache(){
				
			},
			openurl(url){
				// #ifdef APP
				plus.runtime.openWeb(url)
				// #endif
				// #ifdef H5
					window.open(url);
				// #endif
			},
			// 验证是否升级
			checkUpdate() {
				this.loading = true;
				const _this = this;
				let system = uni.getSystemInfoSync();
				plus.runtime.getProperty(plus.runtime.appid, function(inf) {
					checkUpgrade({version:system.appVersion,platform:system.platform,version_wgt:inf.versionCode}).then(res=>{
						_this.loading = false;
						if(!res.data){
							uni.showToast({
								title:"已经是最新版本"
							})
							return ;
						}
						let skip_version = uni.getStorageSync('skip_version')
						if(res && res.version!=skip_version){
							uni.$emit('closeWebview')
							_this.setShow(_this.current, false)
							uni.navigateTo({
								url: '/pages/common/upgrade?model=' + JSON.stringify(res),
								animationType:"fade-in"
							});
						}
					})
				})
			},
		},
	};
</script>

<style lang="scss">
	.page_container {
		background-color: #f8f8f8;

		.logo_area {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin: 24rpx 24rpx 0 24rpx;
			background: #fff;
			border-radius: 6px;
			padding: 48rpx 0 16rpx 0;
			color: $uni-text-color;

			image {
				width: 72px;
				height: 72px;
				margin-bottom: 24rpx;
			}
		}

		.check {
			margin-top: 26rpx;
			border-top: 1px #e8eaef solid;
			padding: 20rpx;
			padding-bottom: 0;
			width: 90%;
		}

		.btn_row {
			padding: 0 44rpx;
		}
	}
</style>