Commit 2a6cb5f4 by xuzhenghua

Merge branch 'master' of gitlab.julyedu.com:baiguangyao/mr-julyedu

parents 21554483 47ab9226
......@@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@babel/core": "7.2.2",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@loadable/component": "^5.10.1",
"@svgr/webpack": "4.1.0",
"antd-mobile": "^2.2.13",
......@@ -67,6 +68,7 @@
"redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0",
"resolve": "1.10.0",
"sass-loader": "^7.1.0",
......@@ -146,6 +148,12 @@
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"import",
{
"libraryName": "antd-mobile",
......
......@@ -6,10 +6,12 @@ const Course = (props) => {
return (
<li className={`course-item ${props.className}`}>
{props.top}
<Link to={`/detail?id=${props.id}`}>
<a onClick={() => props.toDetail(props.id)}>
{/* <Link to={`/detail?id=${props.id}`}> */}
<img src={props.img} alt=""/>
<p className={`course-title ${props.className}`}>{props.title}</p>
</Link>
{/* </Link> */}
</a>
{props.bottom}
</li>
);
......
......@@ -14,15 +14,15 @@ import {Link} from "react-router-dom";
*/
const OrderItem = ({ info, tab, children, src,id, isaist, ...restProps }) => {
const OrderItem = ({ info, tab, children, src,id, isaist, toDetail, ...restProps }) => {
return (
<div className='public-list-item'>
<div className="public-content">
{tab}
<div className="public-cover" >
<Link to={`/detail?id=${id}`}>
<img src={src} alt="" />
</Link>
{/* <Link to={`/detail?id=${id}`}> */}
<img src={src} alt="" onClick={() => toDetail(id)} />
{/* </Link> */}
{
(isaist &&
<span className='return_cash'></span>
......
......@@ -8,9 +8,9 @@ const VList = (props) => {
<div className="content">
<div className="cover">
{props.status}
<Link to={`/detail?id=${props.id}`}>
<img src={props.img} alt=""/>
</Link>
{/* <Link to={`/detail?id=${props.id}`}> */}
<img src={props.img} alt="" onClick={() => props.toDetail(props.id)} />
{/* </Link> */}
</div>
{props.info}
</div>
......
......@@ -10,10 +10,14 @@ import LiveRoom from './liveRoom'
import {Link} from "react-router-dom"
import {Toast} from 'antd-mobile'
import {connect} from "react-redux";
import {getCourses} from './../detail/actions';
const animateTypes = Swiper.animateTypes
@connect(state => ({
user: state.user
}))
class Index extends Component {
constructor(props) {
super(props)
......@@ -104,6 +108,14 @@ class Index extends Component {
this.props.history.push('/search')
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`);
return false;
}));
}
render() {
return (
<div className='index-box'>
......@@ -154,7 +166,7 @@ class Index extends Component {
(this.state.modules && this.state.modules.length > 0) ? this.state.modules.map((item, index) => {
return (
<div key={index}>
<CourseList modules={item}/>
<CourseList modules={item} toDetail={this.toCourseDetail}/>
<p className="borderTop"></p>
</div>
)
......@@ -166,6 +178,7 @@ class Index extends Component {
<p>查看全部课程</p>
<span>数学基础、数学结构、大数据实战、Python...</span>
</Link>
</div>
{/* 直播间预约 */}
......@@ -187,9 +200,11 @@ function TopSwiper({bannerList}) {
<Swiper type={animateTypes.CARD} loop={true} height={168} autoPlay={true} typePro createStyle={createStyle}>
{bannerList && bannerList.length > 0 && bannerList.map((item, index) => {
return (
<Link to={item.jump_url} key={index}>
<a href={item.jump_url}>
{/* <Link to={item.jump_url} key={index}> */}
<img className="item" src={item.name} alt=""/>
</Link>
{/* </Link> */}
</a>
)
})
}
......@@ -199,7 +214,7 @@ function TopSwiper({bannerList}) {
// 课程模块儿公共组件
// 课程数量是奇数第一个课程需要横着展示沾满一行,课程数量是偶数一行显示两个
function CourseList({modules}) {
function CourseList({modules, toDetail}) {
let isOdd = modules.list.length % 2 === 0
// 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图
let filterList = ''
......@@ -223,10 +238,10 @@ function CourseList({modules}) {
<ul className='index-course-detail'>
{
!isOdd && modules.list[0].course_img!=='' &&
<div className="category-vip">
<Link to={`/detail?id=${modules.list[0].course_id}`}>
<div className="category-vip" onClick={() => toDetail(modules.list[0].course_id)}>
{/* <Link to={`/detail?id=${modules.list[0].course_id}`}> */}
<img src={modules.list[0].course_img_small} alt=""/>
</Link>
{/* </Link> */}
</div>
}
{
......@@ -255,9 +270,17 @@ function CourseList({modules}) {
</div>
)
return (
<Course key={index} top={top} data={item} bottom={bottom} img={item.course_img_small}
title={item.course_title} id={item.course_id}
className='text-overflow-2'></Course>
<Course
key={index}
top={top}
data={item}
bottom={bottom}
img={item.course_img_small}
title={item.course_title}
id={item.course_id}
toDetail={toDetail}
className='text-overflow-2'
/>
)
})
}
......@@ -314,7 +337,4 @@ function ScrollBox(props) {
}
export default connect(
state => ({user: state.user}),
null
)(WithTab(Index))
export default WithTab(Index);
......@@ -3,12 +3,14 @@ import {VList} from '../../common'
import {Tabs, WhiteSpace} from 'antd-mobile'
import './courselist.scss'
import HeaderSearch from '../../common/HeaderSearch/index'
import {http, api, getParam} from "@/utils"
import {http, getParam} from "@/utils"
import {Toast} from 'antd-mobile'
import {Link} from 'react-router-dom'
import Loading from '@/common/Loading'
import {connect} from 'react-redux';
import {getCourses} from './../detail/actions';
@connect()
class Classify extends Component {
constructor(props) {
super(props)
......@@ -102,6 +104,13 @@ class Classify extends Component {
}))
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const bottom = (
<i className={'iconfont iconiconfront-69 pull-down'}></i>
......@@ -132,10 +141,10 @@ class Classify extends Component {
{this.state.data && this.state.data.length > 0 && this.state.data.map((item, index) => {
const Info = (
<div className="info">
<p className='title'>
<Link to={`/detail?id=${item.course_id}`}>
<p className='title' onClick={() => this.toCourseDetail(item.course_id)}>
{/* <Link to={`/detail?id=${item.course_id}`}> */}
{item.course_title}
</Link>
{/* </Link> */}
</p>
<p className='contact text-overflow-2'>{item.desc}</p>
<div className='des'>
......@@ -164,9 +173,14 @@ class Classify extends Component {
</div>
)
return (
<VList key={index} status={status}
img={item.image_name} id={item.course_id}
info={Info}></VList>
<VList
key={index}
status={status}
img={item.image_name}
id={item.course_id}
info={Info}
toDetail={this.toCourseDetail}
/>
)
})}
</ul>
......
import {api, getParam, http} from "@/utils";
export const RECEIVE_COURSES_DETAIL = 'RECEIVE_COURSES_DETAIL'
export const ADD_COURSES_TO_CART = 'ADD_COURSES_TO_CART';
export const receiveCourseDetail = payload => ({
type: RECEIVE_COURSES_DETAIL,
payload
})
// 加入购物车
export const addCourseToCart = payload => ({
type: ADD_COURSES_TO_CART,
payload
})
export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
dispatch(getCourses({
courseInfo: getState().detailInfo
}))
}
export const getCourses = payload => dispatch => {
return http.get(`${API.home}/m/course/detail/${getParam('id')}`,).then((res) => {
export const getCourses = (id, cb) => dispatch => {
const courseId = id? id : getParam('id');
return http.get(`${API.home}/m/course/detail/${courseId}`,).then((res) => {
if (res.data.code === 200) {
dispatch(receiveCourseDetail({
...res.data.data
}))
}));
typeof cb === 'function' && cb();
}
})
}
......@@ -135,25 +135,25 @@ class Bargain extends Component {
type: type, // 1 用户自己砍价 2 使用砍价神器 3 好友助力砍价 4 好友第二次助力
parent_uid: uid // 被助力人id 【自己本人操作传0】
}
const { history } = this.props;
http.post(`${API.home}/m/bargain/toBargain`, data).then((res) => {
if (res.data.code === 200) {
const { data: { data, code } } = res;
if (code === 200) {
if (type === 2) {
this.setState({
isShowOverlay: true,
status: 2,
})
} else {
if (res.data.data.user_status === 2) {
if (data.user_status === 2) {
this.setState({
isShowOverlay: true,
status: 3,
})
} else {
// this.getBargainInfo()
document.location.reload()
history.push(`/bargain-middle-page?id=${getParam('id')}&bargaincode=${data.bargain_code}&is_originator=1`)
}
}
} else {
Toast.info(res.data.msg, 2)
}
......
......@@ -18,7 +18,7 @@ class BtnStatus extends Component {
group_status: 3,
in_cart: false,
countdown: 0,
barInfo: ''
// barInfo: ''
}
}
......@@ -40,9 +40,9 @@ class BtnStatus extends Component {
// }
componentWillReceiveProps(nextProps) {
if(nextProps.data && nextProps.data.is_bargain) {
this.getBargainInfo()
}
// if(nextProps.data && nextProps.data.is_bargain) {
// this.getBargainInfo()
// }
this.setState({
...nextProps.data.course_info,
countdown: nextProps.countdown,
......@@ -51,6 +51,7 @@ class BtnStatus extends Component {
// 加入购物车 type:1 加入购物车,2加入购物车并跳转到购物车页面去支付
toCart = (type) => {
const { history, addCourseToCart } = this.props;
let data = {
course_id: getParam('id')
};
......@@ -59,14 +60,13 @@ class BtnStatus extends Component {
if (type === 1) {
Toast.info('已加入购物车', 2)
// this.props.getCourses()
document.location.reload()
// document.location.reload()
addCourseToCart();
} else {
this.props.history.replace('/shopcart');
history.replace('/shopcart');ß
}
} else if (res.data.code === 15001) {
this.props.history.replace('/shopcart');
history.replace('/shopcart');
} else {
Toast.info(res.data.msg, 2);
}
......@@ -110,12 +110,12 @@ class BtnStatus extends Component {
};
// 直接购买
tobuy = () => {
const {user} = this.props
const {user, barInfo} = this.props
const uid = user && user.data && user.data.uid
if (!uid) {
this.props.history.push('/passport/login')
} else {
if (this.state.barInfo.bargain_status === 2) {
if (barInfo.bargain_status === 2) {
// this.toCart(2)
// 新需求 不需要加入购物车 直接走普通课程的立即报名流程 跳到订单页
this.simpleCourse();
......@@ -164,8 +164,15 @@ class BtnStatus extends Component {
isShowOverlay: false,
bargainStatus: '',
})
http.get(`${API['base-api']}/m/cart/addtopreorder/[${getParam('id')}]`).then((res) => {
if (res.data.errno === 0) {
this.props.history.push(`/order?id=[${getParam('id')}]`, {simple: 1});
} else {
Toast.info(res.data.msg, 2);
}
})
// window.location.href = '/shopcart'
this.props.history.push(`/order?id=[${getParam('id')}]`, {simple: 1})
// this.props.history.push(`/order?id=[${getParam('id')}]`, {simple: 1})
} else {
Toast.info(res.data.msg, 2)
}
......@@ -179,22 +186,23 @@ class BtnStatus extends Component {
}
// 砍价接口
toKanjia = () => {
const {user} = this.props
const uid = user && user.data && user.data.uid
const {user, history} = this.props;
const uid = user && user.data && user.data.uid;
const course_id = getParam('id');
if (!uid) {
this.props.history.push('/passport/login')
} else {
let data = {
course_id: getParam('id'),
course_id,
type: 1, // 1 用户自己砍价 2 使用砍价神器 3 好友助力砍价 4 好友第二次助力
parent_uid: 0 // 被助力人id 【自己本人操作传0】
}
http.post(`${API.home}/m/bargain/toBargain`, data).then((res) => {
if (res.data.code === 200) {
// this.props.getBargainInfo()
document.location.reload()
const {data: {data, code, msg}} = res;
if (code === 200) {
history.push(`/bargain-middle-page?id=${course_id}&bargaincode=${data.bargain_code}&is_originator=1`)
} else {
Toast.info(res.data.msg, 2)
Toast.info(msg, 2)
}
})
}
......@@ -227,7 +235,8 @@ class BtnStatus extends Component {
const {countdown} = this.state;
const {user} = this.props
const uid = user && user.data && user.data.uid
const { barInfo = {} } = this.props;
console.log(this.props);
return (
<div>
......@@ -311,15 +320,15 @@ class BtnStatus extends Component {
<span onClick={this.tobuy}>直接购买</span>
</button>
{
(this.state.barInfo.bargain_status === 2 || !uid) &&
(barInfo.bargain_status === 2 || !uid) &&
<button className='btn btn-s bg-E02E24' onClick={this.toKanjia}>
我要砍价
</button>
}
{
(this.state.barInfo.bargain_status === 0 || this.state.barInfo.bargain_status === 1) && (uid) &&
(barInfo.bargain_status === 0 || barInfo.bargain_status === 1) && (uid) &&
<button className='btn btn-s bg-E02E24'>
<span>¥{this.state.barInfo.amount}</span>
<span>¥{barInfo.amount}</span>
<span onClick={this.bargainToOrder}>去支付</span>
</button>
}
......
......@@ -2,7 +2,6 @@ import React, { Component } from 'react'
import './index.scss'
import { getParam } from "@/utils"
import { connect } from "react-redux"
import { Link } from "react-router-dom"
import { Flex } from 'antd-mobile'
import {browser} from "@/utils"
import {Toast} from 'antd-mobile'
......
......@@ -33,7 +33,8 @@ class ToGroup extends Component {
let shareData = {
title: `【仅剩${number}个名额】我${pdd_price}元拼了《${data.course_title}》`,
desc: data.course_title, // 分享描述
link: location.origin + `/detail??id=${data.course_id}`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
// 直接进入课程详情页,isIn: 1
link: location.origin + `/detail?id=${data.course_id}&isIn=1`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: data.image_name, // 分享图标
};
http.post(`${API['base-api']}/m/sale/signature`).then(res => {
......@@ -120,14 +121,22 @@ class ToGroup extends Component {
});
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`);
return false;
}));
}
render() {
const { data: { course_id, course_title, simpledescription, price0, price1 }, pdd_price, is_success, person_num, groupon_member, course_list } = this.state;
const Info = (
<div className="info">
<p className='title'>
<Link to={`/detail?id=${course_id}`}>
<p className='title' onClick={() => this.toCourseDetail(course_id)}>
{/* <Link to={`/detail?id=${course_id}`}> */}
{course_title}
</Link>
{/* </Link> */}
</p>
<p className='contact text-overflow-2'>{simpledescription}</p>
<div className='des'>
......@@ -142,7 +151,13 @@ class ToGroup extends Component {
<div className='to-group-box'>
<HeaderBar title='拼团' arrow={true} cart={false}></HeaderBar>
{
!is_success && <VList img={this.state.data.image_name} id={this.state.data.course_id} info={Info}></VList>
!is_success &&
<VList
img={this.state.data.image_name}
id={this.state.data.course_id}
info={Info}
toDetail={this.toCourseDetail}
/>
}
<GorupContent data={this.state} invitedFriends={this.invitedFriends} />
......@@ -157,10 +172,10 @@ class ToGroup extends Component {
(course_list && course_list.length > 0) && (course_list[0].course && course_list[0].course.length > 0) && course_list[0].course.slice(0, 4).map(item => {
let weekInfo = <div className="info">
<p className='title'>
<Link to={`/detail?id=${item.course_id}`}>
<p className='title' onClick={() => this.toCourseDetail(item.course_id)}>
{/* <Link to={`/detail?id=${item.course_id}`}> */}
{item.course_title}
</Link>
{/* </Link> */}
</p>
<p className='contact text-overflow-2'>{item.simpledescription}</p>
<div className='des'>
......@@ -170,7 +185,15 @@ class ToGroup extends Component {
</p>
</div>
</div>
return (<VList img={item.image_name} key={item.uid} id={item.course_id} info={weekInfo}></VList>)
return (
<VList
img={item.image_name}
key={item.uid}
id={item.course_id}
info={weekInfo}
toDetail={this.toCourseDetail}
/>
)
})
}
......
......@@ -10,10 +10,10 @@ import Single from "./single"
import BtnStatus from "./btnstatus"
import Carouselw from "./carousel"
import {connect} from "react-redux"
import {fetchCoursesListIfNeeded} from "./actions"
import {getCourses, addCourseToCart} from "./actions"
import {getParam, http, browser} from "@/utils"
import {Toast} from 'antd-mobile'
import {compose} from "redux";
import {compose, bindActionCreators} from "redux";
class Detail extends Component {
......@@ -33,7 +33,14 @@ class Detail extends Component {
}
componentDidMount() {
this.props.fetchCoursesListIfNeeded();
// 直接进入课程详情页,isIn: 1
if(getParam('isIn')) {
this.props.getCourses();
}
const { courseInfo } = this.props;
if(courseInfo.is_bargain) {
this.getBargainInfo();
}
}
// 点击子组件试听按钮
......@@ -248,7 +255,7 @@ class Detail extends Component {
{/*分享赚钱*/}
{
courseInfo.is_dist &&
<ShareRank/>
<ShareRank courseInfo={courseInfo}/>
}
{/*拼团*/}
......@@ -272,8 +279,8 @@ class Detail extends Component {
data={this.props.courseInfo}
user={this.props.user}
barInfo={this.state.barInfo}
getBargainInfo={this.getBargainInfo}
invitedFriends={this.invitedFriends}
addCourseToCart={this.props.addCourseToCart}
history={this.props.history}></BtnStatus>
{
......@@ -307,7 +314,18 @@ const mapStateToProps = (state) => {
}
}
const mapDispatchToProps = {
fetchCoursesListIfNeeded
// const mapDispatchToProps = {
// fetchCoursesListIfNeeded
// }
const mapDispatchToProps = (dispatch) => {
return bindActionCreators(
{
getCourses,
addCourseToCart
},
dispatch
)
}
export default connect(mapStateToProps, mapDispatchToProps)(Detail)
\ No newline at end of file
import {RECEIVE_COURSES_DETAIL} from './actions'
import {RECEIVE_COURSES_DETAIL, ADD_COURSES_TO_CART} from './actions'
const initialState = {
......@@ -13,6 +13,12 @@ export default function detailInfo(state = initialState, action) {
...state,
...courseInfo
}
case ADD_COURSES_TO_CART:
const { course_info } = state;
const obj = {
course_info: Object.assign({}, course_info, {in_cart: true})
};
return Object.assign({}, state, obj);
default:
return state
}
......
......@@ -18,6 +18,7 @@ class ShareRank extends Component {
}
componentDidMount() {
console.log(this.props);
this.getRankList()
this.getCode()
}
......
......@@ -2,16 +2,18 @@ import React, {Component} from 'react'
import './index.scss'
import {HeaderBar} from '../../common'
import OrderList from '@/common/OrderList'
import {http, api} from "@/utils"
import {http} from "@/utils"
import {Link} from 'react-router-dom'
import {Modal, Toast} from 'antd-mobile'
import Loading from '@/common/Loading'
import InfiniteScroll from 'react-infinite-scroller'
import {debounce} from 'lodash'
import {getCourses} from './../detail/actions';
import {connect} from 'react-redux';
const alert = Modal.alert
@connect()
class MyOrders extends Component {
page = 1
constructor(props) {
......@@ -71,6 +73,14 @@ class MyOrders extends Component {
])
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`);
return false;
}));
}
render() {
......@@ -95,9 +105,10 @@ class MyOrders extends Component {
item.course && item.course.length > 0 && item.course.map((item, index) => {
const Info = (
<div className="order-info">
<p className='order-title text-overflow-one'>
<Link
to={`/detail?id=${item.course_id}`}>{item.course_title}</Link>
<p className='order-title text-overflow-one' onClick={() => this.toCourseDetail(item.course_id)}>
{/* <Link to={`/detail?id=${item.course_id}`}> */}
{item.course_title}
{/* </Link> */}
</p>
<p className='order-content text-overflow-2'>{item.description}</p>
<p className='order-des'>
......@@ -110,9 +121,13 @@ class MyOrders extends Component {
)
return (
<div className="order-wrap" key={index}>
<OrderList info={Info} src={item.image_name}
isSign={item.is_aist}
id={item.course_id}></OrderList>
<OrderList
info={Info}
src={item.image_name}
isSign={item.is_aist}
id={item.course_id}
toDetail={this.toCourseDetail}
/>
</div>
)
})
......
import React, { Component } from 'react';
import { Flex, NavBar, List, WingBlank, Toast } from 'antd-mobile';
import { Flex, List, WingBlank, Toast } from 'antd-mobile';
import { OrderItem } from '@/common/index';
import { Link } from 'react-router-dom';
import { http, getParam } from "@/utils";
import { throttle } from 'lodash';
import {HeaderBar} from '../../common';
import {connect} from 'react-redux';
import {getCourses} from './../detail/actions';
import "./order.scss"
......@@ -24,7 +26,19 @@ function OrderList(props) {
}
const Info = (
<div className="order-info">
<Link to={`/detail?id=${course_id}`}><p className='order-title' style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{course_title}</p></Link>
{/* <Link to={`/detail?id=${course_id}`}> */}
<p
className='order-title'
style={{
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}
onClick={() => props.toDetail(course_id)}
>
{course_title}
</p>
{/* </Link> */}
<p className='order-content' style={{ WebkitBoxOrient: 'vertical', WebkitLineClamp: '2', wordBreak: 'break-all', overflow: 'hidden', textOverflow: 'ellipsis', display: '-webkit-box' }}>{simpledescription}</p>
<p className='order-des'>
{/*// 这里根据类型判断 来显示什么价格 拼团还是砍价 还是特训营*/ }
......@@ -38,7 +52,15 @@ function OrderList(props) {
);
return (
<OrderItem {...item} src={image_name} id={course_id} key={index} info={Info} isaist={props.isaist}>
<OrderItem
{...item}
src={image_name}
id={course_id}
key={index}
info={Info}
isaist={props.isaist}
toDetail={props.toDetail}
>
{
(props.locationState && (props.locationState.type || props.locationState.simple)) ? (
<div className="order-prefer">
......@@ -73,10 +95,12 @@ function OrderList(props) {
);
}
@connect()
class Order extends Component {
constructor(props) {
super(props);
this.state = {
groupPrice: '',
perfect: this.props.location.state,
user_account: 0.00, // 账户余额
total: 0.00, // 需要支付总金额
......@@ -101,8 +125,8 @@ class Order extends Component {
http.post(`${API['base-api']}/pdd/m`, {course_id: getParam("id"),ischeck:this.state.useBalance}).then(res => {
if(res.data.errno === 200) {
sessionStorage.removeItem('orderUseCacheObj');
if (res.data.data.is_free === 1) {
this.props.history.push(`/togroup?id=${res.data.data.order_id}`);
if (res.data.data.pay_jump === 1) {
this.props.history.push(`/togroup?id=${res.data.data.pdd_order_id}`);
return;
}
this.props.history.replace(`/payorder?oid=${res.data.data.oid}`);
......@@ -201,9 +225,10 @@ class Order extends Component {
};
// 公共方法 存储数据
publicGetData = (res) => {
let { course, total, user_account, user_info, discount } = res.data.data;
let { course, total, user_account, user_info, discount } = res;
if(this.props.location.state && this.props.location.state.group === 1) {
total = this.groupPrice;
console.log(this.state);
total = this.state.groupPrice;
}
this.cacheObj = {
perfect: user_info,
......@@ -237,66 +262,85 @@ class Order extends Component {
componentDidMount() {
let _this = this;
console.log(this.props.location.state);
console.log(0);
// type: 1,返现课程,simple: 1,正常购买
if(this.props.location.state && this.props.location.state.type === 1) {
http.get(`${API['base-api']}/m/order/preorder?type=1`).then((res) => {
if(res.data.errno === 200) {
this.publicGetData(res);
this.publicGetData(res.data.data);
this.publicLocalStorage();
}else{
Toast.info(res.data.msg, 2);
}
})
} else if (this.props.location.state && (this.props.location.state.simple === 1 || this.props.location.state.bargain === 1)) {
console.log(1);
// 普通课程立即报名 不带 type = 1
http.get(`${API['base-api']}/m/order/preorder`).then(res => {
if(res.data.errno === 200) {
this.publicGetData(res);
this.publicGetData(res.data.data);
this.publicLocalStorage();
}else{
Toast.info(res.data.msg, 2);
}
});
} else if (this.props.location.state && this.props.location.state.group === 1){
console.log(2);
// 获取一键开团的课程
Promise.all([http.get(`${API.home}/m/del_cart_order/${getParam('id')}`),http.get(`${API['base-api']}/m/order/preorder`), http.get(`${API.home}/m/course/detail/${getParam('id')}`)]).then(resList => {
console.log(resList);
let courseInfo = resList[1],
orderInfo = resList[2];
Promise.all([http.get(`${API.home}/m/course/detail/${getParam('id')}`),http.get(`${API['base-api']}/m/order/preorder`)]).then(resList => {
let courseInfo = resList[0],
orderInfo = resList[1];
console.log(courseInfo.data);
console.log(orderInfo.data);
if(courseInfo.data.errno === 200) {
let newData = {};
if(orderInfo.data.errno === 200) {
newData = Object.assign({}, orderInfo.data.data, {course: []});
}else{
Toast.info(courseInfo.data.msg, 2);
return;
}
if(orderInfo.data.code === 200) {
if(courseInfo.data.code === 200) {
newData.course.push(courseInfo.data.data.course_info);
this.setState({
groupPrice: courseInfo.data.data.course_info.pdd_group_info.price
})
}else{
Toast.info(courseInfo.data.msg, 2);
return;
}
this.groupPrice = orderInfo.data.data.course_info.pdd_group_info.price;
if(courseInfo.data.data.course.length === 0) {
courseInfo.data.data.course.push(orderInfo.data.data.course_info)
}
this.publicGetData(courseInfo);
// this.groupPrice = orderInfo.data.data.course_info.pdd_group_info.price;
// if(courseInfo.data.data.course.length === 0) {
// courseInfo.data.data.course.push(orderInfo.data.data.course_info)
// }
this.publicGetData(newData);
this.publicLocalStorage();
});
}
else{
http.get(`${API['base-api']}/m/order/preorder`).then((res) => {
console.log('为了验证什么条件下会走这段代码');
if (res.data.errno !== 200) {
Toast.info(res.data.msg, 2);
return;
}
} else {
// if(getParam('id')) {
// Promise.all([http.get(`${API.home}/m/del_cart_order/${getParam('id')}`), http.get(`${API['base-api']}/m/order/preorder`)]).then(res => {
// console.log(res);
// let preorder = res[1],
// orderList = preorder.data.data.course;
// if(preorder.data.errno !== 200) {
// Toast.info(preorder.data.msg, 2);
// return;
// }
this.publicGetData(res);
this.publicLocalStorage();
})
// this.publicGetData(preorder);
// this.publicLocalStorage();
// })
// }else{
http.get(`${API['base-api']}/m/order/preorder`).then((res) => {
console.log('为了验证什么条件下会走这段代码');
if (res.data.errno !== 200) {
Toast.info(res.data.msg, 2);
return;
}
this.publicGetData(res.data.data);
this.publicLocalStorage();
})
// }
}
// else {
// if(getParam('id')) {
......@@ -326,6 +370,14 @@ class Order extends Component {
// }
// }
};
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const {
perfect,
......@@ -336,6 +388,7 @@ class Order extends Component {
useBalance,
info,
offset,
groupPrice
} = this.state;
return (
......@@ -386,7 +439,14 @@ class Order extends Component {
</div>
}
<div className="order-list">
<OrderList list={orderList} compute={this.computedMoney} courseId={getParam('id')} locationState={this.props.location.state} groupPrice={this.groupPrice}/>
<OrderList
list={orderList}
compute={this.computedMoney}
courseId={getParam('id')}
locationState={this.props.location.state}
groupPrice={groupPrice}
toDetail={this.toCourseDetail}
/>
</div>
<div className="order-balance">
<List>
......
......@@ -6,7 +6,11 @@ import HeaderSearch from '../../common/HeaderSearch/index'
import {http} from "@/utils"
import {Link} from 'react-router-dom'
import Loading from '@/common/Loading'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {getCourses} from './../detail/actions';
@connect()
class Preferential extends Component {
constructor(props) {
super(props)
......@@ -74,6 +78,12 @@ class Preferential extends Component {
}
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const tabs = [
......@@ -98,10 +108,10 @@ class Preferential extends Component {
{this.state.dataList.map((item, index) => {
const Info = (
<div className="info">
<p className='title'>
<Link to={`/detail?id=${item.course_id}`}>
<p className='title' onClick={() => this.toCourseDetail(item.course_id)}>
{/* <Link to={`/detail?id=${item.course_id}`}> */}
{item.course_title}
</Link>
{/* </Link> */}
</p>
<p className='contact text-overflow-2'>{item.course_desc}</p>
<div className='des'>
......@@ -134,9 +144,14 @@ class Preferential extends Component {
</div>
)
return (
<VList key={index} img={item.image_name}
id={item.course_id} status={status}
info={Info}></VList>
<VList
key={index}
img={item.image_name}
id={item.course_id}
status={status}
info={Info}
toDetail={this.toCourseDetail}
/>
)
})}
</ul>
......@@ -152,4 +167,4 @@ class Preferential extends Component {
}
export default Preferential
export default Preferential;
......@@ -5,6 +5,7 @@ import { http } from "@/utils";
import {Link} from 'react-router-dom'
import {Toast} from 'antd-mobile'
import {connect} from "react-redux"
import {getCourses} from './../detail/actions';
import Loading from '@/common/Loading'
class Purchased extends Component {
......@@ -34,6 +35,13 @@ class Purchased extends Component {
})
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const {user} = this.props
......@@ -50,10 +58,10 @@ class Purchased extends Component {
this.state.data.map((item, index) => {
const Info = (
<div className="info">
<p className='title'>
<Link to={`/detail?id=${item.course_id}`}>
<p className='title' onClick={() => this.toCourseDetail(item.course_id)}>
{/* <Link to={`/detail?id=${item.course_id}`}> */}
{item.course_title}
</Link>
{/* </Link> */}
</p>
<p className='contact text-overflow-2'>{item.simpledescription}</p>
{
......@@ -67,11 +75,13 @@ class Purchased extends Component {
item.is_aist && <span className='status'>返现</span>
)
return (
<VList key={index}
img={item.image_name}
id={item.course_id}
info={Info}
status={status}
<VList
key={index}
img={item.image_name}
id={item.course_id}
info={Info}
status={status}
toDetail={this.toCourseDetail}
/>
)
})
......
......@@ -8,12 +8,12 @@ export default class CategoryItem extends Component {
super(props);
}
render() {
const {course_title, price1, price0, first_level_tip, image_name, upgrade, upgradeImg, course_id, share} = this.props;
const {course_title, price1, price0, first_level_tip, image_name, upgrade, upgradeImg, course_id, share, toDetail} = this.props;
return (
<WingBlank>
<div className={'scholarship-category'}>
<Link to={`/detail?id=${course_id}`} >
<div className={'imageContainer'}>
{/* <Link to={`/detail?id=${course_id}`} > */}
<div className={'imageContainer'} onClick={() => toDetail(course_id)}>
<img className={'image'} src={image_name}></img>
{
upgrade ? (
......@@ -21,10 +21,17 @@ export default class CategoryItem extends Component {
) : (null)
}
</div>
</Link>
{/* </Link> */}
<div className={'content'}>
<Flex direction='column' justify='around' align='start' style={{height: '90px'}}>
<Link to={`/detail?id=${course_id}`} ><p className={'text-overflow-one'}>{course_title}</p></Link>
{/* <Link to={`/detail?id=${course_id}`} > */}
<p
className={'text-overflow-one'}
onClick={() => toDetail(course_id)}
>
{course_title}
</p>
{/* </Link> */}
<p><span className={'priceNow'}>{`¥${price1}`}</span><span className={'pricePrimary'}>{`¥${price0}`}</span></p>
<div className={'shareMoney'} onClick={()=>{share(course_id, first_level_tip)}}>{`分享赚${first_level_tip}元`}</div>
</Flex>
......
import React, { Component } from 'react';
import { Tabs, WhiteSpace, List, Flex, WingBlank, Modal, ListView, Toast } from 'antd-mobile';
import './scholarship.scss';
import { is_weixin, http, api } from "@/utils";
import { is_weixin, http } from "@/utils";
import CategoryItem from './CategoryItem/CategoryItem.js';
import SortItem from './SortItem/SortItem.js';
import { connect } from 'react-redux';
import OpenApp from '@/common/CallApp';
import {getCourses} from './../detail/actions';
const Item = List.Item;
@connect(state => ({
user: state.user
}))
class _Scholarship extends Component {
constructor(props) {
super(props);
......@@ -156,12 +160,27 @@ class _Scholarship extends Component {
});
this.onEndReached();
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const row = (
rowData,
rowID
) => {
return <CategoryItem {...rowData} key={rowID} share={this.shareCategory}/>;
return (
<CategoryItem
{...rowData}
key={rowID}
share={this.shareCategory}
toDetail={this.toCourseDetail}
/>
);
};
const row1 = (
......@@ -396,19 +415,21 @@ class _Scholarship extends Component {
)
}
}
const mapStateToProps = (state) => {
return {
user: {
...state.user
},
};
};
// const mapStateToProps = (state) => {
// return {
// user: {
// ...state.user
// },
// };
// };
// const mapDispatchToProps = (dispatch) => {
// return {};
// };
const mapDispatchToProps = (dispatch) => {
return {};
};
// export const Scholarship = connect(
// mapStateToProps,
// mapDispatchToProps
// )(_Scholarship);
export const Scholarship = connect(
mapStateToProps,
mapDispatchToProps
)(_Scholarship);
export default _Scholarship;
import React, { Component } from "react";
import {connect} from 'react-redux';
import './recommendation.scss'
import { Course } from "@/common";
import { api, http } from "@/utils";
import { http } from "@/utils";
import { Toast } from 'antd-mobile'
import {withRouter} from 'react-router-dom'
import {getCourses} from './../../detail/actions';
@connect()
class Recommendation extends Component {
state = {
......@@ -26,11 +29,16 @@ class Recommendation extends Component {
}
handleClick = (id) => {
this.props.history.push(`/detail?id=${id}`)
}
// handleClick = (id) => {
// this.props.history.push(`/detail?id=${id}`)
// }
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const {courses} = this.state
......@@ -40,12 +48,11 @@ class Recommendation extends Component {
<div className="courses">
{
courses.length > 0 &&
courses.map((item, index) => {
courses.map((item) => {
const Bottom = (
<div className='bottom'>
<span className='price'>¥{item['price1']}</span>
<span className='old-price'>¥{item['price0']}</span>
<span className='price'>{item['price1']}</span>
<span className='old-price'>{item['price0']}</span>
</div>
)
return (
......@@ -56,7 +63,7 @@ class Recommendation extends Component {
img={item['image_name']}
title={item['course_title']}
bottom={Bottom}
handleClick={this.handleClick}
toDetail={this.toCourseDetail}
/>
)
})
......
import React, { PureComponent } from 'react';
import {connect} from 'react-redux';
import SearchHeader from './searchHead'
import VList from '@/common/VList'
import { http, getParam } from '@/utils'
import './search-result.scss'
import Recommendation from './recommendation'
import {getCourses} from './../detail/actions';
const Bottom = ({item}) => {
return (
......@@ -14,6 +16,7 @@ const Bottom = ({item}) => {
)
}
@connect()
class SearchResult extends PureComponent {
state = {
......@@ -52,6 +55,12 @@ class SearchResult extends PureComponent {
this.setState({value})
}
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
const {courseList} = this.state
......@@ -90,12 +99,13 @@ class SearchResult extends PureComponent {
: null
)
return (
<VList img={item.image_name}
handleClick={this.handleClick}
key={item.course_id}
info={Info}
id={item['course_id']}
status={status}
<VList
img={item.image_name}
toDetail={this.toCourseDetail}
key={item.course_id}
info={Info}
id={item['course_id']}
status={status}
/>
)
})
......@@ -104,9 +114,8 @@ class SearchResult extends PureComponent {
: <div className="empty">
抱歉!没有搜到相关内容
</div>
}
<Recommendation/>
<Recommendation />
</div>
);
}
......
......@@ -22,8 +22,10 @@ class CartItem extends Component {
let item = this.props.item
const Info = (
<div className="order-info">
<p className='order-title text-overflow-one'>
<Link to={`/detail?id=${item.course_id}`}>{item.course_title}</Link>
<p className='order-title text-overflow-one' onClick={()=>this.props.toDetail(item.course_id)}>
{/* <Link to={`/detail?id=${item.course_id}`}> */}
{item.course_title}
{/* </Link> */}
</p>
<p className='order-content text-overflow-2'>{item.simpledescription}</p>
<p className='order-des'>
......@@ -42,7 +44,12 @@ class CartItem extends Component {
</div>
<div className="card-wrap">
<OrderList info={Info} src={item.image_name} id={item.course_id}></OrderList>
<OrderList
info={Info}
src={item.image_name}
id={item.course_id}
toDetail={this.props.toDetail}
></OrderList>
</div>
</div>
......
import React, {Component} from 'react'
import {Link} from 'react-router-dom'
import CartItem from './cartItem'
class cartList extends Component {
render() {
return (
......@@ -19,7 +20,10 @@ class cartList extends Component {
checkChange={(id, val) => {
this.props.checkChange(id, val)
}}
key={index} item={item}/>
key={index}
item={item}
toDetail={this.props.toDetail}
/>
)
})
: <div className="cart-tip">
......
......@@ -6,7 +6,8 @@ import Loading from '@/common/Loading'
import ShopCart from './cartList.js'
import './card.scss'
import classnames from 'classnames'
import {api, http} from "@/utils";
import {http} from "@/utils";
import {getCourses} from './../detail/actions';
const alert = Modal.alert;
......@@ -164,6 +165,14 @@ class Cart extends Component {
}
toCourseDetail = (id) => {
console.log(id);
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
return (
......@@ -172,7 +181,11 @@ class Cart extends Component {
<Loading isLoading={this.state.isLoading}>
<div className="cart-body">
<ShopCart checkChange={this.checkChange.bind(this)} data={this.state.data}/>
<ShopCart
checkChange={this.checkChange.bind(this)}
data={this.state.data}
toDetail={this.toCourseDetail}
/>
<div className="cart-footer">
<div className="cart-label">
......
......@@ -12,6 +12,7 @@ const PAGE_INTERVAL = 1
export const NUM_INTERVAL = 10
export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
const myCourses = getState().myCourses
console.log(myCourses);
const {switchTab, page, noMore} = myCourses
if (!switchTab && !noMore) {
dispatch(getMyCourses({
......@@ -26,11 +27,11 @@ export const getMyCourses = payload => dispatch => {
return http.get(`${API.home}/m/my_course/${payload.page}/${payload.num}`)
.then(res => {
const {data, code, msg} = res.data
if (data.length === 0) {
if (code == 200 && data.length === 0) {
dispatch(nomoreCourse())
return
}
if (data.length % 10 !== 0) {
if (code == 200 && data.length % 10 !== 0) {
dispatch(nomoreCourse())
}
dispatch(receiveMyCourses({
......@@ -50,8 +51,9 @@ export const switchTab = payload => ({
})
export const NOMORE_COURSE = 'NOMORE_COURSES'
export const nomoreCourse = () => ({
type: NOMORE_COURSE
export const nomoreCourse = (payload) => ({
type: NOMORE_COURSE,
payload
})
export const START_FETCHING_COURSES = 'START_FETCHING_COURSES'
......
......@@ -99,15 +99,15 @@ class MyCourses extends PureComponent {
}, 200)
render() {
let list = this.props.courseList
let {courseList, user} = this.props
return <Loading isLoading={this.props.isLoading}>
{
list && list.length !== 0
courseList && courseList.length !== 0
?
<>
<div className="my-course-uid">
{`加群请备注您的学号:${this.props.user.data.uid}`}
{`加群请备注您的学号:${!user.hasError && this.props.user.data.uid}`}
</div>
<InfiniteScroll
pageStart={0}
......@@ -117,7 +117,7 @@ class MyCourses extends PureComponent {
>
<ul ref={el => this.list = el}>
{
list.map((item, index) => {
courseList.map((item, index) => {
const Info = (
<div className="info">
......@@ -159,7 +159,7 @@ class MyCourses extends PureComponent {
</ul>
</InfiniteScroll>
{
list.length % 10 !== 0 ?
courseList.length % 10 !== 0 ?
<AddCourse addCourseClick={this.addCourseClick}/>
: null
}
......
......@@ -4,6 +4,7 @@ import {
NOMORE_COURSE,
START_FETCHING_COURSES
} from './actions'
import { SET_CURRENT_USER } from '@/store/userAction'
const initialState = {
switchTab: false,
......@@ -17,20 +18,23 @@ const initialState = {
export default function myCourses(state = initialState, action) {
switch (action.type) {
const { type, payload=null } = action;
switch (type) {
case RECEIVE_MY_COURSES:
let {courseList, ...rest} = action.payload
let {courseList, ...rest} = payload
return {
...state, ...rest,
courseList: Object.keys(courseList).length === 0 ? state.courseList : state.courseList.concat(courseList),
isLoading: false
}
case START_FETCHING_COURSES:
return {...state, ...action.payload}
return {...state, ...payload}
case SWITCH_TAB:
return {...state, switchTab: action.payload}
return {...state, switchTab: payload}
case NOMORE_COURSE:
return {...state, noMore: true}
case SET_CURRENT_USER:
return payload.hasError ? initialState : {...state, page: 0}
default:
return state
}
......
import React, {Component} from 'react'
import HeaderBar from '@/common/HeaderBar'
import './video.scss'
import {NavLink, Route, Redirect, Switch} from 'react-router-dom'
import {http, api, getParam} from '@/utils'
import { NavLink, Route, Redirect, Switch } from 'react-router-dom'
import { http, getParam } from '@/utils'
import Recommendation from './recommendation'
import VideoCatalog from './video-catalog'
import DatumCatalog from './datum-catalog'
......
import React, { PureComponent } from 'react';
import {connect} from 'react-redux';
import {getCourses} from './../../detail/actions';
import './recommendation.scss'
import { http } from '@/utils'
import { Toast } from "antd-mobile";
import VList from '@/common/v-list-base';
const Bottom = ({item}) => {
return (
<div className='bottom'>
......@@ -15,8 +16,7 @@ const Bottom = ({item}) => {
)
}
@connect()
class Recommendation extends PureComponent {
state = {
num: 10,
......@@ -24,7 +24,6 @@ class Recommendation extends PureComponent {
courseId: null
}
componentDidMount() {
this.getRecommendation()
}
......@@ -45,9 +44,11 @@ class Recommendation extends PureComponent {
})
}
handleClick = id => {
this.props.history.push(`/detail?id=${id}`)
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`)
}));
}
render() {
......@@ -73,7 +74,7 @@ class Recommendation extends PureComponent {
<VList
key={item.course_id}
img={item.image_name}
handleClick={this.handleClick}
handleClick={this.toCourseDetail}
info={Info}
id={item.course_id}
/>
......
......@@ -7,6 +7,18 @@ import thunk from 'redux-thunk'
import logger from 'redux-logger'
import rootReducers from './store'
import App from './App'
import {persistStore, persistReducer} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import {PersistGate} from 'redux-persist/lib/integration/react';
const persistConfig = {
key: 'root',
storage,
stateReconciler: autoMergeLevel2 // 查看 'Merge Process' 部分的具体情况
};
const myPersistReducer = persistReducer(persistConfig, rootReducers)
const reduxDevToolOptions = process.env.REACT_APP_BUILD_ENV === 'production' ? {} : { trace: true, traceLimit: 25 }
......@@ -15,17 +27,20 @@ const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__(reduxDevToolOptions) || compose;
const store = createStore(
rootReducers,
myPersistReducer,
composeEnhancers(
applyMiddleware(thunk, logger)
)
)
const persistor = persistStore(store)
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Router>
<App/>
</Router>
</PersistGate>
</Provider>,
document.getElementById('root'));
\ No newline at end of file
......@@ -4,7 +4,7 @@ import loadable from '@loadable/component'
import Index from '@/components/Index';
import My from '@/components/my';
import Passport from '@/components/passport';
import { Scholarship } from '@/components/scholarship/index';
import Scholarship from '@/components/scholarship';
const Coupons = loadable(() => import(/* webpackChunkName: 'coupons'*/ '@/components/coupons'))
const Study = loadable(() => import(/* webpackChunkName: 'study'*/'@/components/study'))
......
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