s-goods-card.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const sheep_index = require("../../index.js");
  4. const sheep_api_product_spu = require("../../api/product/spu.js");
  5. require("../../url/index.js");
  6. require("../../store/index.js");
  7. require("../../store/app.js");
  8. require("../../api/promotion/diy.js");
  9. require("../../request/index.js");
  10. require("../../config/index.js");
  11. require("../../platform/index.js");
  12. require("../../platform/provider/wechat/index.js");
  13. require("../../platform/provider/wechat/miniProgram.js");
  14. require("../../api/member/auth.js");
  15. require("../../api/member/social.js");
  16. require("../../api/member/user.js");
  17. require("../../platform/provider/apple/index.js");
  18. require("../../platform/share.js");
  19. require("../../router/index.js");
  20. require("../../hooks/useModal.js");
  21. require("../../helper/index.js");
  22. require("../../helper/test.js");
  23. require("../../helper/digit.js");
  24. require("../../api/member/signin.js");
  25. require("../../helper/throttle.js");
  26. require("../../platform/pay.js");
  27. require("../../api/pay/order.js");
  28. require("../../store/user.js");
  29. require("../../store/cart.js");
  30. require("../../api/trade/cart.js");
  31. require("../../api/pay/wallet.js");
  32. require("../../api/trade/order.js");
  33. require("../../api/promotion/coupon.js");
  34. require("../../store/sys.js");
  35. require("../../store/modal.js");
  36. require("../../config/zIndex.js");
  37. if (!Array) {
  38. const _easycom_s_goods_column2 = common_vendor.resolveComponent("s-goods-column");
  39. _easycom_s_goods_column2();
  40. }
  41. const _easycom_s_goods_column = () => "../s-goods-column/s-goods-column.js";
  42. if (!Math) {
  43. _easycom_s_goods_column();
  44. }
  45. const _sfc_main = {
  46. __name: "s-goods-card",
  47. props: {
  48. data: {
  49. type: Object,
  50. default() {
  51. }
  52. },
  53. styles: {
  54. type: Object,
  55. default() {
  56. }
  57. }
  58. },
  59. setup(__props) {
  60. const LayoutTypeEnum = {
  61. // 单列大图
  62. ONE_COL_BIG_IMG: "oneColBigImg",
  63. // 双列
  64. TWO_COL: "twoCol",
  65. // 单列小图
  66. ONE_COL_SMALL_IMG: "oneColSmallImg"
  67. };
  68. const state = common_vendor.reactive({
  69. goodsList: [],
  70. leftGoodsList: [],
  71. rightGoodsList: []
  72. });
  73. const props = __props;
  74. const { layoutType, btnBuy, spuIds } = props.data ?? {};
  75. const { marginLeft, marginRight } = props.styles ?? {};
  76. const buyStyle = common_vendor.computed(() => {
  77. if (btnBuy.type === "text") {
  78. return {
  79. background: `linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient))`
  80. };
  81. }
  82. if (btnBuy.type === "img") {
  83. return {
  84. width: "54rpx",
  85. height: "54rpx",
  86. background: `url(${sheep_index.sheep.$url.cdn(btnBuy.imgUrl)}) no-repeat`,
  87. backgroundSize: "100% 100%"
  88. };
  89. }
  90. });
  91. let count = 0;
  92. let leftHeight = 0;
  93. let rightHeight = 0;
  94. function calculateGoodsColumn(height = 0, where = "left") {
  95. if (!state.goodsList[count])
  96. return;
  97. if (where === "left")
  98. leftHeight += height;
  99. if (where === "right")
  100. rightHeight += height;
  101. if (leftHeight <= rightHeight) {
  102. state.leftGoodsList.push(state.goodsList[count]);
  103. } else {
  104. state.rightGoodsList.push(state.goodsList[count]);
  105. }
  106. count++;
  107. }
  108. async function getGoodsListByIds(ids) {
  109. const { data } = await sheep_api_product_spu.SpuApi.getSpuListByIds(ids);
  110. return data;
  111. }
  112. common_vendor.onMounted(async () => {
  113. state.goodsList = await getGoodsListByIds(spuIds.join(","));
  114. if (layoutType === LayoutTypeEnum.TWO_COL) {
  115. calculateGoodsColumn();
  116. }
  117. });
  118. return (_ctx, _cache) => {
  119. return common_vendor.e({
  120. a: common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_BIG_IMG && state.goodsList.length
  121. }, common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_BIG_IMG && state.goodsList.length ? {
  122. b: common_vendor.f(state.goodsList, (item, k0, i0) => {
  123. var _a;
  124. return {
  125. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  126. id: item.id
  127. }), item.id),
  128. b: "edfbd448-0-" + i0,
  129. c: common_vendor.p({
  130. size: "sl",
  131. goodsFields: __props.data.fields,
  132. tagStyle: __props.data.badge,
  133. data: item,
  134. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  135. subTitleColor: __props.data.fields.introduction.color,
  136. topRadius: __props.data.borderRadiusTop,
  137. bottomRadius: __props.data.borderRadiusBottom
  138. }),
  139. d: item.id
  140. };
  141. }),
  142. c: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  143. d: common_vendor.s(buyStyle.value),
  144. e: common_vendor.s({
  145. marginBottom: __props.data.space * 2 + "rpx"
  146. })
  147. } : {}, {
  148. f: common_vendor.unref(layoutType) === LayoutTypeEnum.TWO_COL && state.goodsList.length
  149. }, common_vendor.unref(layoutType) === LayoutTypeEnum.TWO_COL && state.goodsList.length ? {
  150. g: common_vendor.f(state.leftGoodsList, (item, k0, i0) => {
  151. var _a;
  152. return {
  153. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  154. id: item.id
  155. }), item.id),
  156. b: common_vendor.o(($event) => calculateGoodsColumn($event, "left"), item.id),
  157. c: "edfbd448-1-" + i0,
  158. d: common_vendor.p({
  159. size: "md",
  160. goodsFields: __props.data.fields,
  161. tagStyle: __props.data.badge,
  162. data: item,
  163. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  164. subTitleColor: __props.data.fields.introduction.color,
  165. topRadius: __props.data.borderRadiusTop,
  166. bottomRadius: __props.data.borderRadiusBottom,
  167. titleWidth: 330 - common_vendor.unref(marginLeft) - common_vendor.unref(marginRight)
  168. }),
  169. e: item.id
  170. };
  171. }),
  172. h: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  173. i: common_vendor.s(buyStyle.value),
  174. j: common_vendor.s({
  175. paddingRight: __props.data.space + "rpx",
  176. marginBottom: __props.data.space + "px"
  177. }),
  178. k: common_vendor.f(state.rightGoodsList, (item, k0, i0) => {
  179. var _a;
  180. return {
  181. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  182. id: item.id
  183. }), item.id),
  184. b: common_vendor.o(($event) => calculateGoodsColumn($event, "right"), item.id),
  185. c: "edfbd448-2-" + i0,
  186. d: common_vendor.p({
  187. size: "md",
  188. goodsFields: __props.data.fields,
  189. tagStyle: __props.data.badge,
  190. data: item,
  191. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  192. subTitleColor: __props.data.fields.introduction.color,
  193. topRadius: __props.data.borderRadiusTop,
  194. bottomRadius: __props.data.borderRadiusBottom,
  195. titleWidth: 330 - common_vendor.unref(marginLeft) - common_vendor.unref(marginRight)
  196. }),
  197. e: item.id
  198. };
  199. }),
  200. l: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  201. m: common_vendor.s(buyStyle.value),
  202. n: common_vendor.s({
  203. paddingLeft: __props.data.space + "rpx",
  204. marginBottom: __props.data.space + "px"
  205. })
  206. } : {}, {
  207. o: common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.goodsList.length
  208. }, common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.goodsList.length ? {
  209. p: common_vendor.f(state.goodsList, (item, k0, i0) => {
  210. var _a;
  211. return {
  212. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  213. id: item.id
  214. }), item.id),
  215. b: "edfbd448-3-" + i0,
  216. c: common_vendor.p({
  217. size: "lg",
  218. goodsFields: __props.data.fields,
  219. data: item,
  220. tagStyle: __props.data.badge,
  221. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  222. subTitleColor: __props.data.fields.introduction.color,
  223. topRadius: __props.data.borderRadiusTop,
  224. bottomRadius: __props.data.borderRadiusBottom
  225. }),
  226. d: item.id
  227. };
  228. }),
  229. q: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  230. r: common_vendor.s(buyStyle.value),
  231. s: common_vendor.s({
  232. marginBottom: __props.data.space + "px"
  233. })
  234. } : {});
  235. };
  236. }
  237. };
  238. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-edfbd448"], ["__file", "D:/zx/mall-front-app/sheep/components/s-goods-card/s-goods-card.vue"]]);
  239. wx.createComponent(Component);