渲染捐款日期

This commit is contained in:
WindowBird 2025-09-16 10:00:58 +08:00
parent d9c0d1d4e4
commit 6e07867bcd
2 changed files with 130 additions and 128 deletions

View File

@ -6,7 +6,7 @@
<text class="header-item">捐款金额()</text> <text class="header-item">捐款金额()</text>
<text class="header-item">捐款时间</text> <text class="header-item">捐款时间</text>
</view> </view>
<view class="list-item" v-for="(item, index) in donationList" :key="index"> <view v-for="(item, index) in donationList" :key="index" class="list-item">
<text class="item-id">{{ item.id }}</text> <text class="item-id">{{ item.id }}</text>
<text class="item-name">{{ item.name }}</text> <text class="item-name">{{ item.name }}</text>
<text class="item-amount">{{ item.amount.toLocaleString() }}</text> <text class="item-amount">{{ item.amount.toLocaleString() }}</text>
@ -16,78 +16,78 @@
</template> </template>
<script> <script>
export default { export default {
name: 'DonationList', name: "DonationList",
props: { props: {
donationList: { donationList: {
type: Array, type: Array,
default: () => [], default: () => [],
},
}, },
} },
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.donation-list { .donation-list {
width: 100%; width: 100%;
border-radius: 16rpx; border-radius: 16rpx;
overflow: hidden; overflow: hidden;
padding-bottom: 106rpx; padding-bottom: 106rpx;
} }
.list-header { .list-header {
display: flex; display: flex;
padding: 28rpx 15rpx; padding: 28rpx 15rpx;
} }
.header-item { .header-item {
flex: 1; flex: 1;
font-size: 30rpx; font-size: 30rpx;
color: #643b27; color: #643b27;
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
} }
.list-item { .list-item {
display: flex; display: flex;
padding: 28rpx 20rpx; padding: 28rpx 20rpx;
} }
.list-item:hover { .list-item:hover {
background: #fafafa; background: #fafafa;
} }
.list-item:last-child { .list-item:last-child {
border-bottom: none; border-bottom: none;
} }
.item-id, .item-id,
.item-name, .item-name,
.item-amount, .item-amount,
.item-time { .item-time {
flex: 1; flex: 1;
font-size: 28rpx; font-size: 28rpx;
text-align: center; text-align: center;
line-height: 1.5; line-height: 1.5;
} }
.item-id { .item-id {
color: #666; color: #666;
font-weight: 500; font-weight: 500;
} }
.item-name { .item-name {
color: #333; color: #333;
font-weight: 500; font-weight: 500;
} }
.item-amount { .item-amount {
color: #e74c3c; color: #e74c3c;
font-weight: bold; font-weight: bold;
} }
.item-time { .item-time {
color: #666; color: #666;
font-size: 26rpx; font-size: 26rpx;
} }
</style> </style>

View File

@ -3,9 +3,9 @@
* 提供捐款记录的数据获取搜索分页等功能 * 提供捐款记录的数据获取搜索分页等功能
* 基于重构后的 data-manager.js * 基于重构后的 data-manager.js
*/ */
import { dataManagerMixin } from './data-manager.js' import { dataManagerMixin } from "./data-manager.js";
import { getDonorList } from '@/api/donor/donor.js' import { getDonorList } from "@/api/donor/donor.js";
import { getInstitutionalDetail } from '@/api/institutionalStructure/institutionalStructureDetail.js' import { getInstitutionalDetail } from "@/api/institutionalStructure/institutionalStructureDetail.js";
export const donationMixin = { export const donationMixin = {
mixins: [dataManagerMixin], mixins: [dataManagerMixin],
@ -15,22 +15,23 @@ export const donationMixin = {
// 项目信息 // 项目信息
projectInfo: {}, projectInfo: {},
// 搜索关键词 // 搜索关键词
searchKeyword: '', searchKeyword: "",
// 项目ID // 项目ID
formedId: '', formedId: "",
} };
}, },
computed: { computed: {
// 计算总造价(从项目详情获取,如果没有则计算捐款总和) // 计算总造价(从项目详情获取,如果没有则计算捐款总和)
totalAmount() { totalAmount() {
return ( return (
this.projectInfo.totalAmount || this.dataList.reduce((sum, item) => sum + item.amount, 0) this.projectInfo.totalAmount ||
) this.dataList.reduce((sum, item) => sum + item.amount, 0)
);
}, },
// 计算参与捐款人次(从项目详情获取,如果没有则计算捐款记录数量) // 计算参与捐款人次(从项目详情获取,如果没有则计算捐款记录数量)
participantCount() { participantCount() {
return this.projectInfo.donorCount || this.dataList.length return this.projectInfo.donorCount || this.dataList.length;
}, },
}, },
@ -40,25 +41,25 @@ export const donationMixin = {
*/ */
async loadProjectInfo() { async loadProjectInfo() {
if (!this.formedId) { if (!this.formedId) {
console.error('缺少项目ID') console.error("缺少项目ID");
return return;
} }
try { try {
const response = await getInstitutionalDetail(this.formedId) const response = await getInstitutionalDetail(this.formedId);
console.log('项目详情API响应:', response) console.log("项目详情API响应:", response);
if (response.code === 200) { if (response.code === 200) {
if (response.data) { if (response.data) {
this.projectInfo = response.data this.projectInfo = response.data;
console.log('使用 response.data 作为项目信息') console.log("使用 response.data 作为项目信息");
} }
} }
} catch (error) { } catch (error) {
console.error('获取项目信息失败:', error) console.error("获取项目信息失败:", error);
uni.showToast({ uni.showToast({
title: '网络错误', title: "网络错误",
icon: 'none', icon: "none",
}) });
} }
}, },
@ -66,12 +67,13 @@ export const donationMixin = {
* 捐款记录数据转换器 * 捐款记录数据转换器
*/ */
transformDonationData(dataArray) { transformDonationData(dataArray) {
return dataArray.map(item => ({ return dataArray.map((item) => ({
id: item.id, id: item.id,
name: item.realName, name: item.realName,
amount: item.amount, amount: item.amount,
time: this.formatDate(item.donationDate), // time: this.formatDate(item.donationDate),
})) time: this.formatDate(item.createTime),
}));
}, },
/** /**
@ -80,12 +82,12 @@ export const donationMixin = {
* @returns {string} 格式化后的日期 * @returns {string} 格式化后的日期
*/ */
formatDate(dateStr) { formatDate(dateStr) {
if (!dateStr) return '' if (!dateStr) return "";
const date = new Date(dateStr) const date = new Date(dateStr);
const year = date.getFullYear() const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0') const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, '0') const day = String(date.getDate()).padStart(2, "0");
return `${year}/${month}/${day}` return `${year}/${month}/${day}`;
}, },
/** /**
@ -96,38 +98,38 @@ export const donationMixin = {
formedId: this.formedId, formedId: this.formedId,
minAmount: 1, minAmount: 1,
maxAmount: 10000, maxAmount: 10000,
sortAmount: 'amount', sortAmount: "amount",
orderAmount: 'asc', orderAmount: "asc",
sortTime: 'time', sortTime: "time",
orderTime: 'desc', orderTime: "desc",
} };
}, },
/** /**
* 获取捐款记录 * 获取捐款记录
* @param {string} keyword 搜索关键词 * @param {string} keyword 搜索关键词
*/ */
async loadDonationRecords(keyword = '') { async loadDonationRecords(keyword = "") {
const baseParams = this.getBaseParams() const baseParams = this.getBaseParams();
// 如果有搜索关键词,添加姓名搜索 // 如果有搜索关键词,添加姓名搜索
if (keyword) { if (keyword) {
baseParams.realName = keyword baseParams.realName = keyword;
} }
await this.refreshData({ await this.refreshData({
apiCall: getDonorList, apiCall: getDonorList,
dataTransformer: this.transformDonationData, dataTransformer: this.transformDonationData,
params: baseParams, params: baseParams,
dataPath: 'data.list.rows', dataPath: "data.list.rows",
totalPath: 'data.total', totalPath: "data.total",
onSuccess: (data, response) => { onSuccess: (data, response) => {
console.log('捐款记录加载成功:', data.length, '条') console.log("捐款记录加载成功:", data.length, "条");
}, },
onError: errorMsg => { onError: (errorMsg) => {
console.error('捐款记录加载失败:', errorMsg) console.error("捐款记录加载失败:", errorMsg);
}, },
}) });
}, },
/** /**
@ -135,44 +137,44 @@ export const donationMixin = {
* @param {string} val 搜索关键词 * @param {string} val 搜索关键词
*/ */
async onSearch(val) { async onSearch(val) {
this.searchKeyword = val this.searchKeyword = val;
await this.searchData( await this.searchData(
{ ...this.getBaseParams(), realName: val }, { ...this.getBaseParams(), realName: val },
{ {
apiCall: getDonorList, apiCall: getDonorList,
dataTransformer: this.transformDonationData, dataTransformer: this.transformDonationData,
dataPath: 'data.list.rows', dataPath: "data.list.rows",
totalPath: 'data.total', totalPath: "data.total",
onSuccess: (data, response) => { onSuccess: (data, response) => {
console.log('搜索完成,找到:', data.length, '条记录') console.log("搜索完成,找到:", data.length, "条记录");
}, },
} },
) );
}, },
/** /**
* 筛选功能 * 筛选功能
*/ */
onFilter() { onFilter() {
uni.showToast({ title: '筛选功能开发中', icon: 'none' }) uni.showToast({ title: "筛选功能开发中", icon: "none" });
}, },
/** /**
* 加载更多捐款记录 * 加载更多捐款记录
*/ */
async loadMoreDonationRecords() { async loadMoreDonationRecords() {
const currentParams = this.getDataState().currentParams const currentParams = this.getDataState().currentParams;
await this.loadMoreData({ await this.loadMoreData({
apiCall: getDonorList, apiCall: getDonorList,
dataTransformer: this.transformDonationData, dataTransformer: this.transformDonationData,
params: currentParams, params: currentParams,
dataPath: 'data.list.rows', dataPath: "data.list.rows",
totalPath: 'data.total', totalPath: "data.total",
onSuccess: (data, response) => { onSuccess: (data, response) => {
console.log('加载更多完成,新增:', data.length, '条记录') console.log("加载更多完成,新增:", data.length, "条记录");
}, },
}) });
}, },
/** /**
@ -180,19 +182,19 @@ export const donationMixin = {
* @param {string} formedId 建制ID * @param {string} formedId 建制ID
*/ */
async initData(formedId) { async initData(formedId) {
console.log('初始化捐款记录数据, formedId:', formedId) console.log("初始化捐款记录数据, formedId:", formedId);
try { try {
this.formedId = formedId this.formedId = formedId;
await this.loadProjectInfo() await this.loadProjectInfo();
await this.loadDonationRecords() await this.loadDonationRecords();
console.log('捐款记录数据初始化完成') console.log("捐款记录数据初始化完成");
} catch (error) { } catch (error) {
console.error('初始化捐款记录数据失败:', error) console.error("初始化捐款记录数据失败:", error);
uni.showToast({ uni.showToast({
title: '初始化数据失败', title: "初始化数据失败",
icon: 'none', icon: "none",
}) });
} }
}, },
@ -200,15 +202,15 @@ export const donationMixin = {
* 重置搜索 * 重置搜索
*/ */
resetSearch() { resetSearch() {
this.searchKeyword = '' this.searchKeyword = "";
this.loadDonationRecords() this.loadDonationRecords();
}, },
/** /**
* 刷新数据 * 刷新数据
*/ */
async refreshDonationData() { async refreshDonationData() {
await this.loadDonationRecords(this.searchKeyword) await this.loadDonationRecords(this.searchKeyword);
}, },
}, },
} };