|
|
|
@ -1,156 +1,66 @@ |
|
|
|
<template> |
|
|
|
<view class="container"> |
|
|
|
<view v-for="(item, index) in electionList" :key="index" class="election-item"> |
|
|
|
<view class="year-title"> |
|
|
|
<view class="headpart"> |
|
|
|
<text class="title">{{ item.title }}</text> |
|
|
|
<view |
|
|
|
class="type" |
|
|
|
:style=" |
|
|
|
item.type == '投票中' |
|
|
|
? 'background: #DBEAFE;color: #3B82F6;' |
|
|
|
: item.type == '当选' |
|
|
|
? 'background: #DCFCE7;color: #10B981' |
|
|
|
: 'background: #F3F4F6;color: #4B5563' |
|
|
|
" |
|
|
|
> |
|
|
|
{{ item.type }} |
|
|
|
<scroll-view class="scroll-view" scroll-y @scrolltolower="loadMore" :show-scrollbar="false"> |
|
|
|
<view v-for="(item, index) in electionList" :key="index" class="election-item"> |
|
|
|
<view class="year-title"> |
|
|
|
<view class="headpart"> |
|
|
|
<text class="title">{{ item.title }}</text> |
|
|
|
<view |
|
|
|
class="type" |
|
|
|
:style=" |
|
|
|
item.type == '投票中' |
|
|
|
? 'background: #DBEAFE;color: #3B82F6;' |
|
|
|
: item.type == '当选' |
|
|
|
? 'background: #DCFCE7;color: #10B981' |
|
|
|
: 'background: #F3F4F6;color: #4B5563' |
|
|
|
" |
|
|
|
> |
|
|
|
{{ item.type }} |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="flex-center-between" style="display: flex"> |
|
|
|
<view style="display: grid"> |
|
|
|
<view |
|
|
|
v-for="(candidate, cIndex) in item.candidates.slice(0, expandedStates[index] ? item.candidates.length : 1)" |
|
|
|
:key="cIndex" |
|
|
|
class="candidate-item" |
|
|
|
> |
|
|
|
<view class="info-section"> |
|
|
|
<view style="display: flex; align-items: center"> |
|
|
|
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="item.img" alt="" /> |
|
|
|
<view style="margin-left: 24rpx; display: grid"> |
|
|
|
<text class="name">{{ candidate.name }}</text> |
|
|
|
<text class="college">{{ candidate.college }}</text> |
|
|
|
<view class="flex-center-between" style="display: flex"> |
|
|
|
<view style="display: grid"> |
|
|
|
<view |
|
|
|
v-for="(candidate, cIndex) in item.candidates.slice(0, expandedStates[index] ? item.candidates.length : 1)" |
|
|
|
:key="cIndex" |
|
|
|
class="candidate-item" |
|
|
|
> |
|
|
|
<view class="info-section"> |
|
|
|
<view style="display: flex; align-items: center"> |
|
|
|
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="item.img" alt="" /> |
|
|
|
<view style="margin-left: 24rpx; display: grid"> |
|
|
|
<text class="name">{{ candidate.name }}</text> |
|
|
|
<text class="college">{{ candidate.college }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view style="display: flex; margin-top: 24rpx"> |
|
|
|
我的选择: |
|
|
|
<view :class="['choice-tag', choiceClass(candidate.choice)]"> |
|
|
|
{{ choiceText(candidate.choice) }} |
|
|
|
<view style="display: flex; margin-top: 24rpx"> |
|
|
|
我的选择: |
|
|
|
<view :class="['choice-tag', choiceClass(candidate.choice)]"> |
|
|
|
{{ choiceText(candidate.choice) }} |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="expand-btn" @click="toggleExpand(index)"> |
|
|
|
<text :class="['arrow', expandedStates[index] ? 'up' : 'down']"></text> |
|
|
|
<view class="expand-btn" @click="toggleExpand(index)"> |
|
|
|
<text :class="['arrow', expandedStates[index] ? 'up' : 'down']"></text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</scroll-view> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup> |
|
|
|
import { ref, watch } from 'vue' |
|
|
|
import { getMyvote } from '../../api/votingElection' |
|
|
|
|
|
|
|
const electionList = ref([ |
|
|
|
{ |
|
|
|
type: '投票中', |
|
|
|
title: '2024学生会主席选举', |
|
|
|
candidates: [ |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 1 |
|
|
|
}, |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远2号', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远2号', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 2 |
|
|
|
} |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
type: '投票中', |
|
|
|
title: '2024学生会主席选举', |
|
|
|
candidates: [ |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 1 |
|
|
|
}, |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远2号', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远2号', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 2 |
|
|
|
} |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
type: '投票中', |
|
|
|
title: '2024学生会主席选举', |
|
|
|
candidates: [ |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 1 |
|
|
|
}, |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远2号', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '陈思远2号', |
|
|
|
college: '计算机科学与技术学院', |
|
|
|
choice: 2 |
|
|
|
} |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
type: '当选', |
|
|
|
title: '2023优秀班干部评选', |
|
|
|
candidates: [ |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '李雨晴', |
|
|
|
college: '工商管理学院', |
|
|
|
choice: 0 |
|
|
|
} |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
type: '未当选', |
|
|
|
title: '2023最佳社团负责人', |
|
|
|
candidates: [ |
|
|
|
{ |
|
|
|
img: '../../static/redpacket.png', |
|
|
|
name: '王浩然', |
|
|
|
college: '艺术设计学院', |
|
|
|
choice: 2 |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
]) |
|
|
|
const electionList = ref([]) |
|
|
|
const page = ref(1) |
|
|
|
const pageSize = ref(10) |
|
|
|
const loading = ref(false) |
|
|
|
const noMoreData = ref(false) |
|
|
|
|
|
|
|
// 展开状态管理 |
|
|
|
const expandedStates = ref([]) |
|
|
|
@ -190,6 +100,35 @@ const choiceText = (choice) => { |
|
|
|
}[choice] || '' |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
// 获取数据 |
|
|
|
const getList = async () => { |
|
|
|
try { |
|
|
|
loading.value = true |
|
|
|
|
|
|
|
// 模拟接口请求(替换为你的真实接口) |
|
|
|
const mockData = await getMyvote() |
|
|
|
|
|
|
|
// 处理数据 |
|
|
|
dataList.value = [...dataList.value, ...mockData] |
|
|
|
|
|
|
|
// 判断是否还有数据 |
|
|
|
noMoreData.value = mockData.length < pageSize.value |
|
|
|
} finally { |
|
|
|
loading.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 加载更多 |
|
|
|
const loadMore = () => { |
|
|
|
if (loading.value || noMoreData.value) return |
|
|
|
page.value += 1 |
|
|
|
getList() |
|
|
|
} |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
getList() |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
<style scoped lang="scss"> |
|
|
|
|