基础组件库
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

124 行
3.4 KiB

  1. import 'dart:async';
  2. import 'dart:convert' as convert;
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:intl/intl.dart';
  6. import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
  7. import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_data_model.dart';
  8. import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_model.dart';
  9. import 'package:zhiying_comm/util/base_bloc.dart';
  10. import 'package:zhiying_comm/zhiying_comm.dart';
  11. class WithdrawBloc extends BlocBase {
  12. WithdrawModel _model;
  13. StreamController<WithdrawModel> _dataController =
  14. StreamController<WithdrawModel>();
  15. Stream<WithdrawModel> get outData => _dataController.stream;
  16. WithdrawDataModel withdrawDataModel;
  17. Map<String,dynamic> aliPayModel;
  18. String skipIdentifier;
  19. @override
  20. void dispose() {
  21. _dataController.close();
  22. _dataController = null;
  23. }
  24. void loadData(String skipIdentifier) async {
  25. this.skipIdentifier = skipIdentifier;
  26. NetUtil.request('/api/v1/mod/${skipIdentifier.toString()}',
  27. method: NetMethod.GET, onCache: (data) {
  28. _loadData(data);
  29. }, onSuccess: (data) {
  30. _loadData(data);
  31. });
  32. }
  33. ///加载数据
  34. void loadWithdrawData() {
  35. NetUtil.request("/api/v1/user/cash_out", onSuccess: (data) {
  36. withdrawDataModel = WithdrawDataModel.fromJson(data);
  37. _dataController.add(_model);
  38. });
  39. }
  40. void _loadData(dynamic data) {
  41. try {
  42. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  43. if (json == null || json.length == 0) {
  44. return;
  45. }
  46. List mods = json['mod_list'];
  47. if (mods.first != null) {
  48. json = Map<String, dynamic>.from(mods.first);
  49. String d = json['data'];
  50. if (json.containsKey('data')) {
  51. String d = json['data'];
  52. Map<String, dynamic> da =
  53. Map<String, dynamic>.from(convert.jsonDecode(d));
  54. _model = WithdrawModel.fromJson(da);
  55. _dataController.add(_model);
  56. }
  57. }
  58. } catch (err) {
  59. Logger.error(err);
  60. }
  61. }
  62. ///提交提现申请
  63. void submitApply(BuildContext context, String money) async {
  64. num amount = num.tryParse(money);
  65. if (amount != null && amount > 0) {
  66. var result = await showDialog(
  67. context: context,
  68. child: TipDialog(
  69. btnText: "确定",
  70. content: "确定要提现?",
  71. ));
  72. if (result == null || !result) {
  73. return;
  74. }
  75. NetUtil.request("/api/v1/user/cash_out",
  76. method: NetMethod.POST,
  77. params: {'amount': amount.toString()}, onSuccess: (data) {
  78. showDialog(
  79. context: context,
  80. child: TipDialog(
  81. content: "提现申请已成功提交,请耐心等候审核通过",
  82. ));
  83. loadData(skipIdentifier);
  84. loadWithdrawData();
  85. }, onError: (data) {
  86. showDialog(
  87. context: context,
  88. child: TipDialog(
  89. content: "提现申请提交失败!,请稍后再试",
  90. ));
  91. });
  92. } else {
  93. showDialog(
  94. context: context,
  95. child: TipDialog(
  96. content: "请输入正确的金额!",
  97. ));
  98. }
  99. }
  100. ///支付宝是否绑定请求
  101. getAlipayStatus(){
  102. NetUtil.request("/api/v1/settings/account/security",onSuccess: (data){
  103. aliPayModel=data;
  104. _dataController.add(_model);
  105. });
  106. }
  107. }