<template>
  <view class="login">
    <image class="bg-iamge" src="../../static/img/login/login_back_img.png"></image>
    <view class="body">
      <view class="title">欢迎进入里海供销平台！</view>
      <view class="login-card">
        <view class="top">
          <view class="text item">
            <u-tabs :list="[{name:'账号登录'},{name:'手机登录'}]" @click="changeTabs" lineColor="#3274F9"
              itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;font-size: 32rpx;"></u-tabs>
          </view>
          <input v-if="current==0" class="mobile item" v-model="formData.account" placeholder="输入账号" />
          <input v-if="current==0" class="mobile item" v-model="formData.password" placeholder="输入密码" password
            type="safe-password" />
          <input v-if="current==1" class="mobile item" v-model="formData.account" placeholder="输入手机号" />
          <view v-if="current==1" class="code item">
            <input placeholder="输入验证码" v-model="formData.code" />
            <view class="get-code">获取验证码</view>
          </view>
          <view class="btn">
            <view>新用户注册</view>
            <view>忘记密码?</view>
          </view>
        </view>
        <button class="submit_btn" @click="login">登录</button>
      </view>
    </view>
  </view>
</template>

<script>
  import { loginAccount, test } from "@/api/oaUser.js"
  export default {
    data() {
      return {
        current: 0,
        formData: {
          account: 'admin123',
          password: 'qq123456',
          code: '',
          terminal: 6, //6是APP端
          scene: 1
        }
      };
    },
    methods: {
      changeTabs(e) {
        this.current = e.index;
        this.formData.scene = e.index + 1;
      },
      async login() {
        let that = this;
        // let res = await test();
        // console.log(res);
        let res = await loginAccount(that.formData);
        this.$store.commit('SET_USERINFO', {
          user: res.data.nickname,
          token: res.data.token
        })
        uni.switchTab({
          url: '/pages/oaHome/oaHome'
        })
        // uni.request({
        //   url: 'https://worker-task.lihaink.cn/api/login/account',
        //   method: 'POST',
        //   data: {
        //     account: 'admin123',
        //     terminal: '3',
        //     scene: '1',
        //     password: 'qq123456'
        //   },
        //   success: (res) => {
        //     console.log(res);
        //     this.res = res.data.m
        //   }
        // })

      },
      initTerminal() {
        // #ifndef APP-PLUS
        this.formData.terminal = 6;
        // #endif
        uni.getSystemInfo({
          success: (res) => {
            const platform = res.platform.toLowerCase();
            if (platform === 'ios') {
              this.formData.terminal = 5;
            } else if (platform === 'windows') {
              this.formData.terminal = 4;
            } else if (platform === 'mac') {
              this.formData.terminal = 4;
            } 
          }
        })
        // #ifdef H5
        this.formData.terminal = 3;
        // #endif
        // #ifdef MP-WEIXIN
        this.formData.terminal = 1;
        // #endif
      }
    },
    mounted() {
      this.initTerminal();
    }
  }
</script>

<style lang="scss">
  .login {
    width: 100vw;
    height: 100vh;
    position: relative;
    /* #ifdef H5 */
    background-image: url('../../static/img/login/login_back_img.png');

    /* #endif */
    .bg-iamge {
      width: 100vw;
      height: 100vh;
      position: absolute;
      z-index: -99;
    }

    .body {
      display: flex;
      flex-direction: column;
      align-items: center;

      .title {
        width: 694rpx;
        height: 74rpx;
        margin-top: 200rpx;
        margin-bottom: 51rpx;
        font-size: 53rpx;
        font-weight: 500;
        color: #FFFFFF;
        line-height: 68rpx;
        -webkit-background-clip: text;
      }

      .login-card {
        width: 694rpx;
        height: 643rpx;
        background: #FFFFFF;
        border-radius: 21rpx 21rpx 21rpx 21rpx;
        opacity: 1;
        box-sizing: border-box;
        padding: 38.5rpx 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;

        .top {
          display: flex;
          justify-content: space-evenly;
          flex-direction: column;

          .item {
            margin-bottom: 35rpx;
          }

          .text {
            font-size: 32rpx;
            font-weight: 500;
            color: rgba(0, 0, 0, 0.8);
            line-height: 35rpx;
          }

          .mobile,
          .code {
            width: 613rpx;
            height: 112rpx;
            background: #F5F5F5;
            border-radius: 56rpx 56rpx 56rpx 56rpx;
            opacity: 1;
            padding: 0 45.56rpx;
            box-sizing: border-box;
            font-size: 28rpx;
            font-weight: 400;
            color: #333;
            line-height: 35rpx;
          }

          .code {
            display: flex;
            justify-content: space-between;
            align-items: center;

            input {
              font-size: 28rpx;
            }

            .get-code {
              color: #3274F9;
            }
          }

          .btn {
            display: flex;
            justify-content: space-between;
          }
        }

        .submit_btn {
          width: 613rpx;
          height: 112rpx;
          background: #3274F9;
          border-radius: 56rpx 56rpx 56rpx 56rpx;
          opacity: 1;
          text-align: center;
          line-height: 112rpx;
          color: #FFFFFF;
          font-size: 35rpx;
          font-weight: 500;
        }
      }
    }

  }
</style>