优化租号的详情界面
This commit is contained in:
@@ -8,8 +8,10 @@ export interface ListingDisplayChip {
|
||||
export interface ListingDisplayResource {
|
||||
key: string;
|
||||
label: string;
|
||||
price: string;
|
||||
quantity: number;
|
||||
mode: string;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export function getCoinWan(item: Listing) {
|
||||
@@ -34,6 +36,18 @@ export function getListingDisplayPrice(item: Listing) {
|
||||
return Number(item.price || 0);
|
||||
}
|
||||
|
||||
export function getListingRentPrice(item: Listing) {
|
||||
const buyerCoinBasePrice = readPriceBreakdownNumber(item, "buyer_coin_base_price");
|
||||
if (buyerCoinBasePrice > 0) return Math.round(buyerCoinBasePrice);
|
||||
return Math.max(0, Math.round(getListingDisplayPrice(item) - getListingConsumablePrice(item)));
|
||||
}
|
||||
|
||||
export function getListingConsumablePrice(item: Listing) {
|
||||
const consumablePrice = readPriceBreakdownNumber(item, "consumable_price");
|
||||
if (consumablePrice > 0) return Math.round(consumablePrice);
|
||||
return getListingResources(item).reduce((sum, resource) => sum + resource.amount, 0);
|
||||
}
|
||||
|
||||
export function getListingSellerPrice(item: Listing) {
|
||||
const priceBreakdown = item.asset_summary?.price_breakdown;
|
||||
if (typeof priceBreakdown === "object" && priceBreakdown !== null) {
|
||||
@@ -118,8 +132,13 @@ export function getListingResources(item: Listing): ListingDisplayResource[] {
|
||||
return {
|
||||
key: typeof row.key === "string" ? row.key : "",
|
||||
label: typeof row.label === "string" ? row.label : "",
|
||||
price: typeof row.price === "string" ? row.price : "",
|
||||
quantity: readUnknownNumber(row.quantity),
|
||||
mode: typeof row.mode === "string" ? row.mode : "",
|
||||
amount:
|
||||
row.mode === "收费"
|
||||
? Math.round(readUnknownNumber(row.quantity) * readUnitPrice(typeof row.price === "string" ? row.price : ""))
|
||||
: 0,
|
||||
};
|
||||
})
|
||||
.filter((resource): resource is ListingDisplayResource => {
|
||||
@@ -213,8 +232,7 @@ export function getEstimatedRentalDays(item: Listing) {
|
||||
export function formatEstimatedRentalDuration(item: Listing) {
|
||||
const days = getEstimatedRentalDays(item);
|
||||
if (days <= 0) return "--";
|
||||
if (days < 1) return `约${Math.max(1, Math.round(days * 24))}小时`;
|
||||
return `约${formatCompactNumber(days)}天`;
|
||||
return `${Math.max(1, Math.round(days))}天`;
|
||||
}
|
||||
|
||||
export function readAssetString(item: Listing, key: string) {
|
||||
@@ -235,6 +253,24 @@ function readUnknownNumber(value: unknown) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function readPriceBreakdownNumber(item: Listing, key: string) {
|
||||
const priceBreakdown = item.asset_summary?.price_breakdown;
|
||||
if (typeof priceBreakdown !== "object" || priceBreakdown === null) return 0;
|
||||
return readUnknownNumber((priceBreakdown as Record<string, unknown>)[key]);
|
||||
}
|
||||
|
||||
function readUnitPrice(priceText: string) {
|
||||
const normalized = priceText.replace(/,/g, ",").trim();
|
||||
const fractionMatch = normalized.match(/(\d+(?:\.\d+)?)\s*元\s*\/\s*(\d+(?:\.\d+)?)/);
|
||||
if (fractionMatch) {
|
||||
const amount = Number(fractionMatch[1]);
|
||||
const count = Number(fractionMatch[2]);
|
||||
return count > 0 ? amount / count : 0;
|
||||
}
|
||||
const singleMatch = normalized.match(/(\d+(?:\.\d+)?)\s*元/);
|
||||
return singleMatch ? Number(singleMatch[1]) : 0;
|
||||
}
|
||||
|
||||
function formatInsuranceSlotText(value: string) {
|
||||
const parts = value.split("*").map((item) => Number(item));
|
||||
const rows = parts[0] || 0;
|
||||
|
||||
Reference in New Issue
Block a user