index.vue 2.72 KB
<template>
    <view class="result-page">
        <view class="result-content">
            <icon type="success" size="64" color="#A67939"/>
            <view class="msg">{{ msg }}</view>
            <view class="info" v-if="resultContent">扫码内容: {{ resultContent }}</view>
            <nut-button color="#A67939" class="back-btn" @tap="continueScan">继续核销</nut-button>
            <!-- <nut-button type="default" class="home-btn" @tap="goHome">返回首页</nut-button> -->
        </view>
    </view>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from '@tarojs/taro'
import { useGo } from '@/hooks/useGo'
import { verifyTicketAPI } from '@/api/index'
import Taro, { useDidShow } from '@tarojs/taro'

const router = useRouter()
const go = useGo()
const resultContent = ref('')
const msg = ref('核销成功')

useDidShow(async () => {
    resultContent.value = router.params.result || ''
    if (resultContent.value) {
        Taro.showLoading({ title: '核销中...' })
        const res = await verifyTicketAPI({ code: resultContent.value })
        Taro.hideLoading()
        if (res.code === 1) {
            msg.value = res.msg || '核销成功'
        } else {
            msg.value = res.msg || '核销失败'
            Taro.showToast({ title: msg.value, icon: 'none' })
        }
    }
})

const continueScan = () => {
    Taro.scanCode({
        success: (res) => {
             // Reload current page with new result
             // Taro doesn't support easy reload with params change in same page easily without redirect
             // So we redirect to self
            Taro.redirectTo({
                url: `/pages/verificationResult/index?result=${res.result}`
            })
        },
        fail: () => {
            // Cancelled
        }
    })
}

// const goHome = () => {
//     Taro.reLaunch({ url: '/pages/index/index' })
// }
</script>

<style lang="less">
.result-page {
    padding: 64rpx 32rpx;
    text-align: center;
    min-height: 100vh;
    background-color: #fff;

    .result-content {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .msg {
        font-size: 40rpx;
        margin-top: 32rpx;
        font-weight: bold;
        color: #333;
    }
    .info {
        margin-top: 20rpx;
        color: #999;
        font-size: 28rpx;
        word-break: break-all;
        padding: 0 32rpx;
    }
    .back-btn {
        margin-top: 80rpx;
        background-color: #A67939;
        color: #fff;
        width: 80%;
        border-radius: 44rpx;
    }
    .home-btn {
        margin-top: 32rpx;
        background-color: #fff;
        color: #666;
        width: 80%;
        border-radius: 44rpx;
        border: 1rpx solid #b0b0b0;
    }
}
</style>