index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_utils = require("../../utils/utils.js");
  4. if (!Math) {
  5. (FoodCard + BottomActionBar + CouponModal + CartModal + SelectCouponModal)();
  6. }
  7. const FoodCard = () => "./components/FoodCard.js";
  8. const BottomActionBar = () => "./components/BottomActionBar.js";
  9. const CouponModal = () => "./components/CouponModal.js";
  10. const CartModal = () => "./components/CartModal.js";
  11. const SelectCouponModal = () => "./components/SelectCouponModal.js";
  12. const _sfc_main = {
  13. __name: "index",
  14. setup(__props) {
  15. const currentDiners = common_vendor.ref(common_vendor.index.getStorageSync("currentDiners"));
  16. const currentCategoryIndex = common_vendor.ref(0);
  17. const couponModalOpen = common_vendor.ref(false);
  18. const cartModalOpen = common_vendor.ref(false);
  19. const selectCouponModalOpen = common_vendor.ref(false);
  20. const discountAmount = common_vendor.ref(12);
  21. const selectedCouponId = common_vendor.ref(null);
  22. const categories = common_vendor.ref([
  23. { name: "推荐菜品", id: "recommend" },
  24. { name: "招牌川菜", id: "signature" },
  25. { name: "凉菜", id: "cold" },
  26. { name: "热菜", id: "hot" },
  27. { name: "汤品", id: "soup" },
  28. { name: "主食", id: "staple" },
  29. { name: "饮品", id: "drink" }
  30. ]);
  31. const foodList = common_vendor.ref([
  32. {
  33. id: 1,
  34. name: "炭烤牛排",
  35. price: 26,
  36. desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩",
  37. image: "/static/demo.png",
  38. tags: [
  39. { text: "招牌", type: "signature" },
  40. { text: "中辣", type: "spicy" }
  41. ],
  42. monthlySales: 160,
  43. quantity: 0,
  44. categoryId: "recommend"
  45. },
  46. {
  47. id: 2,
  48. name: "炭烤牛排",
  49. price: 26,
  50. desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩",
  51. image: "/static/demo.png",
  52. tags: [
  53. { text: "招牌", type: "signature" },
  54. { text: "中辣", type: "spicy" }
  55. ],
  56. monthlySales: 160,
  57. quantity: 99,
  58. categoryId: "recommend"
  59. },
  60. {
  61. id: 3,
  62. name: "炭烤牛排",
  63. price: 26,
  64. desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩",
  65. image: "/static/demo.png",
  66. tags: [
  67. { text: "招牌", type: "signature" },
  68. { text: "中辣", type: "spicy" }
  69. ],
  70. monthlySales: 160,
  71. quantity: 23,
  72. categoryId: "cold"
  73. },
  74. {
  75. id: 4,
  76. name: "炭烤牛排",
  77. price: 26,
  78. desc: "正宗川味, 麻辣鲜香, 豆腐滑嫩",
  79. image: "/static/demo.png",
  80. tags: [
  81. { text: "招牌", type: "signature" },
  82. { text: "中辣", type: "spicy" }
  83. ],
  84. monthlySales: 160,
  85. quantity: 0,
  86. categoryId: "cold"
  87. }
  88. ]);
  89. const currentFoodList = common_vendor.computed(() => {
  90. const categoryId = categories.value[currentCategoryIndex.value].id;
  91. return foodList.value.filter((food) => food.categoryId === categoryId);
  92. });
  93. const cartList = common_vendor.computed(() => {
  94. return foodList.value.filter((food) => food.quantity > 0);
  95. });
  96. const couponList = common_vendor.ref([
  97. {
  98. id: 1,
  99. amount: 38,
  100. minAmount: 158,
  101. name: "优惠券名称",
  102. expireDate: "2024/07/28",
  103. isReceived: false
  104. },
  105. {
  106. id: 2,
  107. amount: 8,
  108. minAmount: 158,
  109. name: "优惠券名称",
  110. expireDate: "2024/07/28",
  111. isReceived: false
  112. },
  113. {
  114. id: 3,
  115. amount: 682,
  116. minAmount: 1580,
  117. name: "优惠券名称",
  118. expireDate: "2024/07/28",
  119. isReceived: true
  120. },
  121. {
  122. id: 4,
  123. amount: 1038,
  124. minAmount: 1580,
  125. name: "优惠券名称",
  126. expireDate: "2024/07/28",
  127. isReceived: true
  128. }
  129. ]);
  130. const availableCoupons = common_vendor.computed(() => {
  131. return couponList.value.filter((coupon) => coupon.isReceived);
  132. });
  133. const selectCategory = (index) => {
  134. currentCategoryIndex.value = index;
  135. };
  136. const handleIncrease = (food) => {
  137. if (food) {
  138. food.quantity = (food.quantity || 0) + 1;
  139. }
  140. };
  141. const handleDecrease = (food) => {
  142. if (food && food.quantity > 0) {
  143. food.quantity -= 1;
  144. }
  145. };
  146. const handleCouponClick = () => {
  147. if (cartModalOpen.value) {
  148. cartModalOpen.value = false;
  149. }
  150. if (selectCouponModalOpen.value) {
  151. selectCouponModalOpen.value = false;
  152. }
  153. couponModalOpen.value = true;
  154. };
  155. const handleSelectCouponClick = () => {
  156. if (cartModalOpen.value) {
  157. cartModalOpen.value = false;
  158. }
  159. if (couponModalOpen.value) {
  160. couponModalOpen.value = false;
  161. }
  162. selectCouponModalOpen.value = true;
  163. };
  164. const handleCouponSelect = ({ coupon, index, selectedId }) => {
  165. selectedCouponId.value = selectedId;
  166. if (selectedId) {
  167. discountAmount.value = coupon.amount;
  168. } else {
  169. discountAmount.value = 0;
  170. }
  171. selectCouponModalOpen.value = false;
  172. setTimeout(() => {
  173. cartModalOpen.value = true;
  174. }, 100);
  175. };
  176. const handleSelectCouponClose = () => {
  177. selectCouponModalOpen.value = false;
  178. };
  179. const handleCouponReceive = ({ coupon, index }) => {
  180. common_vendor.index.__f__("log", "at pages/orderFood/index.vue:253", "领取优惠券:", coupon);
  181. couponList.value[index].isReceived = true;
  182. common_vendor.index.showToast({
  183. title: "领取成功",
  184. icon: "success"
  185. });
  186. };
  187. const handleCouponClose = () => {
  188. couponModalOpen.value = false;
  189. };
  190. const handleCartClick = () => {
  191. if (cartList.value.length === 0) {
  192. common_vendor.index.showToast({
  193. title: "购物车为空",
  194. icon: "none"
  195. });
  196. return;
  197. }
  198. if (couponModalOpen.value) {
  199. couponModalOpen.value = false;
  200. }
  201. if (selectCouponModalOpen.value) {
  202. selectCouponModalOpen.value = false;
  203. }
  204. cartModalOpen.value = true;
  205. };
  206. const handleCartClose = () => {
  207. cartModalOpen.value = false;
  208. };
  209. const handleCartClear = () => {
  210. foodList.value.forEach((food) => {
  211. food.quantity = 0;
  212. });
  213. cartModalOpen.value = false;
  214. common_vendor.index.showToast({
  215. title: "已清空购物车",
  216. icon: "success"
  217. });
  218. };
  219. const handleOrderClick = (data) => {
  220. utils_utils.go("/pages/placeOrder/index");
  221. };
  222. common_vendor.onLoad((e) => {
  223. common_vendor.index.setNavigationBarTitle({
  224. title: "店铺名称"
  225. });
  226. });
  227. return (_ctx, _cache) => {
  228. return {
  229. a: common_vendor.t(currentDiners.value),
  230. b: common_vendor.f(categories.value, (category, index, i0) => {
  231. return {
  232. a: common_vendor.t(category.name),
  233. b: index,
  234. c: currentCategoryIndex.value === index ? 1 : "",
  235. d: common_vendor.o(($event) => selectCategory(index), index)
  236. };
  237. }),
  238. c: common_vendor.f(currentFoodList.value, (food, index, i0) => {
  239. return {
  240. a: food.id || index,
  241. b: common_vendor.o(handleIncrease, food.id || index),
  242. c: common_vendor.o(handleDecrease, food.id || index),
  243. d: "6c607792-0-" + i0,
  244. e: common_vendor.p({
  245. food
  246. })
  247. };
  248. }),
  249. d: common_vendor.o(handleCouponClick),
  250. e: common_vendor.o(handleCartClick),
  251. f: common_vendor.o(handleOrderClick),
  252. g: common_vendor.p({
  253. ["cart-list"]: cartList.value
  254. }),
  255. h: common_vendor.o(handleCouponReceive),
  256. i: common_vendor.o(handleCouponClose),
  257. j: common_vendor.o(($event) => couponModalOpen.value = $event),
  258. k: common_vendor.p({
  259. ["coupon-list"]: couponList.value,
  260. open: couponModalOpen.value
  261. }),
  262. l: common_vendor.o(handleIncrease),
  263. m: common_vendor.o(handleDecrease),
  264. n: common_vendor.o(handleCartClear),
  265. o: common_vendor.o(handleSelectCouponClick),
  266. p: common_vendor.o(handleOrderClick),
  267. q: common_vendor.o(handleCartClose),
  268. r: common_vendor.o(($event) => cartModalOpen.value = $event),
  269. s: common_vendor.p({
  270. ["cart-list"]: cartList.value,
  271. ["discount-amount"]: discountAmount.value,
  272. open: cartModalOpen.value
  273. }),
  274. t: common_vendor.o(handleCouponSelect),
  275. v: common_vendor.o(handleSelectCouponClose),
  276. w: common_vendor.o(($event) => selectCouponModalOpen.value = $event),
  277. x: common_vendor.p({
  278. ["coupon-list"]: availableCoupons.value,
  279. ["selected-coupon-id"]: selectedCouponId.value,
  280. open: selectCouponModalOpen.value
  281. })
  282. };
  283. };
  284. }
  285. };
  286. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6c607792"]]);
  287. wx.createPage(MiniProgramPage);
  288. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/orderFood/index.js.map