Commit 78e068f4 by FE

cart btn update course detail

parent eb75aa47
...@@ -30,7 +30,7 @@ class HeaderBar extends Component { ...@@ -30,7 +30,7 @@ class HeaderBar extends Component {
} }
{ {
toHref && typeof toHref === 'function' && toHref && typeof toHref === 'function' &&
<i className='iconfont iconiconfront-68' onClick={toHref}>1</i> <i className='iconfont iconiconfront-68' onClick={toHref}></i>
} }
{ {
toHref && typeof toHref === 'string' && toHref && typeof toHref === 'string' &&
......
...@@ -21,7 +21,8 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => { ...@@ -21,7 +21,8 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
} }
export const getCourses = (id, cb) => dispatch => { export const getCourses = (id, cb) => dispatch => {
const courseId = id? id : getParam('id'); const courseId = id? id : getParam('id');
return http.get(`${API.home}/m/course/detail/${courseId}`,).then((res) => { const url = getParam('dist_code')? `${API.home}/m/course/detail/${courseId}/${getParam('dist_code')}` : `${API.home}/m/course/detail/${courseId}`;
return http.get(url).then((res) => {
if (res.data.code === 200) { if (res.data.code === 200) {
dispatch(receiveCourseDetail({ dispatch(receiveCourseDetail({
...res.data.data ...res.data.data
......
...@@ -47,36 +47,36 @@ class BtnStatus extends Component { ...@@ -47,36 +47,36 @@ class BtnStatus extends Component {
// this.getBargainInfo() // this.getBargainInfo()
// } // }
this.setState({ this.setState({
...nextProps.data.course_info, courseInfo: data,
countdown: nextProps.countdown, countdown: nextProps.countdown,
}); });
} }
// 加入购物车 type:1 加入购物车,2加入购物车并跳转到购物车页面去支付 // // 加入购物车 type:1 加入购物车,2加入购物车并跳转到购物车页面去支付
toCart = (type) => { // toCart = (type) => {
const { history, addCourseToCart } = this.props; // const { history, addCourseToCart } = this.props;
let data = { // let data = {
course_id: getParam('id') // course_id: getParam('id')
}; // };
http.post(`${API.home}/m/cart/add`, data).then((res) => { // http.post(`${API.home}/m/cart/add`, data).then((res) => {
if (res.data.code === 200) { // if (res.data.code === 200) {
if (type === 1) { // if (type === 1) {
Toast.info('已加入购物车', 2) // Toast.info('已加入购物车', 2)
// this.props.getCourses() // // this.props.getCourses()
// document.location.reload() // // document.location.reload()
addCourseToCart(); // addCourseToCart();
} else { // } else {
history.replace('/shopcart');ß // history.replace('/shopcart');ß
} // }
} else if (res.data.code === 15001) { // } else if (res.data.code === 15001) {
history.replace('/shopcart'); // history.replace('/shopcart');
} else if (res.data.code === 4030) { // } else if (res.data.code === 4030) {
history.replace('/passport'); // history.replace('/passport');
} else { // } else {
Toast.info(res.data.msg, 2); // Toast.info(res.data.msg, 2);
} // }
}) // })
}; // };
// 返现课程的立即购买 // 返现课程的立即购买
signUpNow = () => { signUpNow = () => {
if(this.props.user.hasError) { if(this.props.user.hasError) {
...@@ -234,10 +234,12 @@ class BtnStatus extends Component { ...@@ -234,10 +234,12 @@ class BtnStatus extends Component {
} }
render() { render() {
console.log(this.state);
// data 课程信息;barInfo 砍价信息 // data 课程信息;barInfo 砍价信息
const { data: info = {}, user = {} } = this.props; const { user = {}, toCart } = this.props;
const { countdown ,barInfo} = this.state; const { countdown ,barInfo, courseInfo: info = {}} = this.state;
const uid = user.data && user.data.uid; const uid = user.data && user.data.uid;
console.log(info.in_cart);
return ( return (
<div> <div>
{/*正常购买*/} {/*正常购买*/}
...@@ -254,7 +256,7 @@ class BtnStatus extends Component { ...@@ -254,7 +256,7 @@ class BtnStatus extends Component {
} }
{ {
!info.in_cart && !info.in_cart &&
<button className='btn btn-s bg-FCCD05' onClick={e => this.toCart(1)}>加入购物车</button> <button className='btn btn-s bg-FCCD05' onClick={e => toCart(1)}>加入购物车</button>
} }
<span className='btn btn-s bg-FD7700' onClick={e => this.simpleCourse()}>立即报名</span> <span className='btn btn-s bg-FD7700' onClick={e => this.simpleCourse()}>立即报名</span>
......
...@@ -110,6 +110,33 @@ class Detail extends Component { ...@@ -110,6 +110,33 @@ class Detail extends Component {
// } // }
// } // }
// 加入购物车 type:1 加入购物车,2加入购物车并跳转到购物车页面去支付
toCart = (type) => {
const { history, addCourseToCart } = this.props;
let data = {
course_id: getParam('id')
};
http.post(`${API.home}/m/cart/add`, data).then((res) => {
if (res.data.code === 200) {
if (type === 1) {
Toast.info('已加入购物车', 2)
// this.props.getCourses()
// document.location.reload()
addCourseToCart();
this.fetchCourseInfo();
} else {
history.replace('/shopcart');ß
}
} else if (res.data.code === 15001) {
history.replace('/shopcart');
} else if (res.data.code === 4030) {
history.replace('/passport');
} else {
Toast.info(res.data.msg, 2);
}
})
};
invitedFriends = () => { invitedFriends = () => {
const {course_title, image_name, course_id, pdd_group_info, pdd_group_info: {groupon_member, groupon_member: {number}, price}} = this.state.course.course_info; const {course_title, image_name, course_id, pdd_group_info, pdd_group_info: {groupon_member, groupon_member: {number}, price}} = this.state.course.course_info;
if (browser.isWeixin) { if (browser.isWeixin) {
...@@ -312,7 +339,8 @@ class Detail extends Component { ...@@ -312,7 +339,8 @@ class Detail extends Component {
data={course_info} data={course_info}
user={this.props.user} user={this.props.user}
invitedFriends={this.invitedFriends} invitedFriends={this.invitedFriends}
addCourseToCart={this.props.addCourseToCart} // addCourseToCart={this.props.addCourseToCart}
toCart={this.toCart}
history={this.props.history} history={this.props.history}
/>} />}
......
...@@ -56,7 +56,7 @@ class SharePoster extends Component { ...@@ -56,7 +56,7 @@ class SharePoster extends Component {
let qrCodeWidth = (imgList[index].qr_code_width * $width) // 二维码宽度 let qrCodeWidth = (imgList[index].qr_code_width * $width) // 二维码宽度
let qrCodeHeight = (imgList[index].qr_code_height * $height) - avatarHeight / 2 // 二维码高度 let qrCodeHeight = (imgList[index].qr_code_height * $height) - avatarHeight / 2 // 二维码高度
let qrCodeLink = `/detail/${getParam('courseId')}/${getParam('dist_code')}` let qrCodeLink = `https://m.julyedu.com/detail?id=${getParam('courseId')}&dist_code${getParam('dist_code')}`
var canvas = document.getElementById("canvas"), var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"); context = canvas.getContext("2d");
...@@ -156,7 +156,7 @@ class SharePoster extends Component { ...@@ -156,7 +156,7 @@ class SharePoster extends Component {
// 获取二维码 // 获取二维码
getCodeWe() { getCodeWe() {
let _this = this let _this = this
let qrCodeLink = `http://m.julyedu.com/detail/${getParam('courseId')}/${getParam('dist_code')}` let qrCodeLink = `https://m.julyedu.com/detail?id=${getParam('courseId')}&dist_code=${getParam('dist_code')}`
return new Promise(resolve => { return new Promise(resolve => {
QRCode.toDataURL(qrCodeLink, {}, function (err, url) { QRCode.toDataURL(qrCodeLink, {}, function (err, url) {
_this.setState({ _this.setState({
......
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