"use client"; import React, { useEffect, useRef, useState } from "react"; import { Input, List, DotLoading, Toast, Image, Popup, Radio, Picker, Space, } from "antd-mobile"; import { useRouter } from "next/navigation"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft, faClose } from "@fortawesome/free-solid-svg-icons"; import requireAPI from "@/utils/requireAPI"; import { debounce } from "@/utils/tools"; import Empty from "@/components/Empty"; import MySlider from "@/components/MySlider"; import baseRequest from "@/utils/baseRequest"; const filterComprehensiveItems = { age: { lower_bound: 18, upper_bound: 60 }, fans: { lower_bound: 1, upper_bound: 1000 }, weight: { lower_bound: 35, upper_bound: 100 }, height: { lower_bound: 140, upper_bound: 200 }, city: "不限", constellation: "不限", is_active_within_a_week: 0, comprehensiveUsed: { show: false, used: false }, }; const filterPriceItems = { zone_admission_price: { lower_bound: 0, upper_bound: 4000 }, wechat_coin_price: { lower_bound: 0, upper_bound: 100000 }, priceUsed: { show: false, used: false }, }; const newDebounce = debounce(function (fn) { fn && fn(); }, 500); export default function Search() { const base = baseRequest(); const router = useRouter(); const inputRef = useRef(); // 获取屏幕高度 // const scrollHeight = 600; const [searchValue, setSearchValue] = useState(""); const [loading, setLoading] = useState(false); const [streamers, setStreamers] = useState([]); const [recommList, setRecommList] = useState([]); const [dontScroll, setDontScroll] = useState(true); const [isMember, setIsMember] = useState(0); const [isFilterVisible, setIsFilterVisible] = useState({ comprehensive: false, zone_admission_price: false, }); const [filtersValue, setFiltersValue] = useState({ ...filterComprehensiveItems, ...filterPriceItems, }); const [currentFiltersChangeValue, setCurrentFiltersChangeValue] = useState({ ...filterComprehensiveItems, ...filterPriceItems, }); const filters = [ { name: "年龄", upper_bound: 60, lower_bound: 18, default: 19, step: 1, type: "slider", unit: "岁", key: "age", stepValues: Array(61) .fill(null) .map((_, index) => index), }, { name: "全网粉丝", upper_bound: 200, lower_bound: 1, default: 24, step: 200 / 9, type: "slider", unit: "万", key: "fans", stepValues: [1, 5, 10, 20, 50, 75, 100, 150, 200, 1000], }, { name: "身高", upper_bound: 200, lower_bound: 140, default: 160, step: 1, type: "slider", unit: "cm", key: "height", stepValues: Array(201) .fill(null) .map((_, index) => index), }, { name: "体重", upper_bound: 100, lower_bound: 35, default: 50, step: 1, type: "slider", unit: "kg", key: "weight", stepValues: Array(101) .fill(null) .map((_, index) => index), }, { name: "所在地", upper_bound: 1000, lower_bound: 10, default: 0, step: 1, type: "select", items: [ "不限", "北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省", "黑龙江省", "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省", "云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区", "台湾省", "香港特别行政区", "澳门特别行政区", ], key: "city", }, { name: "星座", upper_bound: 1000, lower_bound: 10, default: 0, step: 1, type: "select", key: "constellation", items: [ "不限", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "双鱼座", ], }, { name: "最近7日内空间有更新", upper_bound: 1000, lower_bound: 10, default: 24, step: 1, type: "checkbox", key: "is_active_within_a_week", }, ]; const priceFilters = [ { name: "空间价格", upper_bound: 300, lower_bound: 0, default: 24, step: 300 / 7, type: "slider", unit: "¥", key: "zone", stepValues: [0, 10, 50, 100, 150, 200, 300, 4000], }, { name: "微信价格", desc: "10金币=1元", upper_bound: 30000, lower_bound: 0, default: 24, step: 30000 / 9, type: "slider", unit: "金币", key: "wechat", stepValues: [0, 100, 300, 500, 1000, 5000, 10000, 20000, 30000, 100000], }, ]; useEffect(() => { inputRef.current?.focus(); getIsMember(); }, []); const isNumeric = (str) => { return /^\d+$/.test(str); }; const getResult = async (value) => { // console.log("searchValue", value); if (filtersValue.comprehensiveUsed.used || filtersValue.priceUsed.used) { handleResetFiltersValue(); handleResetFiltersSearchValue(); } const isSearchInt = isNumeric(value); let api = ""; let querryParams = ""; if (isSearchInt) { api = "/api/streamer/list_ext_fuzzily_by_user_id"; querryParams = { user_id: parseInt(value, 10) }; } else { api = "/api/streamer/list_ext_fuzzily_by_name"; querryParams = { name: value }; } try { setLoading(true); const data = await requireAPI("POST", api, { body: { ...querryParams, offset: 0, limit: 20, }, }); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } // if (!ignore) { // const zonesData = data.data.list.filter((item) => item.zones.length > 0); setStreamers(data.data.list); setRecommList([]); // } setLoading(false); } catch (error) { // console.error(error); } }; const getIsMember = async () => { try { const data = await requireAPI( "POST", "/api/account/list_by_mid", {}, true ); setIsMember(data.data.account.is_a_member); } catch (error) { // console.error(error); } }; //重置筛选值 const handleResetFiltersValue = async (type) => { let obj = filtersValue; if (type == "comprehensive") { obj = { ...filtersValue, ...filterComprehensiveItems, }; } else if (type == "zone_admission_price") { obj = { ...filtersValue, ...filterPriceItems, }; } else { obj = { ...filterComprehensiveItems, ...filterPriceItems, }; } setCurrentFiltersChangeValue((old) => { const newObj = { ...old, ...obj, }; return newObj; }); }; //重置筛选查询值 const handleResetFiltersSearchValue = (type) => { let obj = filtersValue; if (type == "comprehensive") { obj = { ...filtersValue, ...filterComprehensiveItems, }; } else if (type == "zone_admission_price") { obj = { ...filtersValue, ...filterPriceItems, }; } else { obj = { ...filterComprehensiveItems, ...filterPriceItems, }; } setFiltersValue((old) => { const newObj = { ...old, ...obj, }; if (!obj.comprehensiveUsed.used && !obj.priceUsed.used) { setRecommList([]); setStreamers([]); } else { getFiltersResult(newObj); } return newObj; }); }; const getFiltersResult = async (obj) => { if (searchValue != "") { setSearchValue(""); } setFiltersValue((old) => { return { ...old, ...obj, }; }); // setFiltersValue({ ...filtersValue, ...currentFiltersChangeValue }); const newObj = obj || { ...filtersValue, ...currentFiltersChangeValue }; let querryParams; let currentFilterValue = { ...newObj, city: newObj.city == "不限" ? "" : newObj.city, constellation: newObj.constellation == "不限" ? "" : newObj.constellation, zone_admission_price: { lower_bound: newObj.zone_admission_price.lower_bound * 100, upper_bound: newObj.zone_admission_price.upper_bound * 100, }, }; delete currentFilterValue.comprehensiveUsed; delete currentFilterValue.priceUsed; querryParams = currentFilterValue; try { const data = await requireAPI("POST", "/api/streamer/filter", { body: { ...querryParams }, }); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } setStreamers(data.data.streamer_list); setRecommList(data.data.recomm_list); setLoading(false); } catch (error) { // console.error(error); } }; return (
{ setSearchValue(""); setStreamers([]); }} > 清空
)}综合筛选
{!isMember ? "开通VIP后即可筛选" : "确定"}
价格筛选
*{priceFilters[1]?.desc}
{!isMember ? "开通VIP后即可筛选" : "确定"}
空间
{(() => { let arr = streamers?.filter( (streamer) => streamer.zones.length > 0 ); return arr?.map((item) => (用户
{streamers.map((item) => (猜你喜欢
)} {recommList .filter((it) => it.zones.length > 0) ?.map((item, index) => ({data?.bio}
Ta的动态· {data?.zones[0].zone_moment_count > 99 ? "99+" : data?.zones[0].zone_moment_count} {data?.zones[0].image_count > 0 && ` | 图片·${ data?.zones[0].image_count > 99 ? "99+" : data?.zones[0].image_count }`} {data?.zones[0].video_count > 0 && ` | 视频·${ data?.zones[0].video_count > 99 ? "99+" : data?.zones[0].video_count }`}