You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
66 lines
1.5 KiB
import 'package:get/get.dart';
|
|
import '../../../routes/app_routes.dart';
|
|
|
|
class GoodsItem {
|
|
final String id;
|
|
final String title;
|
|
final String description;
|
|
final double price;
|
|
final String productId;
|
|
|
|
GoodsItem({
|
|
required this.id,
|
|
required this.title,
|
|
required this.description,
|
|
required this.price,
|
|
required this.productId,
|
|
});
|
|
}
|
|
|
|
class GoodsvipController extends GetxController {
|
|
final RxList<GoodsItem> items = <GoodsItem>[].obs;
|
|
final RxBool loading = false.obs;
|
|
final RxString error = ''.obs;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
_loadProducts();
|
|
}
|
|
|
|
Future<void> _loadProducts() async {
|
|
loading.value = true;
|
|
error.value = '';
|
|
try {
|
|
// 示例数据,可接后端商品接口替换
|
|
items.assignAll([
|
|
GoodsItem(
|
|
id: 'vip_month',
|
|
title: '月度会员',
|
|
description: '解锁高级功能,按月订阅',
|
|
price: 9.9,
|
|
productId: 'vip_101',
|
|
),
|
|
GoodsItem(
|
|
id: 'vip_year',
|
|
title: '年度会员',
|
|
description: '解锁高级功能,按年订阅',
|
|
price: 99.0,
|
|
productId: 'vip_201',
|
|
),
|
|
]);
|
|
} catch (e) {
|
|
error.value = e.toString();
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
void purchase(GoodsItem item) {
|
|
Get.toNamed(Routes.payment, arguments: {
|
|
'productId': item.productId,
|
|
'amount': item.price,
|
|
'description': item.title,
|
|
});
|
|
}
|
|
}
|