s-goods-card.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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("../../api/index.js");
  6. require("../../api/distri/score.js");
  7. require("../../request/index.js");
  8. require("../../config/index.js");
  9. require("../../store/index.js");
  10. require("../../store/app.js");
  11. require("../../api/promotion/diy.js");
  12. require("../../platform/index.js");
  13. require("../../platform/provider/wechat/index.js");
  14. require("../../platform/provider/wechat/miniProgram.js");
  15. require("../../api/member/auth.js");
  16. require("../../api/member/social.js");
  17. require("../../api/member/user.js");
  18. require("../../platform/provider/apple/index.js");
  19. require("../../platform/share.js");
  20. require("../../router/index.js");
  21. require("../../hooks/useModal.js");
  22. require("../../helper/index.js");
  23. require("../../helper/test.js");
  24. require("../../helper/digit.js");
  25. require("../../api/member/signin.js");
  26. require("../../helper/throttle.js");
  27. require("../../url/index.js");
  28. require("../../platform/pay.js");
  29. require("../../api/pay/order.js");
  30. require("../../store/user.js");
  31. require("../../store/cart.js");
  32. require("../../api/trade/cart.js");
  33. require("../../api/pay/wallet.js");
  34. require("../../api/trade/order.js");
  35. require("../../api/promotion/coupon.js");
  36. require("../../store/sys.js");
  37. require("../../store/modal.js");
  38. require("../../api/distri/share.js");
  39. require("../../api/distri/team.js");
  40. require("../../api/infra/file.js");
  41. require("../../api/member/address.js");
  42. require("../../api/member/point.js");
  43. require("../../api/migration/app.js");
  44. require("../../api/migration/chat.js");
  45. require("../../api/migration/index.js");
  46. require("../../api/migration/third.js");
  47. require("../../api/pay/channel.js");
  48. require("../../api/product/category.js");
  49. require("../../api/product/comment.js");
  50. require("../../api/product/favorite.js");
  51. require("../../api/product/history.js");
  52. require("../../api/promotion/activity.js");
  53. require("../../api/promotion/article.js");
  54. require("../../api/promotion/bargain.js");
  55. require("../../api/promotion/combination.js");
  56. require("../../api/promotion/rewardActivity.js");
  57. require("../../api/promotion/seckill.js");
  58. require("../../api/system/area.js");
  59. require("../../api/system/voice.js");
  60. require("../../api/trade/afterSale.js");
  61. require("../../api/trade/brokerage.js");
  62. require("../../api/trade/config.js");
  63. require("../../api/trade/delivery.js");
  64. require("../../config/zIndex.js");
  65. if (!Array) {
  66. const _easycom_s_goods_column2 = common_vendor.resolveComponent("s-goods-column");
  67. _easycom_s_goods_column2();
  68. }
  69. const _easycom_s_goods_column = () => "../s-goods-column/s-goods-column.js";
  70. if (!Math) {
  71. _easycom_s_goods_column();
  72. }
  73. const _sfc_main = {
  74. __name: "s-goods-card",
  75. props: {
  76. data: {
  77. type: Object,
  78. default() {
  79. }
  80. },
  81. styles: {
  82. type: Object,
  83. default() {
  84. }
  85. }
  86. },
  87. setup(__props) {
  88. const LayoutTypeEnum = {
  89. // 单列大图
  90. ONE_COL_BIG_IMG: "oneColBigImg",
  91. // 双列
  92. TWO_COL: "twoCol",
  93. // 单列小图
  94. ONE_COL_SMALL_IMG: "oneColSmallImg"
  95. };
  96. const state = common_vendor.reactive({
  97. goodsList: [],
  98. leftGoodsList: [],
  99. rightGoodsList: []
  100. });
  101. const props = __props;
  102. const { layoutType, btnBuy, spuIds } = props.data ?? {};
  103. const { marginLeft, marginRight } = props.styles ?? {};
  104. const buyStyle = common_vendor.computed(() => {
  105. if (btnBuy.type === "text") {
  106. return {
  107. background: `linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient))`
  108. };
  109. }
  110. if (btnBuy.type === "img") {
  111. return {
  112. width: "54rpx",
  113. height: "54rpx",
  114. background: `url(${sheep_index.sheep.$url.cdn(btnBuy.imgUrl)}) no-repeat`,
  115. backgroundSize: "100% 100%"
  116. };
  117. }
  118. });
  119. let count = 0;
  120. let leftHeight = 0;
  121. let rightHeight = 0;
  122. function calculateGoodsColumn(height = 0, where = "left") {
  123. if (!state.goodsList[count])
  124. return;
  125. if (where === "left")
  126. leftHeight += height;
  127. if (where === "right")
  128. rightHeight += height;
  129. if (leftHeight <= rightHeight) {
  130. state.leftGoodsList.push(state.goodsList[count]);
  131. } else {
  132. state.rightGoodsList.push(state.goodsList[count]);
  133. }
  134. count++;
  135. }
  136. async function getGoodsListByIds(ids) {
  137. const { data } = await sheep_api_product_spu.SpuApi.getSpuListByIds(ids);
  138. return data;
  139. }
  140. common_vendor.onMounted(async () => {
  141. state.goodsList = await getGoodsListByIds(spuIds.join(","));
  142. if (layoutType === LayoutTypeEnum.TWO_COL) {
  143. calculateGoodsColumn();
  144. }
  145. });
  146. return (_ctx, _cache) => {
  147. return common_vendor.e({
  148. a: common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_BIG_IMG && state.goodsList.length
  149. }, common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_BIG_IMG && state.goodsList.length ? {
  150. b: common_vendor.f(state.goodsList, (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: "edfbd448-0-" + i0,
  157. c: common_vendor.p({
  158. size: "sl",
  159. goodsFields: __props.data.fields,
  160. tagStyle: __props.data.badge,
  161. data: item,
  162. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  163. subTitleColor: __props.data.fields.introduction.color,
  164. topRadius: __props.data.borderRadiusTop,
  165. bottomRadius: __props.data.borderRadiusBottom
  166. }),
  167. d: item.id
  168. };
  169. }),
  170. c: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  171. d: common_vendor.s(buyStyle.value),
  172. e: common_vendor.s({
  173. marginBottom: __props.data.space * 2 + "rpx"
  174. })
  175. } : {}, {
  176. f: common_vendor.unref(layoutType) === LayoutTypeEnum.TWO_COL && state.goodsList.length
  177. }, common_vendor.unref(layoutType) === LayoutTypeEnum.TWO_COL && state.goodsList.length ? {
  178. g: common_vendor.f(state.leftGoodsList, (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, "left"), item.id),
  185. c: "edfbd448-1-" + 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. h: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  201. i: common_vendor.s(buyStyle.value),
  202. j: common_vendor.s({
  203. paddingRight: __props.data.space + "rpx",
  204. marginBottom: __props.data.space + "px"
  205. }),
  206. k: common_vendor.f(state.rightGoodsList, (item, k0, i0) => {
  207. var _a;
  208. return {
  209. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  210. id: item.id
  211. }), item.id),
  212. b: common_vendor.o(($event) => calculateGoodsColumn($event, "right"), item.id),
  213. c: "edfbd448-2-" + i0,
  214. d: common_vendor.p({
  215. size: "md",
  216. goodsFields: __props.data.fields,
  217. tagStyle: __props.data.badge,
  218. data: item,
  219. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  220. subTitleColor: __props.data.fields.introduction.color,
  221. topRadius: __props.data.borderRadiusTop,
  222. bottomRadius: __props.data.borderRadiusBottom,
  223. titleWidth: 330 - common_vendor.unref(marginLeft) - common_vendor.unref(marginRight)
  224. }),
  225. e: item.id
  226. };
  227. }),
  228. l: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  229. m: common_vendor.s(buyStyle.value),
  230. n: common_vendor.s({
  231. paddingLeft: __props.data.space + "rpx",
  232. marginBottom: __props.data.space + "px"
  233. })
  234. } : {}, {
  235. o: common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.goodsList.length
  236. }, common_vendor.unref(layoutType) === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.goodsList.length ? {
  237. p: common_vendor.f(state.goodsList, (item, k0, i0) => {
  238. var _a;
  239. return {
  240. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  241. id: item.id
  242. }), item.id),
  243. b: "edfbd448-3-" + i0,
  244. c: common_vendor.p({
  245. size: "lg",
  246. goodsFields: __props.data.fields,
  247. data: item,
  248. tagStyle: __props.data.badge,
  249. titleColor: (_a = __props.data.fields.name) == null ? void 0 : _a.color,
  250. subTitleColor: __props.data.fields.introduction.color,
  251. topRadius: __props.data.borderRadiusTop,
  252. bottomRadius: __props.data.borderRadiusBottom
  253. }),
  254. d: item.id
  255. };
  256. }),
  257. q: common_vendor.t(common_vendor.unref(btnBuy).type === "text" ? common_vendor.unref(btnBuy).text : ""),
  258. r: common_vendor.s(buyStyle.value),
  259. s: common_vendor.s({
  260. marginBottom: __props.data.space + "px"
  261. })
  262. } : {});
  263. };
  264. }
  265. };
  266. 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"]]);
  267. wx.createComponent(Component);