<template>
	<view style="padding: 77rpx;box-sizing: border-box;">
		<!--pages/authorize/authorize.wxml-->
		<block>
			<view class="authorize-title">
				<view>您好，</view>
				<view>欢迎使用皮小电商家版</view>
			</view>
			<view style="margin-top: 50rpx;">
				<view class="input-box">
					<input v-model="userName" placeholder="请输入账号"/>
				</view>
				<view class="input-box ddflex">
					<input v-model="passWord" type="text" class="fflex" :password="!showPassword" placeholder="请输入密码" value="" />
					<view style="padding: 10rpx;">
						<image v-if="showPassword" @click="showPassword=false" style="width: 34rpx;height: 15rpx;margin-left: 10rpx;" src="../../static/pages/images/close-eyes.png"></image>
						<image v-else @click="showPassword=true" style="width: 31rpx;height: 23rpx;margin-left: 10rpx;" src="../../static/pages/images/open-eyes.png"></image>
					</view>
				</view>
			</view>
			
			<button class="login" @click="submitLogin()">授权登录</button>
			<view class="dflex">
				<image v-if='agree' class="agree-icon" src="../../static/pages/images/agree_h.png" @click="agree=false"></image>
				<image v-else class="agree-icon" src="../../static/pages/images/agree.png" @click="agree=true"></image>
				<view hover-class="none" class="xieyi fflex">
					已阅读并同意
					<text @click="jump('/mine/page/page?title=用户协议&isXieyi=true')">《皮小电用户服务协议》</text>
					与
					<text @click="jump('/mine/page/page?title=隐私声明&isYinsi=true')">《皮小电隐私协议》</text>
				</view>
			</view>
		</block>
		
	</view>
</template>

<script>
// pages/authorize/authorize.js
const app = getApp();
const req = require('../../utils/request.js');

export default {
	data() {
		return {
			showPassword:false,
			agree:false,
			userName:'',
			passWord:''
		};
	},

	components: {},
	props: {},
	onLoad: function(options) {
		
	},
	onShow: function() {
	},
	onUnload: function() {
		
	},
	methods: {
		jump(url) {
			uni.navigateTo({
				url: url
			});
		},
		submitLogin(){
			if(!this.userName) return req.msg('请输入账号')
			if(!this.passWord) return req.msg('请输入密码')
			if(!this.agree) return req.msg('请阅读以下协议')
			
			let dataP = {
				account:this.userName,
				password:this.passWord
			}
			
			req.postRequest('/admin/v2/login',dataP,res=>{
				let params = res;
				req.setStorage('userInfo', params);
				req.setStorage('AUTH_TOKEN', params.token);
				console.log(params.token)
				req.msg('登陆成功')
				uni.$emit('reSetLogin',true)
				setTimeout(()=>{
					uni.navigateBack()
				},500)
			})
		}
	}
};
</script>
<style>
@import './authorize.css';
</style>
