feat(积分详情): 优化积分列表查询和显示逻辑
添加积分状态参数支持按类型筛选积分记录 使用API返回的创建时间替代当前时间显示 移除计算属性改用watch监听tab切换自动刷新
Showing
2 changed files
with
31 additions
and
26 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2023-12-22 10:29:37 | 2 | * @Date: 2023-12-22 10:29:37 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-03 18:10:03 | 4 | + * @LastEditTime: 2025-09-04 10:09:32 |
| 5 | * @FilePath: /lls_program/src/api/points.js | 5 | * @FilePath: /lls_program/src/api/points.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -36,6 +36,7 @@ export const collectPointAPI = (params) => fn(fetch.post(Api.COLLECT_POINT, para | ... | @@ -36,6 +36,7 @@ export const collectPointAPI = (params) => fn(fetch.post(Api.COLLECT_POINT, para |
| 36 | /** | 36 | /** |
| 37 | * @description: 查询积分列表 | 37 | * @description: 查询积分列表 |
| 38 | * @param {Object} params - 请求参数 | 38 | * @param {Object} params - 请求参数 |
| 39 | + * @param {string} [params.points_status] - 积分状态, issued=已发放,used=已消耗 | ||
| 39 | * @param {string} [params.page] - 页码,从0开始,默认为0 | 40 | * @param {string} [params.page] - 页码,从0开始,默认为0 |
| 40 | * @param {string} [params.limit] - 每页数量,默认为10 | 41 | * @param {string} [params.limit] - 每页数量,默认为10 |
| 41 | * @returns {Object} response - 响应对象 | 42 | * @returns {Object} response - 响应对象 |
| ... | @@ -46,9 +47,9 @@ export const collectPointAPI = (params) => fn(fetch.post(Api.COLLECT_POINT, para | ... | @@ -46,9 +47,9 @@ export const collectPointAPI = (params) => fn(fetch.post(Api.COLLECT_POINT, para |
| 46 | * @returns {Array} response.data.logs - 积分日志列表 | 47 | * @returns {Array} response.data.logs - 积分日志列表 |
| 47 | * @returns {number} response.data.logs[].id - 积分日志ID | 48 | * @returns {number} response.data.logs[].id - 积分日志ID |
| 48 | * @returns {string} response.data.logs[].points_change - 积分变化 | 49 | * @returns {string} response.data.logs[].points_change - 积分变化 |
| 49 | - * @returns {string} response.data.logs[].balance_after - 最新的家庭积分 | ||
| 50 | * @returns {string} response.data.logs[].log_type - 日志类型 | 50 | * @returns {string} response.data.logs[].log_type - 日志类型 |
| 51 | * @returns {string} response.data.logs[].source_type - 积分来源类型 | 51 | * @returns {string} response.data.logs[].source_type - 积分来源类型 |
| 52 | * @returns {string} response.data.logs[].note - 备注 | 52 | * @returns {string} response.data.logs[].note - 备注 |
| 53 | + * @returns {string} response.data.logs[].created_time - 创建时间 | ||
| 53 | */ | 54 | */ |
| 54 | export const getPointListAPI = (params) => fn(fetch.get(Api.POINT_LIST, params)); | 55 | export const getPointListAPI = (params) => fn(fetch.get(Api.POINT_LIST, params)); | ... | ... |
| ... | @@ -71,25 +71,26 @@ | ... | @@ -71,25 +71,26 @@ |
| 71 | </view> | 71 | </view> |
| 72 | <!-- Points history list --> | 72 | <!-- Points history list --> |
| 73 | <view class="pt-4"> | 73 | <view class="pt-4"> |
| 74 | - <!-- Loading state --> | 74 | + <view v-if="loading"> |
| 75 | - <view v-if="loading && pointsHistory.length === 0" class="py-8 text-center text-gray-500"> | 75 | + <view class="py-8 text-center text-gray-500"> |
| 76 | - 加载中... | 76 | + 加载中... |
| 77 | - </view> | 77 | + </view> |
| 78 | - <!-- Empty state --> | ||
| 79 | - <view v-else-if="!loading && filteredPoints.length === 0" class="py-8 text-center text-gray-500"> | ||
| 80 | - 暂无积分记录 | ||
| 81 | </view> | 78 | </view> |
| 82 | - <!-- Points list --> | ||
| 83 | <view v-else> | 79 | <view v-else> |
| 84 | - <view v-for="item in filteredPoints" :key="item.id" class="py-4 border-b border-gray-100 flex justify-between"> | 80 | + <view v-if="pointsHistory && pointsHistory.length > 0"> |
| 85 | - <view> | 81 | + <view v-for="item in pointsHistory" :key="item.id" class="py-4 border-b border-gray-100 flex justify-between"> |
| 86 | - <h4 class="font-medium">{{ item.title }}</h4> | 82 | + <view> |
| 87 | - <p class="text-sm text-gray-500">{{ item.date }}</p> | 83 | + <h4 class="font-medium">{{ item.title }}</h4> |
| 84 | + <p class="text-sm text-gray-500">{{ item.date }}</p> | ||
| 85 | + </view> | ||
| 86 | + <span :class="['font-medium', item.type === 'earned' ? 'text-green-500' : 'text-red-500']"> | ||
| 87 | + {{ item.type === 'earned' ? '+' : '-' }} | ||
| 88 | + {{ item.points }} | ||
| 89 | + </span> | ||
| 88 | </view> | 90 | </view> |
| 89 | - <span :class="['font-medium', item.type === 'earned' ? 'text-green-500' : 'text-red-500']"> | 91 | + </view> |
| 90 | - {{ item.type === 'earned' ? '+' : '-' }} | 92 | + <view v-else class="py-8 text-center text-gray-500"> |
| 91 | - {{ item.points }} | 93 | + 暂无积分记录 |
| 92 | - </span> | ||
| 93 | </view> | 94 | </view> |
| 94 | </view> | 95 | </view> |
| 95 | </view> | 96 | </view> |
| ... | @@ -100,7 +101,7 @@ | ... | @@ -100,7 +101,7 @@ |
| 100 | </template> | 101 | </template> |
| 101 | 102 | ||
| 102 | <script setup> | 103 | <script setup> |
| 103 | -import { ref, computed, onMounted } from 'vue'; | 104 | +import { ref, computed, onMounted, watch } from 'vue'; |
| 104 | import Taro, { useDidShow } from '@tarojs/taro'; | 105 | import Taro, { useDidShow } from '@tarojs/taro'; |
| 105 | import AppHeader from '../../components/AppHeader.vue'; | 106 | import AppHeader from '../../components/AppHeader.vue'; |
| 106 | import BottomNav from '../../components/BottomNav.vue'; | 107 | import BottomNav from '../../components/BottomNav.vue'; |
| ... | @@ -112,7 +113,7 @@ const pointsHistory = ref([]); | ... | @@ -112,7 +113,7 @@ const pointsHistory = ref([]); |
| 112 | const totalPoints = ref(0); | 113 | const totalPoints = ref(0); |
| 113 | const loading = ref(false); | 114 | const loading = ref(false); |
| 114 | const page = ref(0); | 115 | const page = ref(0); |
| 115 | -const limit = ref(20); | 116 | +const limit = ref(9999); |
| 116 | const hasMore = ref(true); | 117 | const hasMore = ref(true); |
| 117 | 118 | ||
| 118 | /** | 119 | /** |
| ... | @@ -135,6 +136,12 @@ const fetchPointsList = async (isRefresh = false) => { | ... | @@ -135,6 +136,12 @@ const fetchPointsList = async (isRefresh = false) => { |
| 135 | limit: limit.value.toString() | 136 | limit: limit.value.toString() |
| 136 | }; | 137 | }; |
| 137 | 138 | ||
| 139 | + if (activeTab.value === 'earned') { | ||
| 140 | + params.points_status = 'issued'; | ||
| 141 | + } else if (activeTab.value === 'spent') { | ||
| 142 | + params.points_status = 'used'; | ||
| 143 | + } | ||
| 144 | + | ||
| 138 | const response = await getPointListAPI(params); | 145 | const response = await getPointListAPI(params); |
| 139 | 146 | ||
| 140 | if (response.code && response.data) { | 147 | if (response.code && response.data) { |
| ... | @@ -146,7 +153,7 @@ const fetchPointsList = async (isRefresh = false) => { | ... | @@ -146,7 +153,7 @@ const fetchPointsList = async (isRefresh = false) => { |
| 146 | const formattedLogs = logs.map(log => ({ | 153 | const formattedLogs = logs.map(log => ({ |
| 147 | id: log.id, | 154 | id: log.id, |
| 148 | title: log.note || '积分变动', | 155 | title: log.note || '积分变动', |
| 149 | - date: formatDate(new Date()), // API没有返回时间,使用当前时间 | 156 | + date: formatDate(new Date(log.created_time)), |
| 150 | points: Math.abs(parseInt(log.points_change) || 0), | 157 | points: Math.abs(parseInt(log.points_change) || 0), |
| 151 | type: parseInt(log.points_change) > 0 ? 'earned' : 'spent', | 158 | type: parseInt(log.points_change) > 0 ? 'earned' : 'spent', |
| 152 | log_type: log.log_type, | 159 | log_type: log.log_type, |
| ... | @@ -190,11 +197,8 @@ const formatDate = (date) => { | ... | @@ -190,11 +197,8 @@ const formatDate = (date) => { |
| 190 | return `${year}-${month}-${day} ${hours}:${minutes}`; | 197 | return `${year}-${month}-${day} ${hours}:${minutes}`; |
| 191 | }; | 198 | }; |
| 192 | 199 | ||
| 193 | -const filteredPoints = computed(() => { | 200 | +watch(activeTab, () => { |
| 194 | - if (activeTab.value === 'all') { | 201 | + fetchPointsList(true); |
| 195 | - return pointsHistory.value; | ||
| 196 | - } | ||
| 197 | - return pointsHistory.value.filter(p => p.type === activeTab.value); | ||
| 198 | }); | 202 | }); |
| 199 | 203 | ||
| 200 | const handleViewAll = () => { | 204 | const handleViewAll = () => { | ... | ... |
-
Please register or login to post a comment