<template>
	<view class="login">
		<view class="app_top">
			<view class="welcome">
				<view class="desc">您好,</view>
				<view class="desc">欢迎来到边民互市贸易</view>
			</view>
			<image src="../../static/images/my.png" mode="widthFix" class="img"></image>
		</view>
		<view class="dk">
			<view class="bg">
				<text class="icon">&#xe8b9;</text>
				<input type="number" v-model="form.phone" maxlength="11" placeholder="请输入手机号" />
			</view>
			<view class="bg">
				<text class="icon">&#xe8b2;</text>
				<input :password="show" v-model="form.password" placeholder="请输入密码" />
				<view class="label"><view class="icon" :class="{ active: !show }" @click="show = !show">&#xe7a6;</view></view>
			</view>
			<view class="xy">
				<u-checkbox-group class="checkbox" v-model="form.checked">
					<u-checkbox size="15" shape="circle" label="我已阅读并同意" labelSize="13" name="true"></u-checkbox>
				</u-checkbox-group>
				<text class="a" @click="go('/pages/login/userAgreement?id=1')">《用户协议》</text>
				<text>和</text>
				<text class="a" @click="go('/pages/login/userAgreement?id=2')">《隐私政策》</text>
			</view>
			<button class="btn" @click="submit()">登录</button>
			<button class="btn register" @click="go('/pages/login/chooseRole')">注册</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			show: true,
			form: {}
		};
	},
	onLoad() {
		//自动登陆
		if (uni.getStorageSync('token')) {
			uni.switchTab({ url: '/pages/index/index' });
			return;
		}
	},
	methods: {
		submit() {
			let rule = [
				{ name: 'phone', checkType: 'phone', errorMsg: '请输入正确的手机号码' },
				{ name: 'password', checkType: 'notnull', errorMsg: '请输入密码' },
				{ name: 'checked', checkType: 'notnull', errorMsg: '请同意并勾选协议' }
			];
			if (!this.verify.check(this.form, rule)) {
				uni.showModal({ content: this.verify.error, showCancel: false });
				return false;
			}
			this.http.request({
				url: '/sp-admin/app/AppUser/login',
				data: this.form,
				method: 'POST',
				success: resp => {
					let data = resp.data.data;
					console.log(data);
					uni.setStorageSync('token', data.tokenInfo.tokenValue);
					uni.setStorageSync('info', data.appUser);
					uni.setStorageSync('menu', data.per_list);
					uni.switchTab({ url: '/pages/index/index' });
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: white;
}
</style>
