Commit d11521a4 by xuzhenghua

detail

parent 7d149ab1
......@@ -17,9 +17,25 @@ class BtnStatus extends Component {
group_status: 3,
in_cart: false,
countdown: 0,
barInfo: ''
}
}
componentDidMount() {
this.getBargainInfo()
}
// componentDidUpdate(prevProps) {
// let {courseInfo} = this.props
// let {courseInfo: prevCourseInfo} = prevProps
// if (courseInfo && courseInfo.is_bargain) {
// if (prevCourseInfo && courseInfo.is_bargain !== prevCourseInfo.is_bargain) {
// this.getBargainInfo()
// }
// }
// }
componentWillReceiveProps(nextProps) {
this.setState({
...nextProps.data.course_info,
......@@ -54,14 +70,20 @@ class BtnStatus extends Component {
}
// 直接购买
tobuy = () => {
if (this.props.barInfo.bargain_status === 2) {
this.toCart(2)
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) {
this.props.history.push('/passport/login')
} else {
// 取消砍价记录
this.setState({
isShowOverlay: true,
bargainStatus: 1,
})
if (this.state.barInfo.bargain_status === 2) {
this.toCart(2)
} else {
// 取消砍价记录
this.setState({
isShowOverlay: true,
bargainStatus: 1,
})
}
}
}
......@@ -91,15 +113,41 @@ class BtnStatus extends Component {
}
// 砍价接口
toKanjia = () => {
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) {
this.props.history.push('/passport/login')
} else {
let data = {
course_id: getParam('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()
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
//获取砍价信息
getBargainInfo = () => {
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) return
let data = {
course_id: getParam('id'),
type: 1, // 1 用户自己砍价 2 使用砍价神器 3 好友助力砍价 4 好友第二次助力
parent_uid: 0 // 被助力人id 【自己本人操作传0】
courseId: getParam('id')
}
http.post(`${api.home}/m/bargain/toBargain`, data).then((res) => {
http.post(`${api.home}/m/bargain/courseDetail`, data).then((res) => {
if (res.data.code === 200) {
// this.props.getBargainInfo()
document.location.reload()
this.setState({
barInfo: res.data.data
})
} else {
Toast.info(res.data.msg, 2)
}
......@@ -111,8 +159,10 @@ class BtnStatus extends Component {
if (this.props.data && this.props.data.course_info) {
info = this.props.data.course_info
}
let barInfo = this.props.barInfo && this.props.barInfo
const {countdown} = this.state;
const {user} = this.props
const uid = user && user.data && user.data.uid
return (
<div>
......@@ -196,15 +246,15 @@ class BtnStatus extends Component {
<span onClick={this.tobuy}>直接购买</span>
</button>
{
barInfo.bargain_status === 2 &&
(this.state.barInfo.bargain_status === 2 || !uid) &&
<button className='btn btn-s bg-E02E24' onClick={this.toKanjia}>
我要砍价
</button>
}
{
(barInfo.bargain_status === 0 || barInfo.bargain_status === 1) &&
(this.state.barInfo.bargain_status === 0 || this.state.barInfo.bargain_status === 1) && (uid) &&
<button className='btn btn-s bg-E02E24'>
<span>¥{barInfo.amount}</span>
<span>¥{this.state.barInfo.amount}</span>
<span onClick={e => this.toCart(2)}>去支付</span>
</button>
}
......@@ -256,6 +306,8 @@ function CancelBargain(props) {
}
export default connect(
null,
state => ({
user: state.user
}),
{getCourses}
)(BtnStatus)
......@@ -13,6 +13,7 @@ import {connect} from "react-redux"
import {fetchCoursesListIfNeeded} from "./actions"
import {api, getParam, http, browser} from "@/utils"
import {Toast} from 'antd-mobile'
import {compose} from "redux";
class Detail extends Component {
......@@ -35,29 +36,30 @@ class Detail extends Component {
this.props.fetchCoursesListIfNeeded();
}
componentDidUpdate(prevProps) {
let {courseInfo} = this.props
let {courseInfo: prevCourseInfo} = prevProps
if (courseInfo && courseInfo.is_bargain) {
if (prevCourseInfo && courseInfo.is_bargain !== prevCourseInfo.is_bargain) {
this.getBargainInfo()
}
}
}
// 点击子组件试听按钮
toAudition = () => {
this.setState(status => ({
auditionBox: true,
}));
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) {
this.props.history.push('/passport/login')
} else {
this.setState({
auditionBox: true,
})
}
}
// 点击子组件单集购买按钮
toSingleset = (item) => {
this.setState(status => ({
singleBox: true,
singMess: item
}));
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) {
this.props.history.push('/passport/login')
} else {
this.setState({
singleBox: true,
singMess: item
})
}
}
componentWillReceiveProps(nextProps) {
......@@ -138,22 +140,6 @@ class Detail extends Component {
}
}
//获取砍价信息
getBargainInfo = () => {
let data = {
courseId: getParam('id')
}
http.post(`${api.home}/m/bargain/courseDetail`, data).then((res) => {
if (res.data.code === 200) {
this.setState({
barInfo: res.data.data
})
} else {
Toast.info(res.data.msg, 2)
}
})
}
// 自组件传给父组件的boxHide
boxHide = (val) => {
......@@ -262,7 +248,6 @@ class Detail extends Component {
{/*课程按钮*/}
<BtnStatus countdown={countdown}
data={this.props.courseInfo}
barInfo={this.state.barInfo}
getBargainInfo={this.getBargainInfo}
invitedFriends={this.invitedFriends}
history={this.props.history}></BtnStatus>
......@@ -290,13 +275,12 @@ class Detail extends Component {
const mapStateToProps = (state) => {
return {
courseInfo: state.courseInfo
courseInfo: state.courseInfo,
user: state.user
}
}
const mapDispatchToProps = {
fetchCoursesListIfNeeded
}
export default connect(mapStateToProps, mapDispatchToProps)(Detail)
\ No newline at end of file
......@@ -38,6 +38,9 @@ class ShareRank extends Component {
// 获取分销码
getCode = () => {
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) return
let data = {
course_id: getParam('id')
}
......@@ -54,11 +57,17 @@ class ShareRank extends Component {
// 点击分销跳转到海报页
share = (info) => {
const courseId = getParam('id')
const dist_first = info.dist_first_level_ti
const uid = info.uid
const dist_code = this.state.code
this.props.history.push(`/shareposter?courseId=${courseId}&dist_first=${dist_first}&uid=${uid}&dist_code=${dist_code}`)
const {user} = this.props
const uid = user && user.data && user.data.uid
if (!uid) {
this.props.history.push('/passport/login')
} else {
const courseId = getParam('id')
const dist_first = info.dist_first_level_ti
const uid = info.uid
const dist_code = this.state.code
this.props.history.push(`/shareposter?courseId=${courseId}&dist_first=${dist_first}&uid=${uid}&dist_code=${dist_code}`)
}
}
......@@ -146,7 +155,10 @@ class ShareRank extends Component {
export default compose(
connect(
state => ({courseInfo: state}),
state => ({
courseInfo: state,
user: state.user
}),
null
),
withRouter
......
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