问卷调查详情显示问题、已结束不能点击提交;

This commit is contained in:
zhouyanli
2026-06-24 17:12:43 +08:00
parent a501524646
commit 8939fec34b
5 changed files with 61 additions and 23 deletions

View File

@@ -234,7 +234,6 @@
.bottom-btn-wrap { .bottom-btn-wrap {
padding: 20rpx 30rpx 40rpx; padding: 20rpx 30rpx 40rpx;
display: flex; display: flex;
gap: 20rpx;
} }
.btn-modify { .btn-modify {
@@ -246,6 +245,7 @@
font-size: 30rpx; font-size: 30rpx;
border-radius: 8rpx; border-radius: 8rpx;
border: none; border: none;
margin-right: 20rpx;
} }
.btn-delete { .btn-delete {
@@ -257,5 +257,6 @@
border: 1rpx solid #f53f3f; border: 1rpx solid #f53f3f;
font-size: 30rpx; font-size: 30rpx;
border-radius: 8rpx; border-radius: 8rpx;
margin-right: 0rpx;
} }
</style> </style>

View File

@@ -108,10 +108,10 @@ const mapData = (data) => {
repairInfo.value = { repairInfo.value = {
house: data.houseName || '', house: data.houseName || '',
project: data.maintenanceItemName || '', project: data.maintenanceItemName || '',
title: data.title || data.maintenanceItemName || '', title: data.item || '',
description: data.problem || '', description: data.problem || '',
phone: data.phone || '', phone: data.phone || '',
time: data.orderDate || '', time: data.createTime || '',
images images
} }
setStep(data.problemStatus) setStep(data.problemStatus)

View File

@@ -454,6 +454,7 @@
color: #fff; color: #fff;
background-color: #E34D59; background-color: #E34D59;
margin-left: 10rpx; margin-left: 10rpx;
line-height: 1.5;
} }
.arrow { .arrow {

View File

@@ -60,7 +60,7 @@ const questionList = computed(() => {
}) })
const answerMap = computed(() => { const answerMap = computed(() => {
const answerContent = detailItem.value?.answerContent const answerContent = detailItem.value?.myAnswer
if (!answerContent) return {} if (!answerContent) return {}
try { try {
const list = JSON.parse(answerContent) const list = JSON.parse(answerContent)
@@ -77,8 +77,8 @@ const answerMap = computed(() => {
const getDetailData = async () => { const getDetailData = async () => {
try { try {
const params = { questionnairedId: currentId.value } const params = { villageId: uni.getStorageSync('currentVillageId') }
const res = await getQuestionnaireDetail(params) const res = await getQuestionnaireDetail(currentId.value, params)
if (res.code === 200) { if (res.code === 200) {
const data = Array.isArray(res.data) ? res.data[0] : res.data const data = Array.isArray(res.data) ? res.data[0] : res.data
detailItem.value = data || {} detailItem.value = data || {}

View File

@@ -32,7 +32,7 @@
:key="oIdx" :key="oIdx"
class="radio-item" class="radio-item"
:class="{ checked: answers[q.cid] === opt.label }" :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 }"> <view class="radio-circle" :class="{ active: answers[q.cid] === opt.label }">
<text v-if="answers[q.cid] === opt.label" class="check-icon"></text> <text v-if="answers[q.cid] === opt.label" class="check-icon"></text>
@@ -48,7 +48,7 @@
:key="oIdx" :key="oIdx"
class="checkbox-item" class="checkbox-item"
:class="{ checked: isChecked(q.cid, opt.label) }" :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) }"> <view class="checkbox-box" :class="{ active: isChecked(q.cid, opt.label) }">
<text v-if="isChecked(q.cid, opt.label)" class="check-icon"></text> <text v-if="isChecked(q.cid, opt.label)" class="check-icon"></text>
@@ -61,8 +61,10 @@
<view v-if="q.type === 'input'"> <view v-if="q.type === 'input'">
<input <input
class="text-input" class="text-input"
:class="{ 'input-disabled': isEndedAndUnjoined }"
v-model="answers[q.cid]" v-model="answers[q.cid]"
placeholder="请输入" placeholder="请输入"
:disabled="isEndedAndUnjoined"
/> />
</view> </view>
@@ -70,9 +72,11 @@
<view v-if="q.type === 'textarea'"> <view v-if="q.type === 'textarea'">
<textarea <textarea
class="textarea-input" class="textarea-input"
:class="{ 'input-disabled': isEndedAndUnjoined }"
v-model="answers[q.cid]" v-model="answers[q.cid]"
placeholder="请输入" placeholder="请输入"
maxlength="500" maxlength="500"
:disabled="isEndedAndUnjoined"
/> />
</view> </view>
</view> </view>
@@ -81,7 +85,12 @@
<!-- 固定底部提交按钮 --> <!-- 固定底部提交按钮 -->
<view class="submit-btn-wrap"> <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>
</view> </view>
</template> </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({}) const answers = ref({})
let hasLoaded = false
// 获取问卷调查 // 获取问卷调查
const getDetailData = async (id) => { const getDetailData = async (id) => {
try { try {
let params = { let params = {
villageId:uni.getStorageSync('currentVillageId') villageId:uni.getStorageSync('currentVillageId')
} }
const res = await getQuestionnaireDetail(id,params) const res = await getQuestionnaireDetail(id,params)
// console.log('接口返回:', JSON.stringify(res)) // console.log('接口返回:', JSON.stringify(res))
if (res.code === 200) { if (res.code === 200) {
@@ -119,7 +141,7 @@ const getDetailData = async (id) => {
detailItem.value = data || {} detailItem.value = data || {}
} else { } else {
uni.showToast({ title: res.msg || '获取失败', icon: 'none' }) uni.showToast({ title: res.msg || '获取失败', icon: 'none' })
} }
} catch (err) { } catch (err) {
uni.showToast({ title: err.msg || '网络异常', icon: 'none' }) uni.showToast({ title: err.msg || '网络异常', icon: 'none' })
} }
@@ -136,6 +158,10 @@ onLoad((option) => {
// 切换小区后返回页面时,重新获取数据 // 切换小区后返回页面时,重新获取数据
onShow(() => { onShow(() => {
if (!hasLoaded) {
hasLoaded = true
return
}
if (questionnaireId.value) { if (questionnaireId.value) {
getDetailData(questionnaireId.value) getDetailData(questionnaireId.value)
} }
@@ -170,9 +196,9 @@ const handleSubmit = async () => {
const ans = answers.value[q.cid] const ans = answers.value[q.cid]
if (ans === undefined || ans === null || ans === '' || (Array.isArray(ans) && ans.length === 0)) { if (ans === undefined || ans === null || ans === '' || (Array.isArray(ans) && ans.length === 0)) {
uni.showToast({ title: `请填写第${questionList.value.indexOf(q) + 1}`, icon: 'none' }) uni.showToast({ title: `请填写第${questionList.value.indexOf(q) + 1}`, icon: 'none' })
return return
} }
} }
} }
const answerList = [] const answerList = []
@@ -180,14 +206,14 @@ const handleSubmit = async () => {
const val = answers.value[q.cid] const val = answers.value[q.cid]
if (val !== undefined && val !== null && val !== '' && !(Array.isArray(val) && val.length === 0)) { if (val !== undefined && val !== null && val !== '' && !(Array.isArray(val) && val.length === 0)) {
answerList.push({ cid: q.cid, value: val }) answerList.push({ cid: q.cid, value: val })
} }
} }
uni.showLoading({ title: "提交中...", mask: true }) uni.showLoading({ title: "提交中...", mask: true })
try { try {
let params = { let params = {
answerList, answerList,
villageId: uni.getStorageSync("currentVillageId") villageId: uni.getStorageSync("currentVillageId")
} }
const res = await submitQuestionnair(detailItem.value.id,params) const res = await submitQuestionnair(detailItem.value.id,params)
uni.hideLoading() uni.hideLoading()
if (res.code === 200) { if (res.code === 200) {
@@ -195,7 +221,7 @@ const handleSubmit = async () => {
setTimeout(() => { goBack() }, 1500) setTimeout(() => { goBack() }, 1500)
} else { } else {
uni.showToast({ title: res.msg || '提交失败', icon: 'none' }) uni.showToast({ title: res.msg || '提交失败', icon: 'none' })
} }
} catch (err) { } catch (err) {
console.log('errrr',err) console.log('errrr',err)
uni.hideLoading() uni.hideLoading()
@@ -270,7 +296,7 @@ page {
color: #ff3b30; color: #ff3b30;
font-size: 36rpx; font-size: 36rpx;
margin-right: 8rpx; margin-right: 8rpx;
} }
} }
} }
@@ -302,7 +328,7 @@ page {
&.active { &.active {
background-color: #007aff; background-color: #007aff;
border-color: #007aff; border-color: #007aff;
} }
} }
.check-icon { .check-icon {
@@ -345,7 +371,7 @@ page {
&.active { &.active {
background-color: #007aff; background-color: #007aff;
border-color: #007aff; border-color: #007aff;
} }
} }
.check-icon { .check-icon {
@@ -387,6 +413,11 @@ page {
margin-left: 30rpx; margin-left: 30rpx;
} }
.input-disabled {
background-color: #f5f5f5;
color: #999;
}
/* 提交按钮 */ /* 提交按钮 */
.submit-btn-wrap { .submit-btn-wrap {
padding: 20rpx 30rpx 40rpx; padding: 20rpx 30rpx 40rpx;
@@ -406,7 +437,12 @@ page {
&::after { &::after {
border: none; border: none;
} }
&.disabled-btn {
background-color: #ccc;
color: #999;
}
} }
} }