"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
if (!Array) {
  const _easycom_uv_qrcode2 = common_vendor.resolveComponent("uv-qrcode");
  _easycom_uv_qrcode2();
}
const _easycom_uv_qrcode = () => "../../uni_modules/uv-qrcode/components/uv-qrcode/uv-qrcode.js";
if (!Math) {
  (_easycom_uv_qrcode + NoData)();
}
const NoData = () => "../../components/noData.js";
const _sfc_main = {
  __name: "home",
  setup(__props) {
    common_vendor.useCssVars((_ctx) => ({
      "73922f18": statusBarH.value
    }));
    common_vendor.onLoad(() => {
      common_vendor.index.getSystemInfo({
        success: (e) => {
          statusBarH.value = e.statusBarHeight;
          let custom = common_vendor.index.getMenuButtonBoundingClientRect();
          customBarH.value = custom.height;
        }
      });
      userInfo.value = common_vendor.index.getStorageSync("userInfo");
      if (userInfo.value.identityId == 1) {
        getChildMsg();
      }
      getUseAppList();
      common_vendor.index.$on("updateObj", updateObj);
    });
    common_vendor.onShow(() => {
      getQrcode();
    });
    common_vendor.onPullDownRefresh(() => {
      getQrcode();
      qrcodeRef.value.remake();
      if (userInfo.value.identityId == 1) {
        getChildMsg();
      }
      getUseAppList();
      setTimeout(() => {
        common_vendor.index.stopPullDownRefresh();
      }, 1500);
    });
    common_vendor.onPageScroll((e) => {
      if (e.scrollTop > 70) {
        showHeader.value = true;
      } else {
        showHeader.value = false;
      }
    });
    const userInfo = common_vendor.ref({});
    const childMsgList = common_vendor.ref([]);
    const currentChild = common_vendor.ref({});
    const showHeader = common_vendor.ref(false);
    const statusBarH = common_vendor.ref(0);
    const customBarH = common_vendor.ref(0);
    const qrcodeRef = common_vendor.ref(null);
    common_vendor.ref([
      {
        id: 3,
        title: "学生轨迹",
        path: "/pages/track/track"
      },
      {
        id: 7,
        title: "消息通知",
        path: "/pages/msgWarn/msgWarn"
      },
      {
        id: 8,
        title: "访客预约",
        path: "/pagesReservation/reservation/reservation"
      },
      {
        id: 10,
        title: "校园预警",
        path: "/pagesWarning/home/home"
      },
      {
        id: 11,
        title: "通讯录",
        path: "/pages/grade/grade"
      }
    ]);
    const useAppList = common_vendor.ref([]);
    const QRCodeUrl = common_vendor.ref("");
    const options = {
      typeNumber: -1,
      foregroundImageBorderRadius: 5,
      foregroundImageSrc: "/static/images/school-logo.jpg"
    };
    const getQrcode = async () => {
      const res = await utils_api.myRequest({
        url: "/wanzai/api/smartQrcode/generateQrcode",
        data: {
          userId: common_vendor.index.getStorageSync("userInfo").id
        }
      });
      QRCodeUrl.value = res.data.qrcode;
    };
    const getChildMsg = async () => {
      const res = await utils_api.myRequest({
        url: "/wanzai/api/smartUser/queryAffiliateUserById",
        data: {
          id: common_vendor.index.getStorageSync("userInfo").id
        }
      });
      childMsgList.value = res.data;
      if (childMsgList.value.length) {
        currentChild.value = childMsgList.value[0];
      }
    };
    const getUseAppList = async () => {
      const res = await utils_api.myRequest({
        url: "/wanzai/api/smartIdentity/queryIdentityApplyById",
        data: {
          id: common_vendor.index.getStorageSync("userInfo").identityId
        }
      });
      useAppList.value = res.data;
    };
    const goPage = (url, item) => {
      if (item && item.category == "其他小程序") {
        common_vendor.index.navigateToMiniProgram({
          appId: item.appid,
          path: item.path
        });
        return;
      }
      if (item && item.category == "移动端H5") {
        common_vendor.index.navigateTo({
          url: `/pages/web/web?url=${item.path}`
        });
        return;
      }
      if (url === "/pages/track/track") {
        if (userInfo.value.identityId == 1) {
          common_vendor.index.navigateTo({
            url: `/pages/track/track?id=${currentChild.value.id}`
          });
          return;
        } else {
          common_vendor.index.navigateTo({
            url: "/pages/grade/grade?type=学生轨迹"
          });
          return;
        }
      }
      if (url === "/pagesReservation/reservation/reservation") {
        common_vendor.index.setStorageSync("Tab-activeIndex", 0);
      }
      common_vendor.index.navigateTo({
        url
      });
    };
    const handleClickCode = () => {
      common_vendor.index.navigateTo({
        url: `/pages/quickMark/quickMark?value=${QRCodeUrl.value}`
      });
    };
    const updateObj = (data) => {
      currentChild.value = data;
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(($event) => goPage("/pages/myCenter/myCenter")),
        b: customBarH.value * 2 + "rpx",
        c: statusBarH.value * 2 + "rpx",
        d: !showHeader.value,
        e: customBarH.value * 2 + "rpx",
        f: statusBarH.value * 2 + "rpx",
        g: showHeader.value,
        h: common_vendor.t(userInfo.value.name),
        i: userInfo.value.identityId == 1
      }, userInfo.value.identityId == 1 ? {} : {}, {
        j: userInfo.value.identityId == 2
      }, userInfo.value.identityId == 2 ? {} : {}, {
        k: userInfo.value.identityId == 3
      }, userInfo.value.identityId == 3 ? {} : {}, {
        l: common_vendor.sr(qrcodeRef, "07e72d3c-0", {
          "k": "qrcodeRef"
        }),
        m: common_vendor.o(handleClickCode),
        n: common_vendor.p({
          size: "82rpx",
          value: QRCodeUrl.value,
          options
        }),
        o: userInfo.value.identityId == 1
      }, userInfo.value.identityId == 1 ? common_vendor.e({
        p: childMsgList.value.length
      }, childMsgList.value.length ? {
        q: currentChild.value.headImage || "../../static/images/user-photo.png"
      } : {}, {
        r: childMsgList.value.length
      }, childMsgList.value.length ? {
        s: common_vendor.t(currentChild.value.name)
      } : {}, {
        t: childMsgList.value.length
      }, childMsgList.value.length ? {
        v: common_vendor.o(($event) => goPage(`/pages/myMsg/myMsg?id=${currentChild.value.id}`))
      } : {}, {
        w: childMsgList.value.length > 1
      }, childMsgList.value.length > 1 ? {
        x: common_vendor.o(($event) => goPage(`/pages/change/change?list=${JSON.stringify(childMsgList.value)}&id=${currentChild.value.id}`))
      } : {}, {
        y: common_vendor.o(($event) => goPage("/pages/bind/bind")),
        z: common_vendor.o(($event) => goPage("/pages/bind/bind"))
      }) : {}, {
        A: useAppList.value.length
      }, useAppList.value.length ? {
        B: common_vendor.f(useAppList.value, (item, k0, i0) => {
          return {
            a: item.url,
            b: common_vendor.t(item.title),
            c: item.id,
            d: common_vendor.o(($event) => goPage(item.path, item), item.id)
          };
        })
      } : {}, {
        C: !useAppList.value.length
      }, !useAppList.value.length ? {} : {}, {
        D: common_vendor.s(_ctx.__cssVars())
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-07e72d3c"], ["__file", "E:/workSpace/WanZai_School_app/pages/home/home.vue"]]);
_sfc_main.__runtimeHooks = 1;
wx.createPage(MiniProgramPage);
