BottomActionBar.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const utils_file = require("../../../utils/file.js");
  4. const _sfc_main = {
  5. __name: "BottomActionBar",
  6. props: {
  7. // 购物车数据列表
  8. cartList: {
  9. type: Array,
  10. default: () => []
  11. }
  12. },
  13. emits: ["coupon-click", "cart-click", "order-click"],
  14. setup(__props, { emit: __emit }) {
  15. const props = __props;
  16. const emit = __emit;
  17. const totalQuantity = common_vendor.computed(() => {
  18. return props.cartList.reduce((sum, item) => {
  19. return sum + (item.quantity || 0);
  20. }, 0);
  21. });
  22. const totalPrice = common_vendor.computed(() => {
  23. return props.cartList.reduce((sum, item) => {
  24. const quantity = item.quantity || 0;
  25. const price = item.price || 0;
  26. return sum + quantity * price;
  27. }, 0);
  28. });
  29. const formatPrice = (price) => {
  30. return Math.round(price).toFixed(0);
  31. };
  32. const handleCouponClick = () => {
  33. emit("coupon-click");
  34. };
  35. const handleCartClick = () => {
  36. emit("cart-click");
  37. };
  38. const handleOrderClick = () => {
  39. if (totalQuantity.value === 0)
  40. return;
  41. emit("order-click", {
  42. cartList: props.cartList,
  43. totalPrice: totalPrice.value,
  44. totalQuantity: totalQuantity.value
  45. });
  46. };
  47. return (_ctx, _cache) => {
  48. return {
  49. a: common_vendor.unref(utils_file.getFileUrl)("img/icon/shopBtn1.png"),
  50. b: common_vendor.unref(utils_file.getFileUrl)("img/icon/coupon.png"),
  51. c: common_vendor.o(handleCouponClick),
  52. d: common_vendor.unref(utils_file.getFileUrl)("img/icon/shopBtn2.png"),
  53. e: common_vendor.unref(utils_file.getFileUrl)("img/icon/shoppingCart.png"),
  54. f: common_vendor.t(totalQuantity.value),
  55. g: common_vendor.t(formatPrice(totalPrice.value)),
  56. h: common_vendor.o(handleCartClick),
  57. i: common_vendor.o(handleOrderClick)
  58. };
  59. };
  60. }
  61. };
  62. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-65412fc8"]]);
  63. wx.createComponent(Component);
  64. //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/orderFood/components/BottomActionBar.js.map