Commit 5fcc8bf1 by xuzhenghua

717-邀请好友组队答题

parent 307f4f0f
......@@ -117,6 +117,12 @@ class Invitation extends Component {
})
}
// 答题抽奖
drawQuestions=()=>{
const {history,user} = this.props
history.push(`/anniversary_2020/question/${user.data.uid}`)
}
render() {
const {prizes, invitationInfo, isShowGuide, teamInfo, isMaster, isActivityEnd} = this.state
const {location} = this.props
......@@ -186,7 +192,7 @@ class Invitation extends Component {
? <button className={'activity-end'}>活动结束</button>
: teamInfo.status === 1
? <button className={'btn'} onClick={this.joinTeam}>加入队伍</button>
: <button className={'btn'}>答题抽奖</button>
: <button className={'btn'} onClick={this.drawQuestions}>答题抽奖</button>
}
</>
}
......
import React, { Component } from 'react';
import React, {Component} from 'react'
import './index.scss'
import { Toast } from "antd-mobile";
import {Toast} from "antd-mobile"
import classnames from 'classnames'
import { browser, http } from "@/utils"
import { WithFullSize } from "@/HOCs"
import { Link } from "react-router-dom";
import { compose } from 'redux'
import { connect } from 'react-redux'
import { addData, ADD_RECOMMENDS, ADD_QUESTION, ADD_RESULT, REDO } from './store/reducer'
import {browser, http} from "@/utils"
import {WithFullSize} from "@/HOCs"
import {Link} from "react-router-dom"
import {compose} from 'redux'
import {connect} from 'react-redux'
import {addData, ADD_RECOMMENDS, ADD_QUESTION, ADD_RESULT, REDO} from './store/reducer'
class Question extends Component {
state = {
question: {},
result: {},
recommends: [],
selectedOptionId: 0,
isShowConfirm: false,
isTeamHead: this.props.match.params.assistId === undefined,
isActivityEnd: false,
}
componentDidMount() {
const {history, user} = this.props
if (user.hasError) {
if (browser.isWeixin) {
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=" + encodeURIComponent(url + "&aa=bb").toLowerCase() + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
} else {
history.push('/passport')
}
return
state = {
question: {},
result: {},
recommends: [],
selectedOptionId: 0,
isShowConfirm: false,
isResultConfirm: false,
isTeamHead: this.props.match.params.assistId === undefined,
isActivityEnd: false,
is_correct: '',
is_sign: '',
}
if (this.props.cache.recommends.length === 0) {
this.getQuestion()
}
}
componentDidMount() {
const {history, user} = this.props
if (user.hasError) {
if (browser.isWeixin) {
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=" + encodeURIComponent(url + "&aa=bb").toLowerCase() + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
} else {
history.push('/passport')
}
return
}
getQuestion = () => {
const assistId = this.props.match.params.assistId
http.get(`${API.home}/activity/anniversary/get_question/${assistId ? 2 : 1}/${assistId ? assistId : 0}`)
.then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.props.addData({
type: ADD_QUESTION,
payload: data,
})
} else {
Toast.info(msg)
if (this.props.cache.recommends.length === 0) {
this.getQuestion()
}
})
}
}
select = (id) => {
this.setState({
selectedOptionId: id,
});
}
getQuestion = () => {
const assistId = this.props.match.params.assistId
http.get(`${API.home}/activity/anniversary/get_question/${assistId ? 2 : 1}/${assistId ? assistId : 0}`)
.then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.props.addData({
type: ADD_QUESTION,
payload: data,
})
} else {
Toast.info(msg)
}
})
}
submit = () => {
const assistId = this.props.match.params.assistId
const {selectedOptionId} = this.state
http.post(`${API.home}/activity/anniversary/submit`, {
type: assistId ? 2 : 1,
option_id: selectedOptionId,
id: this.props.cache.question.id,
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.getRecommends(data.type_id)
this.afterSubmitted(data)
select = (id) => {
this.setState({
isShowConfirm: false,
selectedOptionId: undefined,
});
this.props.addData({
payload: data,
type: ADD_RESULT,
selectedOptionId: id,
})
} else {
Toast.info(msg)
}
})
}
}
afterSubmitted = (result) => {
const {isTeamHead} = this.state
submit = () => {
const assistId = this.props.match.params.assistId
const {selectedOptionId} = this.state
http.post(`${API.home}/activity/anniversary/submit`, {
type: assistId ? 2 : 1,
option_id: selectedOptionId,
id: this.props.cache.question.id,
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.getRecommends(data.type_id)
this.afterSubmitted(data)
this.setState({
isShowConfirm: false,
isResultConfirm: true,
selectedOptionId: undefined,
is_correct: data.is_correct,
is_sign: data.is_sign
})
this.props.addData({
payload: data,
type: ADD_RESULT,
})
} else {
Toast.info(msg)
}
})
}
if (isTeamHead) {
if (result.stage === 4) {
resultFun = () => {
const {history} = this.props
if (this.state.is_sign) {
history.push('/anniversary_2020')
} else {
http.get(`${API.home}/activity/anniversary/sign`)
.then(res => {
const {code, msg} = res.data
if (code === 200) {
Toast.info('签到成功 抽奖次数+1')
history.push('/anniversary_2020')
} else {
Toast.info(msg)
}
})
}
}
} else {
result.is_correct ? Toast.info('回答正确 抽奖次数+1') : Toast.info('很遗憾 回答错误')
}
} else {
afterSubmitted = (result) => {
const {isTeamHead} = this.state
}
}
if (isTeamHead) {
if (result.stage === 4) {
getRecommends = typeId => {
http.post(`${API.home}/sys/get_commend_course`, {
type_id: typeId,
})
.then(res => {
const {code, data} = res.data
if (code === 200) {
this.props.addData({
payload: data,
type: ADD_RECOMMENDS,
})
} else {
result.is_correct ? Toast.info('回答正确 抽奖次数+1') : Toast.info('很遗憾 回答错误')
}
} else {
}
})
}
}
getOptionLabel = (index) => {
return String.fromCharCode(65 + index)
}
getRecommends = typeId => {
http.post(`${API.home}/sys/get_commend_course`, {
type_id: typeId,
})
.then(res => {
const {code, data} = res.data
if (code === 200) {
this.props.addData({
payload: data,
type: ADD_RECOMMENDS,
})
redo = () => {
this.props.addData({
type: REDO,
})
this.getQuestion()
}
}
})
}
render() {
const {
selectedOptionId,
isShowConfirm,
isActivityEnd,
isTeamHead,
} = this.state
getOptionLabel = (index) => {
return String.fromCharCode(65 + index)
}
const {
cache: {
question,
result,
recommends,
},
} = this.props
redo = () => {
this.props.addData({
type: REDO,
})
this.getQuestion()
}
render() {
const {
selectedOptionId,
isShowConfirm,
isActivityEnd,
isResultConfirm,
isTeamHead,
} = this.state
return (
<div id={'question'}>
<div className="banner"></div>
<div className={'question'}>
{question.ques && <div className="topic" dangerouslySetInnerHTML={{__html: question.ques}}></div>}
<ul>
{
question.options && !!question.options.length && question.options.map((item, index) => {
return <li key={item.id} className={classnames({
selected: selectedOptionId === item.id,
correct: result.right_id === item.id,
wrong: !result.is_correct && parseInt(result.option_id) === item.id,
})} onClick={this.select.bind(this, item.id)}>
<span>{this.getOptionLabel(index)}</span>
{item.des}
</li>
})
}
</ul>
</div>
{
result.analysis && <div className="answered">
<div className="analysis">
<div className="estimate">
您选择的是{this.getOptionLabel(question.options.findIndex(item => item.id == result.option_id))},正确答案是{this.getOptionLabel(question.options.findIndex(item => item.id === result.right_id))} 回答{result.right_id == result.option_id ? '正确' : '错误 '}
</div>
<div className="analysis-content">
<div className="title">
<i className={'icon'}></i>
解析
const {
cache: {
question,
result,
recommends,
},
} = this.props
return (
<div id={'question'}>
<div className="banner"></div>
<div className={'question'}>
{question.ques && <div className="topic" dangerouslySetInnerHTML={{__html: question.ques}}></div>}
<ul>
{
question.options && !!question.options.length && question.options.map((item, index) => {
return <li key={item.id} className={classnames({
selected: selectedOptionId === item.id,
correct: result.right_id === item.id,
wrong: !result.is_correct && parseInt(result.option_id) === item.id,
})} onClick={this.select.bind(this, item.id)}>
<span>{this.getOptionLabel(index)}</span>
{item.des}
</li>
})
}
</ul>
</div>
<div className="content" dangerouslySetInnerHTML={{__html: result.analysis}}></div>
</div>
{
result.analysis && <div className="answered">
<div className="analysis">
<div className="estimate">
您选择的是{this.getOptionLabel(question.options.findIndex(item => item.id == result.option_id))},正确答案是{this.getOptionLabel(question.options.findIndex(item => item.id === result.right_id))} 回答{result.right_id == result.option_id ? '正确' : '错误 '}
</div>
<div className="analysis-content">
<div className="title">
<i className={'icon'}></i>
解析
</div>
<div className="content" dangerouslySetInnerHTML={{__html: result.analysis}}></div>
</div>
</div>
{
!!recommends.length && <Recommends recommends={recommends}></Recommends>
}
</div>
}
<div className="submit-bar">
<BottomButton result={result}
resultFun={this.resultFun}
isTeamHead={isTeamHead}
submit={() => {
if (this.state.selectedOptionId) {
this.setState({
isShowConfirm: true,
})
}
}}
redo={this.redo}
/>
</div>
{
isShowConfirm &&
<Confirm submit={this.submit} cancel={() => {
this.setState({
isShowConfirm: false,
})
}}></Confirm>
}
{
isResultConfirm &&
<ResultConfirm resultFun={this.resultFun} is_correct={this.state.is_correct}
is_sign={this.state.is_sign}></ResultConfirm>
}
</div>
)
}
}
function ResultConfirm({resultFun, is_correct, is_sign}) {
return <div className="modal-cover">
<div className="modal">
{
!!recommends.length && <Recommends recommends={recommends}></Recommends>
is_correct === 1 &&
<div className="title">回答正确,抽奖次数+1</div>
}
</div>
}
<div className="submit-bar">
<BottomButton result={result}
isTeamHead={isTeamHead}
submit={() => {
if (this.state.selectedOptionId) {
this.setState({
isShowConfirm: true,
});
}
}}
redo={this.redo}
/>
{
is_correct === 0 &&
<div className="rusult-title">很遗憾,回答错误 <p>快去抽奖提提神吧</p></div>
}
<div className={'btm-button'}>
<button onClick={resultFun}>{is_sign ? '去抽奖' : '签到领取抽奖机会'}</button>
</div>
</div>
{
isShowConfirm &&
<Confirm submit={this.submit} cancel={() => {
this.setState({
isShowConfirm: false,
});
}}></Confirm>
}
</div>
);
}
</div>
}
function Confirm({submit, cancel}) {
return <div className="modal-cover">
<div className="modal">
<div className="title">提交确认</div>
<div className="btns">
<button onClick={cancel}>取消</button>
<button onClick={submit}>确认提交</button>
</div>
return <div className="modal-cover">
<div className="modal">
<div className="title">提交确认</div>
<div className="btns">
<button onClick={cancel}>取消</button>
<button onClick={submit}>确认提交</button>
</div>
</div>
</div>
</div>
}
function Result() {
return <div className={'modal-cover'}>
<div className="modal">
<div className="title"></div>
return <div className={'modal-cover'}>
<div className="modal">
<div className="title"></div>
</div>
</div>
</div>
}
function BottomButton({result, submit, isTeamHead, redo}) {
if (result.stage === 4) {
return <button className={'activity-end'}>活动已结束</button>
}
if (isTeamHead) {
if (result.analysis) {
return result.practiceNum === 0
? <button className={'lottery-related'}><Link to={`/anniversary_2020/invitation`}>组队答题抽奖</Link></button>
: <button className={'submit'} onClick={redo}>继续答题</button>
function BottomButton({resultFun, result, submit, isTeamHead, redo}) {
if (result.stage === 4) {
return <button className={'activity-end'}>活动已结束</button>
}
if (isTeamHead) {
if (result.analysis) {
return result.practiceNum === 0
? <button className={'lottery-related'}><Link to={`/anniversary_2020/invitation`}>组队答题抽奖</Link></button>
: <button className={'submit'} onClick={redo}>继续答题</button>
}
} else {
if (result.analysis) {
return !result.is_sign
? <button className={'lottery-related'} onClick={resultFun}>签到领取抽奖机会</button>
: <button className={'submit'} onClick={resultFun}>去抽奖</button>
}
return <button className={'submit'} onClick={submit}>提交</button>
}
}
return <button className={'submit'} onClick={submit}>提交</button>
}
function Recommends({recommends}) {
return <div className="recommends">
<div className="title">相关课程</div>
<ul>
{
recommends && !!recommends.length && recommends.map(item => {
return <li key={item.course_id}>
<Link to={`/detail?id=${item.course_id}`}>
<img src={item.image_name} alt=""/>
</Link>
</li>
})
}
</ul>
</div>
return <div className="recommends">
<div className="title">相关课程</div>
<ul>
{
recommends && !!recommends.length && recommends.map(item => {
return <li key={item.course_id}>
<Link to={`/detail?id=${item.course_id}`}>
<img src={item.image_name} alt=""/>
</Link>
</li>
})
}
</ul>
</div>
}
export default compose(
WithFullSize,
connect(
({anniversary2020Question, user}) => ({cache: anniversary2020Question, user}),
dispatch => ({
addData: data => dispatch(addData(data)),
}),
),
)(Question);
\ No newline at end of file
WithFullSize,
connect(
({anniversary2020Question, user}) => ({cache: anniversary2020Question, user}),
dispatch => ({
addData: data => dispatch(addData(data)),
}),
),
)(Question)
\ No newline at end of file
......@@ -204,6 +204,40 @@
color: #525C65;
}
.rusult-title {
text-align: center;
padding-top: 20px;
color: #525C65;
font-size: 18px;
font-weight: 500;
margin-bottom: 20px;
p {
margin-top: 10px;
color: #525C65;
font-size: 15px;
font-weight: 400;
}
}
.btm-button {
width: 100%;
margin: 0 0 20px 0;
text-align: center;
button {
min-width: 128px;
height: 33px;
background: rgba(250, 228, 77, 1);
border-radius: 4px;
border: none;
color: #2034F5;
font-size: 16px;
font-weight: 500;
padding: 0 17px;
}
}
.btns {
border-top: 1px solid #DDD;
height: 44px;
......
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