<template>
  <div class="content">
    <img class="loginimg" src="../assets/images/login.png" alt="" />
    <div class="login">
      <div class="item">
        <van-cell-group>
          <van-field v-model="name" placeholder="请输入登录名" />
        </van-cell-group>
      </div>
      <div class="item">
        <van-cell-group>
          <van-field
            v-model="password"
            type="password"
            placeholder="请输入密码"
          />
        </van-cell-group>
      </div>
      <!-- <div class="item">
				<van-cell-group>
			       <van-field v-model="yzm" type="number"  placeholder="请输入验证码" />
			    </van-cell-group>
			</div> -->
      <div class="btn">
        <van-button type="primary" color="#0c2469" @click="login"
          >登录</van-button
        >
      </div>
      <div class="register">
        <!-- <router-link to="">新用户注册</router-link>
				<router-link to="/Forgetpassword">忘记密码</router-link> -->
      </div>
      <div style="font-size: 10px;text-align: center;padding-top: 1.625rem;">
        <a style="color: black" href="https://beian.miit.gov.cn"
          >沪ICP备2021029008号-1</a
        >
      </div>
    </div>
  </div>
</template>

<script>
import { employee_login } from "../api/index";
import { Toast, Dialog } from "vant";
export default {
  data() {
    return {
      name: "",
      password: "",
      yzm: ""
    };
  },
  created: function() {
    if (localStorage.getItem("name") != null) {
      this.name = localStorage.getItem("name");
    }
    if (localStorage.getItem("password") != null) {
      this.password = localStorage.getItem("password");
    }
  },
  methods: {
    //登录
    async login() {
      if (this.name == "" || this.name == undefined) {
        Toast("请输入登录名");
        return;
      }
      if (this.password == "" || this.password == undefined) {
        Toast("请输入登录名");
        return;
      }
      const regex = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u200B-\u200F\u202A-\u202E\u2028\u2029\uFEFF]/g;
      this.password = this.password.replaceAll(regex, "");
      this.name = this.name.replaceAll(regex, "");

      // this.$http.post(this.$store.state.host + "/appSysUser/employee_login", { account: this.name, password: this.password }, { emulateJSON: true })
      const res = await employee_login(
        { account: this.name, password: this.password,openId:localStorage.openid },
        { emulateJSON: true }
      );
      console.log("=====", res);
      //发送成功
      if (res.result == "success") {
        //localStorage
        localStorage.setItem("userId", res.userId);
        localStorage.setItem("roomId", res.roomId);
        localStorage.setItem("accountType", res.accountType);
        localStorage.setItem("name", this.name);
        localStorage.setItem("password", this.password);
        this.$router.push({ path: "/" });
      } else {
        Toast(res.message);
      }
    }
  }
};
</script>
<style scoped lang="less">
.content {
  height: 100vh;

  .loginimg {
    width: 3.48rem;
    margin: 0 auto;
    display: block;
    padding: 2.15rem 0.8rem;
  }

  .login {
    width: 5.8rem;
    margin: 0 auto;

    .item {
      border: 0.01rem solid #bfbfbf;
      border-radius: 0.1rem;
      margin-bottom: 0.5rem;
      background: white;
      overflow: hidden;
      color: #999999;
    }

    .item:nth-of-type(3) {
      margin-bottom: 0.2rem;
    }

    .btn {
      button {
        width: 100%;
      }
    }

    .register {
      font-size: 0.24rem;
      display: flex;
      justify-content: space-between;
      //margin-top: .2rem;
      margin-bottom: 0.2rem;

      a {
        color: #999999;
      }

      a:nth-of-type(1) {
        color: #02bfb3;
      }
    }
  }
}
</style>
