"use strict";
const common_vendor = require("../../common/vendor.js");
const sheep_index = require("../../sheep/index.js");
const sheep_api_promotion_coupon = require("../../sheep/api/promotion/coupon.js");
const sheep_api_promotion_activity = require("../../sheep/api/promotion/activity.js");
const sheep_api_product_favorite = require("../../sheep/api/product/favorite.js");
const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
const sheep_api_product_spu = require("../../sheep/api/product/spu.js");
require("../../sheep/url/index.js");
require("../../sheep/store/index.js");
require("../../sheep/store/app.js");
require("../../sheep/api/promotion/diy.js");
require("../../sheep/request/index.js");
require("../../sheep/config/index.js");
require("../../sheep/platform/index.js");
require("../../sheep/platform/provider/wechat/index.js");
require("../../sheep/platform/provider/wechat/miniProgram.js");
require("../../sheep/api/member/auth.js");
require("../../sheep/api/member/social.js");
require("../../sheep/api/member/user.js");
require("../../sheep/platform/provider/apple/index.js");
require("../../sheep/platform/share.js");
require("../../sheep/router/index.js");
require("../../sheep/hooks/useModal.js");
require("../../sheep/helper/index.js");
require("../../sheep/helper/test.js");
require("../../sheep/helper/digit.js");
require("../../sheep/helper/throttle.js");
require("../../sheep/platform/pay.js");
require("../../sheep/api/pay/order.js");
require("../../sheep/store/user.js");
require("../../sheep/store/cart.js");
require("../../sheep/api/trade/cart.js");
require("../../sheep/api/pay/wallet.js");
require("../../sheep/api/trade/order.js");
require("../../sheep/store/sys.js");
require("../../sheep/store/modal.js");
require("../../sheep/config/zIndex.js");
require("../../sheep/util/index.js");
if (!Array) {
  const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  const _easycom_su_swiper2 = common_vendor.resolveComponent("su-swiper");
  const _easycom_s_select_sku2 = common_vendor.resolveComponent("s-select-sku");
  const _easycom_s_coupon_get2 = common_vendor.resolveComponent("s-coupon-get");
  const _easycom_s_activity_pop2 = common_vendor.resolveComponent("s-activity-pop");
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  (_easycom_s_empty2 + _easycom_su_swiper2 + _easycom_s_select_sku2 + _easycom_s_coupon_get2 + _easycom_s_activity_pop2 + _easycom_s_layout2)();
}
const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
const _easycom_su_swiper = () => "../../sheep/ui/su-swiper/su-swiper.js";
const _easycom_s_select_sku = () => "../../sheep/components/s-select-sku/s-select-sku.js";
const _easycom_s_coupon_get = () => "../../sheep/components/s-coupon-get/s-coupon-get.js";
const _easycom_s_activity_pop = () => "../../sheep/components/s-activity-pop/s-activity-pop.js";
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  (detailNavbar + detailSkeleton + _easycom_s_empty + _easycom_su_swiper + detailCellSku + _easycom_s_select_sku + detailCommentCard + detailContentCard + detailActivityTip + detailTabbar + _easycom_s_coupon_get + _easycom_s_activity_pop + _easycom_s_layout)();
}
const detailNavbar = () => "./components/detail/detail-navbar.js";
const detailCellSku = () => "./components/detail/detail-cell-sku.js";
const detailTabbar = () => "./components/detail/detail-tabbar.js";
const detailSkeleton = () => "./components/detail/detail-skeleton.js";
const detailCommentCard = () => "./components/detail/detail-comment-card.js";
const detailContentCard = () => "./components/detail/detail-content-card.js";
const detailActivityTip = () => "./components/detail/detail-activity-tip.js";
const _sfc_main = {
  __name: "index",
  setup(__props) {
    common_vendor.onPageScroll(() => {
    });
    const state = common_vendor.reactive({
      goodsId: 0,
      skeletonLoading: true,
      // SPU 加载中
      goodsInfo: {},
      // SPU 信息
      showSelectSku: false,
      // 是否展示 SKU 选择弹窗
      selectedSku: {},
      // 选中的 SKU
      showModel: false,
      // 是否展示 Coupon 优惠劵的弹窗
      couponInfo: [],
      // 可领取的 Coupon 优惠劵的列表
      showActivityModel: false,
      // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
      activityInfo: [],
      // 【满减送/限时折扣】可参与的 Activity 营销活动的列表
      activityList: []
      // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
    });
    function onSkuChange(e) {
      state.selectedSku = e;
    }
    function onAddCart(e) {
      if (!e.id) {
        sheep_index.sheep.$helper.toast("请选择商品规格");
        return;
      }
      sheep_index.sheep.$store("cart").add(e);
    }
    function onBuy(e) {
      if (!state.selectedSku.id) {
        sheep_index.sheep.$helper.toast("请选择商品规格");
        return;
      }
      sheep_index.sheep.$router.go("/pages/order/confirm", {
        data: JSON.stringify({
          items: [{
            skuId: e.id,
            count: e.goods_num
          }],
          // TODO 芋艿：后续清理掉这 2 参数
          deliveryType: 1,
          pointStatus: false
        })
      });
    }
    function onActivity() {
      state.showActivityModel = true;
    }
    async function onGet(id) {
      const { code } = await sheep_api_promotion_coupon.CouponApi.takeCoupon(id);
      if (code !== 0) {
        return;
      }
      common_vendor.index.showToast({
        title: "领取成功"
      });
      setTimeout(() => {
        getCoupon();
      }, 1e3);
    }
    const shareInfo = common_vendor.computed(() => {
      if (common_vendor.lodashExports.isEmpty(state.goodsInfo))
        return {};
      return sheep_index.sheep.$platform.share.getShareInfo({
        title: state.goodsInfo.name,
        image: sheep_index.sheep.$url.cdn(state.goodsInfo.image),
        desc: state.goodsInfo.subtitle,
        params: {
          page: "2",
          query: state.goodsInfo.id
        }
      }, {
        type: "goods",
        // 商品海报
        title: state.goodsInfo.name,
        // 商品标题
        // image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
        image: sheep_index.sheep.$url.cdn(state.goodsInfo.picUrl),
        // 商品主图
        price: sheep_hooks_useGoods.fen2yuan(state.goodsInfo.price),
        // 商品价格
        original_price: sheep_hooks_useGoods.fen2yuan(state.goodsInfo.maretPrice)
        // 商品原价
      });
    });
    async function getCoupon() {
      const { code, data } = await sheep_api_promotion_coupon.CouponApi.getCouponTemplateList(state.goodsId, 2, 10);
      if (code === 0) {
        state.couponInfo = data;
      }
    }
    common_vendor.onLoad((options) => {
      if (!options.id) {
        state.goodsInfo = null;
        return;
      }
      state.goodsId = options.id;
      sheep_api_product_spu.SpuApi.getSpuDetail(state.goodsId).then((res) => {
        if (res.code !== 0 || !res.data) {
          state.goodsInfo = null;
          return;
        }
        state.skeletonLoading = false;
        state.goodsInfo = res.data;
        sheep_api_product_favorite.FavoriteApi.isFavoriteExists(state.goodsId, "goods").then((res2) => {
          if (res2.code !== 0) {
            return;
          }
          state.goodsInfo.favorite = res2.data;
        });
      });
      getCoupon();
      sheep_api_promotion_activity.ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
        if (res.code !== 0) {
          return;
        }
        res.data.forEach((activity) => {
          if ([1, 2, 3].includes(activity.type)) {
            state.activityList.push(activity);
          } else if (activity.type === 5) {
            state.activityInfo.push(activity);
          } else {
            console.log("待实现！优先级不高");
          }
        });
      });
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: state.skeletonLoading
      }, state.skeletonLoading ? {} : state.goodsInfo === null ? {
        c: common_vendor.p({
          text: "商品不存在或已下架",
          icon: "/static/soldout-empty.png",
          showAction: true,
          actionText: "再逛逛",
          actionUrl: "/pages/goods/list"
        })
      } : common_vendor.e({
        d: common_vendor.p({
          isPreview: true,
          list: common_vendor.unref(sheep_hooks_useGoods.formatGoodsSwiper)(state.goodsInfo.sliderPicUrls),
          otStyle: "tag",
          imageMode: "widthFix",
          dotCur: "bg-mask-40",
          seizeHeight: 750
        }),
        e: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.selectedSku.price || state.goodsInfo.price)),
        f: state.goodsInfo.marketPrice > 0
      }, state.goodsInfo.marketPrice > 0 ? {
        g: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.selectedSku.marketPrice || state.goodsInfo.marketPrice))
      } : {}, {
        h: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.formatSales)("exact", state.goodsInfo.salesCount)),
        i: common_vendor.f(state.activityInfo, (promos, k0, i0) => {
          return {
            a: common_vendor.t(promos.name),
            b: promos.id,
            c: common_vendor.o(onActivity, promos.id)
          };
        }),
        j: state.couponInfo.length
      }, state.couponInfo.length ? {
        k: common_vendor.o(($event) => state.showModel = true)
      } : {}, {
        l: common_vendor.t(state.goodsInfo.name),
        m: common_vendor.t(state.goodsInfo.introduction),
        n: common_vendor.o(($event) => state.showSelectSku = true),
        o: common_vendor.o(($event) => state.selectedSku.goods_sku_text = $event),
        p: common_vendor.p({
          sku: state.selectedSku,
          modelValue: state.selectedSku.goods_sku_text
        }),
        q: common_vendor.o(onAddCart),
        r: common_vendor.o(onBuy),
        s: common_vendor.o(onSkuChange),
        t: common_vendor.o(($event) => state.showSelectSku = false),
        v: common_vendor.p({
          goodsInfo: state.goodsInfo,
          show: state.showSelectSku
        }),
        w: common_vendor.p({
          goodsId: state.goodsId
        }),
        x: common_vendor.p({
          content: state.goodsInfo.description
        }),
        y: state.activityList.length > 0
      }, state.activityList.length > 0 ? {
        z: common_vendor.p({
          ["activity-list"]: state.activityList
        })
      } : {}, {
        A: state.goodsInfo.stock > 0
      }, state.goodsInfo.stock > 0 ? {
        B: common_vendor.o(($event) => state.showSelectSku = true),
        C: common_vendor.o(($event) => state.showSelectSku = true)
      } : {}, {
        D: common_vendor.o(($event) => state.goodsInfo = $event),
        E: common_vendor.p({
          modelValue: state.goodsInfo
        }),
        F: common_vendor.o(($event) => state.showModel = false),
        G: common_vendor.o(onGet),
        H: common_vendor.o(($event) => state.couponInfo = $event),
        I: common_vendor.p({
          show: state.showModel,
          modelValue: state.couponInfo
        }),
        J: common_vendor.o(($event) => state.showActivityModel = false),
        K: common_vendor.o(($event) => state.activityInfo = $event),
        L: common_vendor.p({
          show: state.showActivityModel,
          modelValue: state.activityInfo
        })
      }), {
        b: state.goodsInfo === null,
        M: common_vendor.p({
          onShareAppMessage: common_vendor.unref(shareInfo),
          navbar: "goods"
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-24a31e85"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/pages/goods/index.vue"]]);
_sfc_main.__runtimeHooks = 3;
wx.createPage(MiniProgramPage);
