index.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Component } from "react";
  2. import { View, Image, Text } from "@tarojs/components";
  3. import "./index.less";
  4. import Taro from "@tarojs/taro";
  5. import { getCalculatorList } from "../../../service/activity";
  6. export default class Index extends Component {
  7. state = {
  8. inventoryList: [],
  9. page: 1, // 添加页码
  10. totalPages: 1, // 添加总页数
  11. loading: false, // 添加加载状态
  12. };
  13. componentDidMount() {
  14. this.getCalculatorList(true); // 获取捡漏清单
  15. }
  16. // 获取捡漏清单
  17. getCalculatorList = async (isRefresh) => {
  18. this.setState({ loading: true });
  19. const res = await getCalculatorList({
  20. page: this.state.page,
  21. page_size: 10,
  22. });
  23. this.setState({
  24. inventoryList: isRefresh
  25. ? res.jianlou_list
  26. : [...this.state.inventoryList, ...res.jianlou_list],
  27. totalPages: res.total_pages,
  28. loading: false,
  29. });
  30. }
  31. // 查看心愿列表
  32. toWishList = (id) => {
  33. Taro.navigateTo({
  34. url: `/pages/calculatorSub/calculatorWishList/index?id=${id}`,
  35. });
  36. };
  37. // 页面上拉触底
  38. onReachBottom = () => {
  39. const { page, totalPages, loading } = this.state;
  40. if (page < totalPages && !loading) {
  41. this.setState(
  42. (prevState) => ({ page: prevState.page + 1 }),
  43. () => this.getCalculatorList(false)
  44. );
  45. }
  46. };
  47. render() {
  48. return (
  49. <View className="index">
  50. {/* 列表 */}
  51. <View className="list-box">
  52. {this.state.inventoryList.length > 0 &&
  53. this.state.inventoryList.map((item, index) => (
  54. <View key={index} className="list-item">
  55. <View className="list-item-left">
  56. <Image className="avatar" src={item.icon} />
  57. <View className="list-item-left-text">
  58. <Text className="name">{item.name}</Text>
  59. <Text className="wishNum">
  60. {item.activity_jianlou_cnt}次捡漏许愿
  61. </Text>
  62. </View>
  63. </View>
  64. <View
  65. onClick={() => this.toWishList(item.id)}
  66. className="list-item-right"
  67. >
  68. 查看
  69. </View>
  70. </View>
  71. ))}
  72. </View>
  73. </View>
  74. );
  75. }
  76. }