Commit 2beebcbc by 姜雷

修改校区选择列表按字母排序

parent 77b0a743
import { baseFetch } from './index'; import { baseFetch, ResponseDataEntity } from './index';
export const fetchAllArea = () => export type Area = {
id: number;
areaName: string;
initial?: string;
};
export const fetchAllArea = (): Promise<ResponseDataEntity<Area[]>> =>
baseFetch({ baseFetch({
url: '/area/queryAreaList', url: '/area/queryAreaList',
}); });
...@@ -88,4 +88,7 @@ ...@@ -88,4 +88,7 @@
border-bottom: 2px solid #ebebeb; border-bottom: 2px solid #ebebeb;
word-break: break-all; word-break: break-all;
} }
.locationItem:last-child {
border-bottom: none;
}
} }
...@@ -5,17 +5,11 @@ import { connect } from '@tarojs/redux'; ...@@ -5,17 +5,11 @@ import { connect } from '@tarojs/redux';
import { View, Text, Input, Image, ScrollView } from '@tarojs/components'; import { View, Text, Input, Image, ScrollView } from '@tarojs/components';
import SearchIcon from '../../images/login/icon_search@2x.png'; import SearchIcon from '../../images/login/icon_search@2x.png';
import { fetchAllArea } from '../../api/area'; import { fetchAllArea, Area } from '../../api/area';
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo'; import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo';
import './SelectCampus.scss'; import './SelectCampus.scss';
type Area = {
id: number;
areaName: string;
initial?: string;
};
type AreaList = Array<{ type AreaList = Array<{
firstPin: string; firstPin: string;
children: Array<Area>; children: Array<Area>;
...@@ -80,6 +74,34 @@ class SelectCampus extends Component { ...@@ -80,6 +74,34 @@ class SelectCampus extends Component {
fetchAllArea() fetchAllArea()
.then(res => { .then(res => {
console.log(res); console.log(res);
let initialList = [
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
];
let campusIndexArr: Array<string> = []; let campusIndexArr: Array<string> = [];
let campusList: AreaList = []; let campusList: AreaList = [];
res.data.map((area: Area) => { res.data.map((area: Area) => {
...@@ -89,11 +111,12 @@ class SelectCampus extends Component { ...@@ -89,11 +111,12 @@ class SelectCampus extends Component {
if (index > -1) { if (index > -1) {
campusList[index].children.push(area); campusList[index].children.push(area);
} else { } else {
campusIndexArr.push(firstPin); let index = initialList.indexOf(firstPin);
campusList.push({ campusIndexArr[index] = firstPin;
campusList[index] = {
firstPin: firstPin, firstPin: firstPin,
children: [area], children: [area],
}); };
} }
} }
}); });
...@@ -190,14 +213,16 @@ class SelectCampus extends Component { ...@@ -190,14 +213,16 @@ class SelectCampus extends Component {
</View> </View>
</View> </View>
<View className='infoBar'> <View className='infoBar'>
{pinList.map(item => ( {pinList.map(item =>
<View item ? (
key={item} <View
className='infoItem' key={item}
onClick={() => this.showToastHandle(item)}> className='infoItem'
{item} onClick={() => this.showToastHandle(item)}>
</View> {item}
))} </View>
) : null,
)}
</View> </View>
<View className={showToast ? 'show br8 infoToast' : 'br8 infoToast'}> <View className={showToast ? 'show br8 infoToast' : 'br8 infoToast'}>
{localText} {localText}
...@@ -207,22 +232,24 @@ class SelectCampus extends Component { ...@@ -207,22 +232,24 @@ class SelectCampus extends Component {
className='locationList' className='locationList'
scrollIntoView={localText} scrollIntoView={localText}
scrollWithAnimation> scrollWithAnimation>
{filterList.map(campusItem => ( {filterList.map(campusItem =>
<View key={campusItem.firstPin} className='locationArea'> campusItem ? (
<View id={campusItem.firstPin} className='locationTitle'> <View key={campusItem.firstPin} className='locationArea'>
{campusItem.firstPin} <View id={campusItem.firstPin} className='locationTitle'>
</View> {campusItem.firstPin}
{campusItem.children.map(campus => (
<View
key={campus.id}
className='locationItem'
data-campus={campus}
onClick={this.bindCampus}>
{campus.areaName}
</View> </View>
))} {campusItem.children.map(campus => (
</View> <View
))} key={campus.id}
className='locationItem'
data-campus={campus}
onClick={this.bindCampus}>
{campus.areaName}
</View>
))}
</View>
) : null,
)}
</ScrollView> </ScrollView>
</View> </View>
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment