"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_utils = require("../../utils/utils.js"); if (!Math) { (FoodCard + BottomActionBar + CouponModal + CartModal + SelectCouponModal)(); } const FoodCard = () => "./components/FoodCard.js"; const BottomActionBar = () => "./components/BottomActionBar.js"; const CouponModal = () => "./components/CouponModal.js"; const CartModal = () => "./components/CartModal.js"; const SelectCouponModal = () => "./components/SelectCouponModal.js"; const _sfc_main = { __name: "index", setup(__props) { const currentDiners = common_vendor.ref(common_vendor.index.getStorageSync("currentDiners")); const currentCategoryIndex = common_vendor.ref(0); const couponModalOpen = common_vendor.ref(false); const cartModalOpen = common_vendor.ref(false); const selectCouponModalOpen = common_vendor.ref(false); const discountAmount = common_vendor.ref(12); const selectedCouponId = common_vendor.ref(null); const categories = common_vendor.ref([ { name: "推荐菜品", id: "recommend" }, { name: "招牌川菜", id: "signature" }, { name: "凉菜", id: "cold" }, { name: "热菜", id: "hot" }, { name: "汤品", id: "soup" }, { name: "主食", id: "staple" }, { name: "饮品", id: "drink" } ]); const foodList = common_vendor.ref([ { id: 1, name: "炭烤牛排", price: 26, desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩", image: "/static/demo.png", tags: [ { text: "招牌", type: "signature" }, { text: "中辣", type: "spicy" } ], monthlySales: 160, quantity: 0, categoryId: "recommend" }, { id: 2, name: "炭烤牛排", price: 26, desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩", image: "/static/demo.png", tags: [ { text: "招牌", type: "signature" }, { text: "中辣", type: "spicy" } ], monthlySales: 160, quantity: 99, categoryId: "recommend" }, { id: 3, name: "炭烤牛排", price: 26, desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩", image: "/static/demo.png", tags: [ { text: "招牌", type: "signature" }, { text: "中辣", type: "spicy" } ], monthlySales: 160, quantity: 23, categoryId: "cold" }, { id: 4, name: "炭烤牛排", price: 26, desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩", image: "/static/demo.png", tags: [ { text: "招牌", type: "signature" }, { text: "中辣", type: "spicy" } ], monthlySales: 160, quantity: 0, categoryId: "cold" } ]); const currentFoodList = common_vendor.computed(() => { const categoryId = categories.value[currentCategoryIndex.value].id; return foodList.value.filter((food) => food.categoryId === categoryId); }); const cartList = common_vendor.computed(() => { return foodList.value.filter((food) => food.quantity > 0); }); const couponList = common_vendor.ref([ { id: 1, amount: 38, minAmount: 158, name: "优惠券名称", expireDate: "2024/07/28", isReceived: false }, { id: 2, amount: 8, minAmount: 158, name: "优惠券名称", expireDate: "2024/07/28", isReceived: false }, { id: 3, amount: 682, minAmount: 1580, name: "优惠券名称", expireDate: "2024/07/28", isReceived: true }, { id: 4, amount: 1038, minAmount: 1580, name: "优惠券名称", expireDate: "2024/07/28", isReceived: true } ]); const availableCoupons = common_vendor.computed(() => { return couponList.value.filter((coupon) => coupon.isReceived); }); const selectCategory = (index) => { currentCategoryIndex.value = index; }; const handleIncrease = (food) => { if (food) { food.quantity = (food.quantity || 0) + 1; } }; const handleDecrease = (food) => { if (food && food.quantity > 0) { food.quantity -= 1; } }; const handleCouponClick = () => { if (cartModalOpen.value) { cartModalOpen.value = false; } if (selectCouponModalOpen.value) { selectCouponModalOpen.value = false; } couponModalOpen.value = true; }; const handleSelectCouponClick = () => { if (cartModalOpen.value) { cartModalOpen.value = false; } if (couponModalOpen.value) { couponModalOpen.value = false; } selectCouponModalOpen.value = true; }; const handleCouponSelect = ({ coupon, index, selectedId }) => { selectedCouponId.value = selectedId; if (selectedId) { discountAmount.value = coupon.amount; } else { discountAmount.value = 0; } selectCouponModalOpen.value = false; setTimeout(() => { cartModalOpen.value = true; }, 100); }; const handleSelectCouponClose = () => { selectCouponModalOpen.value = false; }; const handleCouponReceive = ({ coupon, index }) => { common_vendor.index.__f__("log", "at pages/orderFood/index.vue:253", "领取优惠券:", coupon); couponList.value[index].isReceived = true; common_vendor.index.showToast({ title: "领取成功", icon: "success" }); }; const handleCouponClose = () => { couponModalOpen.value = false; }; const handleCartClick = () => { if (cartList.value.length === 0) { common_vendor.index.showToast({ title: "购物车为空", icon: "none" }); return; } if (couponModalOpen.value) { couponModalOpen.value = false; } if (selectCouponModalOpen.value) { selectCouponModalOpen.value = false; } cartModalOpen.value = true; }; const handleCartClose = () => { cartModalOpen.value = false; }; const handleCartClear = () => { foodList.value.forEach((food) => { food.quantity = 0; }); cartModalOpen.value = false; common_vendor.index.showToast({ title: "已清空购物车", icon: "success" }); }; const handleOrderClick = (data) => { utils_utils.go("/pages/placeOrder/index"); }; common_vendor.onLoad((e) => { common_vendor.index.setNavigationBarTitle({ title: "店铺名称" }); }); return (_ctx, _cache) => { return { a: common_vendor.t(currentDiners.value), b: common_vendor.f(categories.value, (category, index, i0) => { return { a: common_vendor.t(category.name), b: index, c: currentCategoryIndex.value === index ? 1 : "", d: common_vendor.o(($event) => selectCategory(index), index) }; }), c: common_vendor.f(currentFoodList.value, (food, index, i0) => { return { a: food.id || index, b: common_vendor.o(handleIncrease, food.id || index), c: common_vendor.o(handleDecrease, food.id || index), d: "6c607792-0-" + i0, e: common_vendor.p({ food }) }; }), d: common_vendor.o(handleCouponClick), e: common_vendor.o(handleCartClick), f: common_vendor.o(handleOrderClick), g: common_vendor.p({ ["cart-list"]: cartList.value }), h: common_vendor.o(handleCouponReceive), i: common_vendor.o(handleCouponClose), j: common_vendor.o(($event) => couponModalOpen.value = $event), k: common_vendor.p({ ["coupon-list"]: couponList.value, open: couponModalOpen.value }), l: common_vendor.o(handleIncrease), m: common_vendor.o(handleDecrease), n: common_vendor.o(handleCartClear), o: common_vendor.o(handleSelectCouponClick), p: common_vendor.o(handleOrderClick), q: common_vendor.o(handleCartClose), r: common_vendor.o(($event) => cartModalOpen.value = $event), s: common_vendor.p({ ["cart-list"]: cartList.value, ["discount-amount"]: discountAmount.value, open: cartModalOpen.value }), t: common_vendor.o(handleCouponSelect), v: common_vendor.o(handleSelectCouponClose), w: common_vendor.o(($event) => selectCouponModalOpen.value = $event), x: common_vendor.p({ ["coupon-list"]: availableCoupons.value, ["selected-coupon-id"]: selectedCouponId.value, open: selectCouponModalOpen.value }) }; }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6c607792"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/orderFood/index.js.map