岳鹏龙 1 year ago
parent
commit
7c7f64bdc9
  1. 17
      src/api/common.ts
  2. 7
      src/api/votingElection.ts
  3. 41
      src/pages/electionList/index.vue
  4. 46
      src/pages/electionList/info.vue
  5. 137
      src/pages/myElection/index.vue
  6. 84
      src/pages/votingElection/index.vue
  7. 3
      src/utils/http.ts

17
src/api/common.ts

@ -0,0 +1,17 @@
import { request } from '@/utils/http'
export function getVoteList(data: pageType) {
return request.http({
url: '/api/vote_list',
method: 'GET',
data
})
}
export function getVoteDetail(data: { id: number }) {
return request.http({
url: '/api/vote_result_detail',
method: 'GET',
data
})
}

7
src/api/votingElection.ts

@ -1,12 +1,10 @@
import { request } from '@/utils/http' import { request } from '@/utils/http'
// 获取投票选举(正在进行) // 获取投票选举(正在进行)
export function getVoteprogress() { export function getVoteprogress() {
return request.http({ return request.http({
url: '/api/vote_progress', url: '/api/vote_progress',
method: "GET" method: 'GET'
}) })
} }
@ -22,7 +20,6 @@ export function voteMember(data: any) {
export function getMyvote() { export function getMyvote() {
return request.http({ return request.http({
url: '/api/my_vote', url: '/api/my_vote',
method: "GET" method: 'GET'
}) })
} }

41
src/pages/electionList/index.vue

@ -1,11 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { getVoteList } from '@/api/common'
const navto = (url: string, params = {}) => uni.$util.goToPage({ url, params }) const navto = (url: string, params = {}) => uni.$util.goToPage({ url, params })
const doSearch = (_formData: { page: number; limit: number }, onSuccess: Function) => { const doSearch = (formData: { page: number; limit: number }, onSuccess: Function) => {
onSuccess({ getVoteList(formData).then((res) => {
data: { const { data } = res as { data: { data: any; total: number } }
data: [{ name: '测试一' }, { name: '测试二' }], onSuccess({ data })
total: 4
}
}) })
} }
</script> </script>
@ -18,36 +17,38 @@ const doSearch = (_formData: { page: number; limit: number }, onSuccess: Functio
<view class="flex"> <view class="flex">
<view class="flex1"> <view class="flex1">
<view class="flex-center-start"> <view class="flex-center-start">
<text class="text-ellipsis title">{{ '2024年度学生会主席选举' }}</text> <text class="text-ellipsis title">{{ row.title }}</text>
<text class="status b">进行中</text> <text class="status b" v-if="row.status === 2">进行中</text>
<!-- <text class="status f">未开始</text> --> <text class="status f" v-else-if="row.status === 1">未开始</text>
<!-- <text class="status e">已结束</text> --> <text class="status e" v-else>已结束</text>
</view> </view>
<view class="time">{{ '投票时间:2024-03-01 至 2024-03-07' }}</view> <view class="time">{{ `投票时间:${row.start_time}${row.end_time}` }}</view>
</view> </view>
<view :class="{ arrow: true, active: row.showInfo }" @click="row.showInfo = !row.showInfo"> <view :class="{ arrow: true, active: row.showInfo }" @click="row.showInfo = !row.showInfo">
<u-icon name="arrow-down" color="#9CA3AF" /> <u-icon name="arrow-down" color="#9CA3AF" />
</view> </view>
</view> </view>
<view class="info" v-if="row.showInfo"> <view class="info" v-if="row.showInfo">
<view class="flex info-items" v-for="(v, k) of 2" :key="k"> <view class="flex info-items" v-for="(v, k) of row.candidate" :key="k">
<view class="head"></view> <view class="head">
<image :src="v.photo" mode="aspectFill" />
</view>
<view class="content flex1"> <view class="content flex1">
<view class="name flex-center-start"> <view class="name flex-center-start">
<text>陈佳怡</text> <text>{{ v.name }}</text>
<!-- <text class="status">当选</text> --> <text class="status" v-if="v.vote_result == 1">当选</text>
<text class="status un">未当选</text> <text class="status un" v-else>未当选</text>
</view> </view>
<view class="votes">得票数286</view> <view class="votes">得票数{{ v.agree_num }}</view>
</view> </view>
<view class="progress"> <view class="progress">
<u-line-progress :percentage="60" height="8rpx" active-color="#2563EB" :show-text="false" /> <u-line-progress :percentage="v.ageree_percent" height="8rpx" active-color="#2563EB" :show-text="false" />
<view class="progress-text">60%</view> <view class="progress-text">{{ v.ageree_percent }}%</view>
</view> </view>
</view> </view>
<view class="info-bts" @click.stop="navto('pages/electionList/info')">查看投票详情</view> <view class="info-bts" @click.stop="navto('pages/electionList/info', { id: row.id })">查看投票详情</view>
</view> </view>
</view> </view>
</template> </template>

46
src/pages/electionList/info.vue

@ -1,56 +1,68 @@
<script setup lang="ts"></script> <script setup lang="ts">
import { getVoteDetail } from '@/api/common'
const info = ref<any>({})
onLoad((opt) => {
getVoteDetail({ id: opt?.id }).then((res: any) => {
info.value = res.data
})
})
</script>
<template> <template>
<view class="electionList-info"> <view class="electionList-info">
<view class="head"> <view class="head">
<view class="title">2024年度业主委员会主任选举</view> <view class="title">{{ info.title }}</view>
<view class="status"> <view class="status">
<text style="color: #4b5563; margin-right: 16rpx">已结束</text> <text style="color: #4b5563; margin-right: 16rpx">已结束</text>
<text style="color: #6b7280">2024-01-15 10:00 ~ 2024-01-16 10:00</text> <text style="color: #6b7280">{{ info.start_time }} ~ {{ info.end_time }}</text>
</view> </view>
</view> </view>
<view class="countview flex-center-between"> <view class="countview flex-center-between">
<view class="flex column items"> <view class="flex column items">
<u-count-to :start-val="0" :end-val="20" bold font-size="48rpx" color="#2563EB" /> <u-count-to :start-val="0" :end-val="info.member_num" bold font-size="48rpx" color="#2563EB" />
<view class="tip">参选人数</view> <view class="tip">参选人数</view>
</view> </view>
<view class="flex column items"> <view class="flex column items">
<u-count-to :start-val="0" :end-val="20" bold font-size="48rpx" color="#2563EB" /> <u-count-to :start-val="0" :end-val="info.candidate_num" bold font-size="48rpx" color="#2563EB" />
<view class="tip">候选人数</view> <view class="tip">候选人数</view>
</view> </view>
<view class="flex column items"> <view class="flex column items">
<u-count-to :start-val="0" :end-val="20" bold font-size="48rpx" color="#2563EB" /> <u-count-to :start-val="0" :end-val="info.elected_num" bold font-size="48rpx" color="#2563EB" />
<view class="tip">当选人数</view> <view class="tip">当选人数</view>
</view> </view>
</view> </view>
<view class="content" v-for="(v, k) of 4" :key="k"> <view class="content" v-for="(v, k) of info.candidate" :key="k">
<view class="flex"> <view class="flex">
<view class="headimg"></view> <view class="headimg">
<view class="name">陈志明</view> <image :src="v.photo" mode="aspectFill" />
<view class="status">当选</view> </view>
<!-- <view class="status un">未当选</view> --> <view class="name">{{ v.name }}</view>
<view class="status" v-if="v.vote_result == 1">当选</view>
<view class="status un" v-else>未当选</view>
</view> </view>
<view class="progress"> <view class="progress">
<view class="flex-center-between progress-text"> <view class="flex-center-between progress-text">
<text>同意</text> <text>同意</text>
<text class="b">98 (62.8%)</text> <text class="b">{{ v.agree_num }} ({{ v.ageree_percent.toFixed(2) }}%)</text>
</view> </view>
<u-line-progress :percentage="62.8" height="8rpx" active-color="#2563EB" :show-text="false" /> <u-line-progress :percentage="v.ageree_percent" height="8rpx" active-color="#2563EB" :show-text="false" />
</view> </view>
<view class="progress"> <view class="progress">
<view class="flex-center-between progress-text"> <view class="flex-center-between progress-text">
<text>反对</text> <text>反对</text>
<text class="e">35 (22.4%)</text> <text class="e">{{ v.disagree_num }} ({{ v.giveup_percent.toFixed(2) }}%)</text>
</view> </view>
<u-line-progress :percentage="22.4" height="8rpx" active-color="#ef4444" :show-text="false" /> <u-line-progress :percentage="v.giveup_percent" height="8rpx" active-color="#ef4444" :show-text="false" />
</view> </view>
<view class="progress"> <view class="progress">
<view class="flex-center-between progress-text"> <view class="flex-center-between progress-text">
<text>弃权</text> <text>弃权</text>
<text class="f">23 (14.8%)</text> <text class="f">{{ v.giveup_num }} ({{ v.giveup_percent.toFixed(2) }}%)</text>
</view> </view>
<u-line-progress :percentage="14.8" height="8rpx" active-color="#9CA3AF" :show-text="false" /> <u-line-progress :percentage="v.giveup_percent" height="8rpx" active-color="#9CA3AF" :show-text="false" />
</view> </view>
</view> </view>
</view> </view>

137
src/pages/myElection/index.vue

@ -5,13 +5,16 @@
<view class="year-title"> <view class="year-title">
<view class="headpart"> <view class="headpart">
<text class="title">{{ item.title }}</text> <text class="title">{{ item.title }}</text>
<view class="type" :style=" <view
class="type"
:style="
item.type == '投票中' item.type == '投票中'
? 'background: #DBEAFE;color: #3B82F6;' ? 'background: #DBEAFE;color: #3B82F6;'
: item.type == '当选' : item.type == '当选'
? 'background: #DCFCE7;color: #10B981' ? 'background: #DCFCE7;color: #10B981'
: 'background: #F3F4F6;color: #4B5563' : 'background: #F3F4F6;color: #4B5563'
"> "
>
{{ item.type }} {{ item.type }}
</view> </view>
</view> </view>
@ -20,11 +23,12 @@
<view style="display: grid"> <view style="display: grid">
<view <view
v-for="(candidate, cIndex) in item.candidates.slice(0, expandedStates[index] ? item.candidates.length : 1)" v-for="(candidate, cIndex) in item.candidates.slice(0, expandedStates[index] ? item.candidates.length : 1)"
:key="cIndex" class="candidate-item"> :key="cIndex"
class="candidate-item"
>
<view class="info-section"> <view class="info-section">
<view style="display: flex; align-items: center"> <view style="display: flex; align-items: center">
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="item.img" <img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="item.img" alt="" />
alt="" />
<view style="margin-left: 24rpx; display: grid"> <view style="margin-left: 24rpx; display: grid">
<text class="name">{{ candidate.name }}</text> <text class="name">{{ candidate.name }}</text>
<text class="college">{{ candidate.college }}</text> <text class="college">{{ candidate.college }}</text>
@ -49,37 +53,32 @@
</template> </template>
<script setup> <script setup>
import { import { ref, watch } from 'vue'
ref, import { getMyvote } from '../../api/votingElection'
watch
} from 'vue' const electionList = ref([])
import { const page = ref(1)
getMyvote const pageSize = ref(10)
} from '../../api/votingElection' const loading = ref(false)
const noMoreData = ref(false)
const electionList = ref([]) //
const page = ref(1) const expandedStates = ref([])
const pageSize = ref(10) watch(
const loading = ref(false)
const noMoreData = ref(false)
//
const expandedStates = ref([])
watch(
() => electionList.value, () => electionList.value,
(newVal) => { (newVal) => {
expandedStates.value = newVal.map(() => false) expandedStates.value = newVal.map(() => false)
}, { },
{
immediate: true immediate: true
} }
) )
const toggleExpand = (index) => { const toggleExpand = (index) => {
expandedStates.value[index] = !expandedStates.value[index] expandedStates.value[index] = !expandedStates.value[index]
} }
const choiceClass = (choice) => { const choiceClass = (choice) => {
switch (choice) { switch (choice) {
case 1: case 1:
return 'agree' return 'agree'
@ -90,7 +89,17 @@
default: default:
return '' return ''
} }
} }
const choiceText = (choice) => {
return (
{
1: '同意',
0: '反对',
2: '弃权'
}[choice] || ''
)
}
const choiceText = (choice) => { const choiceText = (choice) => {
return ({ return ({
@ -141,13 +150,13 @@
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.container { .container {
padding: 20rpx; padding: 20rpx;
background-color: #f9fafb; background-color: #f9fafb;
height: 100vh; height: 100vh;
} }
.election-item { .election-item {
margin-bottom: 30rpx; margin-bottom: 30rpx;
padding: 34rpx; padding: 34rpx;
border-radius: 24rpx; border-radius: 24rpx;
@ -155,9 +164,9 @@
box-sizing: border-box; box-sizing: border-box;
border: 2rpx solid #f3f4f6; border: 2rpx solid #f3f4f6;
box-shadow: 0rpx 2rpx 4rpx 0rpx rgba(0, 0, 0, 0.05); box-shadow: 0rpx 2rpx 4rpx 0rpx rgba(0, 0, 0, 0.05);
} }
.year-title { .year-title {
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
color: #333; color: #333;
@ -190,91 +199,91 @@
border-radius: 24rpx; border-radius: 24rpx;
} }
} }
} }
.candidate-item { .candidate-item {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding: 20rpx 0; padding: 20rpx 0;
} }
.info-section { .info-section {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.name { .name {
font-family: Roboto; font-family: Roboto;
font-size: 28rpx; font-size: 28rpx;
font-weight: 500; font-weight: 500;
letter-spacing: normal; letter-spacing: normal;
color: #000000; color: #000000;
} }
.college { .college {
font-family: Roboto; font-family: Roboto;
font-size: 24rpx; font-size: 24rpx;
font-weight: normal; font-weight: normal;
letter-spacing: normal; letter-spacing: normal;
color: #6b7280; color: #6b7280;
} }
.choice-tag { .choice-tag {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
font-family: Roboto; font-family: Roboto;
font-size: 28rpx; font-size: 28rpx;
font-weight: normal; font-weight: normal;
} }
.agree { .agree {
color: #3b82f6; color: #3b82f6;
} }
.oppose { .oppose {
color: #f44336; color: #f44336;
} }
.abstain { .abstain {
color: #9ca3af; color: #9ca3af;
} }
.year-title { .year-title {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
} }
.expand-btn { .expand-btn {
display: flex; display: flex;
align-items: center; align-items: center;
color: #666; color: #666;
font-size: 26rpx; font-size: 26rpx;
padding: 10rpx 20rpx; padding: 10rpx 20rpx;
} }
.arrow { .arrow {
display: inline-block; display: inline-block;
width: 0; width: 0;
height: 0; height: 0;
margin-left: 10rpx; margin-left: 10rpx;
border-left: 10rpx solid transparent; border-left: 10rpx solid transparent;
border-right: 10rpx solid transparent; border-right: 10rpx solid transparent;
} }
.down { .down {
border-top: 15rpx solid #999; border-top: 15rpx solid #999;
} }
.up { .up {
border-bottom: 15rpx solid #999; border-bottom: 15rpx solid #999;
} }
/* 优化候选人项间距 */ /* 优化候选人项间距 */
.candidate-item:last-child { .candidate-item:last-child {
border-bottom: none; border-bottom: none;
} }
</style> </style>

84
src/pages/votingElection/index.vue

@ -1,22 +1,76 @@
<script setup lang="ts"> <script setup lang="ts">
import { getVoteprogress, voteMember } from '../../api/votingElection' import { getVoteprogress, voteMember } from '../../api/votingElection'
import { getUserList } from '../../api/user' import useUserStore from '@/store/user'
import useUserStore from '@/store/user' const userStore = useUserStore()
const userStore = useUserStore()
const xjList = ref({}) const xjList = ref({})
const doSearch = (_formData : { page : number; limit : number }, onSuccess : Function) => { const doSearch = (_formData: { page: number; limit: number }, onSuccess: Function) => {
getVoteprogress().then((res) => { getVoteprogress().then((res) => {
xjList.value = res.data xjList.value = res.data
res.data.data = res.data.candidate; res.data.data = res.data.candidate
// 2. // 2.
delete res.data.candidate; delete res.data.candidate
res.data.total = res.data.candidate?.length res.data.total = res.data.candidate?.length
const { data } = res as { data : { data : any; total : number } } const { data } = res as { data: { data: any; total: number } }
onSuccess({ data }) onSuccess({ data })
}) })
}
const buttlist = ref([
{
type: '1',
butname: '同意'
},
{
type: '2',
butname: '反对'
},
{
type: '3',
butname: '弃权'
}
])
const params = ref([])
const selectBut = (data: any, cardid: any, type: string, butname: string) => {
if (cardid) {
const target = data.find((card: { id: any }) => card.id === cardid)
uni.showModal({
title: '您本轮选举投' + butname + '票',
content: '确定吗?',
success: function (res) {
if (res.confirm) {
if (target) {
target.vote_result = type
}
} else if (res.cancel) {
console.log('用户点击取消')
} }
}
})
params.value.push(target)
} else {
data.forEach((ele: { vote_result: number; id: any }) => {
ele.vote_result = 1
})
}
}
const allChange = () => {
uni.showModal({
title: '您本轮选举全投同意票',
content: '确定吗?',
success: function (res) {
if (res.confirm) {
xjList.value.data?.forEach((ele: { vote_result: number }) => {
ele.vote_result = 1
})
params.value = xjList.value.data
submit()
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
const buttlist = ref([ const buttlist = ref([
{ {
@ -133,9 +187,13 @@
</view> </view>
</view> </view>
<view class="bottomp"> <view class="bottomp">
<view class="minbut" v-for="(item, ele) in buttlist" :key="ele" <view
class="minbut"
v-for="(item, ele) in buttlist"
:key="ele"
@click="selectBut(data, row.id, item.type, item.butname)" @click="selectBut(data, row.id, item.type, item.butname)"
:class="{ active: row.vote_result === item.type }"> :class="{ active: row.vote_result === item.type }"
>
{{ item.butname }} {{ item.butname }}
</view> </view>
</view> </view>
@ -151,7 +209,7 @@
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.box { .box {
width: 100%; width: 100%;
background-color: #f9fafb; background-color: #f9fafb;
@ -381,5 +439,5 @@
bottom: 0; bottom: 0;
border-top: 2rpx solid #ebebec; border-top: 2rpx solid #ebebec;
} }
} }
</style> </style>

3
src/utils/http.ts

@ -30,8 +30,6 @@ export const request = {
const header = Object.assign({ 'content-type': 'application/json', Authorization: '' }, headers) const header = Object.assign({ 'content-type': 'application/json', Authorization: '' }, headers)
console.log('request Url:', url)
uni.request({ uni.request({
url, url,
header, header,
@ -39,6 +37,7 @@ export const request = {
data, data,
success(res) { success(res) {
const data = res.data as { code: number; data: object; msg: string } const data = res.data as { code: number; data: object; msg: string }
switch (data.code) { switch (data.code) {
case 1: case 1:
resolve(res.data) resolve(res.data)

Loading…
Cancel
Save