goods_info.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'package:json_annotation/json_annotation.dart';
  2. import 'package:keyboard/utils/common_expand.dart';
  3. part 'goods_info.g.dart';
  4. @JsonSerializable()
  5. class GoodsInfo {
  6. @JsonKey(name: "id")
  7. late int id;
  8. @JsonKey(name: "sort")
  9. late int sort;
  10. @JsonKey(name: "name")
  11. late String name;
  12. @JsonKey(name: "appleGoodsId")
  13. late String appleGoodsId;
  14. @JsonKey(name: "subscribable")
  15. late int subscribable;
  16. @JsonKey(name: "amount")
  17. late int amount;
  18. @JsonKey(name: "originalAmount")
  19. late int originalAmount;
  20. @JsonKey(name: "auth")
  21. late String auth;
  22. @JsonKey(name: "subscriptionMillis")
  23. late int subscriptionMillis;
  24. @JsonKey(name: "priceDesc")
  25. late String priceDesc;
  26. @JsonKey(name: 'payOptionIds')
  27. List<int>? payOptionIds;
  28. @JsonKey(name: 'description')
  29. String? description;
  30. @JsonKey(name: 'mostDesc')
  31. String? mostDesc;
  32. @JsonKey(name: 'selectDesc')
  33. String? selectDesc;
  34. @JsonKey(name: 'timeLimitDesc')
  35. String? timeLimitDesc;
  36. @JsonKey(name: 'code')
  37. late String code;
  38. @JsonKey(name: 'firstAmount')
  39. int? firstAmount;
  40. @JsonKey(name: 'discountPriceDesc')
  41. String? discountPriceDesc;
  42. GoodsInfo({
  43. required this.id,
  44. required this.sort,
  45. required this.name,
  46. required this.appleGoodsId,
  47. required this.subscribable,
  48. required this.amount,
  49. required this.originalAmount,
  50. required this.auth,
  51. required this.subscriptionMillis,
  52. required this.priceDesc,
  53. required this.code,
  54. this.payOptionIds,
  55. this.description,
  56. this.mostDesc,
  57. this.selectDesc,
  58. this.timeLimitDesc,
  59. this.firstAmount,
  60. this.discountPriceDesc,
  61. });
  62. get amountText => (amount / 100).toFormattedString(2);
  63. get firstAmountText => ((firstAmount ?? 0) / 100).toDouble().toFormattedString(1);
  64. get originalAmountText => "${(originalAmount / 100).toFormattedString(2)}元";
  65. get priceDescNumber => priceDesc.extractAmount();
  66. get priceDescUnit => priceDesc.extractUnit();
  67. factory GoodsInfo.fromJson(Map<String, dynamic> json) =>
  68. _$GoodsInfoFromJson(json);
  69. Map<String, dynamic> toJson() => _$GoodsInfoToJson(this);
  70. GoodsInfo copyWith() {
  71. return GoodsInfo(
  72. id: id,
  73. sort: sort,
  74. name: name,
  75. appleGoodsId: appleGoodsId,
  76. subscribable: subscribable,
  77. amount: amount,
  78. originalAmount: originalAmount,
  79. auth: auth,
  80. subscriptionMillis: subscriptionMillis,
  81. priceDesc: priceDesc,
  82. payOptionIds: payOptionIds,
  83. description: description,
  84. mostDesc: mostDesc,
  85. selectDesc: selectDesc,
  86. timeLimitDesc: timeLimitDesc,
  87. code: code,
  88. firstAmount: firstAmount,
  89. discountPriceDesc: discountPriceDesc,
  90. );
  91. }
  92. }