<template>
    <view style="padding: 100px 0;display: flex;justify-content: center;">
        <uv-button @click="goAuth">回到订单页,可对相关订单进行门禁授权</uv-button>
    </view>
</template>

<script setup>
import { onLoad } from "@dcloudio/uni-app";
import { reactive } from "vue";
import { useOrderApi } from '@/Apis/order.js'
const getApi = useOrderApi()
const state = reactive({
  orderId: "",
  mac: "",
});
onLoad(() => {
    state.mac=options.id;
    if(options.q){
      var query=decodeURIComponent(options.q);
      console.log(query)
      state.mac=query.split("id=")[1];
      if(!state.mac){
        state.mac=query.split("facecode/")[1];
      }
      init()
    }
    
    
});
const init = () => {
    uni.showLoading();
    uni.$on('loginSuccess',function(data){
		console.log('监听到事件来自 loginSuccess ，携带参数 msg 为：' + data.msg);
        getOrder()
	})
}
const getOrder = () => {
	uni.showLoading()
	getApi.GetOrderList().then(res=>{
        uni.hideLoading();
		state.value.orderList = []
		if(res.code === 200){
            state.orderId =	res.data.find(item=>item.accessControl.includes(state.mac) &&item.orderStartStatus == 2 && item.refundLockerStatus === 0)?.orderId
			if(state.orderId){
                uni.navigateTo({
                    url:`/pagesb/AControl/index?id=${state.orderId}`
                })
            }
		}
		
	})
}
const goAuth = () => {
    // 回到主页
    uni.switchTab({
        url: `/pages/unlock/index`,
    });
};
</script>

<style>
</style>