<template>
	<view class="oldlogin">
		<view class="status_bar"></view>
		<view class="oldlogin_img_area">
			<image class="oldlogin_img" src="../../static/loginimg.png" mode="widthFix"></image>
			<view class="oldlogin_img_text">
				{{loginName.substring(0,3)}}****{{loginName.substring(7,11)}}
			</view>
		</view>

		<view class="mt-50 mlr-60 card_area">
			<view class="flex-n fac card_area_item">
				<view class="card_icon  iconfont iconsuotou"></view>
				<view class="flex-n fac ml-19 card_content flex-1">
					<z-input class="card_input  flex-1 mr-20" align="left" :type="switchSave?'':'password'"
						v-model="passWord" placeholder="登录密码"></z-input>
					<switch :checked="switchSave" @change="changeswitchSave" />
				</view>
			</view>
		</view>
		<z-button width="630" class="mt-70" @click="login">登 录</z-button>

		<view class="flex-n fac fja mt-60">
			<view class="oldlogin_text" @click="gotoForgetPage">
				忘记登录密码
			</view>
			<view class="oldlogin_text" @click="switchMode=true">
				切换登录方式
			</view>
		</view>
		<z-select-popup :visible.sync="switchMode">
			<view @click="userOther">使用其他账号登录</view>
		</z-select-popup>
		<z-message></z-message>
	</view>
</template>

<script>
	const app = getApp({
		allowDefault: true
	});
	export default {
		data() {
			return {
				switchSave: false,
				switchMode: false,
				loginName: '15940515817',
				passWord: ''
			};
		},
		mounted() {
			//获取重新修改的登录信息,之前的手机号
			uni.getStorage({
				key: 'loginName',
				success: (res) => {
					this.loginName = res.data;
				}
			})

		},
		methods: {
			login() {
				// app/account/login
				this.$axios.post('account/login', {
					// loginName:this.loginName,
					loginName: 'admin',
					passWord: this.passWord
				}).then(res => {
					console.log(res.data)
					console.log(app.globalData)
					app.globalData.authorization = res.data.Authorization;
					let storeId='';
					if (res.data.storeId) {
						storeId = res.data.storeId;
					} else {
						storeId=res.data.store[0].storeId||''
					}
					uni.setStorage({
						key: 'storeId',
						data:storeId
					})
					
					app.globalData.userId = res.data.userId;
					
					uni.setStorage({
						key:'userInfo',
						data:res.data
					})
					uni.setStorage({
						key: 'loginName',
						data: this.loginName
					})
					this.$store.state.dicChange = true;
					uni.setStorage({
						key: 'passWord',
						data: this.passWord
					})

					uni.switchTab({
						url: '../remind/index/index',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}).catch(err => {
					console.log(err)
					uni.showToast({
						title: err.msg,
						icon: 'none',
						duration: 2000
					})
				})
			},
			userOther() {
				uni.redirectTo({
					url: './newlogin'
				})
			},
			changeswitchSave(e) {
				this.switchSave = e.detail.value;
			},
			gotoForgetPage() {
				uni.navigateTo({
					url: '../center/setting/forgetpass',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.oldlogin {
		width: 100%;
		height: 100vh;
		overflow: hidden;
		background: url(../../static/login_bg.png);
		background-size: 100% auto;
		background-repeat: no-repeat;
		background-position: left bottom;

		.status_bar {
			height: var(--status-bar-height);
		}

		.oldlogin_img_area {
			text-align: center;

			.oldlogin_img {
				width: 200rpx;
				margin-top: 100rpx;
				border-radius: 200rpx;
				background: white;
				border: 5rpx solid #AAAAAA;
				border-radius: 50%;
			}

			.oldlogin_img_text {
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
			}
		}

	}

	.card_area {
		.card_area_item {
			height: 100rpx;
		}

		.card_icon {
			min-width: 40rpx;
			font-size: 40rpx;
			color: #2481EE;
		}

		.card_content {

			border-bottom: 1px solid #B8B8B8;
		}

		.card_input {
			padding: 20rpx 0;
		}
	}

	.oldlogin_text {
		font-size: 24rpx;
		color: #2481EE;
	}
</style>
