<template>
	<layout>
		<!-- #ifdef MP-WEIXIN -->
		<uv-navbar
		  :fixed="false"
		  :title="title"
		  left-arrow
		  @leftClick="$onClickLeft"
		/>
		<!-- #endif -->
		<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">意象CRM</view>
			<view class="font-size-base text-center text-color-assist mt-1 mb-5 ">实现线索到回款全流程管理</view>
			
			<view class="text-color-assist mb-2">账户</view>
			<uv-input placeholder="请输入账户" prefixIcon="account" border="bottom" v-model="username"></uv-input>
			<view class="text-color-assist mt-5 mb-2">密码</view>
			<uv-input placeholder="请输入密码" type="password" prefixIcon="lock" border="bottom" v-model="password"></uv-input>
			
			<button @tap="submit" style="" type="primary" class="login">立即登录</button>
			
		</view>
	<!-- 	<view class="buttom">
			<view class="hint">
					<radio value="isChecked" @tap.stop="onChange" />
					我已经阅读并遵守
					<text class="link" @tap="serv(29,'用户协议')">《用户协议》</text>与
						<text class="link"  @tap="serv(30,'隐私政策')">《隐私政策》</text>
			</view>
		</view> -->
		<uv-toast ref="uToast"></uv-toast>
	</view>
	</layout>
</template>

<script setup>
import {
  ref,
  computed
} from 'vue'
import { onLoad,onShow} from '@dcloudio/uni-app'
import { useMainStore } from '@/store/store'
import {
  userLogin
} from '@/api/auth'
import * as util  from '@/utils/util'
import { mobile as testMobible } from '@/uni_modules/uv-ui-tools/libs/function/test'
import cookie from '@/utils/cookie'
import router from '@/utils/router'
const main = useMainStore()
const title = ref('登录')
const username = ref('admin')
const password = ref('admin123')
const isChecked = ref(false)
const openid = ref(main.openid)
const uToast = ref()




onShow(() => {
   
	// #ifdef MP-WEIXIN
	if(!openid.value){
		//wechatMiniLogin();
	}
	
	// #endif
})



const check = () => {
	if(!isChecked.value){
		uToast.value.show({
			message: '请勾选下面协议',
			type: 'error'
		});
		return
	}
}

// 提交
const submit = () => {
	if (username.value == '') {
		uToast.value.show({
			message: '请填写账户',
			type: 'error'
		});
		return
	}
	
	if (password.value == '') {
		uToast.value.show({
			message: '请填写密码',
			type: 'error'
		});
		return
	}
	
	login()

}

// 登录
const login = async () => {
	let data = await userLogin({
		username: username.value,
		password: password.value,
		socialType: 34
	})
	if (data) {
		// uni.setStorage({
		// 	key: 'userinfo',
		// 	data: data.userInfo
		// });
		uni.setStorage({
			key: 'accessToken',
			data: data.accessToken
		});
		// main.SET_MEMBER(data.userInfo);
		main.SET_TOKEN(data.accessToken);
		uToast.value.show({
			message: '登录成功',
			type: 'success'
		});
		
		setTimeout(function() {
			uni.switchTab({
				url: '/pages/index/index'
			})
		}, 2000);
	}
}


const onChange = () => {
	isChecked.value = !isChecked.value
}

</script>

<style lang="scss" scoped>
.wrap {
	background-color: #ffffff;
	font-size: 28rpx;
	position: relative;
	height: 100%;
	padding-bottom: 100rpx;
	.content {
		width: 600rpx;
		margin: 0 auto;

		.title {
			text-align: center;
			font-size: 50rpx;
			font-weight: 500;
			padding-top: 100rpx;
			color: #09b4f1;
			font-weight: bolder;
		}

		.login {
			background-color: #09b4f1;
			color: #ffffff;
			border-radius: 50rem !important;
			font-size: 26rpx;
			padding: 8rpx 0;
			margin-top: 40rpx;
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $uv-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		bottom: 0;
		.loginType {
			padding: 30rpx 80rpx;
			//justify-content:space-between;
			
			.login-btn {
				background-color: #1aad19!important;
				width: 100%;
				font-size: 26rpx;
				border-radius: 50rem !important;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 8rpx 0;
				text-align: center;
				image {
					width: 36rpx;
					height: 30rpx;
					margin-right: 10rpx;
					vertical-align: middle;
				}
			}
		}
		
		.hint {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $uv-tips-color;
			
			.link {
				color: $uv-warning;
			}
		}
	}
}
</style>
