<template>
  <div class="login-view">
    <img
      class="title"
      src="@/assets/images/login-page-title.png"
      alt=""
      draggable="false"
    >
    <div class="interaction-area">
      <div class="row-1">
        <div class="input-wrap">
          <input
            v-model="nickName"
            type="text"
            maxlength="6"
            placeholder="请输入昵称"
          >
          <div class="count">
            {{ nickName.length }}/6
          </div>
        </div>
        <button
          class="as-visitor"
          :disabled="!nickName"
          @click="onClickAsVisitor"
        >
          游客模式
        </button>
      </div>
      <button class="as-wx-user" />
    </div>
  </div>
</template>

<script setup>
import { ref, computed, watch, onMounted } from "vue"
import { useRoute, useRouter } from "vue-router"
import { useStore } from "vuex"

const route = useRoute()
const router = useRouter()
const store = useStore()

const nickName = ref('')
nickName.value = `云城居民${utils.getRandomString(2)}`

function onClickAsVisitor() {
  store.commit('setLoginStatus', store.getters.loginStatusEnum.visitor)
  store.commit('setUserName', nickName.value)
  if (route.query.redirect && !route.query.redirect.includes('login')) {
    router.push({
      path: decodeURI(route.query.redirect)
    })
  } else {
    router.push({
      name: 'HomeView'
    })
  }
}


</script>

<style lang="less" scoped>
.login-view{
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-image: url(@/assets/images/login-bg.jpg);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  >img.title{
    position: absolute;
    left: 50%;
    bottom: 50%;
    transform: translate(-50%, 0);
    width: 30vw;
  }
  >.interaction-area{
    position: absolute;
    left: 50%;
    bottom: calc(107 / 972 * 100%);
    transform: translate(-50%, 0);
    >.row-1{
      display: flex;
      align-items: center;
      margin-bottom: 4px;
      >.input-wrap{
        width: 283px;
        height: 75px;
        background: rgba(0,0,0,0.25);
        border-radius: 8px 8px 8px 8px;
        border: 2px solid #FFFFFF;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 27px;
        padding-right: 22px;
        margin-right: 7px;
        >input{
          width: 170px;
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 24px;
          color: #FFFFFF;
          line-height: 28px;
          &::placeholder {
            font-size: 24px;
            color: rgba(255, 255, 255, 0.5);
            line-height: 28px;
          }
        }
        >.count{
          flex: 0 0 auto;
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 24px;
          color: #FFFFFF;
          line-height: 28px;
          opacity: 0.5;
        }
      }
      >button.as-visitor{
        width: 135px;
        height: 88px;
        background-image: url(@/assets/images/visitor-login-button-bg.png);
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center center;
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 400;
        font-size: 24px;
        color: #FFFFFF;
        line-height: 28px;
        text-shadow: 0px 1px 1px rgba(135,111,82,0.5);
        &[disabled] {
          opacity: 0.7;
          cursor: not-allowed;
        }
      }
    }
    >button.as-wx-user{
      width: 422px;
      height: 75px;
      background-image: url(@/assets/images/button-wechat.png);
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center center;
    }
  }

}
</style>