Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiguangyao
mr-julyedu
Commits
5fd2370c
Commit
5fd2370c
authored
Oct 30, 2019
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
定金bug
parent
c42220e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
525 additions
and
514 deletions
+525
-514
src/components/coupons/Coupon/index.js
+195
-184
src/components/coupons/myCoupons/index.js
+330
-330
No files found.
src/components/coupons/Coupon/index.js
View file @
5fd2370c
...
@@ -3,210 +3,221 @@ import './coupon.scss'
...
@@ -3,210 +3,221 @@ import './coupon.scss'
import
classnames
from
'classnames'
import
classnames
from
'classnames'
import
{
http
}
from
"@/utils"
import
{
http
}
from
"@/utils"
import
showAlert
from
'@common/deposit/end-expansion-alert'
import
showAlert
from
'@common/deposit/end-expansion-alert'
import
{
Toast
}
from
'antd-mobile'
import
{
Toast
}
from
'antd-mobile'
import
{
withRouter
}
from
"react-router-dom"
class
Coupon
extends
PureComponent
{
VOUCHER
=
1
//代金券
FREE
=
2
//免单券
EXPAND
=
4
//膨胀全
class
Coupon
extends
PureComponent
{
pick
=
()
=>
{
VOUCHER
=
1
//代金券
let
{
useCoupon
,
invalid
}
=
this
.
props
FREE
=
2
//免单券
!
invalid
&&
useCoupon
&&
useCoupon
(
this
.
props
.
id
)
EXPAND
=
4
//膨胀全
}
GoToUse
=
()
=>
{
pick
=
(
e
)
=>
{
this
.
props
.
useCoupon
(
this
.
props
.
id
)
let
{
useCoupon
,
invalid
,
start_amount
,
id
,
location
,
history
,
code
}
=
this
.
props
const
{
state
}
=
location
if
(
state
&&
state
.
from
&&
state
.
from
===
'/my'
){
history
.
push
(
`/expand/index?deposit_code=
${
code
}
`
)
return
}
}
ExchangeCourse
=
(
e
)
=>
{
if
(
start_amount
)
{
this
.
props
.
toExchangeCourse
(
e
,
this
.
props
.
code
)
this
.
stopExpanding
(
id
,
e
)
}
else
{
!
invalid
&&
useCoupon
&&
useCoupon
(
this
.
props
.
id
)
}
}
stopExpanding
=
(
id
,
e
)
=>
{
}
const
{
amount
,
limit_amount
}
=
this
.
props
e
.
stopPropagation
()
GoToUse
=
()
=>
{
showAlert
({
this
.
props
.
useCoupon
(
this
.
props
.
id
)
amount
,
}
limit_amount
,
ExchangeCourse
=
(
e
)
=>
{
onConfirm
:
()
=>
{
this
.
props
.
toExchangeCourse
(
e
,
this
.
props
.
code
)
http
.
post
(
`
${
API
.
home
}
/m/end_expansion`
,
{
}
id
})
stopExpanding
=
(
id
,
e
)
=>
{
.
then
(
res
=>
{
const
{
amount
,
limit_amount
}
=
this
.
props
const
{
data
}
=
res
e
.
stopPropagation
()
if
(
data
.
code
==
200
)
{
showAlert
({
this
.
props
.
endExpansion
(
id
)
amount
,
}
else
{
limit_amount
,
Toast
.
info
(
data
.
msg
)
onConfirm
:
()
=>
{
}
http
.
post
(
`
${
API
.
home
}
/m/end_expansion`
,
{
})
id
}
})
})
.
then
(
res
=>
{
const
{
data
}
=
res
if
(
data
.
code
==
200
)
{
this
.
props
.
endExpansion
(
id
,
data
.
data
.
coupon_id
)
}
else
{
Toast
.
info
(
data
.
msg
)
}
})
}
})
}
render
()
{
let
{
ctype
,
amount
,
course_title
,
showUseButton
,
id
,
format_expire_time
,
start_amount
,
limit_amount
}
=
this
.
props
let
top
,
bottom
switch
(
ctype
)
{
case
this
.
VOUCHER
:
top
=
(
<>
<
p
className
=
'denomination'
>
{
amount
}
<
span
>
元
<
/span></
p
>
<
p
className
=
'expire'
>
有效期至:
{
format_expire_time
}
<
/p
>
<
/
>
}
)
bottom
=
(
<>
<
span
className
=
{
'limit'
}
>
可用于大于代金券金额的课程
<
/span
>
{
showUseButton
&&
ctype
==
this
.
VOUCHER
&&
<
button
className
=
'use'
onClick
=
{
this
.
GoToUse
}
>
立即使用
<
/button
>
}
<
/
>
)
break
case
this
.
FREE
:
top
=
(
<>
<
p
className
=
'course-title'
>
{
course_title
}
<
/p
>
<
p
className
=
'expire'
>
有效期至:
{
format_expire_time
}
<
/p
>
<
/
>
)
bottom
=
(
<>
<
span
className
=
{
'limit'
}
>
{
`仅适用于《
${
course_title
}
》`
}
<
/span
>
{
showUseButton
&&
ctype
==
this
.
FREE
&&
<
button
className
=
'use'
onClick
=
{(
e
)
=>
this
.
ExchangeCourse
(
e
)}
>
立即兑换
<
/button
>
}
<
/
>
render
()
{
)
let
{
break
ctype
,
case
this
.
EXPAND
:
amount
,
if
(
!
start_amount
)
{
course_title
,
top
=
(
showUseButton
,
<>
id
,
<
p
className
=
'denomination'
>
{
amount
}
<
span
>
元
<
/span></
p
>
format_expire_time
,
<
p
className
=
'expire'
>
有效期至:
{
format_expire_time
}
<
/p
>
start_amount
,
<
/
>
limit_amount
)
}
=
this
.
props
}
else
{
let
top
,
bottom
top
=
(
<>
switch
(
ctype
)
{
<
div
className
=
"progress-container"
>
case
this
.
VOUCHER
:
<
p
className
=
'denomination'
>
{
amount
}
<
span
>
元
<
/span></
p
>
top
=
(
<
div
className
=
{
'progress-bar-container'
}
>
<>
<
p
className
=
'denomination'
>
{
amount
}
<
span
>
元
<
/span></
p
>
<
p
className
=
'expire'
>
有效期至:
{
format_expire_time
}
<
/p
>
<
/
>
)
bottom
=
(
<>
<
span
className
=
{
'limit'
}
>
可用于大于代金券金额的课程
<
/span
>
{
showUseButton
&&
ctype
==
this
.
VOUCHER
&&
<
button
className
=
'use'
onClick
=
{
this
.
GoToUse
}
>
立即使用
<
/button
>
}
<
/
>
)
break
case
this
.
FREE
:
top
=
(
<>
<
p
className
=
'course-title'
>
{
course_title
}
<
/p
>
<
p
className
=
'expire'
>
有效期至:
{
format_expire_time
}
<
/p
>
<
/
>
)
bottom
=
(
<>
<
span
className
=
{
'limit'
}
>
{
`仅适用于《
${
course_title
}
》`
}
<
/span
>
{
showUseButton
&&
ctype
==
this
.
FREE
&&
<
button
className
=
'use'
onClick
=
{(
e
)
=>
this
.
ExchangeCourse
(
e
)}
>
立即兑换
<
/button
>
}
<
/
>
)
break
case
this
.
EXPAND
:
if
(
!
start_amount
)
{
top
=
(
<>
<
p
className
=
'denomination'
>
{
amount
}
<
span
>
元
<
/span></
p
>
<
p
className
=
'expire'
>
有效期至:
{
format_expire_time
}
<
/p
>
<
/
>
)
}
else
{
top
=
(
<>
<
div
className
=
"progress-container"
>
<
p
className
=
'denomination'
>
{
amount
}
<
span
>
元
<
/span></
p
>
<
div
className
=
{
'progress-bar-container'
}
>
<
span
className
=
{
'progress-bar'
}
<
span
className
=
{
'progress-bar'
}
style
=
{{
width
:
`
${
Math
.
round
((
amount
-
start_amount
)
/
limit_amount
*
100
)}
%`
}}
style
=
{{
width
:
`
${
Math
.
round
((
amount
-
start_amount
)
/
limit_amount
*
100
)}
%`
}}
><
/span
>
><
/span
>
<
/div
>
<
/div
>
<
div
className
=
{
'money'
}
>
<
div
className
=
{
'money'
}
>
<
span
>
{
start_amount
}
元
<
/span
>
<
span
>
{
start_amount
}
元
<
/span
>
<
span
>
{
limit_amount
}
元
<
/span
>
<
span
>
{
limit_amount
}
元
<
/span
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
<
/
>
<
/
>
)
)
}
bottom
=
(
<>
<
span
className
=
{
'limit'
}
>
全场通用
<
/span
>
{
start_amount
&&
<
button
className
=
'stop-expanding'
onClick
=
{
this
.
stopExpanding
.
bind
(
this
,
id
)}
>
立即结束膨胀
<
/button
>
}
<
/
>
)
break
}
}
bottom
=
(
<>
<
span
className
=
{
'limit'
}
>
全场通用
<
/span
>
{
start_amount
&&
<
button
className
=
'stop-expanding'
onClick
=
{
this
.
stopExpanding
.
bind
(
this
,
id
)}
>
立即结束膨胀
<
/button
>
}
<
/
>
return
(
<
BaseCoupon
{...
this
.
props
}
top
=
{
top
}
VOUCHER
=
{
this
.
VOUCHER
}
FREE
=
{
this
.
FREE
}
EXPAND
=
{
this
.
EXPAND
}
pick
=
{
this
.
pick
}
bottom
=
{
bottom
}
/
>
)
)
break
}
}
}
function
BaseCoupon
(
{
pick
,
ctype
,
invalid
,
top
,
VOUCHER
,
FREE
,
EXPAND
,
selectedCouponId
,
id
,
bottom
})
{
let
couponTypes
=
{
[
VOUCHER
]:
'代金券'
,
[
FREE
]:
'课程券'
,
[
EXPAND
]:
'膨胀券'
}
return
(
return
(
<
li
className
=
'coupon'
onClick
=
{
pick
}
>
<
BaseCoupon
<
div
className
=
{
classnames
(
'coupon-info'
,
invalid
?
'invalid'
:
`coupon-type
${
ctype
}
`
)}
>
{...
this
.
props
}
<
p
className
=
'type'
>
{
couponTypes
[
ctype
]}
<
/p
>
top
=
{
top
}
{
top
}
VOUCHER
=
{
this
.
VOUCHER
}
{
FREE
=
{
this
.
FREE
}
selectedCouponId
===
id
&&
EXPAND
=
{
this
.
EXPAND
}
<
i
className
=
{
classnames
(
'iconfont icondanseshixintubiao-5'
,
{
pick
=
{
this
.
pick
}
check
:
!
invalid
bottom
=
{
bottom
}
})}
/
>
/
>
}
<
ul
>
{
new
Array
(
19
).
fill
(
'a'
).
map
((
item
,
index
)
=>
{
return
<
li
key
=
{
index
}
/
>
})
}
<
/ul
>
<
/div
>
<
div
className
=
"coupon-des"
>
{
bottom
}
<
/div
>
<
/li
>
)
)
}
}
function
BaseCoupon
(
{
pick
,
ctype
,
invalid
,
top
,
VOUCHER
,
FREE
,
EXPAND
,
selectedCouponId
,
id
,
bottom
})
{
let
couponTypes
=
{
[
VOUCHER
]:
'代金券'
,
[
FREE
]:
'课程券'
,
[
EXPAND
]:
'膨胀券'
}
return
(
<
li
className
=
'coupon'
onClick
=
{
pick
}
>
<
div
className
=
{
classnames
(
'coupon-info'
,
invalid
?
'invalid'
:
`coupon-type
${
ctype
}
`
)}
>
<
p
className
=
'type'
>
{
couponTypes
[
ctype
]}
<
/p
>
{
top
}
{
selectedCouponId
===
id
&&
<
i
className
=
{
classnames
(
'iconfont icondanseshixintubiao-5'
,
{
check
:
!
invalid
})}
/
>
}
<
ul
>
{
new
Array
(
19
).
fill
(
'a'
).
map
((
item
,
index
)
=>
{
return
<
li
key
=
{
index
}
/
>
})
}
<
/ul
>
<
/div
>
<
div
className
=
"coupon-des"
>
{
bottom
}
<
/div
>
<
/li
>
)
}
}
export
default
Coupon
export
default
withRouter
(
Coupon
)
src/components/coupons/myCoupons/index.js
View file @
5fd2370c
...
@@ -6,389 +6,389 @@ import Coupon from '../Coupon'
...
@@ -6,389 +6,389 @@ import Coupon from '../Coupon'
import
{
http
,
getParam
}
from
'@/utils'
import
{
http
,
getParam
}
from
'@/utils'
import
{
WithFullSize
}
from
'@/HOCs'
import
{
WithFullSize
}
from
'@/HOCs'
import
{
Toast
}
from
'antd-mobile'
import
{
Toast
}
from
'antd-mobile'
import
{
isEmpty
}
from
'lodash'
import
{
connect
}
from
'react-redux'
import
{
connect
}
from
'react-redux'
@
connect
()
@
connect
()
class
UseCoupon
extends
PureComponent
{
class
UseCoupon
extends
PureComponent
{
state
=
{
state
=
{
selectedCouponId
:
0
,
selectedCouponId
:
0
,
redeemCode
:
''
,
redeemCode
:
''
,
couponList
:
[],
couponList
:
[],
valid_coupons
:
[],
valid_coupons
:
[],
invalid_coupons
:
[],
invalid_coupons
:
[],
courseId
:
getParam
(
'id'
),
courseId
:
getParam
(
'id'
),
showUseButton
:
false
,
showUseButton
:
false
,
courseCouponExchange
:
false
,
// 课程券兑换弹窗
courseCouponExchange
:
false
,
// 课程券兑换弹窗
courseCouponData
:
''
// 兑换课程信息
courseCouponData
:
''
// 兑换课程信息
}
componentDidMount
()
{
const
{
history
,
location
}
=
this
.
props
const
{
state
}
=
this
.
props
.
location
if
(
state
&&
state
.
from
)
{
if
(
state
.
from
===
'/my'
)
{
this
.
getMyCoupons
()
this
.
setState
({
showUseButton
:
true
})
}
else
{
if
(
!
this
.
state
.
courseId
)
{
location
.
state
&&
location
.
state
.
from
?
history
.
replace
(
location
.
state
.
from
)
:
history
.
goBack
()
}
this
.
getAllCoupons
()
}
}
}
}
handleChange
=
e
=>
{
let
value
=
e
?
e
.
target
.
value
:
''
this
.
setState
({
redeemCode
:
value
})
}
// 兑换
exchange
=
()
=>
{
const
{
location
:
{
state
=
{}}}
=
this
.
props
if
(
this
.
state
.
redeemCode
!==
''
)
{
http
.
post
(
`
${
API
.
home
}
/m/coupon/exchange`
,
{
code
:
this
.
state
.
redeemCode
,
type
:
state
.
from
.
substr
(
1
)
})
.
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
code
===
200
)
{
// 如果从我的页面进来,点击兑换直接兑换成功课程,弹出弹窗
// 如果从订单页面进来,点击兑换兑换成券
const
coupon
=
data
.
data
componentDidMount
()
{
const
{
history
,
location
}
=
this
.
props
const
{
state
}
=
this
.
props
.
location
if
(
state
&&
state
.
from
)
{
if
(
state
.
from
===
'/my'
)
{
if
(
state
.
from
===
'/my'
)
{
this
.
getMyCoupons
()
if
(
coupon
[
'ctype'
]
==
2
)
{
this
.
setState
({
this
.
setState
({
showUseButton
:
true
courseCouponData
:
coupon
,
courseCouponExchange
:
true
,
redeemCode
:
''
})
})
}
else
{
}
else
{
if
(
!
this
.
state
.
courseId
)
{
this
.
setState
({
location
.
state
&&
location
.
state
.
from
?
history
.
replace
(
location
.
state
.
from
)
:
history
.
goBack
()
couponList
:
[...
this
.
state
.
couponList
,
coupon
],
}
redeemCode
:
''
this
.
getAllCoupons
()
}
}
}
handleChange
=
e
=>
{
let
value
=
e
?
e
.
target
.
value
:
''
this
.
setState
({
redeemCode
:
value
})
}
// 兑换
exchange
=
()
=>
{
const
{
location
:
{
state
=
{}}}
=
this
.
props
if
(
this
.
state
.
redeemCode
!==
''
)
{
http
.
post
(
`
${
API
.
home
}
/m/coupon/exchange`
,
{
code
:
this
.
state
.
redeemCode
,
type
:
state
.
from
.
substr
(
1
)
})
.
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
code
===
200
)
{
// 如果从我的页面进来,点击兑换直接兑换成功课程,弹出弹窗
// 如果从订单页面进来,点击兑换兑换成券
const
coupon
=
data
.
data
if
(
state
.
from
===
'/my'
)
{
if
(
coupon
[
'ctype'
]
==
2
)
{
this
.
setState
({
courseCouponData
:
coupon
,
courseCouponExchange
:
true
,
redeemCode
:
''
})
}
else
{
this
.
setState
({
couponList
:
[...
this
.
state
.
couponList
,
coupon
],
redeemCode
:
''
})
Toast
.
info
(
'兑换成功'
)
this
.
getMyCoupons
()
}
}
if
(
state
.
from
===
'/order'
)
{
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
({
valid_coupons
:
[...
this
.
state
.
valid_coupons
,
coupon
],
redeemCode
:
''
})
}
Toast
.
info
(
'兑换成功'
)
this
.
getAllCoupons
()
}
}
else
{
Toast
.
info
(
data
.
msg
)
}
})
})
}
else
{
Toast
.
info
(
'兑换成功'
)
Toast
.
info
(
'请输入兑换码'
)
this
.
getMyCoupons
()
}
}
}
getMyCoupons
=
()
=>
{
Promise
.
all
([
http
.
get
(
`
${
API
.
home
}
/m/coupon/all`
),
http
.
get
(
`
${
API
.
home
}
/m/coupon/expansion`
)
]).
then
((
coupons
)
=>
{
let
myCoupons
=
[]
const
[
allCoupons
,
expansionCoupons
]
=
coupons
const
{
data
:
all
}
=
allCoupons
const
{
data
:
expansion
}
=
expansionCoupons
if
(
all
.
code
==
200
)
{
Array
.
isArray
(
all
.
data
)
&&
(
myCoupons
=
myCoupons
.
concat
(
all
.
data
))
}
else
{
Toast
.
info
(
all
.
msg
)
}
if
(
expansion
.
code
==
200
)
{
Array
.
isArray
(
expansion
.
data
)
&&
(
expansion
.
data
=
expansion
.
data
.
map
(
item
=>
(
item
.
ctype
=
4
,
item
)))
&&
(
myCoupons
=
myCoupons
.
concat
(
expansion
.
data
))
}
else
{
Toast
.
info
(
expansion
.
msg
)
}
}
if
(
state
.
from
===
'/order'
)
{
const
coupon
=
data
.
data
this
.
setState
({
if
(
coupon
[
'ctype'
]
==
2
couponList
:
myCoupons
&&
coupon
[
'limit_course'
]
!=
this
.
state
.
courseId
)
{
})
})
}
getAllCoupons
=
()
=>
{
Promise
.
all
([
http
.
post
(
`
${
API
.
home
}
/m/coupon/select`
,
{
course_id
:
this
.
state
.
courseId
}),
http
.
get
(
`
${
API
.
home
}
/m/coupon/expansion`
)
]).
then
((
coupons
)
=>
{
const
[
selectCoupons
,
expansionCoupons
]
=
coupons
const
{
data
:
select
}
=
selectCoupons
const
{
data
:
expansion
}
=
expansionCoupons
if
(
select
.
code
===
200
)
{
const
inuse_coupon
=
select
.
data
[
'inuse_coupon'
]
this
.
setState
({
this
.
setState
({
valid_coupons
:
inuse_coupon
invalid_coupons
:
[...
this
.
state
.
invalid_coupons
,
coupon
],
?
[...
inuse_coupon
,
...
select
.
data
.
valid_coupons
]
showUseButton
:
null
,
:
select
.
data
.
valid_coupons
,
redeemCode
:
''
invalid_coupons
:
select
.
data
.
invalid_coupons
,
selectedCouponId
:
inuse_coupon
.
length
?
inuse_coupon
[
0
].
id
:
0
})
})
}
else
{
}
else
{
Toast
.
info
(
data
.
msg
)
}
if
(
expansion
.
code
==
200
)
{
Array
.
isArray
(
expansion
.
data
)
&&
(
expansion
.
data
=
expansion
.
data
.
map
(
item
=>
(
item
.
ctype
=
4
,
item
)))
&&
(
this
.
setState
({
valid_coupons
:
this
.
state
.
valid_coupons
.
concat
(
expansion
.
data
)
}))
}
else
{
Toast
.
info
(
expansion
.
msg
)
}
})
}
// 立即兑换课程
toExchangeCourse
=
(
e
,
code
)
=>
{
e
.
stopPropagation
()
http
.
post
(
`
${
API
[
'base-api'
]}
/pay/miandan/
${
code
}
`
,
{}).
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
errno
===
200
)
{
this
.
setState
({
this
.
setState
({
courseCouponExchange
:
true
,
valid_coupons
:
[...
this
.
state
.
valid_coupons
,
coupon
]
,
courseCouponData
:
res
.
data
.
data
redeemCode
:
''
})
})
this
.
getMyCoupons
()
}
}
else
{
Toast
.
info
(
'兑换成功'
)
Toast
.
info
(
data
.
msg
)
this
.
getAllCoupons
(
)
}
}
}
else
{
Toast
.
info
(
data
.
msg
)
}
})
})
}
else
{
Toast
.
info
(
'请输入兑换码'
)
}
}
}
getMyCoupons
=
()
=>
{
Promise
.
all
([
http
.
get
(
`
${
API
.
home
}
/m/coupon/all`
),
http
.
get
(
`
${
API
.
home
}
/m/coupon/expansion`
)
]).
then
((
coupons
)
=>
{
let
myCoupons
=
[]
const
[
allCoupons
,
expansionCoupons
]
=
coupons
const
{
data
:
all
}
=
allCoupons
const
{
data
:
expansion
}
=
expansionCoupons
if
(
all
.
code
==
200
)
{
Array
.
isArray
(
all
.
data
)
&&
(
myCoupons
=
myCoupons
.
concat
(
all
.
data
))
}
else
{
Toast
.
info
(
all
.
msg
)
}
if
(
expansion
.
code
==
200
)
{
Array
.
isArray
(
expansion
.
data
)
&&
(
expansion
.
data
=
expansion
.
data
.
map
(
item
=>
(
item
.
ctype
=
4
,
item
)))
&&
(
myCoupons
=
myCoupons
.
concat
(
expansion
.
data
))
}
else
{
Toast
.
info
(
expansion
.
msg
)
}
this
.
setState
({
couponList
:
myCoupons
})
})
}
getAllCoupons
=
()
=>
{
Promise
.
all
([
http
.
post
(
`
${
API
.
home
}
/m/coupon/select`
,
{
course_id
:
this
.
state
.
courseId
}),
http
.
get
(
`
${
API
.
home
}
/m/coupon/expansion`
)
]).
then
((
coupons
)
=>
{
const
[
selectCoupons
,
expansionCoupons
]
=
coupons
const
{
data
:
select
}
=
selectCoupons
const
{
data
:
expansion
}
=
expansionCoupons
if
(
select
.
code
===
200
)
{
const
inuse_coupon
=
select
.
data
[
'inuse_coupon'
]
this
.
setState
({
valid_coupons
:
inuse_coupon
?
[...
inuse_coupon
,
...
select
.
data
.
valid_coupons
]
:
select
.
data
.
valid_coupons
,
invalid_coupons
:
select
.
data
.
invalid_coupons
,
selectedCouponId
:
inuse_coupon
.
length
?
inuse_coupon
[
0
].
id
:
0
})
useCoupon
=
val
=>
{
}
else
{
const
{
history
}
=
this
.
props
Toast
.
info
(
data
.
msg
)
const
coupon
=
this
.
state
.
couponList
.
find
(
item
=>
item
.
id
===
val
)
}
if
(
expansion
.
code
==
200
)
{
if
(
val
)
{
Array
.
isArray
(
expansion
.
data
)
if
(
this
.
state
.
showUseButton
)
{
&&
(
expansion
.
data
=
expansion
.
data
.
map
(
item
=>
(
item
.
ctype
=
4
,
item
)))
&&
(
this
.
setState
({
if
(
coupon
[
'limit_course'
]
===
0
)
{
valid_coupons
:
this
.
state
.
valid_coupons
.
concat
(
expansion
.
data
)
history
.
push
(
`/classify`
)
}))
}
else
{
}
else
{
history
.
push
(
`/detail?id=
${
coupon
[
'limit_course'
]}
`
)
Toast
.
info
(
expansion
.
msg
)
return
false
}
}
}
else
{
})
}
const
{
courseId
,
selectedCouponId
}
=
this
.
state
// 立即兑换课程
if
(
selectedCouponId
===
val
)
{
toExchangeCourse
=
(
e
,
code
)
=>
{
e
.
stopPropagation
()
http
.
post
(
`
${
API
[
'base-api'
]}
/pay/miandan/
${
code
}
`
,
{}).
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
errno
===
200
)
{
this
.
setState
({
courseCouponExchange
:
true
,
courseCouponData
:
res
.
data
.
data
})
this
.
getMyCoupons
()
}
else
{
Toast
.
info
(
data
.
msg
)
}
})
}
useCoupon
=
val
=>
{
const
{
history
}
=
this
.
props
const
coupon
=
this
.
state
.
couponList
.
find
(
item
=>
item
.
id
===
val
)
if
(
val
)
{
if
(
this
.
state
.
showUseButton
)
{
if
(
coupon
[
'limit_course'
]
===
0
)
{
history
.
push
(
`/classify`
)
}
else
{
history
.
push
(
`/detail?id=
${
coupon
[
'limit_course'
]}
`
)
return
false
}
}
else
{
http
.
post
(
`
${
API
.
home
}
/m/coupon/cancel`
,
{
const
{
courseId
,
selectedCouponId
}
=
this
.
state
course_id
:
courseId
}).
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
code
===
200
)
{
if
(
selectedCouponId
===
val
)
{
this
.
setState
({
selectedCouponId
:
0
})
http
.
post
(
`
${
API
.
home
}
/m/coupon/cancel`
,
{
course_id
:
courseId
}).
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
code
===
200
)
{
}
else
{
Toast
.
info
(
data
.
msg
)
}
})
this
.
setState
({
selectedCouponId
:
0
})
}
else
{
http
.
post
(
`
${
API
.
home
}
/m/coupon/use`
,
{
course_id
:
this
.
state
.
courseId
,
coupon_id
:
val
})
.
then
(
res
=>
{
const
data
=
res
&&
res
.
data
if
(
data
.
code
===
200
)
{
this
.
setState
({
selectedCouponId
:
val
})
}
else
{
this
.
props
.
history
.
goBack
()
Toast
.
info
(
data
.
msg
)
}
})
}
else
{
}
else
{
Toast
.
info
(
data
.
msg
)
http
.
post
(
`
${
API
.
home
}
/m/coupon/use`
,
{
}
course_id
:
this
.
state
.
courseId
,
})
coupon_id
:
val
})
.
then
(
res
=>
{
const
data
=
res
&&
res
.
data
if
(
data
.
code
===
200
)
{
}
this
.
setState
({
selectedCouponId
:
val
})
this
.
props
.
history
.
goBack
()
}
}
else
{
Toast
.
info
(
data
.
msg
)
}
})
}
else
{
Toast
.
info
(
'未知错误'
)
location
.
reload
()
}
}
}
// 开始学习
}
toStudy
=
(
vCourseId
,
isHaveVideo
)
=>
{
const
{
history
}
=
this
.
props
if
(
isHaveVideo
==
0
)
{
Toast
.
info
(
'尚未开课,开课后立即上传课程~'
,
2
)
}
else
{
history
.
push
(
`/play/video?id=
${
vCourseId
}
`
)
}
this
.
setState
({
courseCouponExchange
:
false
})
}
// 关闭弹窗
}
else
{
closeFreeCourse
=
()
=>
{
Toast
.
info
(
'未知错误'
)
this
.
setState
({
location
.
reload
()
courseCouponExchange
:
false
})
}
}
endExpansion
=
id
=>
{
}
this
.
setState
({
couponList
:
this
.
state
.
couponList
.
map
(
item
=>
{
// 开始学习
if
(
item
.
id
===
id
)
{
toStudy
=
(
vCourseId
,
isHaveVideo
)
=>
{
delete
item
.
start_amount
const
{
history
}
=
this
.
props
}
if
(
isHaveVideo
==
0
)
{
return
item
Toast
.
info
(
'尚未开课,开课后立即上传课程~'
,
2
)
})
}
else
{
}
)
history
.
push
(
`/play/video?id=
${
vCourseId
}
`
)
}
}
this
.
setState
({
courseCouponExchange
:
false
})
}
// 关闭弹窗
closeFreeCourse
=
()
=>
{
this
.
setState
({
courseCouponExchange
:
false
})
}
endExpansion
=
(
id
,
validId
)
=>
{
this
.
setState
({
valid_coupons
:
this
.
state
.
valid_coupons
.
map
(
item
=>
{
if
(
item
.
id
===
id
)
{
delete
item
.
start_amount
item
.
id
=
validId
}
return
item
})
})
}
render
()
{
render
()
{
const
{
state
}
=
this
.
props
.
location
const
{
state
}
=
this
.
props
.
location
const
{
showUseButton
,
selectedCouponId
}
=
this
.
state
const
{
showUseButton
,
selectedCouponId
}
=
this
.
state
return
(
return
(
<
div
className
=
'use-coupon'
>
<
div
className
=
'use-coupon'
>
<
RedeemBar
onChange
=
{
this
.
handleChange
}
<
RedeemBar
onChange
=
{
this
.
handleChange
}
exchange
=
{
this
.
exchange
}
exchange
=
{
this
.
exchange
}
redeemCode
=
{
this
.
state
.
redeemCode
}
/
>
redeemCode
=
{
this
.
state
.
redeemCode
}
/
>
<
div
className
=
"coupons-area"
>
<
div
className
=
"coupons-area"
>
<
Content
<
Content
coupons
=
{
coupons
=
{
state
state
&&
state
.
from
&&
state
.
from
&&
state
.
from
===
'/my'
&&
state
.
from
===
'/my'
?
this
.
state
.
couponList
?
this
.
state
.
couponList
:
this
.
state
.
valid_coupons
:
this
.
state
.
valid_coupons
}
}
showUseButton
=
{
showUseButton
}
showUseButton
=
{
showUseButton
}
selectedCouponId
=
{
selectedCouponId
}
selectedCouponId
=
{
selectedCouponId
}
select
=
{
this
.
select
}
select
=
{
this
.
select
}
useCoupon
=
{
this
.
useCoupon
}
useCoupon
=
{
this
.
useCoupon
}
toExchangeCourse
=
{
this
.
toExchangeCourse
}
toExchangeCourse
=
{
this
.
toExchangeCourse
}
endExpansion
=
{
this
.
endExpansion
}
endExpansion
=
{
this
.
endExpansion
}
/
>
/
>
{
{
this
.
state
.
invalid_coupons
.
length
>
0
&&
this
.
state
.
invalid_coupons
.
length
>
0
&&
(
(
<>
<>
<
div
className
=
'invalid-title'
>-
不可使用的优惠券
-<
/div
>
<
div
className
=
'invalid-title'
>-
不可使用的优惠券
-<
/div
>
<
Content
<
Content
coupons
=
{
this
.
state
.
invalid_coupons
}
coupons
=
{
this
.
state
.
invalid_coupons
}
selectedCouponId
=
{
selectedCouponId
}
selectedCouponId
=
{
selectedCouponId
}
select
=
{
this
.
select
}
select
=
{
this
.
select
}
purpose
=
{
'use'
}
purpose
=
{
'use'
}
invalid
=
{
'invalid'
}
invalid
=
{
'invalid'
}
/
>
/
>
<
/
>
<
/
>
)
)
}
}
<
/div
>
<
/div
>
{
{
this
.
state
.
courseCouponExchange
&&
this
.
state
.
courseCouponExchange
&&
<
FreeCouponCourse
toStudy
=
{
this
.
toStudy
}
closeFreeCourse
=
{
this
.
closeFreeCourse
}
<
FreeCouponCourse
toStudy
=
{
this
.
toStudy
}
closeFreeCourse
=
{
this
.
closeFreeCourse
}
courseCouponData
=
{
this
.
state
.
courseCouponData
}
/
>
courseCouponData
=
{
this
.
state
.
courseCouponData
}
/
>
}
}
<
/div
>
<
/div
>
)
)
}
}
}
}
function
Content
({
coupons
,
...
rest
})
{
function
Content
({
coupons
,
...
rest
})
{
if
(
coupons
.
length
===
0
)
{
if
(
coupons
.
length
===
0
)
{
return
(
<
div
className
=
'empty'
>
<
p
>
暂无可使用的优惠券
<
/p
>
<
/div
>
)
}
return
(
return
(
<
ul
>
<
div
className
=
'empty'
>
{
<
p
>
暂无可使用的优惠券
<
/p
>
coupons
.
map
(
item
=>
{
<
/div
>
return
(
<
Coupon
key
=
{
item
.
id
}
{...
item
}
id
=
{
item
.
id
}
{...
rest
}
/
>
)
})
}
<
/ul
>
)
)
}
return
(
<
ul
>
{
coupons
.
map
(
item
=>
{
return
(
<
Coupon
key
=
{
item
.
id
}
{...
item
}
id
=
{
item
.
id
}
{...
rest
}
/
>
)
})
}
<
/ul
>
)
}
}
function
FreeCouponCourse
(
props
)
{
function
FreeCouponCourse
(
props
)
{
const
{
toStudy
,
closeFreeCourse
,
courseCouponData
}
=
props
const
{
toStudy
,
closeFreeCourse
,
courseCouponData
}
=
props
return
(
return
(
<
div
className
=
"free-coupon-box"
>
<
div
className
=
"free-coupon-box"
>
<
div
className
=
"free-coupon-content"
>
<
div
className
=
"free-coupon-content"
>
<
div
className
=
"coures-content-success"
><
i
className
=
{
'iconfont icondanseshixintubiao-5'
}
/></
div
>
<
div
className
=
"coures-content-success"
><
i
className
=
{
'iconfont icondanseshixintubiao-5'
}
/></
div
>
<
div
className
=
"coures-content-title"
>
恭喜你课程兑换成功
!
赶快去学习吧
~<
/div
>
<
div
className
=
"coures-content-title"
>
恭喜你课程兑换成功
!
赶快去学习吧
~<
/div
>
<
img
className
=
"coures-content-img"
src
=
{
courseCouponData
.
image_name
}
alt
=
""
/>
<
img
className
=
"coures-content-img"
src
=
{
courseCouponData
.
image_name
}
alt
=
""
/>
{
{
courseCouponData
.
course_expire
!=
0
&&
courseCouponData
.
course_expire
!=
0
&&
<
div
className
=
"coures-content-tip"
><
i
<
div
className
=
"coures-content-tip"
><
i
className
=
{
'iconfont icondanseshixintubiao-8'
}
/><span>课程有效期:自今日起{courseCouponData.course_expire}天内,请在有效期内学习该课程哦~</
span
>
className
=
{
'iconfont icondanseshixintubiao-8'
}
/><span>课程有效期:自今日起{courseCouponData.course_expire}天内,请在有效期内学习该课程哦~</
span
>
<
/div
>
<
/div
>
}
}
<
a
className
=
'toStudy'
<
a
className
=
'toStudy'
onClick
=
{()
=>
toStudy
(
courseCouponData
.
v_course_id
,
courseCouponData
.
is_is_start
)}
>
去学习
<
/a
>
onClick
=
{()
=>
toStudy
(
courseCouponData
.
v_course_id
,
courseCouponData
.
is_is_start
)}
>
去学习
<
/a
>
<
/div
>
<
/div
>
<
div
className
=
"free-coupon-close"
>
<
div
className
=
"free-coupon-close"
>
<
i
className
=
{
'iconfont iconiconfront-2'
}
onClick
=
{()
=>
closeFreeCourse
()}
/
>
<
i
className
=
{
'iconfont iconiconfront-2'
}
onClick
=
{()
=>
closeFreeCourse
()}
/
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
)
)
}
}
export
default
WithFullSize
(
UseCoupon
)
export
default
WithFullSize
(
UseCoupon
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment