<template>
  <view class="transfer_contents" v-if="!scanQrCode"> 正在识别二维码...请稍后 </view>
  <view class="error_contents" v-else>
    <view> 二维码识别有误，请换二维码重新扫描 </view>
    <hs-footer btnParimaryName="返回首页" />
  </view>
</template>

<script lang="ts" setup>
import getLoginStatus from '@/common/libraries/userUserLogin'
import { onShow } from '@dcloudio/uni-app'
import { getCurrentInstance, ref } from 'vue'
const scanQrCode = ref(false)

onShow(async () => {
  await getCurrentInstance()?.appContext.config.globalProperties.$onLaunched
  //获得二维码上数据
  if (getLoginStatus?.getLoginStatus()) {
    const getQrcode: any = uni.getEnterOptionsSync()
    console.log(getQrcode, 'getQrcode')
    let qrData = getQrcode?.query
    if (!qrData?.scene) {
      scanQrCode.value = true
    } else {
      let data = qrData?.scene?.split('_')
      if (data[0] === '1') {
        //物品放行
        uni.redirectTo({
          url: `/INDEX/release_items/index?id=${data[1]}`
        })
      }
      if (data[0] === '2') {
        //通行证
        uni.redirectTo({
          url: `/INDEX/pass/index?source=2&id=${data[1]}`
        })
      }
      if (data[0] === '3') {
        //安防巡检-扫码
        uni.redirectTo({
          url: `/INDEX/patrol_task_list/index?id=${data[1]}`
        })
      }
      if (data[0] === '4') {
        //业主租客或者已经绑定房屋-扫码
        //通行证
        uni.redirectTo({
          url: `/INDEX/pass/index?source=4&customers_id=${data[1]}&asset_houses_id=${data[2]}`
        })
      }
    }
  } else {
    uni.showModal({
      title: '提示',
      content: '检测到您还未登录，是否去登录？',
      confirmText: '去登录',
      cancelText: '返回首页',
      confirmColor: '#0082FA',
      success: function (res) {
        if (res.confirm) {
          uni.navigateTo({
            url: '/pages/login?source=transfer'
          })
          console.log('用户点击确定')
        } else if (res.cancel) {
          uni.switchTab({
            url: '/pages/index/index'
          })
          console.log('用户点击取消')
        }
      }
    })
  }
})
</script>

<style lang="scss">
@import './style.scss';
</style>
