"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_request = require("../../../api/request.js");
const common_global = require("../../../common/global.js");
const _sfc_main = {
  __name: "timePopUp",
  props: ["pid"],
  setup(__props) {
    const cookie = common_vendor.wx$1.getStorageSync("cookie");
    const father = __props;
    const pid = common_vendor.ref(0);
    const productInfo = common_vendor.ref({});
    const bookTimeList = common_vendor.ref([]);
    const timeSlotList = common_vendor.ref([]);
    const selected = common_vendor.ref({
      //选中的日期+时间
      date: "",
      time: "",
      minNum: 0,
      maxNum: 0
    });
    const classNum = common_vendor.ref(1);
    common_vendor.ref(0);
    common_vendor.onLoad((options) => {
    });
    common_vendor.onMounted(async () => {
      await getProduct();
      await chooseDate(0);
      await chooseTimeSlot(0);
    });
    const chooseDate = (index) => {
      selected.value.date = bookTimeList.value[index].specificDate;
      selected.value.time = "";
      classNum.value = 1;
      bookTimeList.value.forEach((item) => {
        if (item != bookTimeList.value[index]) {
          item.color = "#000000";
        } else {
          bookTimeList.value[index].color = "#C35C5D";
        }
      });
      timeSlotList.value = bookTimeList.value[index].timePeriodVOList;
      console.log("选中下日期时间段--->", bookTimeList.value[index].timePeriodVOList);
    };
    const chooseTimeSlot = (index) => {
      selected.value.time = timeSlotList.value[index].timeSlot;
      selected.value.maxNum = timeSlotList.value[index].maxNumber;
      classNum.value = 1;
      timeSlotList.value.forEach((item) => {
        if (item != timeSlotList.value[index]) {
          item.color = "#FFFFFF";
        } else {
          item.color = "#FBDEDF";
        }
      });
    };
    const getProduct = async () => {
      pid.value = father.pid;
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/goods/service/list/id",
        method: "POST",
        data: { id: pid.value },
        header: { cookie }
      });
      console.log("后端传来的商品信息--->", res.data.data);
      if (res.data.code === 1) {
        productInfo.value = res.data.data;
        bookTimeList.value = res.data.data.appointmentDateVOList;
      }
      console.log("商品信息--->", productInfo.value);
      console.log("日期+时间段信息--->", bookTimeList.value);
    };
    const short = () => {
      if (selected.value.maxNum === 0) {
        common_vendor.index.showToast({
          icon: "error",
          title: "请先选择时间段",
          duration: 1e3
        });
        return;
      }
      if (classNum.value > 1) {
        classNum.value -= 1;
      }
    };
    const add = () => {
      if (selected.value.maxNum === 0) {
        common_vendor.index.showToast({
          icon: "error",
          title: "请先选择时间段",
          duration: 1e3
        });
        return;
      }
      if (classNum.value < selected.value.maxNum) {
        classNum.value += 1;
      }
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: productInfo.value.goodImg,
        b: common_vendor.t(productInfo.value.price),
        c: common_vendor.o(($event) => short()),
        d: common_vendor.t(classNum.value),
        e: common_vendor.o(($event) => add()),
        f: common_vendor.t(selected.value.date),
        g: common_vendor.f(bookTimeList.value, (item, index, i0) => {
          return {
            a: common_vendor.t(common_vendor.unref(common_global.weekDay)(item.specificDate)),
            b: common_vendor.t(item.specificDate.substring(5, 10)),
            c: item.color,
            d: index,
            e: common_vendor.o(($event) => chooseDate(index), index)
          };
        }),
        h: timeSlotList.value.length <= 2
      }, timeSlotList.value.length <= 2 ? {
        i: common_vendor.f(timeSlotList.value, (item, index, i0) => {
          return {
            a: item.color,
            b: common_vendor.t(item.timeSlot),
            c: index,
            d: common_vendor.o(($event) => chooseTimeSlot(index), index)
          };
        })
      } : {}, {
        j: timeSlotList.value.length >= 3
      }, timeSlotList.value.length >= 3 ? {
        k: common_vendor.f(timeSlotList.value, (item, index, i0) => {
          return {
            a: item.color,
            b: common_vendor.t(item.timeSlot),
            c: index,
            d: common_vendor.o(($event) => chooseTimeSlot(index), index)
          };
        })
      } : {}, {
        l: common_vendor.t(selected.value.date),
        m: common_vendor.t(selected.value.time)
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-66de04e2"], ["__file", "D:/微信小程序/课设整合/匠承非遗小程序端/jiangchengfeiyi-xiaochengxu/pages/workshop/component/timePopUp.vue"]]);
wx.createPage(MiniProgramPage);
