search.vue 4.54 KB
<!--
 * @Date: 2024-01-26 13:08:09
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-01-26 14:38:09
 * @FilePath: /xysBooking/src/views/search.vue
 * @Description: 文件描述
-->
<template>
  <div class="search-page">
    <div>
      <div v-if="!is_search">
        <div class="input-item">
          <div>证件号码</div>
          <div>
            <input type="text" v-model="idCode" placeholder="请输入证件号码" @blur="checkIdCode" maxlength="18" style="width: 100%;">
          </div>
        </div>
        <div style="color:#A67939; font-size: 0.95rem; text-align: center;">
          <van-icon name="warning-o" />&nbsp;温馨提示<br/>获取参观码,扫码或识别身份证成功进闸机
        </div>
      </div>
      <div v-else>
        <qrCodeSearch :id="id_number" />
      </div>
      <div v-if="!is_search" class="save-wrapper">
        <div class="save-btn" @click="searchBtn">查询</div>
      </div>
      <div v-else class="success-btn">
        <div @click="goToHome" class="btn-item btn-left">首页</div>
        <div @click="goBack" class="btn-item btn-right">返回查询</div>
      </div>
    </div>
    <div class="logo"></div>

    <van-toast v-model:show="show_error" style="">
      <template #message>
        {{ error_message }}
      </template>
    </van-toast>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { validateCIN } from '@code-ts/cin'
import qrCodeSearch from '@/components/qrCodeSearch';
import { Cookies, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
//import { } from '@/utils/generateModules.js'
//import { } from '@/utils/generateIcons.js'
//import { } from '@/composables'
import { showSuccessToast, showFailToast } from 'vant';
import { useGo } from '@/hooks/useGo'
import { queryQrCodeAPI } from '@/api/index'

const $route = useRoute();
const $router = useRouter();
useTitle($route.meta.title);

const go = useGo();
const is_search = ref(false);
const idCode = ref('');
const id_number = ref('');

const show_error = ref(false);
const error_message = ref('');

const checkIdCode = () => { // 检查身份证号是否为空
  let flag = true;
  if (idCode.value.length === 15) { // 15位身份证号码不校验
    flag = true;
  } else {
    if (!validateCIN(idCode.value)) {
      show_error.value = true;
      error_message.value = '请检查身份证号码';
      flag = false;
    }
  }
  return flag;
}

const searchBtn = async () => {
  // 查询用户信息
  if (checkIdCode()) {
    is_search.value = true;
    id_number.value = idCode.value;
    idCode.value = ''
  }
}
const goBack = () => {
  is_search.value = false;
}
const goToHome = () => {
  go('/')
}
</script>

<style lang="less" scoped>
.search-page {
  padding: 1rem;
  position: relative;
  height: calc(100vh - 2rem);
  background-image: url('https://cdn.ipadbiz.cn/xys/booking/bg.jpg');
  background-repeat: no-repeat;
  background-position: center;
  .logo {
    position: absolute;
    right: 0;
    bottom: calc(15vh);
    height: 30vh;
    width: 20vw;
    background-image: url('https://cdn.ipadbiz.cn/xys/booking/logo.png');
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
  }
  .input-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #A67939;
    input {
      border: 0;
      text-align: right;
    }
  }
  .save-wrapper {
    background-color: #FFF;
    position: fixed;
    width: 100vw;
    bottom: 0;
    left: 0;
    height: 5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    .save-btn {
      text-align: center;
      flex-grow: 1;
      background-color: #A67939;
      padding: 0.8rem 0;
      margin: 1rem;
      color: #FFF;
      border-radius: 5px;
      font-size: 1.1rem;
    }
  }
  .success-btn {
    background-color: #FFF;
    position: fixed;
    width: 100vw;
    bottom: 0;
    left: 0;
    height: 5rem;
    display: flex;
    align-items: center;
    justify-content: space-around;
    .btn-item {
      flex: 1;
      padding: 0.7rem 0;
      border-radius: 5px;
      font-size: 1.05rem;
      text-align: center;
      margin: 0 0.25rem;
    }
    .btn-left{
      background-color: #A67939;
      color: #FFF;
      margin-left: 0.7rem;
    }
    .btn-right{
      border: 1px solid #A67939;
      color: #A67939;
      font-size: 1.05rem;
      margin-right: 0.7rem;
    }
  }
}
</style>