index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. if (this.state.current == index) return;
  91. this.setState(
  92. {
  93. current: index,
  94. page: 1,
  95. productList: [],
  96. isLoading: false,
  97. },
  98. () => {
  99. this.getProductList(true);
  100. }
  101. );
  102. };
  103. // 商品详情
  104. handleProductDetail = (product) => {
  105. Taro.navigateTo({
  106. url: `/pages/indexSub/productDetail/index?id=${product.id}&&isShare=${this.state.isShare}&&isShowBack=${this.state.isShowBack}`,
  107. });
  108. };
  109. // 滚动到底部
  110. handleScrollToLower = () => {
  111. const { page, totalPages, loading } = this.state;
  112. if (page < totalPages && !loading) {
  113. this.setState(
  114. (prevState) => ({ page: prevState.page + 1 }),
  115. () => this.getProductList()
  116. );
  117. }
  118. };
  119. // 配置分享内容
  120. onShareAppMessage() {
  121. let shareUserId = "";
  122. if (Taro.getStorageSync("loginInfo")) {
  123. shareUserId = Taro.getStorageSync("loginInfo").id;
  124. }
  125. return {
  126. title: "新春活动",
  127. path: `/pages/indexSub/activity/index?isShare=true&&isShowBack=true&&shareUserId=${shareUserId}`,
  128. imageUrl: "",
  129. };
  130. }
  131. render() {
  132. return (
  133. <View className="index">
  134. {/* 返回按钮 */}
  135. {!this.state.isShare && (
  136. <Image
  137. onClick={this.handleBack}
  138. style={{ top: Taro.navigationBarHeight + "px" }}
  139. className="top-back"
  140. src="https://yushi.tos-cn-beijing.volces.com/activity/back.png"
  141. mode="widthFix"
  142. />
  143. )}
  144. {/* 顶部图片包裹盒子 */}
  145. <View className="top-img-wrap">
  146. <Image
  147. className="top-img"
  148. src="https://yushi.tos-cn-beijing.volces.com/activity/topImg.png"
  149. mode="widthFix"
  150. />
  151. <Image
  152. className="top-title-img"
  153. src="https://yushi.tos-cn-beijing.volces.com/activity/titleImgOne.png"
  154. mode="widthFix"
  155. />
  156. </View>
  157. {/* 专场 */}
  158. {this.state.tabList.length > 0 && (
  159. <View className="activity-wrap">
  160. <View className="topBox">
  161. <View
  162. className="item"
  163. onClick={() => {
  164. this.siteClick("下午茶专场", "0");
  165. }}
  166. >
  167. <View className="item-title">下午茶专场</View>
  168. <Image
  169. className="item-img"
  170. src="https://yushi.tos-cn-beijing.volces.com/activity/topOne.png"
  171. mode="widthFix"
  172. />
  173. <View className="item-text">点击进入</View>
  174. </View>
  175. <View
  176. className="item"
  177. onClick={() => {
  178. this.siteClick("餐饮美食专场", "1");
  179. }}
  180. >
  181. <View className="item-title">餐饮美食专场</View>
  182. <Image
  183. className="item-img"
  184. src="https://yushi.tos-cn-beijing.volces.com/activity/topTwo.png"
  185. mode="widthFix"
  186. />
  187. <View className="item-text">点击进入</View>
  188. </View>
  189. </View>
  190. <View className="centerBox">
  191. <View
  192. className="item"
  193. onClick={() => {
  194. this.siteClick("酒店出行专场", "2");
  195. }}
  196. >
  197. <View className="item-title">酒店出行专场</View>
  198. <Image
  199. className="item-img"
  200. src="https://yushi.tos-cn-beijing.volces.com/activity/centerOne.png"
  201. mode="widthFix"
  202. />
  203. <View className="item-text">点击进入</View>
  204. </View>
  205. <View
  206. className="item"
  207. onClick={() => {
  208. this.siteClick("清洗服务专场", "3");
  209. }}
  210. >
  211. <View className="item-title">清洗服务专场</View>
  212. <Image
  213. className="item-img"
  214. src="https://yushi.tos-cn-beijing.volces.com/activity/centerTwo.png"
  215. mode="widthFix"
  216. />
  217. <View className="item-text">点击进入</View>
  218. </View>
  219. <View
  220. className="item"
  221. onClick={() => {
  222. this.siteClick("游玩娱乐专场", "4");
  223. }}
  224. >
  225. <View className="item-title">游玩娱乐专场</View>
  226. <Image
  227. className="item-img"
  228. src="https://yushi.tos-cn-beijing.volces.com/activity/centerThree.png"
  229. mode="widthFix"
  230. />
  231. <View className="item-text">点击进入</View>
  232. </View>
  233. </View>
  234. <View className="bottomBox">
  235. <View
  236. className="item"
  237. onClick={() => {
  238. this.siteClick("咖啡专场", "5");
  239. }}
  240. >
  241. <View className="item-title">咖啡专场</View>
  242. <Image
  243. className="item-img"
  244. src="https://yushi.tos-cn-beijing.volces.com/activity/bottom.png"
  245. mode="widthFix"
  246. />
  247. <View className="item-text">点击进入</View>
  248. </View>
  249. </View>
  250. </View>
  251. )}
  252. <Image
  253. className="bottom-title-img"
  254. src="https://yushi.tos-cn-beijing.volces.com/activity/titleImgTwo.png"
  255. mode="widthFix"
  256. />
  257. {/* 商品列表盒子 */}
  258. <View className="product-list-wrap">
  259. {/* tab分类 */}
  260. <View className="tabs-list">
  261. <AtTabs
  262. current={this.state.current}
  263. scroll
  264. tabList={this.state.tabList}
  265. onClick={this.tabClick}
  266. />
  267. </View>
  268. <ScrollView
  269. onScrollToLower={this.handleScrollToLower}
  270. className="product-list"
  271. scrollY
  272. >
  273. <View className="product-list-container">
  274. {this.state.productList.map((product) => (
  275. <View
  276. onClick={() => this.handleProductDetail(product)}
  277. key={product.id}
  278. className="product-list-item"
  279. >
  280. <Image
  281. className="product-img"
  282. src={product.image_url}
  283. mode="aspectFill"
  284. />
  285. <View className="product-content">
  286. <Text className="product-title">{product.item_title}</Text>
  287. <View className="product-price">
  288. <View className="product-price-left">
  289. <Text className="product-price-text">到手价</Text>
  290. <Text className="product-price-text-price">
  291. ¥{product.reserve_price}
  292. </Text>
  293. </View>
  294. <View className="product-commission">
  295. <Text className="product-commission-text">
  296. 赚¥{product.estimated_commission_promotion}
  297. </Text>
  298. </View>
  299. </View>
  300. </View>
  301. </View>
  302. ))}
  303. {this.state.loading && (
  304. <View className="loading">
  305. <AtActivityIndicator
  306. content="加载中..."
  307. isOpened={this.state.loading}
  308. mode="center"
  309. color="#fff"
  310. />
  311. </View>
  312. )}
  313. </View>
  314. </ScrollView>
  315. </View>
  316. </View>
  317. );
  318. }
  319. }