index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. import { Component } from "react";
  2. import { View, Image, Text, ScrollView } from "@tarojs/components";
  3. import { AtTabs, AtActivityIndicator } from "taro-ui";
  4. import "./index.less";
  5. import Taro from "@tarojs/taro";
  6. import {
  7. getNewYearTab,
  8. getNewYearProductList,
  9. } from "../../../service/activity";
  10. import { handleLog } from "../../../common/track";
  11. export default class Index extends Component {
  12. state = {
  13. current: 0,
  14. page: 1, //页数
  15. loading: false, //加载状态
  16. totalPages: 1, // 添加总页数
  17. tabList: [], //tab列表
  18. productList: [], //商品列表
  19. isShare: false, // 是否是分享跳转
  20. isShowBack: false, // 是否显示返回按钮
  21. };
  22. componentDidMount() {
  23. const { isShare, isShowBack, shareUserId } =
  24. Taro.getCurrentInstance().router.params || "";
  25. this.setState(
  26. {
  27. isShare: isShare || false,
  28. isShowBack: isShowBack || false,
  29. shareUserId: shareUserId || "",
  30. },
  31. () => {
  32. if (isShare) {
  33. Taro.hideHomeButton(); //隐藏返回首页
  34. }
  35. this.getTab(); //获取tab
  36. handleLog({
  37. event_type: this.state.isShare
  38. ? "share_to_activity"
  39. : "click_to_activity",
  40. event_type_title: this.state.isShare
  41. ? "从分享链接进入春节活动页"
  42. : "直接点击进入春节活动页",
  43. goods_id: 0,
  44. }); //埋点
  45. }
  46. );
  47. }
  48. // 获取tab
  49. getTab = async () => {
  50. const res = await getNewYearTab();
  51. const arr = [];
  52. res.forEach((item) => {
  53. arr.push({ title: item.title, id: item.id, name: item.name });
  54. });
  55. this.setState({ tabList: arr }, () => {
  56. this.getProductList(true);
  57. });
  58. };
  59. // 获取商品列表
  60. getProductList = async (isRefresh = false) => {
  61. const { page } = this.state;
  62. this.setState({ loading: true });
  63. const res = await getNewYearProductList({
  64. tag_id: this.state.tabList[this.state.current].id,
  65. page,
  66. page_size: 10,
  67. });
  68. this.setState((prevState) => ({
  69. productList: isRefresh
  70. ? res.goods_list
  71. : [...prevState.productList, ...res.goods_list],
  72. totalPages: res.total_pages,
  73. loading: false,
  74. }));
  75. };
  76. // 返回
  77. handleBack = () => {
  78. Taro.navigateBack();
  79. };
  80. // 专场点击
  81. siteClick = (title, index) => {
  82. const item = this.state.tabList.find((item) => item.name === title);
  83. const id = item ? item.id : "";
  84. Taro.navigateTo({
  85. url: `/pages/indexSub/seckillIndex/index?id=${id}&&title=${title}&&isShowBack=${this.state.isShowBack}&&isShare=${this.state.isShare}&&isDirect=true`,
  86. });
  87. };
  88. // 切换tab
  89. tabClick = (index) => {
  90. this.setState(
  91. {
  92. current: index,
  93. page: 1,
  94. productList: [],
  95. isLoading: false,
  96. },
  97. () => {
  98. this.getProductList(true);
  99. }
  100. );
  101. };
  102. // 商品详情
  103. handleProductDetail = (product) => {
  104. Taro.navigateTo({
  105. url: `/pages/indexSub/productDetail/index?id=${product.id}&&isShare=${this.state.isShare}&&isShowBack=${this.state.isShowBack}`,
  106. });
  107. };
  108. // 滚动到底部
  109. handleScrollToLower = () => {
  110. const { page, totalPages, loading } = this.state;
  111. if (page < totalPages && !loading) {
  112. this.setState(
  113. (prevState) => ({ page: prevState.page + 1 }),
  114. () => this.getProductList()
  115. );
  116. }
  117. };
  118. // 配置分享内容
  119. onShareAppMessage() {
  120. let shareUserId = "";
  121. if (Taro.getStorageSync("loginInfo")) {
  122. shareUserId = Taro.getStorageSync("loginInfo").id;
  123. }
  124. return {
  125. title: "新春活动",
  126. path: `/pages/indexSub/activity/index?isShare=true&&isShowBack=true&&shareUserId=${shareUserId}`,
  127. imageUrl: "",
  128. };
  129. }
  130. render() {
  131. return (
  132. <View className="index">
  133. {/* 返回按钮 */}
  134. {!this.state.isShare && (
  135. <Image
  136. onClick={this.handleBack}
  137. style={{ top: Taro.navigationBarHeight + "px" }}
  138. className="top-back"
  139. src="https://yushi.tos-cn-beijing.volces.com/activity/back.png"
  140. mode="widthFix"
  141. />
  142. )}
  143. {/* 顶部图片包裹盒子 */}
  144. <View className="top-img-wrap">
  145. <Image
  146. className="top-img"
  147. src="https://yushi.tos-cn-beijing.volces.com/activity/topImg.png"
  148. mode="widthFix"
  149. />
  150. <Image
  151. className="top-title-img"
  152. src="https://yushi.tos-cn-beijing.volces.com/activity/titleImgOne.png"
  153. mode="widthFix"
  154. />
  155. </View>
  156. {/* 专场 */}
  157. {this.state.tabList.length > 0 && (
  158. <View className="activity-wrap">
  159. <View className="topBox">
  160. <View
  161. className="item"
  162. onClick={() => {
  163. this.siteClick("下午茶专场", "0");
  164. }}
  165. >
  166. <View className="item-title">下午茶专场</View>
  167. <Image
  168. className="item-img"
  169. src="https://yushi.tos-cn-beijing.volces.com/activity/topOne.png"
  170. mode="widthFix"
  171. />
  172. <View className="item-text">点击进入</View>
  173. </View>
  174. <View
  175. className="item"
  176. onClick={() => {
  177. this.siteClick("餐饮美食专场", "1");
  178. }}
  179. >
  180. <View className="item-title">餐饮美食专场</View>
  181. <Image
  182. className="item-img"
  183. src="https://yushi.tos-cn-beijing.volces.com/activity/topTwo.png"
  184. mode="widthFix"
  185. />
  186. <View className="item-text">点击进入</View>
  187. </View>
  188. </View>
  189. <View className="centerBox">
  190. <View
  191. className="item"
  192. onClick={() => {
  193. this.siteClick("酒店出行专场", "2");
  194. }}
  195. >
  196. <View className="item-title">酒店出行专场</View>
  197. <Image
  198. className="item-img"
  199. src="https://yushi.tos-cn-beijing.volces.com/activity/centerOne.png"
  200. mode="widthFix"
  201. />
  202. <View className="item-text">点击进入</View>
  203. </View>
  204. <View
  205. className="item"
  206. onClick={() => {
  207. this.siteClick("清洗服务专场", "3");
  208. }}
  209. >
  210. <View className="item-title">清洗服务专场</View>
  211. <Image
  212. className="item-img"
  213. src="https://yushi.tos-cn-beijing.volces.com/activity/centerTwo.png"
  214. mode="widthFix"
  215. />
  216. <View className="item-text">点击进入</View>
  217. </View>
  218. <View
  219. className="item"
  220. onClick={() => {
  221. this.siteClick("游玩娱乐专场", "4");
  222. }}
  223. >
  224. <View className="item-title">游玩娱乐专场</View>
  225. <Image
  226. className="item-img"
  227. src="https://yushi.tos-cn-beijing.volces.com/activity/centerThree.png"
  228. mode="widthFix"
  229. />
  230. <View className="item-text">点击进入</View>
  231. </View>
  232. </View>
  233. <View className="bottomBox">
  234. <View
  235. className="item"
  236. onClick={() => {
  237. this.siteClick("咖啡专场", "5");
  238. }}
  239. >
  240. <View className="item-title">咖啡专场</View>
  241. <Image
  242. className="item-img"
  243. src="https://yushi.tos-cn-beijing.volces.com/activity/bottom.png"
  244. mode="widthFix"
  245. />
  246. <View className="item-text">点击进入</View>
  247. </View>
  248. </View>
  249. </View>
  250. )}
  251. <Image
  252. className="bottom-title-img"
  253. src="https://yushi.tos-cn-beijing.volces.com/activity/titleImgTwo.png"
  254. mode="widthFix"
  255. />
  256. {/* 商品列表盒子 */}
  257. <View className="product-list-wrap">
  258. {/* tab分类 */}
  259. <View className="tabs-list">
  260. <AtTabs
  261. current={this.state.current}
  262. scroll
  263. tabList={this.state.tabList}
  264. onClick={this.tabClick}
  265. />
  266. </View>
  267. <ScrollView
  268. onScrollToLower={this.handleScrollToLower}
  269. className="product-list"
  270. scrollY
  271. >
  272. <View className="product-list-container">
  273. {this.state.productList.map((product) => (
  274. <View
  275. onClick={() => this.handleProductDetail(product)}
  276. key={product.id}
  277. className="product-list-item"
  278. >
  279. <Image
  280. className="product-img"
  281. src={product.image_url}
  282. mode="aspectFill"
  283. />
  284. <View className="product-content">
  285. <Text className="product-title">{product.item_title}</Text>
  286. <View className="product-price">
  287. <View className="product-price-left">
  288. <Text className="product-price-text">到手价</Text>
  289. <Text className="product-price-text-price">
  290. ¥{product.reserve_price}
  291. </Text>
  292. </View>
  293. <View className="product-commission">
  294. <Text className="product-commission-text">
  295. 赚¥{product.estimated_commission_promotion}
  296. </Text>
  297. </View>
  298. </View>
  299. </View>
  300. </View>
  301. ))}
  302. {this.state.loading && (
  303. <View className="loading">
  304. <AtActivityIndicator
  305. content="加载中..."
  306. isOpened={this.state.loading}
  307. mode="center"
  308. color="#fff"
  309. />
  310. </View>
  311. )}
  312. </View>
  313. </ScrollView>
  314. </View>
  315. </View>
  316. );
  317. }
  318. }