mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-11 03:46:48 +08:00
feat:增加投票模块提交查询及时间判断
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- 面包屑导航 -->
|
||||
<div class="debateTitle">【投票】{{ dataInfo?.voteName }}</div>
|
||||
<div class="debateTitle">【投票】{{ state.dataInfo?.voteName }}</div>
|
||||
<!-- 详细信息 -->
|
||||
<div class="detailinfo">
|
||||
<div class="detail">
|
||||
@@ -41,8 +41,8 @@
|
||||
<div class="item allbox1">
|
||||
<div class="item1" style="color: #089dff">
|
||||
{{
|
||||
dataInfo.numberOfInvolved || dataInfo.numberOfInvolved == 0
|
||||
? dataInfo.numberOfInvolved
|
||||
state.dataInfo.numberOfInvolved || state.dataInfo.numberOfInvolved == 0
|
||||
? state.dataInfo.numberOfInvolved
|
||||
: "-"
|
||||
}}
|
||||
</div>
|
||||
@@ -51,8 +51,8 @@
|
||||
<div class="item allbox2">
|
||||
<div class="item1" style="color: #387df7">
|
||||
{{
|
||||
dataInfo.votesTotal || dataInfo.votesTotal == 0
|
||||
? dataInfo.votesTotal
|
||||
state.dataInfo.votesTotal || state.dataInfo.votesTotal == 0
|
||||
? state.dataInfo.votesTotal
|
||||
: "-"
|
||||
}}
|
||||
</div>
|
||||
@@ -61,8 +61,8 @@
|
||||
<div class="item allbox3">
|
||||
<div class="item1" style="color: #00c6ff">
|
||||
{{
|
||||
dataInfo.numberOfBrowse || dataInfo.numberOfBrowse == 0
|
||||
? dataInfo.numberOfBrowse
|
||||
state.dataInfo.numberOfBrowse || state.dataInfo.numberOfBrowse == 0
|
||||
? state.dataInfo.numberOfBrowse
|
||||
: "-"
|
||||
}}
|
||||
</div>
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
<div class="join">
|
||||
<div
|
||||
v-for="(item, index) in dataInfo.ballotVo?.voteStemVoList"
|
||||
v-for="(item, index) in state.dataInfo.ballotVo?.voteStemVoList"
|
||||
:key="index"
|
||||
style="margin-bottom: 41px"
|
||||
>
|
||||
@@ -102,7 +102,7 @@
|
||||
:src="value.optionPictureAddress"
|
||||
/> -->
|
||||
<div class="radio">
|
||||
<label @click="choiceQuestion(key,value.optionId,dataInfo,index)">
|
||||
<label @click="choiceQuestion(key,value.optionId,state.dataInfo,index)">
|
||||
<!-- <input type="radio" name="one" value="right"/> -->
|
||||
<div v-if="value.isAnswer" style="width:10px;height:10px;background:#4a9cf8;position:relative;left:15px;border-radius:10px;"></div>
|
||||
<div v-else style="width:10px;height:10px;background:#fff;position:relative;left:15px;border-radius:10px;"></div>
|
||||
@@ -115,12 +115,16 @@
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="
|
||||
width: 100%;
|
||||
style="width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 30px;">
|
||||
<button class="submitbtn btn01" :style="{background:dataInfo.isSubmit?'#ccc':''}" @click="submitVote(dataInfo)">{{dataInfo.isSubmit?'已提交':'提交'}}</button>
|
||||
<button
|
||||
class="submitbtn btn01"
|
||||
:style="{background: (new Date().getTime() > new Date(state.dataInfo.voteEndTime).getTime() || new Date().getTime() < new Date(state.dataInfo.voteStartTime).getTime() )? '#ccc' : state.dataInfo.isSubmit?'#ccc':'' }"
|
||||
@click="submitVote(state.dataInfo)">
|
||||
{{state.dataInfo.isSubmit?'已提交':'提交'}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
@@ -135,9 +139,9 @@
|
||||
<div class="timebox clearfix">
|
||||
<div class="innertime">
|
||||
{{
|
||||
dataInfo?.voteStartTime
|
||||
state.dataInfo?.voteStartTime
|
||||
}} 至 {{
|
||||
dataInfo?.voteEndTime
|
||||
state.dataInfo?.voteEndTime
|
||||
}}
|
||||
</div>
|
||||
<div class="endtime clearfix">
|
||||
@@ -145,11 +149,11 @@
|
||||
距离结束还有
|
||||
<span class="te">{{
|
||||
parseInt(
|
||||
dayjs(dataInfo?.voteEndTime).diff(dayjs(), "minute") / 60
|
||||
dayjs(state.dataInfo?.voteEndTime).diff(dayjs(), "minute") / 60
|
||||
)
|
||||
}}</span
|
||||
> 小时 <span class="te">{{
|
||||
dayjs(dataInfo?.voteEndTime).diff(dayjs(), "minute") % 60
|
||||
dayjs(state.dataInfo?.voteEndTime).diff(dayjs(), "minute") % 60
|
||||
}}</span
|
||||
> 分钟
|
||||
</div>
|
||||
@@ -168,7 +172,7 @@
|
||||
<div
|
||||
class="explaincontent"
|
||||
v-html="
|
||||
dataInfo?.voteExplain ? dataInfo?.voteExplain : '暂无说明'
|
||||
state.dataInfo?.voteExplain ? state.dataInfo?.voteExplain : '暂无说明'
|
||||
"
|
||||
></div>
|
||||
</div>
|
||||
@@ -181,15 +185,16 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {useRequest} from "@/api/request";
|
||||
import {useRequest,request} from "@/api/request";
|
||||
import {
|
||||
VOTE_DETAIL2,
|
||||
VOTE_DETAIL_SUBMIT
|
||||
} from "@/api/api";
|
||||
import dayjs from "dayjs";
|
||||
import store from "@/store";
|
||||
import { ElMessage } from "element-plus";
|
||||
import {useRoute,useRouter} from "vue-router/dist/vue-router";
|
||||
import {watch, reactive, toRefs} from "vue";
|
||||
import {computed, reactive, toRefs} from "vue";
|
||||
// const { data } = useRequest(TASK_VOTE_DETAIL, {});
|
||||
// console.log("datadatadata", data);
|
||||
// const state = reactive({
|
||||
@@ -197,43 +202,90 @@ import {watch, reactive, toRefs} from "vue";
|
||||
// });
|
||||
// let { votedetail } = toRefs(state);
|
||||
const {
|
||||
query: {courseId, pName, sName, chapterOrStageId, infoId, id},
|
||||
query: {courseId, pName, sName, chapterOrStageId, infoId, id, btype},
|
||||
} = useRoute();
|
||||
|
||||
const router = useRouter();
|
||||
const returnclick = () => {
|
||||
router.back();
|
||||
};
|
||||
//获取基本信息
|
||||
const {data: dataInfo} = useRequest(VOTE_DETAIL2(courseId));
|
||||
const state = reactive({
|
||||
dataInfo: {},
|
||||
});
|
||||
|
||||
console.log('我是获取的投票基本信息', dataInfo)
|
||||
//获取基本信息
|
||||
// const {data: dataInfo} = useRequest(VOTE_DETAIL2(courseId));
|
||||
const userInfo = computed(() => store.state.userInfo);
|
||||
|
||||
let timer = setInterval(() => {
|
||||
if(userInfo.value.id){
|
||||
clearInterval(timer)
|
||||
console.log('获取信息传递参数',{
|
||||
"chapterOrStageId": chapterOrStageId ? chapterOrStageId : 0,
|
||||
"courseId": courseId,
|
||||
"studentId": userInfo.value.id,
|
||||
"targetId": infoId,
|
||||
"type": btype
|
||||
})
|
||||
|
||||
request(VOTE_DETAIL2, {
|
||||
"chapterOrStageId": chapterOrStageId ? chapterOrStageId : 0,
|
||||
"courseId": courseId,
|
||||
"studentId": userInfo.value.id,
|
||||
"targetId": infoId,
|
||||
"type": btype
|
||||
}).then(res=>{
|
||||
console.log(res)
|
||||
state.dataInfo = res.data
|
||||
}).catch(err=>{
|
||||
console.log(err)
|
||||
});
|
||||
}
|
||||
}, 500);
|
||||
|
||||
console.log('我是获取的投票基本信息', state.dataInfo)
|
||||
|
||||
// 答题时间
|
||||
const answerTime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// 选择题目
|
||||
const choiceQuestion = (order, id, dates, torder) => {
|
||||
// 当已经提交过时候 不让选择题目
|
||||
if(state.dataInfo.isSubmit){
|
||||
return
|
||||
}
|
||||
console.log('当前选择题目的id及序号', order, id, dates,torder)
|
||||
for(let i=0;i<dates.ballotVo.voteStemVoList[torder].optionDetailList.length;i++){
|
||||
dates.ballotVo.voteStemVoList[torder].optionDetailList[i].isAnswer = false;
|
||||
}
|
||||
dates.ballotVo.voteStemVoList[torder].optionDetailList[order].isAnswer = true;
|
||||
console.log(dataInfo)
|
||||
console.log(state.dataInfo)
|
||||
}
|
||||
|
||||
// 提交投票
|
||||
const submitVote = () => {
|
||||
console.log(state.dataInfo)
|
||||
let nowTime = new Date().getTime()
|
||||
let maxTime = new Date(state.dataInfo.voteEndTime).getTime()
|
||||
let minTime = new Date(state.dataInfo.voteStartTime).getTime()
|
||||
|
||||
console.log(nowTime, maxTime, minTime)
|
||||
// 当未到开始时间
|
||||
if(nowTime < minTime || nowTime > maxTime) {
|
||||
ElMessage.error("未到投票开始时间")
|
||||
return
|
||||
}
|
||||
|
||||
// 当已经提交过时候 不让提交即可
|
||||
if(dataInfo.value.isSubmit){
|
||||
if(state.dataInfo.isSubmit){
|
||||
return
|
||||
}
|
||||
let isSubmit = true;
|
||||
let isSubArr = []
|
||||
for(let i=0;i<dataInfo.value.ballotVo.voteStemVoList.length;i++){
|
||||
for(let j=0; j<dataInfo.value.ballotVo.voteStemVoList[i].optionDetailList.length;j++){
|
||||
if(dataInfo.value.ballotVo.voteStemVoList[i].optionDetailList[j].isAnswer){
|
||||
isSubArr[i] = dataInfo.value.ballotVo.voteStemVoList[i].optionDetailList[j].isAnswer
|
||||
for(let i=0;i<state.dataInfo.ballotVo.voteStemVoList.length;i++){
|
||||
for(let j=0; j<state.dataInfo.ballotVo.voteStemVoList[i].optionDetailList.length;j++){
|
||||
if(state.dataInfo.ballotVo.voteStemVoList[i].optionDetailList[j].isAnswer){
|
||||
isSubArr[i] = state.dataInfo.ballotVo.voteStemVoList[i].optionDetailList[j].isAnswer
|
||||
break
|
||||
}else{
|
||||
isSubArr[i] = false
|
||||
@@ -254,17 +306,30 @@ const submitVote = () => {
|
||||
let obj = {
|
||||
"beginTime": answerTime,
|
||||
"chapterOrStageId": chapterOrStageId ? chapterOrStageId : 0,
|
||||
"result": JSON.stringify(dataInfo.value),
|
||||
"result": JSON.stringify(state.dataInfo),
|
||||
"targetId": infoId, // 项目 路径图 id
|
||||
"taskId": id,
|
||||
"type": 1, // 1 项目 2 路径图
|
||||
"voteId": dataInfo.value.voteId
|
||||
"type": btype, // 1 项目 2 路径图
|
||||
"voteId": state.dataInfo.voteId
|
||||
}
|
||||
|
||||
console.log('我是投票提交的信息', obj)
|
||||
|
||||
useRequest(VOTE_DETAIL_SUBMIT,obj,(e)=>{
|
||||
console.log(e)
|
||||
request(VOTE_DETAIL2, {
|
||||
"chapterOrStageId": chapterOrStageId ? chapterOrStageId : 0,
|
||||
"courseId": courseId,
|
||||
"studentId": userInfo.value.id,
|
||||
"targetId": infoId,
|
||||
"type": btype
|
||||
}).then(res=>{
|
||||
console.log(res)
|
||||
ElMessage.success("投票成功")
|
||||
state.dataInfo = res.data
|
||||
}).catch(err=>{
|
||||
console.log(err)
|
||||
});
|
||||
})
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user