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
98181fab
Commit
98181fab
authored
Aug 17, 2019
by
FE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
solve quesiont that reload when click btn of add cart
parent
8395e193
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
25 deletions
+52
-25
src/components/detail/actions.js
+8
-0
src/components/detail/btnstatus/index.js
+5
-5
src/components/detail/index.js
+18
-5
src/components/detail/reducers.js
+7
-1
src/components/order/index.js
+14
-14
No files found.
src/components/detail/actions.js
View file @
98181fab
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
...
...
src/components/detail/btnstatus/index.js
View file @
98181fab
...
...
@@ -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
);
}
...
...
src/components/detail/index.js
View file @
98181fab
...
...
@@ -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,7 @@ class Detail extends Component {
}
componentDidMount
()
{
this
.
props
.
fetchCoursesListIfNeeded
();
this
.
props
.
getCourses
();
}
// 点击子组件试听按钮
...
...
@@ -273,6 +273,7 @@ class Detail extends Component {
barInfo
=
{
this
.
state
.
barInfo
}
getBargainInfo
=
{
this
.
getBargainInfo
}
invitedFriends
=
{
this
.
invitedFriends
}
addCourseToCart
=
{
this
.
props
.
addCourseToCart
}
history
=
{
this
.
props
.
history
}
><
/BtnStatus
>
{
...
...
@@ -306,7 +307,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
src/components/detail/reducers.js
View file @
98181fab
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
}
...
...
src/components/order/index.js
View file @
98181fab
...
...
@@ -279,20 +279,20 @@ class Order extends Component {
this
.
publicLocalStorage
();
});
}
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
;
}
//
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
(
preorder
);
this
.
publicLocalStorage
();
})
}
else
{
//
this.publicGetData(preorder);
//
this.publicLocalStorage();
//
})
//
}else{
http
.
get
(
`
${
API
[
'base-api'
]}
/m/order/preorder`
).
then
((
res
)
=>
{
console
.
log
(
'为了验证什么条件下会走这段代码'
);
if
(
res
.
data
.
errno
!==
200
)
{
...
...
@@ -303,7 +303,7 @@ class Order extends Component {
this
.
publicGetData
(
res
);
this
.
publicLocalStorage
();
})
}
//
}
}
};
render
()
{
...
...
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