"use strict";
const common_vendor = require("../../common/vendor.js");
const util_api = require("../../util/api.js");
const util_isWeixin = require("../../util/isWeixin.js");
const _sfc_main = {
  __name: "home",
  setup(__props) {
    common_vendor.onLoad(() => {
      util_isWeixin.isWeixin();
      card_number.value = common_vendor.index.getStorageSync("card_number");
      getUserInfo();
      getTimeList();
    });
    const card_number = common_vendor.ref("");
    const currentIndex1 = common_vendor.ref(null);
    const currentIndex2 = common_vendor.ref(null);
    const currentTime = common_vendor.ref(null);
    const currentBus = common_vendor.ref(null);
    const timeList = common_vendor.ref([]);
    const busPath = common_vendor.ref("");
    const startTime = common_vendor.ref("");
    const busList = common_vendor.ref([]);
    const getUserInfo = async () => {
      const res = await util_api.myRequest({
        url: "/appget_user.action",
        method: "get",
        data: {
          card_number: card_number.value
        }
      });
      common_vendor.index.setStorageSync("bus-userInfo", JSON.stringify(res));
    };
    const getTimeList = async () => {
      const res = await util_api.myRequest({
        url: "/appallTime.action",
        method: "post"
      });
      timeList.value = res;
    };
    const getBusList = async (ci_time) => {
      busList.value = [];
      const res = await util_api.myRequest({
        url: "/appbanByTime.action",
        method: "get",
        data: {
          ci_time
        }
      });
      busList.value = res;
    };
    const handleChangeCurrentIndex = (index, type, item) => {
      if (type === 1) {
        currentIndex1.value = index;
        currentTime.value = item.start_time;
        getBusList(currentTime.value);
      } else {
        currentIndex2.value = index;
        currentBus.value = item.car_number;
        startTime.value = item.starty_time;
        busPath.value = item.route;
      }
    };
    const handleSub = () => {
      if (!currentTime.value) {
        common_vendor.index.showToast({
          title: "请选择发车时间",
          icon: "none"
        });
        return;
      }
      if (!currentBus.value) {
        common_vendor.index.showToast({
          title: "请选择预约车辆",
          icon: "none"
        });
        return;
      }
      common_vendor.index.showModal({
        title: "提示",
        content: "确定预约吗？",
        success: (res) => {
          if (res.confirm) {
            handleSubscribe();
          } else if (res.cancel)
            ;
        }
      });
    };
    const handleSubscribe = async () => {
      const res = await util_api.myRequest({
        url: "/apporder.action",
        method: "post",
        data: {
          card_number: card_number.value,
          car_number: currentBus.value,
          ci_time: currentTime.value
        }
      });
      console.log(res);
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.f(timeList.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.start_time),
            b: common_vendor.n(currentIndex1.value === index ? "active" : "time-list-item"),
            c: item.id,
            d: common_vendor.o(($event) => handleChangeCurrentIndex(index, 1, item), item.id)
          };
        }),
        b: busList.value.length
      }, busList.value.length ? {
        c: common_vendor.t(busPath.value)
      } : {}, {
        d: busList.value.length
      }, busList.value.length ? {
        e: common_vendor.f(busList.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.car_number),
            b: common_vendor.n(currentIndex2.value === index ? "active" : "bus-list-item"),
            c: item.id,
            d: common_vendor.o(($event) => handleChangeCurrentIndex(index, 2, item), item.id)
          };
        })
      } : {}, {
        f: startTime.value
      }, startTime.value ? {
        g: common_vendor.t(startTime.value),
        h: common_vendor.o(handleSub)
      } : {});
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-07e72d3c"], ["__file", "E:/workSpace/schoolBus-reservation/pages/home/home.vue"]]);
wx.createPage(MiniProgramPage);
