FoodCard.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const utils_file = require("../../../utils/file.js");
  4. const utils_utils = require("../../../utils/utils.js");
  5. const _sfc_main = {
  6. __name: "FoodCard",
  7. props: {
  8. food: {
  9. type: Object,
  10. required: true,
  11. default: () => ({
  12. id: null,
  13. name: "",
  14. price: 0,
  15. desc: "",
  16. image: "",
  17. tags: [],
  18. monthlySales: 0,
  19. quantity: 0
  20. })
  21. }
  22. },
  23. emits: ["increase", "decrease"],
  24. setup(__props, { emit: __emit }) {
  25. const props = __props;
  26. const emit = __emit;
  27. const handleFoodClick = () => {
  28. utils_utils.go("/pages/foodDetail/index");
  29. };
  30. const handleIncrease = () => {
  31. if (props.food.quantity >= 99)
  32. return;
  33. emit("increase", props.food);
  34. };
  35. const handleDecrease = () => {
  36. if (props.food.quantity > 0) {
  37. emit("decrease", props.food);
  38. }
  39. };
  40. const getPriceMain = (price) => {
  41. if (!price)
  42. return "0";
  43. const priceStr = String(price);
  44. const dotIndex = priceStr.indexOf(".");
  45. return dotIndex > -1 ? priceStr.substring(0, dotIndex) : priceStr;
  46. };
  47. const getPriceDecimal = (price) => {
  48. if (!price)
  49. return "";
  50. const priceStr = String(price);
  51. const dotIndex = priceStr.indexOf(".");
  52. return dotIndex > -1 ? priceStr.substring(dotIndex + 1) : "";
  53. };
  54. return (_ctx, _cache) => {
  55. return common_vendor.e({
  56. a: __props.food.image,
  57. b: common_vendor.o(handleFoodClick),
  58. c: common_vendor.t(__props.food.name),
  59. d: common_vendor.t(getPriceMain(__props.food.price)),
  60. e: getPriceDecimal(__props.food.price)
  61. }, getPriceDecimal(__props.food.price) ? {
  62. f: common_vendor.t(getPriceDecimal(__props.food.price))
  63. } : {}, {
  64. g: common_vendor.t(__props.food.desc),
  65. h: common_vendor.f(__props.food.tags, (tag, tagIndex, i0) => {
  66. return {
  67. a: common_vendor.t(tag.text),
  68. b: tagIndex,
  69. c: common_vendor.n(tag.type)
  70. };
  71. }),
  72. i: common_vendor.unref(utils_file.getFileUrl)("img/icon/star.png"),
  73. j: common_vendor.t(__props.food.monthlySales || 0),
  74. k: common_vendor.unref(utils_file.getFileUrl)("img/icon/reduce1.png"),
  75. l: __props.food.quantity == 0,
  76. m: common_vendor.unref(utils_file.getFileUrl)("img/icon/reduce2.png"),
  77. n: __props.food.quantity != 0,
  78. o: __props.food.quantity === 0 ? 1 : "",
  79. p: common_vendor.o(handleDecrease),
  80. q: common_vendor.t(__props.food.quantity || 0),
  81. r: common_vendor.unref(utils_file.getFileUrl)("img/icon/add2.png"),
  82. s: __props.food.quantity < 99,
  83. t: common_vendor.unref(utils_file.getFileUrl)("img/icon/add1.png"),
  84. v: __props.food.quantity >= 99,
  85. w: common_vendor.o(handleIncrease)
  86. });
  87. };
  88. }
  89. };
  90. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-9fc46e58"]]);
  91. wx.createComponent(Component);
  92. //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/orderFood/components/FoodCard.js.map