| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- "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
|