Commit 9000a6bc by zhanghaozhe

Merge branch 'search'

parents c4ebb26d 24903ff9
......@@ -3,6 +3,7 @@ import SearchHead from './searchHead'
import Tag from '@common/Tag/index.js'
import { http, api } from '@/utils'
import './index.scss';
import { Link } from 'react-router-dom'
class Search extends PureComponent {
......@@ -10,14 +11,22 @@ class Search extends PureComponent {
super(props);
this.state = {
history: JSON.parse(localStorage.getItem('history')) || [],
searchHot: ['rec', '电脑', '照片扫描仪', '智能手表', '功夫茶杯', '广角镜头手机'],
hot_words: [],
searchList: []
}
}
async componentDidMount() {
const data = await http.get(`${api['search-api']}/search_hot_word`)
console.log(data)
const res = await http.get(`${api['search-api']}/search_hot_word`)
if (res.data.errno === 0) {
this.setState({
hot_words: res.data.data.info.hot_words
})
}
}
search = text => {
}
render() {
......@@ -47,9 +56,13 @@ class Search extends PureComponent {
</label>
<div className="search-tag">
{
this.state.searchHot.length > 0 ?
this.state.searchHot.map((v, i) => {
return (<Tag key={i}>{v}</Tag>)
this.state['hot_words'].length > 0 ?
this.state['hot_words'].map((v, i) => {
return (
<Link key={i} to={`/search-result?word=${v}`}>
<Tag>{v}</Tag>
</Link>
)
})
: <div style={{textAlign: 'center', padding: '20px'}}>暂无热门</div>
}
......
import React, { PureComponent } from 'react';
import SearchHeader from './searchHead'
import VList from '@/common/VList'
import { http, api, getParam } from '@/utils'
import './search-result.scss'
const Bottom = ({item}) => {
return (
<div className='bottom'>
<span className='price'>¥{item.price1}</span>
<span className='stale-price'>¥{item.price0}</span>
</div>
)
}
class SearchResult extends PureComponent {
state = {
courseList: []
}
componentDidMount() {
http.get(`${api['search-api']}/search/${encodeURIComponent(getParam('word'))}?type=course&page=1`)
.then(res => {
const data = res.data
if (data.errno === 0) {
this.setState({
courseList: data.data.info.search_data.course
});
}
})
}
render() {
const {courseList} = this.state
return (
<div className='search-result'>
<SearchHeader/>
<ul>
{
courseList && courseList.length > 0 ?
courseList.map(item => {
const Info = (
<div className="info">
<p className='title'>{item.course_title}</p>
<p className='des'>{item.simpledescription}</p>
<Bottom
item={item}
/>
</div>
)
return (
<VList img={item.image_name}
handleClick={this.handleClick}
key={item.course_id}
info={Info}/>
)
}) : null
}
</ul>
</div>
);
}
}
export default SearchResult;
\ No newline at end of file
.search-result {
ul {
list-style: none;
}
.info {
display: flex;
flex-wrap: wrap;
.des {
font-size: $font_14;
line-height: 16px;
align-self: flex-start;
}
.price {
color: $red;
font-size: $font_16;
margin-right: 14px;
}
.stale-price {
text-decoration: line-through;
color: $color_999;
font-size: $font_12;
}
.bottom{
align-self: flex-end;
}
}
}
\ No newline at end of file
import React, { PureComponent } from 'react'
import { SearchBar } from 'antd-mobile'
import { withRouter } from 'react-router-dom'
import './search_header.scss'
......@@ -15,7 +16,7 @@ class SearchHead extends PureComponent {
// 返回某个页面
returnPage() {
console.log(111);
this.props.history.go(-1)
}
//组件装载完毕
......@@ -58,4 +59,4 @@ class SearchHead extends PureComponent {
}
}
export default SearchHead
\ No newline at end of file
export default withRouter(SearchHead)
\ No newline at end of file
export const CHANGEVAL = 'CHANGEVAL'
\ No newline at end of file
import reducer from './reducer';
import * as constants from './constants';
export { reducer, constants };
\ No newline at end of file
const initState = {
}
export default (state = initState, actions) => {
switch (actions.type) {
default:
return state
}
}
\ No newline at end of file
import React, { PureComponent } from 'react'
import { Course, Tag } from '../../../common'
import { api } from '@/utils'
import { http, api } from '@/utils'
import './free-courses.scss'
......@@ -42,11 +42,11 @@ class FreeCourse extends PureComponent {
}
getFreeCourses = () => {
return api.get(`/api/m/free_course/${this.state.page}/${this.state.num}`)
return http.get(`${api.home}/m/free_course/${this.state.page}/${this.state.num}`)
}
getFreeLive = () => {
return api.get(`/m/live/free_list`)
return http.get(`${api.home}/m/live/free_list`)
}
render() {
......
import { api } from '@/utils'
import { http, api } from '@/utils'
export const RECEIVE_MY_COURSES = 'RECEIVE_MY_COURSES'
......@@ -22,7 +22,7 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
}
export const getMyCourses = payload => dispatch => {
return api.get(`/m/my_course/${payload.page}/${payload.num}`)
return http.get(`${api.home}/m/my_course/${payload.page}/${payload.num}`)
.then(res => {
const {data, code, msg} = res.data
if (data.length === 0) {
......
......@@ -6,6 +6,7 @@ import CourseList from '@/components/classify/courselist';
import Order from '@/components/order/index';
import Preferential from '@/components/preferential/index';
import Search from '@/components/search/index'
import SearchResult from '@/components/search/search-result'
import Detail from '@/components/detail/index'
import Examination from '@/components/examination'
import ExchangeCoupons from '@/components/coupons/exchange-coupons'
......@@ -43,9 +44,14 @@ export default [
},
{
path: '/search',
exact: true,
component: Search
},
{
path: '/search-result',
component: SearchResult
},
{
path: '/order',
component: Order
},
......
import { combineReducers } from 'redux';
import searchReducer from '@/components/search/store/reducer';
import myCourses from '@/components/study/myCourses/reducers'
const reducer = combineReducers({
searchReducer,
myCourses
});
......
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