Browse Source

选举结果

dev
沈明 1 year ago
parent
commit
d9c6f0ea11
  1. 8
      src/api/common.ts
  2. 2
      src/pages.json
  3. 41
      src/pages/electionResults/index.vue
  4. 82
      src/pages/myElection/index.vue
  5. 121
      src/pages/votingElection/index.vue

8
src/api/common.ts

@ -15,3 +15,11 @@ export function getVoteDetail(data: { id: number }) {
data data
}) })
} }
export function getVoteResult(data: pageType) {
return request.http({
url: '/api/vote_result',
method: 'GET',
data
})
}

2
src/pages.json

@ -33,7 +33,7 @@
"style": { "style": {
"navigationBarTitleText": "选举结果", "navigationBarTitleText": "选举结果",
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",
"enablePullDownRefresh": false "enablePullDownRefresh": true
} }
}, },
{ {

41
src/pages/electionResults/index.vue

@ -1,11 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { getVoteResult } 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({ getVoteResult(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>

82
src/pages/myElection/index.vue

@ -101,52 +101,42 @@ const choiceText = (choice) => {
) )
} }
const choiceText = (choice) => { //
return ({ const getList = async () => {
1: '同意', try {
0: '反对', loading.value = true
2: '弃权'
} [choice] || '') //
} const mockData = await getMyvote()
// //
const getList = async () => { dataList.value = [...dataList.value, ...mockData]
try {
loading.value = true //
noMoreData.value = mockData.length < pageSize.value
// } finally {
const mockData = await getMyvote().then((res)=> { loading.value = false
}
}) }
// //
dataList.value = [...dataList.value, ...mockData] const loadMore = () => {
if (loading.value || noMoreData.value) return
// page.value += 1
noMoreData.value = mockData.length < pageSize.value getList()
} finally { }
loading.value = false
} onMounted(() => {
} getList()
})
//
const loadMore = () => { onShow(() => {
if (loading.value || noMoreData.value) return if (userStore.mobile) {
page.value += 1 uni.navigateTo({
getList() url: '/pages/login/login'
} })
}
onMounted(() => { })
getList()
})
onShow(() => {
if (userStore.mobile) {
uni.navigateTo({
url: '/pages/login/login'
});
}
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

121
src/pages/votingElection/index.vue

@ -30,6 +30,7 @@ const buttlist = ref([
butname: '弃权' butname: '弃权'
} }
]) ])
const params = ref([]) const params = ref([])
const selectBut = (data: any, cardid: any, type: string, butname: string) => { const selectBut = (data: any, cardid: any, type: string, butname: string) => {
if (cardid) { if (cardid) {
@ -72,95 +73,37 @@ const allChange = () => {
}) })
} }
const buttlist = ref([ function extractTwoProps(arr: any, key1: string, key2: string) {
{ return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({
type: '1', [key1]: prop1,
butname: '同意' [key2]: prop2
}, }))
{ }
type: '2', const submit = () => {
butname: '反对' let param = {
}, openid: userStore.openId,
{ id: xjList.value.id,
type: '3', candidate: JSON.stringify(extractTwoProps(params.value, 'id', 'vote_result'))
butname: '弃权' }
} if (param.candidate === '[]') {
]) uni.showToast({
const params = ref([]) title: '未选举',
const selectBut = (data : any, cardid : any, type : string, butname : string) => { icon: 'none', // 'success', 'loading', 'none'
if (cardid) { duration: 1500 // ms
const target = data.find((card : { id : any }) => card.id === cardid) })
uni.showModal({ } else {
title: '您本轮选举投' + butname + '票', voteMember(param).then((res) => {
content: '确定吗?', console.log(res, 555555555555555)
success: function (res) { })
if (res.confirm) { }
if (target) { }
target.vote_result = type onShow(() => {
} if (userStore.mobile) {
} else if (res.cancel) { uni.navigateTo({
console.log('用户点击取消') url: '/pages/login/login'
} })
} }
}) })
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('用户点击取消')
}
}
})
}
function extractTwoProps(arr:any, key1:string, key2:string) {
return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({
[key1]: prop1,
[key2]: prop2
}));
}
const submit = () => {
let param = {
openid: userStore.openId,
id: xjList.value.id,
candidate: JSON.stringify(extractTwoProps(params.value,'id','vote_result'))
}
if(param.candidate === '[]') {
uni.showToast({
title: '未选举',
icon: 'none', // 'success', 'loading', 'none'
duration: 1500 // ms
});
} else {
voteMember(param).then((res)=> {
console.log(res,555555555555555)
})
}
}
onShow(() => {
if (userStore.mobile) {
uni.navigateTo({
url: '/pages/login/login'
});
}
})
</script> </script>
<template> <template>

Loading…
Cancel
Save