<template>
  <view class="content">
    <view class="top">
      <view class="inputs" >
        <input type="text" v-model="userName" placeholder="请输入用户名">
      </view>
      <view class="inputs">
        <input type="password"  v-model="wrod" placeholder="请输入密码">
      </view>
    </view>

    <view class="dl" @click="getlogin()">
      <text>登 录</text>
    </view>
  </view>
</template>

<script>
import request from '../../utils/request';
import {setToken, setTenantId} from '../../utils/auth.js'
import {
  getTenantIdByWebsite
} from '@/api/login.js'
export default{
  data(){
    return{
      phoneNumber: "",
      isButtonDisabled: false,
      countdownTime: 60,
      qh:[
        {text:'密码登录'},
        {text:'验证码登录'}
      ],
      userName:'',
      yzm:'',
      wrod:'',
      activeid:0,
      tenantCode: 'lanan'
    }
  },
  created() {
    // getTenantIdByWebsite(this.tenantCode).then(res => {
    //   const tenantId = res.data;
    //   if (tenantId && tenantId >= 0) {
    //     setTenantId(tenantId)
    //   }
    // })
  },
  computed: {
    buttonText() {
      if (this.isButtonDisabled) {
        return `${this.countdownTime}s 后重新发送`;
      } else {
        return "获取验证码";
      }
    },
  },
  methods:{
    //登录请求
    getlogin(){
      if(this.userName == ''){
        uni.showToast({
          title:'输入框不能为空！',
          icon:'none'
        })
        return
      }

      let data ={
        username:this.userName,
        password:this.wrod,
        type:0
      }
      console.log('密码请求',data);
      request({
        url: '/rescue/loginQx',
        method: 'post',
        data: data
      }).then((res)=>{
        console.log('密码请求',res);
        if(res.code == 200){
          setToken(res.data.accessToken)

          // this.userinfo()
          uni.reLaunch({
            url: '/pages/index/index'
          })
        }
      })
    },
    userinfo(){
      request({
        url: '/rescue/getRescueDriverInfo',
        method: 'get',

      }).then((res)=>{
        if(res.code =='200'){
          console.log(res)
          uni.setStorageSync('driverInfo', res.data.driverInfo.id)
          uni.setStorageSync('userId', res.data.user.id)
          this.goselect()
        }



      })
    },
    getxz(index){
      this.activeid = index
    },
    goregister(){
      uni.navigateTo({
        url:'/pages/login/register'
      })
    },
    goforgot(){
      uni.navigateTo({
        url:'/pages/login/forgot'
      })
    },
    goselect(){

      console.log('去司机端首页');
      uni.navigateTo({
        url:'/pages/index/index'
      })
    },
    disableButton() {
      this.isButtonDisabled = true;
    },
    enableButton() {
      this.isButtonDisabled = false;
    },
    startCountdown() {
      let countdown = setInterval(() => {
        this.countdownTime--;
        if (this.countdownTime === 0) {
          clearInterval(countdown);
          this.enableButton(); // 启用按钮
        }
      }, 1000);
    },
  }
}

</script>

<style scoped lang="scss">
.jsq{
  border: none !important;
  font-size: 14px;
  font-weight: 400;
  color: #0078FF;
}
button {
  border: none !important;
  background: none !important;
  margin: 0px;
  display: block;
}
button:focus {
  color: #0078FF;
  outline: none;
  box-shadow: none;
}
.content{
  box-sizing: border-box;
}
.top{
  box-sizing: border-box;
  padding: 0px 27px;
  padding-top: 100px;
  // background-color:lightseagreen;
  //background-image: url('../../static/loginbj.png');
  background-size: cover;
  background-position: center;
  width: 100%;
  // height: 385px;
}
.touxiang{
  width: 88px;
  height: 88px;
  border-radius: 10px;
  background: #D7D7D7;
  margin: 0 auto;
  margin-bottom: 40px;
  overflow: hidden;
  image{
    width: 100%;
    height: 100%;
  }
}
.twotap{
  width: 100%;
  display: flex;
  align-items: center;
  view{
    font-size: 15px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #666666;
    margin-right: 38.5px;
  }
}
.blck{
  color: #333333 !important;
  font-weight: bold !important;
}
.inputs{
  box-sizing: border-box;
  padding: 16px 0px;
  display: flex;
  align-items: center;
  border-bottom: 2px solid #E8E8E8 ;
  margin-top: 20px;
}
.wjworb{
  margin-top: 5px;
  width: 100%;
  display: flex;
  font-size: 12px;
  color: #0078FF;
  justify-content: flex-end;
  align-items: center;

}
.dl{
  width: 90%;
  height: 44px;
  background: linear-gradient(-46deg, #0853C4 0%, #4282D8 80%);
  border-radius: 5px;
  margin: 0 auto;
  font-size: 16px;
  color: #FFFFFF;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 22px;
}
.hging{
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-weight: 400;
  color: #636363;
  margin-top: 20px;
}
.wx{
  width: 38px;
  height: 38px;
  overflow: hidden;
  box-sizing: border-box;
  margin: 0px auto;
  margin-top: 20px;
  image{
    width: 100%;
    height: 100%;
  }
}
.hui{
  font-size: 10px;
  width: 100%;
  text-align: center;
  font-weight: 400;
  color: #666666;
}
.dbottom{
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: #333333;
  margin-top: 40px;
  position: fixed;
  bottom: 25px;
}
.lan{
  color: #0078FF;
}
</style>
