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