<script setup lang="ts">
import { onLaunch, onShow, onHide, onReady } from "@dcloudio/uni-app";
import {useAddressStore} from "~/stores/addressStore";
import {useGlobalData} from "@uni-helper/uni-use";
import {useUserStore} from "~/stores/userStore";
const addressStore = useAddressStore()
const that = this
const privacyData = uni.getStorageSync('PRIVACY')
const userStore = useUserStore()
onLaunch(() => {
  console.log("App Launch");
  // that.globalData = {
  //   privacyContractName: '' ,
  //   showPrivacy: false,
  // }
  wx.getPrivacySetting({
    success(res) {
      // console.log('是否需要授权：', res.needAuthorization, '隐私协议的名称为：', res.privacyContractName);
      if (res.needAuthorization) {
        uni.setStorageSync('PRIVACY', { privacyContractName: res.privacyContractName, showPrivacy: true})
        // that.globalData.privacyContractName = res.privacyContractName
        // that.globalData.showPrivacy = true
        // globalData.privacyContractName = res.privacyContractName;
        // app.globalDatashowPrivacy = true;
      } else {
        // globalData.showPrivacy = false;
        // this.globalData.showPrivacy = false
        uni.setStorageSync('PRIVACY', { privacyContractName: res.privacyContractName, showPrivacy: false})

      }
    }
  });


// #ifdef MP-WEIXIN
  wx.onAppRoute((res) => {
    // console.log('路由监听',res)
    if (res.openType === 'switchTab') {
      if (res.path === "pages/order_addcart/index") {

      }
      // console.log(res)
      // #ifdef MP-WEIXIN
      // wx.hideTabBar()
      // #endif
    }
  })
  // #endif
});
// useGlobalData()
onShow(() => {

  console.log("App Show");
  addressStore.getCurrentAddress()
});
onHide(() => {
  console.log("App Hide");
});
onReady(() => {
  const app = getApp()
  app.globalData = {
    privacyContractName: '', //隐私协议的名字
    showPrivacy: false //控制隐私弹窗显隐
  }


  // const that = this;
  // wx.getPrivacySetting({
  //   success(res) {
  //     console.log('是否需要授权：', res.needAuthorization, '隐私协议的名称为：', res.privacyContractName);
  //     if (res.needAuthorization) {
  //       globalData.privacyContractName = res.privacyContractName;
  //       app.globalDatashowPrivacy = true;
  //     } else {
  //       globalData.showPrivacy = false;
  //     }
  //   }
  // });
})
</script>
<style lang="scss">
@import 'nutui-uniapp/styles/index';
</style>
