98b7600797
对标安卓正式版、对接 app-server(8770)的 SwiftUI 客户端。iOS 无障碍受限、无比价核心,做自成一体:美团 CPS 导购 + 福利(签到/任务/金币)+ 查看(比价记录/省钱战绩)。 功能完整 M0-M5:脚手架、短信登录(JWT+Keychain+401 自动刷新)、首页券 feed 导购、比价记录+省钱战绩、福利、我的(资料/反馈/设置/注销)。 单 target、0 三方依赖、XcodeGen 生成工程;Debug/Release 双 plist 分流 ATS。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
86 lines
3.3 KiB
Swift
86 lines
3.3 KiB
Swift
import SwiftUI
|
|
|
|
/// 我的比价记录(每次比价的概要,含成功/失败)。数据由安卓端比价后上报,iOS 只读。
|
|
struct CompareRecordsView: View {
|
|
@State private var vm = CompareRecordsViewModel()
|
|
|
|
var body: some View {
|
|
Group {
|
|
if vm.isLoading && vm.records.isEmpty {
|
|
ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
} else if vm.loaded && vm.records.isEmpty {
|
|
ContentUnavailableView {
|
|
Label("还没有比价记录", systemImage: "list.bullet.rectangle")
|
|
} description: {
|
|
Text(vm.errorMessage ?? "在安卓 App 上完成比价后,记录会自动同步到这里")
|
|
}
|
|
} else {
|
|
List {
|
|
ForEach(vm.records) { record in
|
|
CompareRecordRow(record: record)
|
|
.listRowSeparator(.hidden)
|
|
}
|
|
if vm.hasMore {
|
|
HStack { Spacer(); ProgressView(); Spacer() }
|
|
.listRowSeparator(.hidden)
|
|
.onAppear { Task { await vm.loadMore() } }
|
|
}
|
|
}
|
|
.listStyle(.plain)
|
|
.refreshable { await vm.loadFirst() }
|
|
}
|
|
}
|
|
.navigationTitle("我的比价记录")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.task { if !vm.loaded { await vm.loadFirst() } }
|
|
}
|
|
}
|
|
|
|
private struct CompareRecordRow: View {
|
|
let record: ComparisonRecordDTO
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text(record.storeName ?? "比价记录")
|
|
.font(.headline)
|
|
.lineLimit(1)
|
|
Spacer()
|
|
Text(AppDate.friendly(record.createdAt))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
if record.status == "success" {
|
|
HStack(spacing: 6) {
|
|
if let sp = record.sourcePlatformName, let spc = record.sourcePriceCents {
|
|
Text("\(sp) \(spc.centsToYuanText)")
|
|
.strikethrough(record.isSourceBest != true)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Image(systemName: "arrow.right").font(.caption2).foregroundStyle(.secondary)
|
|
if let bp = record.bestPlatformName, let bpc = record.bestPriceCents {
|
|
Text("\(bp) \(bpc.centsToYuanText)").bold()
|
|
}
|
|
}
|
|
.font(.subheadline)
|
|
|
|
if let saved = record.savedAmountCents, saved > 0 {
|
|
Text("省 \(saved.centsToYuanText)")
|
|
.font(.subheadline.bold())
|
|
.foregroundStyle(AppColors.success)
|
|
} else if record.isSourceBest == true {
|
|
Text("源平台已是最低价")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
} else {
|
|
Text(record.information ?? "本次比价未完成")
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.padding(.vertical, 6)
|
|
}
|
|
}
|