import Taro from "@tarojs/taro"; import dayjs from "dayjs"; import { View, Text, Image, ScrollView } from "@tarojs/components"; import classnames from "classnames"; import { calculateDistance } from "@/utils"; import { useUserInfo } from "@/store/userStore"; import * as LoginService from "@/services/loginService"; import img from "@/config/images"; import { navto, formatNtrpDisplay } from "@/utils/helper"; import styles from "./index.module.scss"; function genRecommendGames(games, location, avatar) { return games.map((item) => { const { id, title, start_time, end_time, court_type, location_name, current_players, max_players, latitude, longitude, skill_level_max, skill_level_min, play_type, } = item; const [c_latitude, c_longitude] = location; const distance = calculateDistance(c_latitude, c_longitude, latitude, longitude) / 1000; const startTime = dayjs(start_time); const endTime = dayjs(end_time); return { id, title, time: startTime.format("YYYY-MM-DD HH:MM"), timeLength: endTime.diff(startTime, "hour"), venue: location_name, venueType: court_type, distance: `${distance.toFixed(2)}km`, avatar, applications: max_players, checkedApplications: current_players, levelRequirements: skill_level_max !== skill_level_min ? `${formatNtrpDisplay(skill_level_min) || "-"}-${ formatNtrpDisplay(skill_level_max) || "-" }` : skill_level_min === "1" ? "无要求" : `${formatNtrpDisplay(skill_level_min)}以上`, playType: play_type, }; }); } export default function OrganizerInfo(props) { const { userInfo, currentLocation: location, onUpdateUserInfo = () => {}, handleViewUserInfo, handleAddComment, } = props; const { id, nickname, avatar_url, is_following, ntrp_level, stats: { hosted_games_count } = {}, ongoing_games = [], } = userInfo; const myInfo = useUserInfo(); const { id: my_id } = myInfo as LoginService.UserInfoType; const recommendGames = genRecommendGames(ongoing_games, location, avatar_url); const toggleFollow = async (follow) => { try { if (follow) { await LoginService.unFollowUser(id); } else { await LoginService.followUser(id); } onUpdateUserInfo(); Taro.showToast({ title: `${nickname} ${follow ? "已取消关注" : "已关注"}`, icon: "success", }); } catch (e) { Taro.showToast({ title: `${nickname} ${follow ? "取消关注失败" : "关注失败"}`, icon: "error", }); } }; function handleViewGame(gameId) { navto(`/game_pages/detail/index?id=${gameId}&from=current`); } return ( {/* orgnizer title */} 组织者 {/* organizer avatar and name */} {nickname} 已组织 {hosted_games_count} 次 NTRP {ntrp_level ? formatNtrpDisplay(ntrp_level) : "初学者"} {my_id === id ? ( "" ) : ( {is_following ? ( 取消关注 ) : ( <> 关注 )} )} handleAddComment()} > {/* recommend games by organizer */} {recommendGames.length > 0 && ( TA的更多活动 {recommendGames.map((game, index) => ( {/* game title */} {game.title} {/* game time and range */} {game.time} {game.timeLength} {/* game location、vunue、distance */} {game.venue} · {game.venueType} · {game.distance} {/* organizer avatar、applications、level requirements、play type */} { e.stopPropagation(); handleViewUserInfo(id); }} /> 已加入 {game.checkedApplications} /{game.applications} {game.levelRequirements} {game.playType} {/* {game.playType} */} ))} )} ); }