|
|
|
@ -9,7 +9,7 @@
|
|
|
|
|
<ch-empty emptyText="暂无答题任务" v-if="!options.length"></ch-empty>
|
|
|
|
|
<ch-flex class="answer-options" justify="around" items="center" @tap.native="selectOpt" v-else>
|
|
|
|
|
<block v-for="option in options" :key="option.id">
|
|
|
|
|
<view class="option" :class="{ 'selected': selectOpts.includes(option.id) }" :data-opt="option">
|
|
|
|
|
<view class="option" :class="{ 'selected': selectOpts.includes(option.text) }" :data-opt="option">
|
|
|
|
|
{{ option.text }}
|
|
|
|
|
</view>
|
|
|
|
|
</block>
|
|
|
|
@ -20,6 +20,7 @@
|
|
|
|
|
<script setup>
|
|
|
|
|
import { getIClickerData, submitIClickerData } from '@/api/iClicker.js'
|
|
|
|
|
import { reactive, toRefs } from 'vue';
|
|
|
|
|
import { useUserStore } from '../../store/user';
|
|
|
|
|
|
|
|
|
|
const defaultOptions = [
|
|
|
|
|
{
|
|
|
|
@ -40,6 +41,9 @@ const defaultOptions = [
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
const userId = userStore.userId;
|
|
|
|
|
|
|
|
|
|
const data = reactive({
|
|
|
|
|
options: [...defaultOptions],
|
|
|
|
|
selectOpts: []
|
|
|
|
@ -50,9 +54,9 @@ const { options, selectOpts } = toRefs(data);
|
|
|
|
|
function selectOpt (e) {
|
|
|
|
|
const opt = e.target.dataset.opt || null;
|
|
|
|
|
if (!opt) return;
|
|
|
|
|
const index = selectOpts.value.findIndex(id => id == opt.id)
|
|
|
|
|
selectOpts.value = index == -1 ? [...selectOpts.value, opt.id]
|
|
|
|
|
: selectOpts.value.filter(id => id !== opt.id)
|
|
|
|
|
const index = selectOpts.value.findIndex(text => text == opt.text)
|
|
|
|
|
selectOpts.value = index == -1 ? [...selectOpts.value, opt.text]
|
|
|
|
|
: selectOpts.value.filter(text => text!== opt.text)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function submitAnswer () {
|
|
|
|
@ -61,7 +65,23 @@ function submitAnswer () {
|
|
|
|
|
confirmText: '提交',
|
|
|
|
|
cancelText: '放弃',
|
|
|
|
|
success: () => {
|
|
|
|
|
const params = {
|
|
|
|
|
studentanswer: selectOpts.value.join(','),
|
|
|
|
|
studentid: userId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
submitIClickerData(params).then(res => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: 'success',
|
|
|
|
|
title: '已提交'
|
|
|
|
|
})
|
|
|
|
|
refresh();
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon:'error',
|
|
|
|
|
title: '提交失败'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|