<!-- 账号密码登录 accountLogin  -->
<template>
  <view>
    <!-- 表单项 -->
    <u-form
      ref="accountLoginRef"
      labelWidth="140"
      labelAlign="left"
      labelPosition="top"
    >
      <u-form-item prop="loginName" label="账号">
        <view class="input-line">
					<u-input
							placeholder="请输入账号"
							v-model="model.loginName"
							border="none"
					></u-input>
        </view>
      </u-form-item>

      <u-form-item prop="password" label="密码">
        <view class="input-line">
					<input
						:type="passwordType"
						placeholder="请输入密码"
						v-model="model.password"
						border="none"
					>
					</input>
					<view class="eye-box" @click="eyeClick">
						<u-icon :name="eyeIcon"></u-icon>
					</view>
        </view>
      </u-form-item>
    </u-form>
  </view>
</template>

<script>
	import {login} from '@/common/request/apis/login'
	import md5 from '@/common/request/md5.js'
	export default{
		data() {
			return {
				model:{
					loginName:'',
					password:'',
				},
				passwordType:'password',
				eyeIcon:'eye-off'
			}
		},
		methods:{
			eyeClick() {
				if(this.passwordType == 'password') {
					this.passwordType = 'text'
					this.eyeIcon = 'eye'
				}else {
					this.passwordType = 'password'
					this.eyeIcon = 'eye-off'
				}
			},
			accountLoginSubmit() {
			  if(!this.model.loginName){
			  	return uni.$u.toast("请输入账号");
			  }
			  if(!this.model.password) {
			  	return uni.$u.toast("请输入密码");
			  }
				let params = {
					...this.model,
					password: md5(this.model.password)
				}
				login(params)
				.then(res=>{
					if(res.code == 200) {
						let err = {}
						if (res.data.msgTip === 'user can login') {
							let userInfo = {
								token:res.data.token,
								...res.data.user
							}
							this.$store.dispatch('userLogin',userInfo)
							console.log('userInfo======',userInfo)
						} else if (res.data.msgTip === 'user is not exist') {
							uni.$u.toast("用户不存在")
						} else if (res.data.msgTip === 'user password error') {
							uni.$u.toast("用户密码不正确")
						} else if (res.data.msgTip === 'user is black') {
							uni.$u.toast("用户被禁用")
						} else if (res.data.msgTip === 'tenant is black') {
							if (loginName === 'jsh') {
								uni.$u.toast("jsh用户已停用，请注册租户进行体验！")
							} else {
								uni.$u.toast("用户所属的租户被禁用")
							}
						} else if (res.data.msgTip === 'tenant is expire') {
							uni.$u.toast("试用期已结束，请联系客服续费")
						} else if (res.data.msgTip === 'access service error') {
							uni.$u.toast("查询服务异常")
						}
						
					}
				})
			}
		}
	}

</script>

<style lang="scss" scoped>
// @import "../index.scss";
.input-line {
	display: flex;
	align-items: center;
	width: 100%;
  background-color: #f5f7fb;
  border-radius: 16rpx;
  padding-left: 30rpx;
  height: 88rpx;
  box-sizing: border-box;
	
	input{
		width: 100%;
	}
}
.eye-box {
	width: 100rpx;
	height: 88rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}
</style>
