<template>
	<view class="zd_content bg">
		<view class="p1">欢迎来到</view>
		<view class="p2">恒森ACS手持系统！</view>
		<view class="input-box" style="margin-bottom: 20px">
			<view class="input-wrap">
				<view class="input-label">服务器地址</view>
				<input type="text" class="setup-input" placeholder="请输入服务器地址" v-model="addrip">
			</view>
		</view>
		<view class="zd-row" style="justify-content: flex-end;margin-bottom: 30rpx">
			<view class="zd-col-5 setup-text" @tap="isUpdate">升级版本</view>
		</view>
		<button class="login-btn" @tap="toLogin">进入</button>
		<view v-if="version !== ''" class="version-name">v{{version}}</view>
		<Up-grade v-if="grade === true" @closeUpdate="closeUpdate" :androidUrl="androidUrl"></up-grade>
	</view>
</template>

<script>
	import {handLogin, pdaUpdate} from '@/utils/getData2.js'
	import UpGrade from './upgrade.vue'
	export default {
		components: {
			UpGrade
		},
		data() {
			return {
				addrip: this.$store.getters.baseUrl,
				version: '',
				versionCode: '',
				grade: false,
				androidUrl: ''
			}
		},
		created () {
			//#ifdef APP-PLUS
				// 获取本地应用资源版本号
				plus.runtime.getProperty(plus.runtime.appid, (info) => {
					console.log(JSON.stringify(info));
					this.version = info.version;
					this.versionCode = info.versionCode ;
				}) 
			//#endif
		},
		methods: {
			isUpdate () {
				this._pdaUpdate()
			},
			toLogin() {
				if (this.addrip === '') {
					uni.showToast({
						title: '服务器地址不能为空',
						icon: 'none'
					})
					return
				}
				this.$store.dispatch('setConfig',{baseUrl: this.addrip})
				uni.redirectTo({
					url: '/pages/home/home'
				})
			},
			async _pdaUpdate () {
				try {
					let res = await pdaUpdate()
					this.grade = true
					this.androidUrl = res.url
				} catch (e) {
					console.log(e)
				}
				
			},
			closeUpdate () {
				this.grade = false
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.p1
  _font(60rpx,75rpx,#222)
  padding-top: 90rpx
.p2
  _font(50rpx,1,#222)
  padding: 40rpx 0 25rpx
  margin-bottom 10vh
.input-wrap
	width 100%
.input-label
	_font(30rpx,70rpx,#333)
	margin-bottom 2vh
.setup-input
	height 70rpx
	background #fff
	_font(30rpx,70rpx,#787878)
	border-bottom 1px solid #eeeeee
.bg
	background-color: #fff;
	_bis('../../static/image/login_bg.png', 100%,,bottom)
	padding: 92rpx 30rpx 82rpx 30rpx;
.login-btn
  width 100%
  border-radius 46rpx
  _font(36rpx,92rpx,#fff,,center)
  background-color $red
.zd_content
	position: relative
	height: 100%
.version-name
	width 100%
	position: absolute
	bottom: 30rpx
	_font(30rpx, 60rpx, #999,,center)
.setup-text
	_font(28rpx, 28rpx,$red,,right)
</style>
