expense_apply_api.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'package:flutter_riverpod/flutter_riverpod.dart';
  2. import '../../core/network/api_client.dart';
  3. import '../../app.dart';
  4. import '../../shared/models/pagination_model.dart';
  5. import 'expense_apply_model.dart';
  6. final expenseApplyApiProvider = Provider<ExpenseApplyApi>(
  7. (ref) => ExpenseApplyApi(ref.read(apiClientProvider)),
  8. );
  9. // ═══ 参考数据模型(API 返回) ═══
  10. class CostTypeItem {
  11. final String typeNo;
  12. final String typeName;
  13. final String accNo;
  14. final String accName;
  15. const CostTypeItem({required this.typeNo, required this.typeName, required this.accNo, required this.accName});
  16. factory CostTypeItem.fromJson(Map<String, dynamic> json) => CostTypeItem(
  17. typeNo: json['typeNo'] as String? ?? '',
  18. typeName: json['typeName'] as String? ?? '',
  19. accNo: json['accNo'] as String? ?? '',
  20. accName: json['accName'] as String? ?? '',
  21. );
  22. }
  23. class ProjectCodeItem {
  24. final String objNo;
  25. final String name;
  26. const ProjectCodeItem({required this.objNo, required this.name});
  27. factory ProjectCodeItem.fromJson(Map<String, dynamic> json) => ProjectCodeItem(
  28. objNo: json['objNo'] as String? ?? '',
  29. name: json['name'] as String? ?? '',
  30. );
  31. }
  32. class DepartmentItem {
  33. final String dep;
  34. final String name;
  35. const DepartmentItem({required this.dep, required this.name});
  36. factory DepartmentItem.fromJson(Map<String, dynamic> json) => DepartmentItem(
  37. dep: json['dep'] as String? ?? '',
  38. name: json['name'] as String? ?? '',
  39. );
  40. }
  41. class ExpenseApplyApi {
  42. final ApiClient _client;
  43. ExpenseApplyApi(this._client);
  44. /// 费用申请列表(分页)
  45. Future<PaginatedData<ExpenseApplyModel>> fetchList({
  46. String status = '',
  47. String keyword = '',
  48. String startDate = '',
  49. String endDate = '',
  50. String usr = '',
  51. int page = 1,
  52. int size = 20,
  53. }) async {
  54. final response = await _client.get<Map<String, dynamic>>(
  55. '/OA/GetExpenseApplies',
  56. queryParameters: {
  57. 'status': status,
  58. 'keyword': keyword,
  59. 'startDate': startDate,
  60. 'endDate': endDate,
  61. 'usr': usr,
  62. 'page': page,
  63. 'size': size,
  64. },
  65. );
  66. return PaginatedData.fromJson(response.data!, ExpenseApplyModel.fromJson);
  67. }
  68. /// 费用申请详情(主表+明细)
  69. Future<ExpenseApplyModel> fetchDetail(String billNo) async {
  70. final response = await _client.get<Map<String, dynamic>>(
  71. '/OA/GetExpenseApplyDetail',
  72. queryParameters: {'billNo': billNo},
  73. );
  74. return ExpenseApplyModel.fromJson(response.data!);
  75. }
  76. /// 费用类别字典
  77. Future<List<CostTypeItem>> getCostTypes({String keyword = '', String accNo = ''}) async {
  78. final response = await _client.get<Map<String, dynamic>>(
  79. '/OA/GetCostTypes',
  80. queryParameters: {'keyword': keyword, 'accNo': accNo, 'page': 1, 'size': 100},
  81. );
  82. final list = (response.data?['list'] as List<dynamic>?) ?? [];
  83. return list.map((e) => CostTypeItem.fromJson(e as Map<String, dynamic>)).toList();
  84. }
  85. /// 项目代号
  86. Future<List<ProjectCodeItem>> getProjectCodes({String keyword = '', String billDate = ''}) async {
  87. final response = await _client.get<Map<String, dynamic>>(
  88. '/OA/GetProjectCodes',
  89. queryParameters: {'keyword': keyword, 'billDate': billDate, 'page': 1, 'size': 100},
  90. );
  91. final list = (response.data?['list'] as List<dynamic>?) ?? [];
  92. return list.map((e) => ProjectCodeItem.fromJson(e as Map<String, dynamic>)).toList();
  93. }
  94. /// 部门
  95. Future<List<DepartmentItem>> getDepartments({String keyword = '', bool onlyActive = true}) async {
  96. final response = await _client.get<Map<String, dynamic>>(
  97. '/OA/GetDepartments',
  98. queryParameters: {'keyword': keyword, 'onlyActive': onlyActive, 'page': 1, 'size': 100},
  99. );
  100. final list = (response.data?['list'] as List<dynamic>?) ?? [];
  101. return list.map((e) => DepartmentItem.fromJson(e as Map<String, dynamic>)).toList();
  102. }
  103. /// 提交审批
  104. Future<void> submit(Map<String, dynamic> data) async {
  105. await _client.post('/OA/BillSave', data: {
  106. 'erpCategory': 'MasterService',
  107. 'billId': 'AE',
  108. 'procId': '',
  109. 'data': data,
  110. });
  111. }
  112. }