2025-08-01 16:01:58 +08:00
|
|
|
/**
|
|
|
|
|
* 捐款记录相关 Mixin
|
|
|
|
|
* 提供捐款记录的数据获取、搜索、分页等功能
|
|
|
|
|
*/
|
|
|
|
|
import { getDonorList } from '@/api/donor/donor.js'
|
|
|
|
|
import { getInstitutionalDetail } from '@/api/institutionalStructure/institutionalStructureDetail.js'
|
|
|
|
|
|
|
|
|
|
export const donationMixin = {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
// 捐款记录相关数据
|
|
|
|
|
donationList: [],
|
|
|
|
|
projectInfo: {},
|
|
|
|
|
loading: false,
|
|
|
|
|
searchKeyword: '',
|
|
|
|
|
formedId: '',
|
|
|
|
|
// 分页参数
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
hasMore: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
|
// 计算总造价(从项目详情获取,如果没有则计算捐款总和)
|
|
|
|
|
totalAmount() {
|
|
|
|
|
return this.projectInfo.totalAmount || this.donationList.reduce((sum, item) => sum + item.amount, 0)
|
|
|
|
|
},
|
|
|
|
|
// 计算参与捐款人次(从项目详情获取,如果没有则计算捐款记录数量)
|
|
|
|
|
participantCount() {
|
|
|
|
|
return this.projectInfo.donorCount || this.donationList.length
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
/**
|
|
|
|
|
* 获取项目详情
|
|
|
|
|
*/
|
|
|
|
|
async loadProjectInfo() {
|
|
|
|
|
if (!this.formedId) {
|
|
|
|
|
console.error('缺少项目ID')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await getInstitutionalDetail(this.formedId)
|
2025-08-02 11:14:12 +08:00
|
|
|
console.log('项目详情API响应:', response)
|
2025-08-01 16:01:58 +08:00
|
|
|
if (response.code === 200) {
|
2025-08-02 11:14:12 +08:00
|
|
|
if (response.data) {
|
|
|
|
|
this.projectInfo = response.data
|
|
|
|
|
console.log('使用 response.data 作为项目信息')
|
|
|
|
|
}
|
2025-08-01 16:01:58 +08:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取项目信息失败:', error)
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '网络错误',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 获取捐款记录
|
|
|
|
|
* @param {string} keyword 搜索关键词
|
|
|
|
|
*/
|
|
|
|
|
async loadDonationRecords(keyword = '') {
|
|
|
|
|
this.loading = true
|
|
|
|
|
try {
|
|
|
|
|
const params = {
|
|
|
|
|
formedId: this.formedId,
|
|
|
|
|
pageNum: this.pageNum,
|
|
|
|
|
pageSize: this.pageSize,
|
|
|
|
|
minAmount: 1,
|
|
|
|
|
maxAmount: 10000,
|
|
|
|
|
sortAmount: 'amount',
|
|
|
|
|
orderAmount: 'asc',
|
|
|
|
|
sortTime: 'time',
|
|
|
|
|
orderTime: 'desc'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果有搜索关键词,添加姓名搜索
|
|
|
|
|
if (keyword) {
|
|
|
|
|
params.realName = keyword
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = await getDonorList(params)
|
2025-08-02 11:14:12 +08:00
|
|
|
console.log('捐款记录API响应:', response)
|
2025-08-01 16:01:58 +08:00
|
|
|
|
|
|
|
|
if (response.code === 200) {
|
2025-08-02 11:14:12 +08:00
|
|
|
// 根据实际后端数据结构获取数据数组
|
2025-08-06 18:00:59 +08:00
|
|
|
let dataArray = response.data.list.rows
|
2025-08-02 11:14:12 +08:00
|
|
|
|
2025-08-01 16:01:58 +08:00
|
|
|
// 转换数据格式
|
2025-08-02 11:14:12 +08:00
|
|
|
const newData = dataArray.map(item => ({
|
2025-08-01 16:01:58 +08:00
|
|
|
id: item.id,
|
|
|
|
|
name: item.realName,
|
|
|
|
|
amount: item.amount,
|
|
|
|
|
time: this.formatDate(item.donationDate)
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
// 如果是第一页,直接替换数据
|
|
|
|
|
if (this.pageNum === 1) {
|
|
|
|
|
this.donationList = newData
|
|
|
|
|
} else {
|
|
|
|
|
// 如果是加载更多,追加数据
|
|
|
|
|
this.donationList = [...this.donationList, ...newData]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断是否还有更多数据
|
|
|
|
|
this.hasMore = newData.length === this.pageSize
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: response.msg || '获取数据失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取捐款记录失败:', error)
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '获取数据失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.loading = false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搜索捐款记录
|
|
|
|
|
* @param {string} val 搜索关键词
|
|
|
|
|
*/
|
|
|
|
|
onSearch(val) {
|
|
|
|
|
this.pageNum = 1 // 重置页码
|
|
|
|
|
this.loadDonationRecords(val)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 筛选功能
|
|
|
|
|
*/
|
|
|
|
|
onFilter() {
|
|
|
|
|
uni.showToast({ title: '筛选功能开发中', icon: 'none' })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化日期
|
|
|
|
|
* @param {string} dateStr 日期字符串
|
|
|
|
|
* @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}`
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化数据
|
|
|
|
|
* @param {string} formedId 建制ID
|
|
|
|
|
*/
|
2025-08-02 11:14:12 +08:00
|
|
|
async initData(formedId) {
|
|
|
|
|
console.log('初始化捐款记录数据, formedId:', formedId)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.formedId = formedId
|
|
|
|
|
await this.loadProjectInfo()
|
|
|
|
|
await this.loadDonationRecords()
|
|
|
|
|
console.log('捐款记录数据初始化完成')
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('初始化捐款记录数据失败:', error)
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '初始化数据失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-08-01 16:01:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|