hookehuyr

✨ feat(幼儿园捐赠排行榜): API联调

1 +/*
2 + * @Author: hookehuyr hookehuyr@gmail.com
3 + * @Date: 2022-05-18 21:12:23
4 + * @LastEditors: hookehuyr hookehuyr@gmail.com
5 + * @LastEditTime: 2022-06-01 11:06:29
6 + * @FilePath: /tswj/src/api/C/kg.js
7 + * @Description: 幼儿园相关接口
8 + */
1 import { fn, fetch } from '@/api/fn'; 9 import { fn, fetch } from '@/api/fn';
2 10
3 const Api = { 11 const Api = {
4 KG_LIST: '/srv/?a=kg_list', 12 KG_LIST: '/srv/?a=kg_list',
13 + KG_DONATE_LIST: '/srv/?a=donate_list',
5 } 14 }
6 15
7 /** 16 /**
...@@ -10,3 +19,12 @@ const Api = { ...@@ -10,3 +19,12 @@ const Api = {
10 * @returns {array} data 19 * @returns {array} data
11 */ 20 */
12 export const kgListAPI = (params) => fn(fetch.get(Api.KG_LIST, params)); 21 export const kgListAPI = (params) => fn(fetch.get(Api.KG_LIST, params));
22 +
23 +/**
24 + * @description 幼儿园捐赠列表页
25 + * @param {*} kg_id 幼儿园ID
26 + * @param {*} limit 20
27 + * @param {*} offset 0
28 + * @returns {array} data
29 + */
30 +export const kgDonateListAPI = (params) => fn(fetch.get(Api.KG_DONATE_LIST, params));
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
2 * @Author: hookehuyr hookehuyr@gmail.com 2 * @Author: hookehuyr hookehuyr@gmail.com
3 * @Date: 2022-05-30 13:51:47 3 * @Date: 2022-05-30 13:51:47
4 * @LastEditors: hookehuyr hookehuyr@gmail.com 4 * @LastEditors: hookehuyr hookehuyr@gmail.com
5 - * @LastEditTime: 2022-05-31 17:45:22 5 + * @LastEditTime: 2022-06-01 15:02:10
6 * @FilePath: /tswj/src/views/client/donateList.vue 6 * @FilePath: /tswj/src/views/client/donateList.vue
7 * @Description: 幼儿园捐赠人捐赠金额排行榜 7 * @Description: 幼儿园捐赠人捐赠金额排行榜
8 --> 8 -->
9 <template> 9 <template>
10 <div class="wrapper"> 10 <div class="wrapper">
11 <van-row> 11 <van-row>
12 - <van-col span="20" style="padding: 1rem 0.5rem 1rem 0;"> 12 + <van-col span="18" style="padding: 1rem 0.5rem 1rem 0;">
13 <div :class="[kgInfo.multi_name ? 'heightHigh' : 'heightLow', 'kg-name']"> 13 <div :class="[kgInfo.multi_name ? 'heightHigh' : 'heightLow', 'kg-name']">
14 <van-row align="center" justify="center" style="position: relative; top: 50%; transform: translateY(-50%);"> 14 <van-row align="center" justify="center" style="position: relative; top: 50%; transform: translateY(-50%);">
15 <van-col span="4"> 15 <van-col span="4">
16 - <van-image round width="4rem" height="4rem" :src="kgInfo.avatar ? kgInfo.avatar : icon_avatar" style="vertical-align: text-bottom;" /> 16 + <van-image round width="4rem" height="4rem" :src="kgInfo.kg_logo ? kgInfo.kg_logo : icon_logo" style="vertical-align: text-bottom;" />
17 </van-col> 17 </van-col>
18 <van-col span="20"> 18 <van-col span="20">
19 <div v-if="kgInfo.multi_name" style="margin-left: 1.5rem;"> 19 <div v-if="kgInfo.multi_name" style="margin-left: 1.5rem;">
...@@ -21,84 +21,102 @@ ...@@ -21,84 +21,102 @@
21 <p>{{ kgInfo.multi_name[1] }}</p> 21 <p>{{ kgInfo.multi_name[1] }}</p>
22 </div> 22 </div>
23 <p v-else style="margin-left: 1.5rem;"> 23 <p v-else style="margin-left: 1.5rem;">
24 - {{ kgInfo.name }} 24 + {{ kgInfo.kg_name }}
25 </p> 25 </p>
26 </van-col> 26 </van-col>
27 </van-row> 27 </van-row>
28 </div> 28 </div>
29 </van-col> 29 </van-col>
30 - <van-col span="4"> 30 + <van-col span="6">
31 <div class="flower"> 31 <div class="flower">
32 - <van-icon :name="icon_flower" color="#c5c5c5" size="1.5rem" style="vertical-align: bottom;" />&nbsp;3000 32 + <van-icon :name="icon_flower" color="#c5c5c5" size="1.5rem" style="vertical-align: bottom;" />&nbsp;{{ kgInfo.kg_total }}
33 - </div>
34 - </van-col>
35 - </van-row>
36 - </div>
37 - <div class="van-hairline--bottom">
38 - <van-row style="padding: 0.5rem 1rem;">
39 - <van-col span="4">
40 - <van-image v-if="info.avatar" round width="3rem" height="3rem" :src="info.avatar ? info.avatar : icon_avatar" />
41 - </van-col>
42 - <van-col span="16">
43 - <div class="name-info" style="position: relative; top: 50%; transform: translateY(-50%);">
44 - <p>{{ info.name }}</p>
45 - <p style="color: #C5C5C5;">2022-05-27</p>
46 - </div>
47 - </van-col>
48 - <van-col span="4" style="text-align: right; font-size: 1rem;">
49 - <div style="color: #222222;position: relative; top: 50%; transform: translateY(-50%);">
50 - <van-icon style="vertical-align: top;" size="1.25rem" :name="icon_flower" />
51 - <span>&nbsp;2</span>
52 </div> 33 </div>
53 </van-col> 34 </van-col>
54 </van-row> 35 </van-row>
55 </div> 36 </div>
37 + <van-list v-model:loading="loading" :finished="finished" :finished-text="finishedTextStatus ? '没有更多了' : ''" :immediate-check="false" @load="onLoad">
38 + <template v-for="(item, key) in donateList" :key="key">
39 + <div class="van-hairline--bottom">
40 + <van-row style="padding: 0.5rem 1rem;">
41 + <van-col span="4">
42 + <van-image round width="3rem" height="3rem" :src="item.avatar ? item.avatar : icon_avatar" />
43 + </van-col>
44 + <van-col span="14">
45 + <div class="name-info glob-center">
46 + <p>{{ item.name }}</p>
47 + <p style="color: #C5C5C5;">{{ item.donate_time }}</p>
48 + </div>
49 + </van-col>
50 + <van-col span="6" style="color: #222222; text-align: right; font-size: 1rem;">
51 + <div class="glob-center">
52 + <van-icon style="vertical-align: top;" size="1.25rem" :name="icon_flower" />
53 + <span>&nbsp;2</span>
54 + </div>
55 + </van-col>
56 + </van-row>
57 + </div>
58 + </template>
59 + </van-list>
60 + <van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无明细" />
56 </template> 61 </template>
57 62
58 <script setup> 63 <script setup>
59 -import { ref } from 'vue' 64 +import { onMounted, ref } from 'vue'
60 import { useRoute, useRouter } from 'vue-router' 65 import { useRoute, useRouter } from 'vue-router'
61 import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' 66 import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
62 //import { } from '@/utils/generateModules.js' 67 //import { } from '@/utils/generateModules.js'
63 -import { icon_avatar, icon_ranking1, icon_ranking2, icon_ranking3, icon_flower } from '@/utils/generateIcons.js' 68 +import { icon_avatar, no_image, icon_flower, icon_logo } from '@/utils/generateIcons.js'
64 //import { } from '@/composables' 69 //import { } from '@/composables'
70 +import { kgDonateListAPI } from '@/api/C/kg.js'
71 +
65 const $route = useRoute(); 72 const $route = useRoute();
66 const $router = useRouter(); 73 const $router = useRouter();
67 useTitle($route.meta.title); 74 useTitle($route.meta.title);
68 75
69 -const info = ref({ 76 +const kgInfo = ref({});
70 - avatar: 'https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng76a8e87552945e0800cea4e5eb14ff2175cc7816e6acb5c79d714793c82d37f5', 77 +const kg_id = $route.query.kg_id;
71 - name: '杨妮妮' 78 +const donateList = ref([])
72 -}, { 79 +const loading = ref(false)
73 - avatar: 'https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng76a8e87552945e0800cea4e5eb14ff2175cc7816e6acb5c79d714793c82d37f5', 80 +const finished = ref(false)
74 - name: '杨妮妮' 81 +const limit = ref(10)
75 -}, { 82 +const offset = ref(0)
76 - avatar: 'https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng76a8e87552945e0800cea4e5eb14ff2175cc7816e6acb5c79d714793c82d37f5', 83 +const finishedTextStatus = ref(false);
77 - name: '杨妮妮' 84 +const emptyStatus = ref(false);
78 -}, {
79 - avatar: 'https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng76a8e87552945e0800cea4e5eb14ff2175cc7816e6acb5c79d714793c82d37f5',
80 - name: '杨妮妮'
81 -}, {
82 - avatar: 'https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng76a8e87552945e0800cea4e5eb14ff2175cc7816e6acb5c79d714793c82d37f5',
83 - name: '杨妮妮'
84 -})
85 85
86 -const kgInfo = ref({ 86 +onMounted(async () => {
87 - name: '杨浦民办科技幼稚园', 87 + const { data } = await kgDonateListAPI({ kg_id, limit: limit.value, offset: offset.value });
88 - multi_name: '', 88 + kgInfo.value = data;
89 - avatar: '', 89 + donateList.value = data.donate_list;
90 + offset.value = donateList.value.length;
91 + // 有空格分割name
92 + if (kgInfo.value.kg_name.indexOf(' ') > -1) {
93 + kgInfo.value.multi_name = kgInfo.value.kg_name.split(' ');
94 + }
90 }) 95 })
91 -// TEMP: 测试数据 96 +
92 -// kgInfo.value.name = kgInfo.value.name + ' ' + kgInfo.value.name; 97 +
93 -// 有空格分割name 98 +const onLoad = async () => {
94 -if (kgInfo.value.name.indexOf(' ') > -1) { 99 + const { data } = await kgDonateListAPI({ kg_id, limit: limit.value, offset: offset.value });
95 - kgInfo.value.multi_name = kgInfo.value.name.split(' '); 100 + donateList.value = [...donateList.value, ...data.donate_list];
101 + // donateList.value = _.uniqBy(donateList.value, 'id');
102 + offset.value = donateList.value.length;
103 + loading.value = false;
104 + // 数据全部加载完成
105 + if (!data.donate_list.length) {
106 + // 加载状态结束
107 + finished.value = true;
108 + }
109 + if (!donateList.value.length) {
110 + finishedTextStatus.value = false;
111 + emptyStatus.value = true;
112 + }
96 } 113 }
97 </script> 114 </script>
98 115
99 <style lang="less" scoped> 116 <style lang="less" scoped>
100 .wrapper { 117 .wrapper {
101 - padding: 0 2rem 0 0.5rem; 118 + padding-left: 0.5rem;
119 + padding-right: 1rem;
102 background-color: #F7F7F7; 120 background-color: #F7F7F7;
103 position: relative; 121 position: relative;
104 122
...@@ -123,6 +141,7 @@ if (kgInfo.value.name.indexOf(' ') > -1) { ...@@ -123,6 +141,7 @@ if (kgInfo.value.name.indexOf(' ') > -1) {
123 text-align: center; 141 text-align: center;
124 position: absolute; 142 position: absolute;
125 top: 40%; 143 top: 40%;
144 + right: 1rem;
126 color: #713610; 145 color: #713610;
127 font-size: 1.25rem; 146 font-size: 1.25rem;
128 } 147 }
......