<template>
	<view class="container">
		<view class="form-border">
			<view class="title">
				智慧党建系统
			</view>
			<view class="title1">
				<!-- 信息管理系统 -->
			</view>
			<view class="form">
				<view class="name">
					<view class="name_icon">
						<image src="../../static/images/name.png" mode=""></image>
					</view>
					<input type="text" v-model="account" placeholder="请输入账号" />
				</view>
				<view class="name">
					<view class="name_icon">
						<image src="../../static/images/pwd.png" mode=""></image>
					</view>
					<input type="text" :password="showPassword" v-model="password" placeholder="请输入密码" />
					<view class="eyes" @click="showEyes()">
						<text v-if="showPassword==true" class="iconfont icon-yanjing-bi"
							style="font-size: 40upx;"></text>
						<text v-else class="iconfont icon-yanjing" style="font-size: 40upx; font-weight: bold;"></text>
					</view>
				</view>
				<view class="submit" @click="Login">
					登录
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Base64 from 'base-64';
	var app = getApp()
	import configData from '../../config.js'
	export default {
		data() {
			return {
				account: "2016184014",
				password: "qaz123456",
				showPassword: true
			}
		},
		onLoad() {
			console.log(configData, "ceshi")
		},
		methods: {
			showEyes: function() {
				this.showPassword = !this.showPassword
			},
			Login: function() {
				uni.showLoading()
				let date = {
					account: this.account,
					password: Base64.encode(this.password),
				}
				uni.request({
					// url: 'http://api.party.site.ximengnaikang.com/authorization',
					url: configData.data.baseUrl + '/authorization',
					data: date,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'type': 'weapp',
					},
					success: (res) => {
						if (res.statusCode == 200) {
							uni.hideLoading()
							uni.setStorageSync('token', res.data.data.access_token)
							uni.showToast({
								title: '登录成功',
								icon: 'none',
							})

							this.getUserInfo();
							this.getUserId()
						} else {
							console.log(res)
							uni.showToast({
								title: res.data.message || "登陆失败请重试",
								icon: 'none'
							})
						}
					}
				})

			},
			getUserInfo() {
				app.request('/staff-me', '', 'get').then(res => {
					console.log(res.data.data, '---------------------个人信息')
					uni.setStorageSync('userInfo', res.data.data)


				})

			},
			getUserId() {
				app.request('/authorization', '', 'get').then(res => {
					console.log(res, '------------')
					let is_reset_password = res.data.data.is_reset_password
					if (is_reset_password == 1) {
						uni.reLaunch({
							url: '/pages/login/changePwd'
						})
					} else {
						uni.switchTab({
							url: '../index/index'
						})
					}
					uni.setStorageSync('userId', res.data.data.id)
				})
			}
		}
	}
</script>

<style>
	page {
		width: 100vh;
		background-image: url(../../static/images/login.jpg);
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}

	.form-border {
		position: fixed;
		z-index: 300;
		width: 100%;
		top: 20%;
	}

	.title {
		color: #ff0000;
		font-size: 64upx;
		font-weight: bold;
		text-align: center;
		height: 120upx;
		line-height: 120upx;
		letter-spacing: 5upx;
	}

	.title1 {
		color: #80797a;
		font-size: 52upx;
		font-weight: bold;
		text-align: center;
		letter-spacing: 5upx;
		margin-bottom: 70upx;
	}

	.form {
		width: 70%;
		margin: 0 auto;
		padding: 30upx 30upx 70upx;
		background-color: rgba(255, 255, 255, 0.8);
		/* box-shadow: 3px 3px 5px #888888; */
	}

	.name {
		height: 90upx;
		display: flex;
		background-color: #ededed;
		margin-top: 40upx;
		position: relative;

	}

	.name input {
		flex: 1;
		font-size: 30upx;
		height: 90upx;
		color: #e61916;
		line-height: 90upx;
		padding-left: 20upx;
	}

	.name_icon {
		flex: 0 0 90upx;
		height: 90upx;

		overflow: hidden;
		text-align: center;
		background-color: #e65538;
	}

	.eyes {
		position: absolute;
		height: 90upx;
		width: 90upx;

		z-index: 30000;
		right: 0;
		line-height: 90upx;
		text-align: center;
		color: #e69d90;
		font-size: 40upx;
	}

	.name_icon image {
		width: 50upx;
		height: 50upx;
		margin-top: 20upx;
	}

	.submit {
		height: 70upx;
		background-color: #ffde13;
		line-height: 70upx;
		width: 90%;
		margin: 0 auto;
		color: #FFFFFF;
		font-size: 28upx;
		text-align: center;
		margin-top: 40upx;
	}
</style>
