建制项中的货币单位都改为“元”,捐款人数的暂无数据改为招募中

This commit is contained in:
WindowBird 2025-09-19 14:13:04 +08:00
parent 55883c67b9
commit 4716301b44
2 changed files with 207 additions and 190 deletions

View File

@ -2,8 +2,8 @@
<view class="data"> <view class="data">
<!-- 标题和状态行 --> <!-- 标题和状态行 -->
<view class="header-row"> <view class="header-row">
<view class="project-title">{{ item.topLeft || '暂无数据' }}</view> <view class="project-title">{{ item.topLeft || "暂无数据" }}</view>
<view class="status">{{ item.topRight || '暂无数据' }}</view> <view class="status">{{ item.topRight || "暂无数据" }}</view>
</view> </view>
<!-- 详细信息表格 --> <!-- 详细信息表格 -->
@ -15,154 +15,158 @@
<text class="label detail-col">捐赠名单</text> <text class="label detail-col">捐赠名单</text>
</view> </view>
<view class="table-row"> <view class="table-row">
<text class="value year-col">{{ item.year || '暂无数据' }}</text> <text class="value year-col">{{ item.year || "暂无数据" }}</text>
<text class="value amount-col">{{ item.amount || '暂无数据' }}</text> <text class="value amount-col">{{ item.amount || "暂无数据" }}</text>
<text class="value donor-col">{{ item.donorCount || '暂无数据' }}</text> <text class="value donor-col">{{
<text class="view-details detail-col" @click="onViewDetail">查看详情</text> item.donorCount || "持续招募中"
}}</text>
<text class="view-details detail-col" @click="onViewDetail"
>查看详情</text
>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'InstitutionalItem', name: "InstitutionalItem",
props: { props: {
// //
item: { item: {
type: Object, type: Object,
required: true, required: true,
default: () => ({ default: () => ({
topLeft: '', topLeft: "",
topRight: '', topRight: "",
bottomLeft: '', bottomLeft: "",
bottomRight: '', bottomRight: "",
}), }),
},
//
index: {
type: Number,
default: 0,
},
}, },
methods: { //
// index: {
onViewDetail() { type: Number,
// default: 0,
this.$emit('view-detail', {
item: this.item,
index: this.index,
})
},
}, },
} },
methods: {
//
onViewDetail() {
//
this.$emit("view-detail", {
item: this.item,
index: this.index,
});
},
},
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.data { .data {
background-color: #fffbf5; background-color: #fffbf5;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 720rpx; width: 720rpx;
box-sizing: border-box; box-sizing: border-box;
min-height: 180rpx; min-height: 180rpx;
border-radius: 11px; border-radius: 11px;
border: 1px solid #c7a26d; border: 1px solid #c7a26d;
margin: 15rpx auto; margin: 15rpx auto;
padding: 12rpx; padding: 12rpx;
} }
.header-row { .header-row {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 15rpx; margin-bottom: 15rpx;
padding-bottom: 12rpx; padding-bottom: 12rpx;
} }
.project-title { .project-title {
font-size: 32rpx; font-size: 32rpx;
font-weight: 500; font-weight: 500;
color: #522510; color: #522510;
flex: 1; flex: 1;
} }
.status { .status {
font-size: 28rpx; font-size: 28rpx;
color: #7f7f7f; color: #7f7f7f;
padding: 8rpx 16rpx; padding: 8rpx 16rpx;
border-radius: 20rpx; border-radius: 20rpx;
} }
.details-table { .details-table {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 10rpx; gap: 10rpx;
} }
.table-row { .table-row {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
gap: 10rpx; gap: 10rpx;
width: 100%; width: 100%;
} }
.label { .label {
font-size: 26rpx; font-size: 26rpx;
color: #7c736e; color: #7c736e;
font-weight: 500; font-weight: 500;
flex: 1; flex: 1;
text-align: left; text-align: left;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.value { .value {
font-size: 26rpx; font-size: 26rpx;
color: #695347; color: #695347;
font-weight: 600; font-weight: 600;
flex: 1; flex: 1;
text-align: left; text-align: left;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.view-details { .view-details {
font-size: 28rpx; font-size: 28rpx;
color: #522510; color: #522510;
font-weight: 500; font-weight: 500;
cursor: pointer; cursor: pointer;
flex: 1; flex: 1;
text-align: left; text-align: left;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.view-details:active { .view-details:active {
opacity: 0.7; opacity: 0.7;
} }
/* 不同列的弹性比例 */ /* 不同列的弹性比例 */
.year-col { .year-col {
flex: 1; flex: 1;
} }
.amount-col { .amount-col {
flex: 1.5; flex: 1.5;
} }
.donor-col { .donor-col {
flex: 1; flex: 1;
} }
.detail-col { .detail-col {
flex: 0 0 auto; flex: 0 0 auto;
margin-left: auto; margin-left: auto;
min-width: 80rpx; min-width: 80rpx;
} }
</style> </style>

View File

@ -8,15 +8,15 @@ export class InstitutionalDataFormatter {
* @returns {string} 格式化后的金额字符串 * @returns {string} 格式化后的金额字符串
*/ */
static formatAmount(amount) { static formatAmount(amount) {
if (!amount) return '不详' if (!amount) return "不详";
// 超过一亿以亿为单位 // 超过一亿以亿为单位
if (amount >= 100000000) { if (amount >= 100000000) {
return `${(amount / 100000000).toFixed(1)}亿` return `${(amount / 100000000).toFixed(1)}亿`;
} else if (amount >= 10000) { } else if (amount >= 10000) {
return `${(amount / 10000).toFixed(1)}` return `${(amount / 10000).toFixed(1)}`;
} else { } else {
return `${amount.toLocaleString()}` return `${amount.toLocaleString()}`;
} }
} }
@ -26,16 +26,16 @@ export class InstitutionalDataFormatter {
* @param {string} currency 货币单位 * @param {string} currency 货币单位
* @returns {string} 格式化后的金额字符串 * @returns {string} 格式化后的金额字符串
*/ */
static formatHistoricalAmount(amount, currency = '银元') { static formatHistoricalAmount(amount, currency = "银元") {
if (!amount) return '不详' if (!amount) return "不详";
// 超过一亿以亿为单位 // 超过一亿以亿为单位
if (amount >= 100000000) { if (amount >= 100000000) {
return `${currency}${(amount / 100000000).toFixed(1)}亿` return `${currency}${(amount / 100000000).toFixed(1)}亿`;
} else if (amount >= 10000) { } else if (amount >= 10000) {
return `${currency}${(amount / 10000).toFixed(0)}` return `${currency}${(amount / 10000).toFixed(0)}`;
} else { } else {
return `${currency}${amount.toLocaleString()}` return `${currency}${amount.toLocaleString()}`;
} }
} }
@ -46,8 +46,8 @@ export class InstitutionalDataFormatter {
*/ */
static formatTopLeft(projectName) { static formatTopLeft(projectName) {
// 如果年份和项目名称都为空,返回暂无数据 // 如果年份和项目名称都为空,返回暂无数据
if (!projectName) return '暂无数据' if (!projectName) return "暂无数据";
return projectName return projectName;
} }
/** /**
@ -57,15 +57,15 @@ export class InstitutionalDataFormatter {
* @returns {string} 格式化后的项目名称 * @returns {string} 格式化后的项目名称
*/ */
static formatProjectName(projectName, isHistorical = false) { static formatProjectName(projectName, isHistorical = false) {
if (!projectName) return '暂无数据' if (!projectName) return "暂无数据";
// 如果是历史项目,可能需要特殊处理 // 如果是历史项目,可能需要特殊处理
if (isHistorical && projectName.includes('寺')) { if (isHistorical && projectName.includes("寺")) {
// 对于寺庙项目,保持原有格式 // 对于寺庙项目,保持原有格式
return projectName return projectName;
} }
return projectName return projectName;
} }
/** /**
@ -74,14 +74,14 @@ export class InstitutionalDataFormatter {
* @returns {string} 格式化后的年份 * @returns {string} 格式化后的年份
*/ */
static formatYear(year) { static formatYear(year) {
if (!year) return '暂无数据' if (!year) return "暂无数据";
// 如果已经是格式化过的字符串(包含"年"字),直接返回 // 如果已经是格式化过的字符串(包含"年"字),直接返回
if (typeof year === 'string' && year.includes('年')) { if (typeof year === "string" && year.includes("年")) {
return year return year;
} }
return `${year}` return `${year}`;
} }
/** /**
@ -90,30 +90,30 @@ export class InstitutionalDataFormatter {
* @returns {string} 格式化后的年份 * @returns {string} 格式化后的年份
*/ */
static formatHistoricalYear(year) { static formatHistoricalYear(year) {
if (!year) return '暂无数据' if (!year) return "暂无数据";
// 如果已经是格式化过的字符串,直接返回 // 如果已经是格式化过的字符串,直接返回
if (typeof year === 'string') { if (typeof year === "string") {
if (year.includes('年')) { if (year.includes("年")) {
return year return year;
} }
if (year.includes('时期') || year.includes('朝代')) { if (year.includes("时期") || year.includes("朝代")) {
return year return year;
} }
} }
// 如果是公元前的年份 // 如果是公元前的年份
if (year < 0) { if (year < 0) {
return `公元前${Math.abs(year)}` return `公元前${Math.abs(year)}`;
} }
// 如果是公元后的年份但小于1000年 // 如果是公元后的年份但小于1000年
if (year < 1000) { if (year < 1000) {
return `${year}` return `${year}`;
} }
// 正常年份 // 正常年份
return `${year}` return `${year}`;
} }
/** /**
@ -123,16 +123,16 @@ export class InstitutionalDataFormatter {
*/ */
static getStatusText(state) { static getStatusText(state) {
switch (state) { switch (state) {
case '1': case "1":
return '规划' return "规划";
case '2': case "2":
return '进行中' return "进行中";
case '3': case "3":
return '已完成' return "已完成";
case '4': case "4":
return '已取消' return "已取消";
default: default:
return '未知状态' return "未知状态";
} }
} }
@ -142,31 +142,35 @@ export class InstitutionalDataFormatter {
* @returns {boolean} 是否为历史项目 * @returns {boolean} 是否为历史项目
*/ */
static isHistoricalProject(year) { static isHistoricalProject(year) {
if (!year) return false if (!year) return false;
// 处理字符串格式的年份(如"916年"、"明末时期" // 处理字符串格式的年份(如"916年"、"明末时期"
if (typeof year === 'string') { if (typeof year === "string") {
// 如果包含"年"字,提取数字部分 // 如果包含"年"字,提取数字部分
if (year.includes('年')) { if (year.includes("年")) {
const yearNum = parseInt(year.replace('年', '')) const yearNum = parseInt(year.replace("年", ""));
return yearNum < 1900 return yearNum < 1900;
} }
// 如果包含历史时期描述,认为是历史项目 // 如果包含历史时期描述,认为是历史项目
if (year.includes('时期') || year.includes('朝代') || year.includes('古代')) { if (
return true year.includes("时期") ||
year.includes("朝代") ||
year.includes("古代")
) {
return true;
} }
// 尝试解析纯数字 // 尝试解析纯数字
const yearNum = parseInt(year) const yearNum = parseInt(year);
if (!isNaN(yearNum)) { if (!isNaN(yearNum)) {
return yearNum < 1900 return yearNum < 1900;
} }
} }
// 处理数字格式的年份 // 处理数字格式的年份
const yearNum = parseInt(year) const yearNum = parseInt(year);
return yearNum < 1900 return yearNum < 1900;
} }
/** /**
@ -176,12 +180,12 @@ export class InstitutionalDataFormatter {
* @returns {string} 格式化后的人数 * @returns {string} 格式化后的人数
*/ */
static formatDonorCount(count, isHistorical = false) { static formatDonorCount(count, isHistorical = false) {
if (!count || count === 0) return '暂无数据' if (!count || count === 0) return "持续招募中";
if (isHistorical) { if (isHistorical) {
return `${count}` return `${count}`;
} else { } else {
return `${count}` return `${count}`;
} }
} }
@ -191,36 +195,45 @@ export class InstitutionalDataFormatter {
* @returns {Array} 转换后的数据 * @returns {Array} 转换后的数据
*/ */
static transformData(rows) { static transformData(rows) {
console.log('原始数据:', rows) // 添加调试日志 console.log("原始数据:", rows); // 添加调试日志
return rows.map(item => { return rows.map((item) => {
console.log('处理项目:', item) // 添加调试日志 console.log("处理项目:", item); // 添加调试日志
const year = item.formedYear || item.startYear || item.start_year || item.year const year =
const isHistorical = InstitutionalDataFormatter.isHistoricalProject(year) item.formedYear || item.startYear || item.start_year || item.year;
const isHistorical = InstitutionalDataFormatter.isHistoricalProject(year);
const projectName = item.proName || item.pro_name || item.projectName const projectName = item.proName || item.pro_name || item.projectName;
return { return {
topLeft: InstitutionalDataFormatter.formatTopLeft( topLeft: InstitutionalDataFormatter.formatTopLeft(
InstitutionalDataFormatter.formatProjectName(projectName, isHistorical) InstitutionalDataFormatter.formatProjectName(
projectName,
isHistorical,
),
), ),
topRight: InstitutionalDataFormatter.getStatusText(item.state), topRight: InstitutionalDataFormatter.getStatusText(item.state),
year: isHistorical year: isHistorical
? InstitutionalDataFormatter.formatHistoricalYear(year) ? InstitutionalDataFormatter.formatHistoricalYear(year)
: InstitutionalDataFormatter.formatYear(year), : InstitutionalDataFormatter.formatYear(year),
amount: isHistorical amount: isHistorical
? InstitutionalDataFormatter.formatHistoricalAmount(item.totalAmount || item.total_amount) ? // ? InstitutionalDataFormatter.formatHistoricalAmount(
: InstitutionalDataFormatter.formatAmount(item.totalAmount || item.total_amount), InstitutionalDataFormatter.formatAmount(
item.totalAmount || item.total_amount,
)
: InstitutionalDataFormatter.formatAmount(
item.totalAmount || item.total_amount,
),
donorCount: InstitutionalDataFormatter.formatDonorCount( donorCount: InstitutionalDataFormatter.formatDonorCount(
item.donorCount || item.donor_count || 0, item.donorCount || item.donor_count || 0,
isHistorical isHistorical,
), ),
// 保存原始数据,用于跳转 // 保存原始数据,用于跳转
formedId: item.id, formedId: item.id,
// 保存项目类型信息 // 保存项目类型信息
isHistorical: isHistorical, isHistorical: isHistorical,
} };
}) });
} }
} }