//事件列表
import { View } from "@tarojs/components";
import { useEffect, useState } from "react";
import EventList from "./component/EventList";
import "./index.less";
import ITitle from "./component/ITitle";
import services from "@/services";
import Taro from "@tarojs/taro";
import Empty from "@/components/Empty";
function MyEvent() {
  const params = Taro.getCurrentInstance().router?.params;
  const [eventList, setEventList] = useState<API.EventListDto>({
    //事件列表
    items: [],
    total: 0,
    page: 1,
    pages: 1,
    noMoreText: "",
  });
  useEffect(() => {
    queryEventList();
  }, []);
  //查询事件列表
  const queryEventList = (page: number = 1, count: number = 10) => {
    services.event
      .postEventList({
        page,
        count,
        eventType: params?.type === "take" ? 1 : 2,
      })
      .then((res) => {
        let tableList =
          page === 1 ? res.data.items : eventList.items.concat(res.data.items);
        setEventList({
          ...res.data,
          items: tableList,
          noMoreText: page == res.data.pages ? "没有更多数据了" : "加载中...",
        });
      });
  };
  //滚动触底
  const onScrollToLower = () => {
    if (eventList.hasNext) {
      queryEventList(++eventList.page);
    }
  };
  console.log(90, eventList);
  return (
    <View className="wrap">
      <ITitle
        title={params?.type === "take" ? "我的随手拍" : "我的举手之劳"}
        style={{ padding: "10px 15px 4px" }}
      />
      <>
        {Number(eventList.total) === 0 ? (
          <Empty />
        ) : (
          <EventList
            list={eventList.items}
            noMoreText={eventList.noMoreText}
            onScrollToLower={onScrollToLower}
            eventType={params?.type}
          />
        )}
      </>
    </View>
  );
}

export default MyEvent;
