<template>
	<view class="app-container">
		<uni-nav-bar ref="refTitle" dark :fixed="true" shadow background-color="#007AFF" status-bar 
					:title="title"/>
		<uni-section title="基本功能" subTitle="" type="line">
			<view class="warp">
				<button class="button" type="primary" @click="version">检查更新</button>
			</view>
			<view class="warp">
				<button class="button" type="primary" @click="moveReviewe">移位审核人</button>
			</view>
		</uni-section>
		<uni-section title="退出登录" subTitle="" type="line">
			<view class="warp">
				<button class="button" type="primary" @click="logOut">退出</button>
			</view>
		</uni-section>
	</view>
</template>

<script>
	import silenceUpdate from '@/uni_modules/rt-uni-update/js_sdk/silence-update.js'//引入静默更新
	import { latestEdition,download } from '@/api/wms/report.js'
	import request from '@/utils/request'
	
	export default {
		data() {
			return {
				title:"设置",
			};
		},
		methods:{
			logOut(){
				// 跳转到登录页面或其他需要重新登录的页面
				uni.navigateTo({
				    url: '/pages/login'
				});
			},
			version(){
				//获取版本号，必须为数字
				let edition_number = ""
				try{
					plus.runtime.getProperty(plus.runtime.appid,(inf) => {
						edition_number = inf.versionCode
						//获取版本号，如果没有缓存的版本号再取app的版本号
						//传参
						let params = {
							edition_number: edition_number
						}
						
						//查询新版本接口
						latestEdition(params).then(res => {
							if(res.code === 200 && res.data){
								let baseUrl = uni.getStorageSync("baseUrl");
								res.data.edition_url = res.data.edition_url.replace("${baseUrl}",baseUrl);
								if (res.data.package_type == 1 && res.data.edition_silence == 1) {
									//调用静默更新方法 传入下载地址
									silenceUpdate(res.data)
								} else {
									//跳转更新页面 （注意！！！如果pages.json第一页的代码里有一打开就跳转其他页面的操作，下面这行代码最好写在setTimeout里面设置延时3到5秒再执行）
									uni.navigateTo({
										url: '/uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update?obj=' +
											JSON.stringify(res.data)
									});
								}
							}else{
								uni.showToast({
									title: '已是最新版本',
									icon: 'none'
								})
							}
						});
					})
				}catch(e){}
			},
			moveReviewe(){
				uni.navigateTo({
				    url: "/pages/menu/stockMove/reviewerEdit"
				});
			},
		},
		onLoad: function (options) {
			this.$nextTick(() => {
				this.title = "设置("+ uni.getStorageSync('name') +")";
			});
		},
	}
</script>

<style lang="less">
	.warp .button{
		margin:5px;
	}
</style>
