<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 { onLoad, onShow } from '@dcloudio/uni-app'
import getLoginStatus from '@/common/libraries/userUserLogin'
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()
    let qrData = getQrcode?.query
    if (!qrData?.scene) {
      scanQrCode.value = true
    } else {
      let data = qrData?.scene?.split('_')
      console.log('qrData', qrData)
      if (data[0] === '1') {
        //账单->订单支付
        uni.redirectTo({
          url: `/INDEX/pay/index?id=${data[1]}`
        })
      }
      if (data[0] === '2') {
        //其他收费-订单支付
        uni.redirectTo({
          url: `/INDEX/pay_general/index?id=${data[1]}`
        })
      }
    }
  } else {
    uni.showModal({
      title: '提示',
      content: '检测到您还未登录，是否去登录？',
      confirmText: '去登录',
      cancelText: '返回首页',
      confirmColor: '#0082FA',
      success: function (res) {
        if (res.confirm) {
          uni.redirectTo({
            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>
