<template>

</template>

<script lang='ts' setup>

import { getStoreId } from '@/api/company';
import { isLogin, setCompanyId, setRegisterStoreId } from '@/utils';

onLoad(async (options) => {
  getApp().globalData?.logger?.info('ticketsBuy share options: ', options);

  let couponId = options?.couponsId;
  if(couponId) {
    const path = `/pages/common/groupbuy/detail?couponId=${couponId}`;
    if(!isLogin() && getApp()?.globalData) {
      getApp().globalData!.sharePath = path;
    }

    if(options?.companyId && options?.creatorId) {
      const storeId = await getStoreId({
        companyid: options?.companyId,
        deviceid: options?.creatorId
      });
      setCompanyId(options?.companyId);
      if(storeId) {
        setRegisterStoreId(storeId);
        if(getApp()?.globalData) {
          getApp().globalData!.shareCompanyId = options?.companyId;
          getApp().globalData!.shareStoreId = storeId;
        }
      }
    }

    setTimeout(() => {
      uni.reLaunch({
        url: path
      });
    }, 300);
  } else {
    uni.reLaunch({
      url: '/pages/home/index'
    });
  }
});


</script>

<style lang='scss' scoped>

</style>
