沈明 1 year ago
parent
commit
8008b88ab8
  1. 10
      src/api/votingElection.ts
  2. 25
      src/pages/myElection/index.vue
  3. 90
      src/pages/votingElection/index.vue
  4. BIN
      src/static/img/Group.png

10
src/api/votingElection.ts

@ -1,10 +1,12 @@
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"
}) })
} }
@ -17,9 +19,11 @@ export function voteMember(data: any) {
} }
// 获取我的选举 // 获取我的选举
export function getMyvote() { export function getMyvote(data:any) {
return request.http({ return request.http({
url: '/api/my_vote', url: '/api/my_vote',
method: 'GET' method: "GET",
data
}) })
} }

25
src/pages/myElection/index.vue

@ -55,6 +55,8 @@
<script setup> <script setup>
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
import { getMyvote } from '../../api/votingElection' import { getMyvote } from '../../api/votingElection'
import useUserStore from '@/store/user'
const userStore = useUserStore()
const electionList = ref([]) const electionList = ref([])
const page = ref(1) const page = ref(1)
@ -106,14 +108,22 @@ const getList = async () => {
try { try {
loading.value = true loading.value = true
let param = {
openid: userStore.openId,
page: page.value,
limit: pageSize.value
}
// //
const mockData = await getMyvote() const mockData = await getMyvote(param).then((res)=> {
console.log(res,66666666666);
})
// //
dataList.value = [...dataList.value, ...mockData] // electionList.value = [...electionList.value, ...mockData]
electionList.value.push(mockData)
// //
noMoreData.value = mockData.length < pageSize.value // noMoreData.value = mockData.length < pageSize.value
} finally { } finally {
loading.value = false loading.value = false
} }
@ -126,17 +136,10 @@ const loadMore = () => {
getList() getList()
} }
onMounted(() => { onShow(() => {
getList() getList()
}) })
onShow(() => {
if (userStore.mobile) {
uni.navigateTo({
url: '/pages/login/login'
})
}
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

90
src/pages/votingElection/index.vue

@ -1,22 +1,24 @@
<script setup lang="ts"> <script setup lang="ts">
import { getVoteprogress, voteMember } from '../../api/votingElection' import { getVoteprogress, voteMember } from '../../api/votingElection'
import useUserStore from '@/store/user' import useUserStore from '@/store/user'
const userStore = useUserStore() const userStore = useUserStore()
const xjList = ref({}) const xjList = ref<any>({})
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 const { data } = res as { data : { candidate : any[] } }
res.data.data = res.data.candidate xjList.value = data || {}
// 2. onSuccess({
delete res.data.candidate data: {
res.data.total = res.data.candidate?.length data: data.candidate || [],
const { data } = res as { data: { data: any; total: number } } total: (data.candidate || []).length
onSuccess({ data }) }
}) })
} })
}
const buttlist = ref([ const buttlist = ref([
{ {
type: '1', type: '1',
butname: '同意' butname: '同意'
@ -29,12 +31,12 @@ const buttlist = ref([
type: '3', type: '3',
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) {
const target = data.find((card: { id: any }) => card.id === cardid) const target = data.find((card : { id : any }) => card.id === cardid)
uni.showModal({ uni.showModal({
title: '您本轮选举投' + butname + '票', title: '您本轮选举投' + butname + '票',
content: '确定吗?', content: '确定吗?',
@ -50,18 +52,18 @@ const selectBut = (data: any, cardid: any, type: string, butname: string) => {
}) })
params.value.push(target) params.value.push(target)
} else { } else {
data.forEach((ele: { vote_result: number; id: any }) => { data.forEach((ele : { vote_result : number; id : any }) => {
ele.vote_result = 1 ele.vote_result = 1
}) })
} }
} }
const allChange = () => { const allChange = () => {
uni.showModal({ uni.showModal({
title: '您本轮选举全投同意票', title: '您本轮选举全投同意票',
content: '确定吗?', content: '确定吗?',
success: function (res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
xjList.value.data?.forEach((ele: { vote_result: number }) => { xjList.value.data?.forEach((ele : { vote_result : number }) => {
ele.vote_result = 1 ele.vote_result = 1
}) })
params.value = xjList.value.data params.value = xjList.value.data
@ -71,15 +73,15 @@ const allChange = () => {
} }
} }
}) })
} }
function extractTwoProps(arr: any, key1: string, key2: string) { function extractTwoProps(arr : any, key1 : string, key2 : string) {
return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({ return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({
[key1]: prop1, [key1]: prop1,
[key2]: prop2 [key2]: prop2
})) }))
} }
const submit = () => { const submit = () => {
let param = { let param = {
openid: userStore.openId, openid: userStore.openId,
id: xjList.value.id, id: xjList.value.id,
@ -96,19 +98,19 @@ const submit = () => {
console.log(res, 555555555555555) console.log(res, 555555555555555)
}) })
} }
} }
onShow(() => { onShow(() => {
if (userStore.mobile) { if (!userStore.mobile) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/login' url: '/pages/login/login'
}) })
} }
}) })
</script> </script>
<template> <template>
<!-- 你的页面内容 --> <!-- 你的页面内容 -->
<view class="box"> <view class="box" v-if="xjList.length != 0">
<view class="headpart"> <view class="headpart">
<view class="title">{{ xjList.title }}</view> <view class="title">{{ xjList.title }}</view>
<view class="time">投票开始时间{{ xjList.start_time }}</view> <view class="time">投票开始时间{{ xjList.start_time }}</view>
@ -130,13 +132,9 @@ onShow(() => {
</view> </view>
</view> </view>
<view class="bottomp"> <view class="bottomp">
<view <view class="minbut" v-for="(item, ele) in buttlist" :key="ele"
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>
@ -149,10 +147,16 @@ onShow(() => {
<view class="tjtp" @click="submit">提交投票</view> <view class="tjtp" @click="submit">提交投票</view>
</view> </view>
</view> </view>
<view style="display: grid;align-items: center;justify-content: center;width: 100%;height: 100vh;align-content: center;" v-else>
<img style="width: 188px;height: 140px;" src="@/static/img/Group.png" alt="" />
<text class="nodata">
暂时没有选举 请刷新重试
</text>
</view>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.box { .box {
width: 100%; width: 100%;
background-color: #f9fafb; background-color: #f9fafb;
@ -382,5 +386,13 @@ onShow(() => {
bottom: 0; bottom: 0;
border-top: 2rpx solid #ebebec; border-top: 2rpx solid #ebebec;
} }
} }
.nodata {
margin-top: 43px;
font-family: Source Han Sans;
font-size: 18px;
font-weight: 500;
letter-spacing: normal;
color: #34343F;
}
</style> </style>

BIN
src/static/img/Group.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Loading…
Cancel
Save