Commit 5b7c6e53 by xuzhenghua

免单券优化

parent abc3e1e1
...@@ -53,14 +53,17 @@ class UseCoupon extends PureComponent { ...@@ -53,14 +53,17 @@ class UseCoupon extends PureComponent {
const {location: {state = {}}} = this.props; const {location: {state = {}}} = this.props;
if (this.state.redeemCode !== '') { if (this.state.redeemCode !== '') {
http.post(`${API.home}/m/coupon/exchange`, { http.post(`${API.home}/m/coupon/exchange`, {
code: this.state.redeemCode code: this.state.redeemCode,
type: state.from.substr(1)
}) })
.then(res => { .then(res => {
const data = res.data const data = res.data
if (data.code === 200) { if (data.code === 200) {
// 如果从我的页面进来,点击兑换直接兑换成功课程,弹出弹窗
// 如果从订单页面进来,点击兑换兑换成券
const coupon = data.data const coupon = data.data
if (state.from === '/my') {
if (coupon['ctype'] == 2) { if (coupon['ctype'] == 2) {
this.setState({ this.setState({
courseCouponData: coupon, courseCouponData: coupon,
...@@ -68,27 +71,34 @@ class UseCoupon extends PureComponent { ...@@ -68,27 +71,34 @@ class UseCoupon extends PureComponent {
redeemCode: '' redeemCode: ''
}) })
} else { } else {
if (this.state.showUseButton) {
this.setState({ this.setState({
couponList: [...this.state.couponList, coupon], couponList: [...this.state.couponList, coupon],
redeemCode: '' redeemCode: ''
}) })
} else { Toast.info('兑换成功')
this.getMyCoupons()
}
}
if (state.from === '/order') {
const coupon = data.data const coupon = data.data
if (coupon['ctype'] == 2
&& coupon['limit_course'] != this.state.courseId) {
this.setState({
invalid_coupons: [...this.state.invalid_coupons, coupon],
showUseButton: null,
redeemCode: ''
});
} else {
this.setState({ this.setState({
valid_coupons: [...this.state.valid_coupons, coupon], valid_coupons: [...this.state.valid_coupons, coupon],
redeemCode: '' redeemCode: ''
}) })
} }
Toast.info('兑换成功') Toast.info('兑换成功')
if (state.from === '/my') {
this.getMyCoupons()
}
if (state.from === '/order') {
this.getAllCoupons() this.getAllCoupons()
} }
}
} else { } else {
Toast.info(data.msg) Toast.info(data.msg)
} }
...@@ -136,15 +146,14 @@ class UseCoupon extends PureComponent { ...@@ -136,15 +146,14 @@ class UseCoupon extends PureComponent {
} }
// 立即兑换课程 // 立即兑换课程
toExchangeCourse = (e,code)=>{ toExchangeCourse = (e, code) => {
e.stopPropagation(); e.stopPropagation();
http.post(`${API['base-api']}/pay/miandan/${code}`, { http.post(`${API['base-api']}/pay/miandan/${code}`, {}).then(res => {
}).then(res => {
const data = res.data const data = res.data
if (data.errno === 200) { if (data.errno === 200) {
this.setState({ this.setState({
courseCouponExchange: true, courseCouponExchange: true,
courseCouponData:res.data.data courseCouponData: res.data.data
}) })
this.getMyCoupons() this.getMyCoupons()
} else { } else {
......
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