CartModal.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const utils_file = require("../../../utils/file.js");
  4. if (!Math) {
  5. BasicModal();
  6. }
  7. const BasicModal = () => "../../../components/Modal/BasicModal.js";
  8. const _sfc_main = {
  9. __name: "CartModal",
  10. props: {
  11. open: {
  12. type: Boolean,
  13. default: false
  14. },
  15. cartList: {
  16. type: Array,
  17. default: () => []
  18. },
  19. discountAmount: {
  20. type: Number,
  21. default: 0
  22. },
  23. showCouponSection: {
  24. type: Boolean,
  25. default: true
  26. }
  27. },
  28. emits: ["update:open", "increase", "decrease", "clear", "coupon-click", "order-click", "close"],
  29. setup(__props, { emit: __emit }) {
  30. const props = __props;
  31. const emit = __emit;
  32. const getOpen = common_vendor.computed({
  33. get: () => props.open,
  34. set: (val) => emit("update:open", val)
  35. });
  36. common_vendor.computed(() => {
  37. return props.cartList.reduce((sum, item) => {
  38. return sum + (item.quantity || 0);
  39. }, 0);
  40. });
  41. common_vendor.computed(() => {
  42. return props.cartList.reduce((sum, item) => {
  43. const quantity = item.quantity || 0;
  44. const price = item.price || 0;
  45. return sum + quantity * price;
  46. }, 0);
  47. });
  48. const formatPrice = (price) => {
  49. return Math.round(price).toFixed(0);
  50. };
  51. const handleIncrease = (item) => {
  52. if (item.quantity >= 99)
  53. return;
  54. emit("increase", item);
  55. };
  56. const handleDecrease = (item) => {
  57. if (item && item.quantity > 0) {
  58. emit("decrease", item);
  59. }
  60. };
  61. const handleClear = () => {
  62. common_vendor.index.showModal({
  63. title: "提示",
  64. content: "确定要清空购物车吗?",
  65. success: (res) => {
  66. if (res.confirm) {
  67. emit("clear");
  68. }
  69. }
  70. });
  71. };
  72. const handleCouponClick = () => {
  73. emit("coupon-click");
  74. };
  75. return (_ctx, _cache) => {
  76. return common_vendor.e({
  77. a: __props.cartList.length > 0
  78. }, __props.cartList.length > 0 ? {
  79. b: common_vendor.o(handleClear)
  80. } : {}, {
  81. c: common_vendor.f(__props.cartList, (item, index, i0) => {
  82. return common_vendor.e({
  83. a: item.image,
  84. b: common_vendor.t(item.name),
  85. c: item.tags && item.tags.length > 0
  86. }, item.tags && item.tags.length > 0 ? {
  87. d: common_vendor.f(item.tags, (tag, tagIndex, i1) => {
  88. return {
  89. a: common_vendor.t(tag.text),
  90. b: tagIndex,
  91. c: common_vendor.n(tag.type)
  92. };
  93. })
  94. } : {}, {
  95. e: common_vendor.t(formatPrice(item.price)),
  96. f: item.quantity == 0,
  97. g: item.quantity != 0,
  98. h: item.quantity === 0 ? 1 : "",
  99. i: common_vendor.o(($event) => handleDecrease(item), item.id || index),
  100. j: common_vendor.t(item.quantity || 0),
  101. k: item.quantity < 99,
  102. l: item.quantity >= 99,
  103. m: common_vendor.o(($event) => handleIncrease(item), item.id || index),
  104. n: item.id || index
  105. });
  106. }),
  107. d: common_vendor.unref(utils_file.getFileUrl)("img/icon/reduce1.png"),
  108. e: common_vendor.unref(utils_file.getFileUrl)("img/icon/reduce2.png"),
  109. f: common_vendor.unref(utils_file.getFileUrl)("img/icon/add2.png"),
  110. g: common_vendor.unref(utils_file.getFileUrl)("img/icon/add1.png"),
  111. h: __props.showCouponSection
  112. }, __props.showCouponSection ? common_vendor.e({
  113. i: __props.discountAmount > 0
  114. }, __props.discountAmount > 0 ? {
  115. j: common_vendor.t(formatPrice(__props.discountAmount))
  116. } : {}, {
  117. k: common_vendor.o(handleCouponClick)
  118. }) : {}, {
  119. l: common_vendor.o(($event) => getOpen.value = $event),
  120. m: common_vendor.p({
  121. type: "bottom",
  122. isMack: true,
  123. open: getOpen.value
  124. })
  125. });
  126. };
  127. }
  128. };
  129. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1091c94b"]]);
  130. wx.createComponent(Component);
  131. //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/orderFood/components/CartModal.js.map