"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Array) {
  const _easycom_uni_swipe_action_item2 = common_vendor.resolveComponent("uni-swipe-action-item");
  const _easycom_uni_swipe_action2 = common_vendor.resolveComponent("uni-swipe-action");
  (_easycom_uni_swipe_action_item2 + _easycom_uni_swipe_action2)();
}
const _easycom_uni_swipe_action_item = () => "../../uni_modules/uni-swipe-action/components/uni-swipe-action-item/uni-swipe-action-item.js";
const _easycom_uni_swipe_action = () => "../../uni_modules/uni-swipe-action/components/uni-swipe-action/uni-swipe-action.js";
if (!Math) {
  (_easycom_uni_swipe_action_item + _easycom_uni_swipe_action + recommend)();
}
const recommend = () => "../recommend/recommend.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "order",
  setup(__props) {
    common_vendor.ref(1);
    const incrementQuantity = (index) => {
      if (cartItems.value[index].quantity < 9) {
        cartItems.value[index].quantity++;
      }
    };
    const decrementQuantity = (index) => {
      if (cartItems.value[index].quantity > 1) {
        cartItems.value[index].quantity--;
      }
    };
    const cartItems = common_vendor.ref(common_vendor.index.getStorageSync("cartItems"));
    console.log("购物车order页面");
    console.log(cartItems.value);
    const deleteCard = (itemId) => {
      common_vendor.index.getStorage({
        key: "cartItems",
        success: function(res) {
          let cartItems2 = res.data;
          console.log("原始购物车数据:", cartItems2);
          console.log("尝试删除的 itemId:", itemId.id);
          const updatedCartItems = cartItems2.filter((item) => item.id !== itemId.id);
          console.log("更新后的购物车数据:", updatedCartItems);
          common_vendor.index.setStorage({
            key: "cartItems",
            data: updatedCartItems,
            success: function() {
              console.log("删除成功");
              common_vendor.index.reLaunch({ url: "/pages/order/order" });
            },
            fail: function(err) {
              console.log("删除失败：" + err);
            }
          });
        },
        fail: function(err) {
          console.log("获取购物车数据失败：" + err);
        }
      });
    };
    const totalAmount = common_vendor.computed(() => {
      return cartItems.value.reduce((total, item) => {
        return total + item.dishesPrice * item.quantity;
      }, 0);
    });
    const account = () => {
      console.log("Total amount to pay:", totalAmount.value);
      common_vendor.index.navigateTo({
        url: `/pages/account/account?totalAmount=${encodeURIComponent(totalAmount.value.toString())}`
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.f(cartItems.value, (item, index, i0) => {
          return {
            a: item.dishesImage,
            b: common_vendor.t(item.dishesName),
            c: common_vendor.t(item.dishesPrice),
            d: common_vendor.o(($event) => decrementQuantity(index)),
            e: common_vendor.t(item.quantity),
            f: common_vendor.o(($event) => incrementQuantity(index)),
            g: common_vendor.o(($event) => deleteCard(item)),
            h: index,
            i: "03a9cc6c-1-" + i0 + ",03a9cc6c-0"
          };
        }),
        b: `/pages/goods/goods?id=1435025`
      }, {
        c: common_vendor.t(common_vendor.unref(totalAmount)),
        d: common_vendor.o(account)
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/111111000000/uniapp04/pages/order/order.vue"]]);
my.createPage(MiniProgramPage);
