"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const utils_api = require("../../utils/api.js");
if (!Array) {
  const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon");
  const _easycom_wd_status_tip2 = common_vendor.resolveComponent("wd-status-tip");
  const _component_AuthorizePopup = common_vendor.resolveComponent("AuthorizePopup");
  (_easycom_wd_icon2 + _easycom_wd_status_tip2 + _component_AuthorizePopup)();
}
const _easycom_wd_icon = () => "../../uni_modules/wot-design-uni/components/wd-icon/wd-icon.js";
const _easycom_wd_status_tip = () => "../../uni_modules/wot-design-uni/components/wd-status-tip/wd-status-tip.js";
if (!Math) {
  (_easycom_wd_icon + _easycom_wd_status_tip)();
}
const _sfc_main = {
  __name: "home",
  setup(__props) {
    const show = common_vendor.ref(false);
    const paddingTop = common_vendor.ref(0);
    const userInfo = common_vendor.index.getStorageSync("carUserInfo");
    const currentTime = common_vendor.ref("");
    const pathList = common_vendor.ref([]);
    const currentPath = common_vendor.ref(null);
    const currentIndex = common_vendor.ref(0);
    const busList = common_vendor.ref([]);
    const yy_end = common_vendor.ref(0);
    const workTele = common_vendor.ref("");
    const getRouteParts = (str) => {
      if (typeof str === "string" && str.length > 0) {
        return str.split("→");
      }
      return [];
    };
    async function getOrderConfig() {
      const res = await utils_api.myRequest({
        url: "/appqueryConfig.action"
      });
      yy_end.value = res.data.data.yy_end || 0;
    }
    async function getBusList(route) {
      const res = await utils_api.myRequest({
        url: "/tAppqueryCarNums.action",
        data: {
          date: currentTime.value,
          route: route || currentPath.value,
          mobile: userInfo.mobile
        }
      });
      if (res.data && res.data.data) {
        res.data.data.forEach((item) => {
          const targetDateStr = `${item.s_date} ${item.yy_end}`;
          const targetTimestamp = new Date(targetDateStr).getTime();
          const nowTimestamp = (/* @__PURE__ */ new Date()).getTime();
          item.isExpired = nowTimestamp > targetTimestamp;
        });
        busList.value = res.data.data || [];
        console.log(busList.value, "车次");
      }
    }
    async function getTuigai() {
      const res = await utils_api.myRequest({
        url: "/carBook/cnqueryHb.action",
        data: {}
      });
      if (res.code == 200) {
        workTele.value = res.data.workMobile;
      } else {
        common_vendor.index.showToast({
          title: res.message,
          icon: "none"
        });
      }
    }
    async function getPathList() {
      var _a;
      const res = await utils_api.myRequest({
        url: "/appqueryRoute.action"
      });
      pathList.value = res.data.data || [];
      if (pathList.value.length) {
        currentPath.value = (_a = pathList.value[0]) == null ? void 0 : _a.route;
        getBusList(currentPath.value);
      }
    }
    common_vendor.onMounted(() => {
      const bus_date = common_vendor.index.getStorageSync("bus_date");
      if (bus_date) {
        currentTime.value = bus_date;
      } else {
        currentTime.value = common_vendor.dayjs(Date.now()).format("YYYY-MM-DD");
      }
      paddingTop.value = common_vendor.index.getMenuButtonBoundingClientRect().top;
      getTuigai();
      getOrderConfig();
      getPathList();
    });
    common_vendor.onLoad(() => {
    });
    function handleChangeCurrentIndex(index, item) {
      currentIndex.value = index;
      currentPath.value = item.route;
      getBusList(currentPath.value);
    }
    function chooseDate() {
      common_vendor.index.navigateTo({
        url: "/pages/date/date"
      });
    }
    function handleClickItem(item) {
      const info = encodeURIComponent(JSON.stringify(item), "l");
      common_vendor.index.navigateTo({
        url: `/pages/chooseCar/chooseCar?info=${info}`
      });
    }
    const handleClose = () => {
      show.value = false;
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_assets._imports_0$2,
        b: `${paddingTop.value * 2}rpx`,
        c: common_assets._imports_1$2,
        d: common_vendor.p({
          name: "warning",
          color: "#707070",
          size: "10"
        }),
        e: common_vendor.t(currentTime.value ? currentTime.value : "请选择日期"),
        f: common_vendor.n(currentTime.value ? "" : "novalue"),
        g: common_vendor.p({
          name: "calendar",
          color: "#707070",
          size: "26"
        }),
        h: common_vendor.o(chooseDate),
        i: common_vendor.f(pathList.value, (item, index, i0) => {
          return common_vendor.e({
            a: index % 2 === 1
          }, index % 2 === 1 ? {
            b: common_assets._imports_2
          } : {
            c: common_assets._imports_3
          }, {
            d: common_vendor.t(item.route),
            e: index,
            f: common_vendor.n(currentIndex.value === index ? "active" : ""),
            g: common_vendor.o(($event) => handleChangeCurrentIndex(index, item), index)
          });
        }),
        j: common_vendor.f(busList.value, (item, index, i0) => {
          return common_vendor.e({
            a: common_vendor.t(item.ci_time),
            b: common_vendor.f(getRouteParts(item.route_end), (item2, index2, i1) => {
              return {
                a: common_vendor.t(item2),
                b: index2 > 0 ? 1 : "",
                c: index2
              };
            }),
            c: common_vendor.t(item.price),
            d: common_vendor.t(item.contain - item.boarde_num),
            e: item.isExpired == false
          }, item.isExpired == false ? {} : {}, {
            f: common_vendor.t(item.car_number),
            g: common_vendor.t(item.contain),
            h: index,
            i: item.isExpired ? 1 : "",
            j: !item.isExpired ? 1 : "",
            k: common_vendor.o(($event) => handleClickItem(item), index)
          });
        }),
        k: !busList.value.length
      }, !busList.value.length ? {
        l: common_vendor.p({
          image: "content",
          tip: "暂无数据"
        })
      } : {}, {
        m: common_vendor.o(handleClose),
        n: common_vendor.p({
          show: show.value
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-07e72d3c"], ["__file", "D:/创海项目/CH2025/约车小程序/yueche_app/pages/home/home.vue"]]);
_sfc_main.__runtimeHooks = 2;
wx.createPage(MiniProgramPage);
