|
|
|
@ -4,7 +4,6 @@ import {Category, HomeApi} from "@/api"; |
|
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
|
import styles from './sort.module.scss' |
|
|
|
|
import Tabs, {TabList} from "@/components/tabs/tabs"; |
|
|
|
|
import {Search} from "@/pages/home/components/search"; |
|
|
|
|
import {illnessApi} from "@/api/illness"; |
|
|
|
|
import Empty from "@/components/empty/empty"; |
|
|
|
|
import leftArrow from "@/static/img/leftArrow.png" |
|
|
|
@ -16,10 +15,10 @@ const Sort: FC = () => { |
|
|
|
|
const [secondId, setSecondId] = useState<number | undefined>(undefined) |
|
|
|
|
const [list, setList] = useState<any[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const globalData = Taro.getApp().globalData |
|
|
|
|
const menu = Taro.getMenuButtonBoundingClientRect() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getData() { |
|
|
|
|
const res = await HomeApi.category(3) |
|
|
|
|
setData(res) |
|
|
|
@ -30,7 +29,7 @@ const Sort: FC = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function jump(id: number) { |
|
|
|
|
Taro.navigateTo({url: '/pages/preview/illness/article/article?id=' + id}) |
|
|
|
|
Taro.navigateTo({url: '/pages/preview/illness/list/list?id=' + id}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getTabList = useMemo((): TabList[] => { |
|
|
|
@ -48,10 +47,6 @@ const Sort: FC = () => { |
|
|
|
|
paddingLeft: '10px' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function onConfirm(value: string) { |
|
|
|
|
console.log(value) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function firstIdChange(id: number) { |
|
|
|
|
setFirstId(id) |
|
|
|
|
const resource_category = data.find(d => d.id === id)?.resource_category |
|
|
|
@ -64,16 +59,14 @@ const Sort: FC = () => { |
|
|
|
|
if (secondId) { |
|
|
|
|
Taro.showLoading({title: '加载中'}) |
|
|
|
|
illnessApi.list(secondId, 1, 100).then(res => { |
|
|
|
|
const data = [] |
|
|
|
|
res.list.forEach(d => { |
|
|
|
|
data.push(...d.articles as []) |
|
|
|
|
}) |
|
|
|
|
setList(data) |
|
|
|
|
setList(res.list) |
|
|
|
|
}).finally(() => { |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
}).catch(() => { |
|
|
|
|
setList([]) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
setList([]) |
|
|
|
|
} |
|
|
|
|
}, [secondId]) |
|
|
|
|
|
|
|
|
@ -86,13 +79,11 @@ const Sort: FC = () => { |
|
|
|
|
onClick={() => Taro.navigateBack()}/> |
|
|
|
|
<Tabs tabList={getTabList} onChange={(data) => firstIdChange(data.tab?.value as number)}/> |
|
|
|
|
</View> |
|
|
|
|
<Search onConfirm={onConfirm}/> |
|
|
|
|
<View className='flex'> |
|
|
|
|
<ScrollView |
|
|
|
|
scrollY |
|
|
|
|
scrollWithAnimation |
|
|
|
|
scrollIntoView={`${prefix}-${secondId}`} |
|
|
|
|
className={styles.firstOrder}> |
|
|
|
|
|
|
|
|
|
{/*<Search onConfirm={onConfirm}/>*/} |
|
|
|
|
|
|
|
|
|
<View className={styles.scrollView} style={{top: `${globalData.statusBarHeight + 59}px`}}> |
|
|
|
|
<ScrollView scrollY className={styles.firstOrder}> |
|
|
|
|
{ |
|
|
|
|
data.find(d => d.id === firstId)?.resource_category?.map(d => <View |
|
|
|
|
id={`${prefix}-${d.id}`} |
|
|
|
@ -110,7 +101,7 @@ const Sort: FC = () => { |
|
|
|
|
scrollWithAnimation> |
|
|
|
|
{ |
|
|
|
|
list.length ? |
|
|
|
|
list.map(d => <View className={styles.list} onClick={() => jump(d.id)}>{d.title}</View>) |
|
|
|
|
list.map(d => <View className={styles.list} onClick={() => jump(d.id)}>{d.name}</View>) |
|
|
|
|
: <Empty name='暂无数据'/> |
|
|
|
|
} |
|
|
|
|
</ScrollView> |
|
|
|
|