问卷调查详情显示问题、已结束不能点击提交;
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
:key="oIdx"
|
||||
class="radio-item"
|
||||
:class="{ checked: answers[q.cid] === opt.label }"
|
||||
@click="selectRadio(q.cid, opt.label)"
|
||||
@click="!isEndedAndUnjoined && selectRadio(q.cid, opt.label)"
|
||||
>
|
||||
<view class="radio-circle" :class="{ active: answers[q.cid] === opt.label }">
|
||||
<text v-if="answers[q.cid] === opt.label" class="check-icon">✓</text>
|
||||
@@ -48,7 +48,7 @@
|
||||
:key="oIdx"
|
||||
class="checkbox-item"
|
||||
:class="{ checked: isChecked(q.cid, opt.label) }"
|
||||
@click="toggleCheckbox(q.cid, opt.label)"
|
||||
@click="!isEndedAndUnjoined && toggleCheckbox(q.cid, opt.label)"
|
||||
>
|
||||
<view class="checkbox-box" :class="{ active: isChecked(q.cid, opt.label) }">
|
||||
<text v-if="isChecked(q.cid, opt.label)" class="check-icon">✓</text>
|
||||
@@ -61,8 +61,10 @@
|
||||
<view v-if="q.type === 'input'">
|
||||
<input
|
||||
class="text-input"
|
||||
:class="{ 'input-disabled': isEndedAndUnjoined }"
|
||||
v-model="answers[q.cid]"
|
||||
placeholder="请输入"
|
||||
:disabled="isEndedAndUnjoined"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -70,9 +72,11 @@
|
||||
<view v-if="q.type === 'textarea'">
|
||||
<textarea
|
||||
class="textarea-input"
|
||||
:class="{ 'input-disabled': isEndedAndUnjoined }"
|
||||
v-model="answers[q.cid]"
|
||||
placeholder="请输入"
|
||||
maxlength="500"
|
||||
:disabled="isEndedAndUnjoined"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
@@ -81,7 +85,12 @@
|
||||
|
||||
<!-- 固定底部提交按钮 -->
|
||||
<view class="submit-btn-wrap">
|
||||
<button class="submit-btn" @click="handleSubmit">提交</button>
|
||||
<button
|
||||
v-if="isEndedAndUnjoined"
|
||||
class="submit-btn disabled-btn"
|
||||
disabled
|
||||
>已结束</button>
|
||||
<button v-else class="submit-btn" @click="handleSubmit">提交</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -105,13 +114,26 @@ const questionList = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
// 是否已结束且未参与
|
||||
const isEndedAndUnjoined = computed(() => {
|
||||
const endTime = detailItem.value?.endTime
|
||||
const participated = detailItem.value?.participated
|
||||
// participated 不存在(null/undefined)说明接口没返回参与状态,按未参与处理
|
||||
const isNotParticipated = !participated
|
||||
// endTime 存在且已过期
|
||||
const isEnded = endTime && new Date(endTime.replace(/-/g, '/')).getTime() < Date.now()
|
||||
return isEnded && isNotParticipated
|
||||
})
|
||||
|
||||
const answers = ref({})
|
||||
let hasLoaded = false
|
||||
|
||||
// 获取问卷调查
|
||||
const getDetailData = async (id) => {
|
||||
try {
|
||||
let params = {
|
||||
villageId:uni.getStorageSync('currentVillageId')
|
||||
}
|
||||
}
|
||||
const res = await getQuestionnaireDetail(id,params)
|
||||
// console.log('接口返回:', JSON.stringify(res))
|
||||
if (res.code === 200) {
|
||||
@@ -119,7 +141,7 @@ const getDetailData = async (id) => {
|
||||
detailItem.value = data || {}
|
||||
} else {
|
||||
uni.showToast({ title: res.msg || '获取失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
uni.showToast({ title: err.msg || '网络异常', icon: 'none' })
|
||||
}
|
||||
@@ -136,6 +158,10 @@ onLoad((option) => {
|
||||
|
||||
// 切换小区后返回页面时,重新获取数据
|
||||
onShow(() => {
|
||||
if (!hasLoaded) {
|
||||
hasLoaded = true
|
||||
return
|
||||
}
|
||||
if (questionnaireId.value) {
|
||||
getDetailData(questionnaireId.value)
|
||||
}
|
||||
@@ -170,9 +196,9 @@ const handleSubmit = async () => {
|
||||
const ans = answers.value[q.cid]
|
||||
if (ans === undefined || ans === null || ans === '' || (Array.isArray(ans) && ans.length === 0)) {
|
||||
uni.showToast({ title: `请填写第${questionList.value.indexOf(q) + 1}题`, icon: 'none' })
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const answerList = []
|
||||
@@ -180,14 +206,14 @@ const handleSubmit = async () => {
|
||||
const val = answers.value[q.cid]
|
||||
if (val !== undefined && val !== null && val !== '' && !(Array.isArray(val) && val.length === 0)) {
|
||||
answerList.push({ cid: q.cid, value: val })
|
||||
}
|
||||
}
|
||||
}
|
||||
uni.showLoading({ title: "提交中...", mask: true })
|
||||
try {
|
||||
let params = {
|
||||
answerList,
|
||||
villageId: uni.getStorageSync("currentVillageId")
|
||||
}
|
||||
villageId: uni.getStorageSync("currentVillageId")
|
||||
}
|
||||
const res = await submitQuestionnair(detailItem.value.id,params)
|
||||
uni.hideLoading()
|
||||
if (res.code === 200) {
|
||||
@@ -195,7 +221,7 @@ const handleSubmit = async () => {
|
||||
setTimeout(() => { goBack() }, 1500)
|
||||
} else {
|
||||
uni.showToast({ title: res.msg || '提交失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('errrr',err)
|
||||
uni.hideLoading()
|
||||
@@ -270,7 +296,7 @@ page {
|
||||
color: #ff3b30;
|
||||
font-size: 36rpx;
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +328,7 @@ page {
|
||||
&.active {
|
||||
background-color: #007aff;
|
||||
border-color: #007aff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.check-icon {
|
||||
@@ -345,7 +371,7 @@ page {
|
||||
&.active {
|
||||
background-color: #007aff;
|
||||
border-color: #007aff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.check-icon {
|
||||
@@ -387,6 +413,11 @@ page {
|
||||
margin-left: 30rpx;
|
||||
}
|
||||
|
||||
.input-disabled {
|
||||
background-color: #f5f5f5;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 提交按钮 */
|
||||
.submit-btn-wrap {
|
||||
padding: 20rpx 30rpx 40rpx;
|
||||
@@ -406,7 +437,12 @@ page {
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.disabled-btn {
|
||||
background-color: #ccc;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,4 +450,4 @@ page {
|
||||
width: 100vw;
|
||||
height: 46px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user