41 lines
1.1 KiB
Swift
41 lines
1.1 KiB
Swift
import SwiftUI
|
|
import Shared
|
|
|
|
struct DetailView: View {
|
|
let product: Product
|
|
let favoriteStore: FavoriteStore
|
|
let cartStore: CartStore
|
|
let onChanged: () -> Void
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
Text(product.title)
|
|
.font(.title2)
|
|
|
|
Text("价格:¥\(String(format: "%.2f", product.price))")
|
|
.font(.headline)
|
|
|
|
Text(product.description_)
|
|
.foregroundStyle(.secondary)
|
|
|
|
HStack(spacing: 10) {
|
|
Button("加入购物车") {
|
|
cartStore.add(product: product)
|
|
onChanged()
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
|
|
Button(favoriteStore.isFavorite(productId: product.id) ? "取消收藏" : "收藏") {
|
|
favoriteStore.toggle(productId: product.id)
|
|
onChanged()
|
|
}
|
|
.buttonStyle(.bordered)
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
.navigationTitle("商品详情")
|
|
}
|
|
}
|