<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-03-21 15:37:55
 * @Description: file content
 * @FilePath: \oms\pages\login\index.vue
-->
<template>
  <view class="login">
    <view class="nav">
      <view :style="{ paddingTop }">
        <view class="title" :style="[{ height }, { lineHeight: height }]">
          <text>OMS</text>
        </view>
      </view>
    </view>
    <view class="main">
      <view class="bg flex1">
        <view class="tips">欢迎使用OMS</view>
        <image class="login-img" src="../../static/images/login.png" mode="scaleToFill" />
      </view>
      <u-form :model="loginForm" :rules="rules" ref="loginForm" label-width="0">
        <u-form-item prop="username" customStyle="padding-top:38rpx;border-bottom:1px solid #CDCDCD">
          <u-input placeholder="请输⼊账号" v-model="loginForm.username" border="none" clearable></u-input>
        </u-form-item>
        <u-form-item prop="password" customStyle="padding-top:38rpx;border-bottom:1px solid #CDCDCD">
          <u-input
            placeholder="请输⼊密码"
            :password="true"
            v-model="loginForm.password"
            border="none"
            clearable></u-input>
        </u-form-item>
      </u-form>
      <view style="padding-top: 30rpx">
        <u-checkbox-group v-model="loginForm.rememberPassword">
          <u-checkbox shape="circle" label="记住密码" name="checked"></u-checkbox>
        </u-checkbox-group>
      </view>
      <u-text
        color="#CDCDCD"
        size="20rpx"
        customStyle="padding-top:32rpx"
        text="登录代表您已同意用户协议及隐私条款"></u-text>
      <view class="login-btn" @click="handleLogin()">登录</view>
      <view class="footer">
        <u-text color="#646464" size="24rpx" align="center" text="由-青岛大数华创科技有限公司 提供技术支持"></u-text>
      </view>
    </view>
  </view>
</template>
<script>
  import { mapActions } from 'vuex'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    data() {
      return {
        height: '',
        paddingTop: '',
        loginForm: {
          username: '',
          password: '',
          rememberPassword: [],
        },
        rules: {
          username: {
            type: 'string',
            required: true,
            message: '请填写账号',
            trigger: ['blur'],
          },
          password: {
            type: 'string',
            required: true,
            message: '请填写密码',
            trigger: ['blur'],
          },
        },
      }
    },
    onLoad() {
      // 检查本地存储是否保存了用户名和密码
      const userInfo = uni.getStorageSync('userInfo')
      if (userInfo) {
        this.loginForm.username = userInfo.username
        this.loginForm.password = userInfo.password
        this.loginForm.rememberPassword = ['checked']
      }
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    mounted() {},
    methods: {
      ...mapActions(['login']),
      async handleLogin() {
        const [valid] = await to(this.$refs.loginForm.validate())
        if (valid !== null) return
        await this.login(this.loginForm)
      },
    },
  }
</script>
<style>
  page {
    background: #fff;
  }
</style>
<style lang="scss" scoped>
  .login {
    padding-top: 188rpx;

    .nav {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      background: #ffffff;
      .title {
        position: relative;
        text-align: center;
        font-size: 32rpx;
        font-weight: bold;
        color: #000;
        .back {
          position: absolute;
          top: 0;
          bottom: 0;
          margin: auto;
          left: 70rpx;
          display: flex;
        }
      }
    }

    .main {
      position: absolute;
      width: 100%;
      height: calc(100vh - 188rpx);
      background: #ffffff;
      padding: 0 88rpx 0 90rpx;
      .bg {
        padding-top: 40rpx;
        .tips {
          font-size: 46rpx;
          font-weight: bold;
          color: #060606;
        }
        .login-img {
          width: 292rpx;
          height: 292rpx;
        }
      }
      .login-btn {
        margin-top: 42rpx;
        width: 100%;
        height: 92rpx;
        background: #3e7ef8;
        border-radius: 32rpx;
        font-size: 32rpx;
        color: #ffffff;
        text-align: center;
        line-height: 92rpx;
      }
      .footer {
        position: absolute;
        bottom: 100rpx;
        left: 0;
        right: 0;
        margin: auto;
      }
    }
  }
</style>
