<template>
  <view class="container">
    <view class="tips">
      <view class="name">谢谢老板</view>
      <view class="desc">请在这里扫码</view>
    </view>
    <view class="box">
      <image class="img" :src="dataUrl" />
    </view>
  </view>
</template>

<script setup lang="ts">
import { onUnmounted, ref } from "vue";
import Taro from "@tarojs/taro";
import { getAfterOrder } from "@/api/admin";

const time_id = ref();

const dataUrl = ref("");

const info = ref<any>({});

Taro.useLoad((e) => {
  info.value = e;
  dataUrl.value = Taro.getStorageSync("pay_code");
  time_id.value = setInterval(async () => {
    const { data } = await getAfterOrder({
      bid: info.value.bid,
      oid: info.value.oid,
    });
    if (data.data.status !== 0 && data.data.status !== 2) {
      Taro.showToast({
        title: "支付成功",
        icon: "success",
      });
      setTimeout(() => {
        Taro.removeStorageSync("pay_code");
        Taro.navigateTo({
          url: `/pages/admin/add_order/pending_order/pending_order_detail/index?oid=${info.value.oid}&bid=${info.value.bid}`,
        });
      }, 3000);
    }
  }, 1000);
});

Taro.useDidHide(() => {
  clearInterval(time_id.value);
  Taro.removeStorageSync("pay_code");
});

onUnmounted(() => {
  clearInterval(time_id.value);
  Taro.removeStorageSync("pay_code");
});
</script>

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