Bläddra i källkod

Merge branch 'master' of http://gogs.efunbox.cn/Rorschach/efunbox-mobile-8

zhangmengjie 5 år sedan
förälder
incheckning
60fea51c5d

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 125 - 0
android/app/src/main/assets/index.android.bundle


BIN
android/app/src/main/res/drawable-mdpi/pages_images_common_search.png


BIN
android/app/src/main/res/drawable-xhdpi/pages_images_common_search.png


BIN
android/app/src/main/res/drawable-xxhdpi/pages_images_common_search.png


+ 4 - 4
package-lock.json

@@ -6295,7 +6295,7 @@
     },
     "opencollective": {
       "version": "1.0.3",
-      "resolved": "https://registry.npm.taobao.org/opencollective/download/opencollective-1.0.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fopencollective%2Fdownload%2Fopencollective-1.0.3.tgz",
+      "resolved": "https://registry.npm.taobao.org/opencollective/download/opencollective-1.0.3.tgz",
       "integrity": "sha1-ruY3K8KBRFg2kMPKja7PwSDdDvE=",
       "requires": {
         "babel-polyfill": "6.23.0",
@@ -6313,12 +6313,12 @@
         },
         "ansi-styles": {
           "version": "2.2.1",
-          "resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-2.2.1.tgz",
+          "resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-2.2.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-2.2.1.tgz",
           "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4="
         },
         "chalk": {
           "version": "1.1.3",
-          "resolved": "https://registry.npm.taobao.org/chalk/download/chalk-1.1.3.tgz",
+          "resolved": "https://registry.npm.taobao.org/chalk/download/chalk-1.1.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fchalk%2Fdownload%2Fchalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "requires": {
             "ansi-styles": "^2.2.1",
@@ -6330,7 +6330,7 @@
         },
         "inquirer": {
           "version": "3.0.6",
-          "resolved": "https://registry.npm.taobao.org/inquirer/download/inquirer-3.0.6.tgz",
+          "resolved": "https://registry.npm.taobao.org/inquirer/download/inquirer-3.0.6.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Finquirer%2Fdownload%2Finquirer-3.0.6.tgz",
           "integrity": "sha1-4EqqnQW3o8ubD0B9BDdfBEcZA0c=",
           "requires": {
             "ansi-escapes": "^1.1.0",

+ 15 - 6
pages/components/MainPage.js

@@ -80,7 +80,6 @@ export default class MainPage extends BasePage {
 
 	state = {
 		grade: '大学',
-		text: '小伙子',
 		ifGradeMenuShow: false,
 		fadeAnim: new Animated.Value(0),
 		schedule: [],
@@ -194,11 +193,11 @@ export default class MainPage extends BasePage {
 				/>
 				{/* 搜索区域 */}
 				<View style={styles.searchSection}>
-					<TextInput
-						style={styles.searchBox}
-						onChangeText={(text) => this.setState({ text })}
-						value={this.state.text}
-					/>
+					<View style={styles.searchBox}>
+						<TouchableOpacity onPress={() => this.search(this)} style={{position: 'absolute', left: '45%', top: 10}}>
+							<Image style={styles.search} source={require('../images/common/search.png')}></Image>
+						</TouchableOpacity>
+					</View>
 					<TouchableOpacity onPress={this.tabCallOutHandler}>
 						<View style={styles.rightBtn}>
 							<Image source={require('../images/common/switch.png')} style={styles.rightBtnIcon} />
@@ -463,6 +462,7 @@ export default class MainPage extends BasePage {
 			});
 		}
 	};
+	// 获取用户信息
 	async getUserInfo() {
 		await global.storage
 			.load({
@@ -519,6 +519,10 @@ export default class MainPage extends BasePage {
 			return true;
 		});
 	}
+	// 搜索
+	search() {
+		this.toNextPage('SearchResult')
+	}
 }
 
 const styles = StyleSheet.create({
@@ -543,11 +547,16 @@ const styles = StyleSheet.create({
 		position: 'relative'
 	},
 	searchBox: {
+		position: 'relative',
 		width: Dimensions.getWidth(232),
 		height: Dimensions.getHeight(40),
 		backgroundColor: '#fff',
 		borderRadius: 20
 	},
+	search: {
+		width: 30,
+		height: 30,
+	},
 	rightBtn: {
 		width: Dimensions.getWidth(113),
 		height: Dimensions.getHeight(40),

BIN
pages/images/common/search.png


BIN
pages/images/common/search@2x.png


BIN
pages/images/common/search@3x.png


+ 306 - 14
pages/searchResult.js

@@ -16,18 +16,88 @@ import {
     TouchableHighlight,
     DeviceEventEmitter,
     FlatList,
-    TextInput
+    TextInput,
+    ScrollView,
+    Animated
 } from "react-native";
 import BasePage from "./BasePage";
 import Dimensions from './utils/dimensions';
 import ShopBox from "./components/ShopBox";
 import TopicTitle from './components/TopicTitle';
 import ScrollRow from './components/ScrollRow';
+import CourseTitle from './components/CourseTitle';
+import search from './services/search'
 
 export default class SearchResult extends BasePage {
+    // componentDidMount() {
+    //     const { searchText } = this.props.navigation.state.params;
+    //     console.log('searchText',searchText)
+    //     this.setState({
+    //         text: searchText
+    //     })
+    //     this.search(searchText)
+    //     // courseDetails.getCourseDetails(courseId).then(res => {
+    //     //   console.log('列表',res.data)
+    //     //   const courseList = res.data.course;
+    //     //   const wareList = res.data.wareList;
+    //     //   this.setState({
+    //     //     courseList,
+    //     //     wareList,
+    //     //     uri: wareList[0].playUrl
+    //     //   })
+    //     // }).catch(err => {
+    //     //   console.log(err)
+    //     // });
+    // }
     state = {
-        text: '123123123123'
+        text: '',
+        list: [],
+        ifCourseMenuShow: false,
+        currentCourseSwitch: { title: '课程', param: 'course' },
+        switchCourseList: [
+			// { title: '幼儿园', param: 'KINDERGARTEN' },
+			{ title: '课程', param: 'course' },
+			{ title: '课件', param: 'ware' }
+        ],
+        fadeCourseAnim: new Animated.Value(0),
     };
+    search (text) {
+        if (!text) {
+            alert('请输入关键字搜索');
+            return false;
+        }
+        const param = this.state.currentCourseSwitch.param;
+        if (param == 'course') {
+            search.getSearchCourseList(text).then( res => {
+                console.log('搜索', res.data)
+                const list = res.data.list;
+                if(list.length == 0) {
+                    alert('请换个关键字搜索')
+                    return false;
+                }
+                this.setState({
+                    list
+                })
+            }).catch( err => {
+                console.log(err)
+            })
+        } else {
+            search.getSearchWareList(text).then( res => {
+                console.log('搜索', res.data)
+                const list = res.data.list;
+                if(list.length == 0) {
+                    alert('请换个关键字搜索')
+                    return false;
+                }
+                this.setState({
+                    list
+                })
+            }).catch( err => {
+                console.log(err)
+            })
+        }
+
+    }
     searchBox = () => {
         return (
             <View style={styles.searchBox}>
@@ -35,23 +105,147 @@ export default class SearchResult extends BasePage {
                     style={styles.searchInput}
                     onChangeText={(text) => this.setState({ text })}
                     value={this.state.text}
-                    renderItem={item => this.renderItem(item)}
                 />
+                <TouchableOpacity onPress={this.courseCallOutHandler} style={{position: 'absolute', left: 14, top: 10,width: '30%',height: 40}}>
+                    <View style={styles.rightBtn}>
+                        <Image source={require('./images/common/switch.png')} style={styles.rightBtnIcon} />
+                        <Text style={styles.rightBtnText}>{this.state.currentCourseSwitch.title}</Text>
+                        <View style={{ width:2, height:19, backgroundColor: '#63AEFF'}}></View>
+                    </View>
+                </TouchableOpacity>               
+                <TouchableOpacity onPress={() => this.search(this.state.text)} style={{position: 'absolute', right: 20, top: 15}}>
+                    <Image style={styles.search} source={require('./images/common/search.png')}></Image>
+                </TouchableOpacity>                
+            </View>
+        )
+    }
+    searchHead = () => {
+        return (
+            this.state.list.length == 0 ?
+            null:
+            <View style={styles.head}>
+                <Text style={{ fontSize: 16 }}>以下课程包含:</Text>
+                <Text style={{ color: '#63AEFF', fontSize: 16 }}>{this.state.text}</Text>
             </View>
         )
     }
     renderItem = (item) =>{
+        const param = this.state.currentCourseSwitch.param;
         return (
-            <View>
-                
+            param == 'course' ?
+            <View style={styles.course} key={item.id}>
+                <View style={styles.img}>
+                    <Image source={{
+                        uri: item.iconImg
+                    }} style={styles.iconImg} />
+                </View>
+                <Text>{item.title}</Text>
+            </View>
+            :
+            <View style={[ styles.padding, styles.title, styles.border ]} key={item.id}>
+                <Text style={styles.courseFont}>{item.title}</Text>
+                <Text style={styles.courseFont}>></Text>
             </View>
         )
+
+         {/* <View style={styles.ware}>
+
+                </View> */}
     } 
+    // 点击选择
+    courseCallOutHandler = () => {
+		this.setState(
+			{
+				ifCourseMenuShow: !this.state.ifCourseMenuShow
+			},
+			() => {
+				Animated.timing(this.state.fadeCourseAnim, {
+					toValue: this.state.ifCourseMenuShow ? 1 : 0,
+					duration: 300
+				}).start();
+			}
+		);
+    };
+    // 如果切换课程在显示状态,那么在它失去焦点时将它隐藏
+	hideCourseMenu = () => {
+		if (this.state.ifCourseMenuShow) {
+			this.setState({
+				ifCourseMenuShow: false
+			});
+		}
+    };
+    //渲染按钮
+	renderCourseBtn = (item, index) => {
+		return (
+			<TouchableOpacity
+				onPress={() => this.switchCourseGrade(index)}
+				key={index}
+				style={styles.gradeItemMid}
+			>
+				<Text style={styles.gradeText}>{item.title}</Text>
+			</TouchableOpacity>
+		);
+    };
+    // 点击按钮
+    switchCourseGrade = (index) => {
+		const obj = this.state.switchCourseList[index];
+		this.setState({
+			currentCourseSwitch: obj
+		});
+        this.hideCourseMenu();
+		// if (obj.param === this.state.currentCourseSwitch.param) return
+		//这里更新个人信息学龄选项
+		// var bool = this.updateUserInfo(obj.param);
+		// this.updateRender(obj.param);
+	};    
     render() {
         return (
-            <FlatList
-                ListHeaderComponent={() => this.searchBox()}
-            />
+            <View style={{backgroundColor: '#f6f7f8'}}>
+            	<View style={{
+						height: 30,
+						backgroundColor: 'white'
+				}}>
+					<CourseTitle
+						width={Dimensions.width}
+						title="搜索"
+						lefttype={1}
+						textcolor={'#231F20'}
+						backPress={() => this.goBack()}
+						// backPress={() => alert("左侧按钮")}
+					/>
+				</View>
+                {
+                    this.searchBox() 
+                }
+                {
+                    this.searchHead()
+                }
+                <ScrollView style={{paddingBottom: 100, backgroundColor: '#fff'}}>
+                    <View style={ this.state.currentCourseSwitch.param == 'coerse' ? styles.list : null}>
+                        {
+                            this.state.list.map(item => 
+                            this.renderItem(item)
+                            )
+                        }                        
+                    </View>
+                </ScrollView>
+                {/* <FlatList
+                    style={styles.list}
+                    data={this.state.list}
+                    ListHeaderComponent={() => this.searchHead()}
+                    renderItem={({item}) => this.renderItem(item)}
+                /> */}
+                {this.state.ifCourseMenuShow ? (
+					<Animated.View
+						style={{
+							...styles.callUpGrade,
+							opacity: this.state.fadeCourseAnim
+						}}
+					>
+						{this.state.switchCourseList.map((item, index) => this.renderCourseBtn(item, index))}
+					</Animated.View>
+				) : null}
+            </View>
         )
     }
 
@@ -59,16 +253,114 @@ export default class SearchResult extends BasePage {
 
 const styles = StyleSheet.create({
     searchBox: {
-        width: Dimensions.width,
+        width: '100%',
         height: 60,
+        paddingLeft: 14,
+        paddingRight: 14,
+        position: 'relative',
         alignItems: 'center',
-        justifyContent: 'center',
-        backgroundColor: '#f6f7f8'
+        justifyContent: 'center'
     },
     searchInput: {
-        width: '88.5%',
+        width: '100%',
         height: 40,
         borderRadius: 20,
-        backgroundColor: '#fff'
-    }
+        backgroundColor: '#fff',
+        paddingLeft: '31%'
+    },
+    list: {
+        width: '100%',
+        display: 'flex',
+        flexDirection: 'row',
+        justifyContent: 'space-between',
+        flexWrap: 'wrap',
+        paddingLeft: 14,
+        paddingRight: 14
+    },
+    head: {
+        display: 'flex',
+        flexDirection: 'row',
+        backgroundColor: '#fff',
+        paddingTop: 16,
+        paddingBottom: 16,
+        paddingLeft: 14,
+        paddingRight: 14
+    },
+    course: {
+        width: '30%',
+        display: 'flex',
+        flexDirection: 'column',
+        alignItems: 'center'
+    },
+    img: {
+        width: '100%',
+        height: 155
+    },
+    iconImg: {
+        width: '100%',
+        height: '100%'
+    },
+    callUpGrade: {
+		width: 113,
+		height: 120,
+		borderRadius: 20,
+		position: 'absolute',
+		left: 9,
+		top: 75,
+		zIndex: 999,
+		backgroundColor: '#fff',
+        flexDirection: 'column',
+        borderStyle: 'solid',
+        borderWidth: 1,
+        borderColor: '#F0F1F5'
+    },
+    rightBtn: {
+		width: '100%',
+		height: 40,
+		backgroundColor: '#fff',
+		borderRadius: 20,
+		alignItems: 'center',
+		justifyContent: 'space-around',
+		flexDirection: 'row',
+		paddingLeft: 20,
+        paddingRight: 10,
+	},
+	rightBtnIcon: {
+		width: Dimensions.getWidth(23),
+		height: Dimensions.getHeight(23)
+	},
+	rightBtnText: {
+		color: '#151515',
+		fontSize: 18
+    },
+    gradeItemMid: {
+		zIndex: 999,
+		flex: 1,
+		alignItems: 'center',
+		justifyContent: 'center',
+		borderTopWidth: 1,
+		borderBottomWidth: 1,
+		borderColor: '#f0f1f5'
+    },
+    title: {
+        display: 'flex',
+        flexDirection: 'row',
+        justifyContent: 'space-between',
+        alignItems: 'center',
+    },
+    courseFont: {
+        color: '#373737',
+        fontSize: 16
+    },
+    border: {
+        borderStyle: 'solid',
+        borderBottomWidth: 1,
+        borderColor: '#F0F1F5'
+    },
+    padding: {
+        paddingLeft: 20,
+        paddingRight: 20,
+        paddingTop: 10,
+        paddingBottom: 10,
+    },    
 })

+ 0 - 1
pages/services/schedule.js

@@ -11,6 +11,5 @@ export default class ScheduleUrl {
             code
         }).get();
     }
-    
 
 }

+ 20 - 0
pages/services/search.js

@@ -0,0 +1,20 @@
+import APIConfig from './api.js';
+// import efunRequest from '../utils/efunRequest'
+import request from '../utils/request'
+
+export default class search {
+  // 获取搜索课程列表
+  static getSearchCourseList(keyword) {
+    console.log(keyword)
+    return request(`http://ott80testlibrary.yifangjiaoyu.cn/mobile/course?keyword=${keyword}`, {
+      method: "get",
+    })
+  }
+  // 获取搜索课件列表
+  static getSearchWareList(keyword) {
+    console.log(keyword)
+    return request(`http://ott80testlibrary.yifangjiaoyu.cn/mobile/course/ware?keyword=${keyword}`, {
+      method: "get",
+    })
+  }
+}