<template>
	<view class="wrapper">
		<view class="nav_area">
			<image src="../../static/pay/left.png" mode="" style="width: 50rpx;height: 50rpx;"></image>
			<image src="../../static/pay/help.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
		</view>
		<view class="icon_area">
			<image src="../../static/pay/success.png" mode="" class="success_icon"></image>
			<view class="success_txt">支付成功</view>
		</view>
		<view class="content_area">
			<view class="">
				<view class="title">请根据指引下载安装</view>
				<view class="subtitle">请根据指引步骤进行国家文化专网网络入网应用安装</view>
			</view>
			<view class="">
				<view class="s_title">1.应用下载</view>
				<view class="down_area">
					<view class="down_item">
						<view class="left_icon"></view>
						<view class="down_link">国家文化专网网络应用入口</view>
						<view class="right_icon" @click="zwdz()"></view>
					</view>
					<view class="down_item">
						<view class="left_icon"></view>
						<view class="down_link">手机绑定关联程序</view>
						<view class="right_icon" @click="downapp()"></view>
					</view>
				</view>
				<view class="s_title">2.输入设备安装码</view>
				<view class="">
					<input type="text" v-model="installationCode" placeholder="请输入" placeholder-style="color: #B7B7B7;" class="input_box">
				</view>
				<view class="s_title">3.交易中心账号绑定</view>
				<view class="">
					<input type="text" v-model="account" placeholder="默认为注册手机号" placeholder-style="color: #B7B7B7;" class="input_box">
				</view>
			</view>
		</view>
		<view class="footer_area">
			<button class="btn" @click="submit()">提交</button>
		</view>
	</view>
</template>

<script>
	import store from '@/store'
	// 校验登录
	import { checkLogin, showError } from '@/core/app'
	import * as UserApi from '@/api/user'
	
	export default {
		data() {
			return {
				installationCode: '',
				account: '',
				// dev refer
				devpath:"",
				//用户信息
				userInfo:[]
			}
		},
		onLoad(opt) {
			this.devpath = opt.dev
		},
		mounted() {
			// this.getUserInfo()
			this.mkdevsn()
			this.init()
		},
		methods: {
			// 生成安装码
			mkdevsn(){
				const dev = this.devpath
				const td = dev.charAt(2)
				// console.log(td)
				const tdd = dev.substring(2,-1).toUpperCase()+Date.now()
				this.installationCode = tdd
				
				this.account = this.userInfo.mobile
			},
			
			init(){
				if(checkLogin()==true){
					this.isLogin = true
					//console.log(this.userInfo)
					this.getUserInfo()
				}else{
					this.isLogin= false
					//this.$navTo("pages/login/index")
					showError("请登录后再操作",this.gotologin())
				}
			},
			// 专网地址
			zwdz(){
				const zwurl="http://10.24.4.14"
				window.location.href=zwurl
			},
			
			// 跳转到登录页
			handleLogin() {
			  !this.isLogin && this.$navTo('pages/login/index')
			},
			
			// 获取当前用户信息
			getUserInfo() {
			  const app = this
			  return new Promise((resolve, reject) => {
			    !app.isLogin ? resolve(null) : UserApi.info({}, { load: app.isFirstload })
			      .then(result => {
					 // console.log(result)
			        app.userInfo = result.data.userInfo
					app.account = result.data.userInfo.mobile
			        resolve(app.userInfo)
			      })
			      .catch(err => {
			        if (err.result && err.result.status == 401) {
			          app.isLogin = false
			          resolve(null)
			        } else {
			          reject(err)
			        }
			      })
			  })
			},
			
			//下载
			downapp(){
				const durl ="";
				//判断当前设备，切换到相应位置
				var u = navigator.userAgent;
				if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
					//alert('这是安卓手机')
					durl="https://pelerin.cn/CCDE.apk"
				} else if (u.indexOf('iPhone') > -1) {//苹果手机
					durl="https://bf-analyze.oss-cn-shenzhen.aliyuncs.com/test/planet"
					//alert('这是iPhone')
				} else if (u.indexOf('Windows Phone') > -1) {//winphone手机
					//alert('这是 windows Phone')
				}
				//
				window.location.href=durl
				    
			},
			//提交成功
			submit(){
				const app = this
				app.$navTo("pages/book/success")
			}
		}
	}
</script>

<style scoped>
.wrapper{
	color: #101010;
	padding-bottom: 160rpx;
}
.nav_area{
	height: 94rpx;
	padding: 0px 50rpx;
	padding-top: var(--status-bar-height);
	margin-bottom: 24rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.icon_area{
	text-align: center;
}
.success_icon{
	width: 220rpx;
	height: 220rpx;
}
.success_txt{
	font-size: 20px;
	margin: 20px 0px 35px;
}
.content_area{
	padding: 0px 50rpx;
}
.title{
	font-size: 26px;
	font-weight: bold;
	line-height: 50px;
}
.subtitle{
	color: #999;
	font-size: 13px;
	margin-bottom: 26px;
}
.s_title{
	font-size: 16px;
	margin-bottom: 10px;
}
.down_area{
	margin-bottom: 10px;
}
.down_item{
	height: 70rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.left_icon{
	width: 40rpx;
	height: 40rpx;
	background-image: url("../../static/pay/install.png");
	background-size: cover;
}
.down_link{
	font-size: 12px;
	flex: 1;
	margin: 0px 40rpx;
}
.right_icon{
	width: 40rpx;
	height: 40rpx;
	background-image: url("../../static/pay/download.png");
	background-size: cover;
}
.input_box{
	width: 640rpx;
	height: 90rpx;
	padding: 0px 40rpx;
	box-sizing: border-box;
	background-color: #f8f8f8;
	font-size: 14px;
	margin-bottom: 26px;
}
.footer_area{
	width: 100vw;
	height: 100rpx;
	position: fixed;
	bottom: 60rpx;
	left: 0px;
}
.footer_area .btn{
	width: 100%;
	height: 100%;
	font-size: 16px;
	color: #fff;
	background-color: #10476E;
	border-radius: 0px;
	line-height: 100rpx;
}
</style>
