goods_info.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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: "subscribable")
  13. late int subscribable;
  14. @JsonKey(name: "amount")
  15. late int amount;
  16. @JsonKey(name: "originalAmount")
  17. late int originalAmount;
  18. @JsonKey(name: "auth")
  19. late String auth;
  20. @JsonKey(name: "subscriptionMillis")
  21. late int subscriptionMillis;
  22. @JsonKey(name: "priceDesc")
  23. late String priceDesc;
  24. @JsonKey(name: 'payOptionIds')
  25. List<int>? payOptionIds;
  26. @JsonKey(name: 'description')
  27. String? description;
  28. @JsonKey(name: 'discountDesc')
  29. String? discountDesc;
  30. @JsonKey(name: 'mostDesc')
  31. String? mostDesc;
  32. @JsonKey(name: 'selectDesc')
  33. String? selectDesc;
  34. GoodsInfo({
  35. required this.id,
  36. required this.sort,
  37. required this.name,
  38. required this.subscribable,
  39. required this.amount,
  40. required this.originalAmount,
  41. required this.auth,
  42. required this.subscriptionMillis,
  43. required this.priceDesc,
  44. this.payOptionIds,
  45. this.description,
  46. this.discountDesc,
  47. this.mostDesc,
  48. this.selectDesc,
  49. });
  50. get amountText => (amount / 100).toFormattedString(2);
  51. get originalAmountText => "${(originalAmount / 100).toFormattedString(2)}元";
  52. get priceDescNumber => priceDesc.extractAmount();
  53. get priceDescUnit => priceDesc.extractUnit();
  54. factory GoodsInfo.fromJson(Map<String, dynamic> json) =>
  55. _$GoodsInfoFromJson(json);
  56. Map<String, dynamic> toJson() => _$GoodsInfoToJson(this);
  57. GoodsInfo copyWith() {
  58. return GoodsInfo(
  59. id: id,
  60. sort: sort,
  61. name: name,
  62. subscribable: subscribable,
  63. amount: amount,
  64. originalAmount: originalAmount,
  65. auth: auth,
  66. subscriptionMillis: subscriptionMillis,
  67. priceDesc: priceDesc,
  68. payOptionIds: payOptionIds,
  69. description: description,
  70. discountDesc: discountDesc,
  71. mostDesc: mostDesc,
  72. selectDesc: selectDesc,
  73. );
  74. }
  75. }