我的接口补充
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'package:getx_scaffold/getx_scaffold.dart';
|
||||
import 'package:ln_jq_app/common/model/base_model.dart';
|
||||
import 'package:ln_jq_app/common/model/vehicle_info.dart';
|
||||
import 'package:ln_jq_app/common/styles/theme.dart';
|
||||
import 'package:ln_jq_app/storage_service.dart';
|
||||
|
||||
import '../../login/view.dart';
|
||||
@@ -12,6 +15,8 @@ class MineController extends GetxController with BaseControllerMixin {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
renderData();
|
||||
renderViolation();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -19,9 +24,124 @@ class MineController extends GetxController with BaseControllerMixin {
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void logout() async{
|
||||
void logout() async {
|
||||
await StorageService.to.clearLoginInfo();
|
||||
|
||||
Get.offAll(() => LoginPage());
|
||||
}
|
||||
|
||||
String rate = "";
|
||||
String accident = "";
|
||||
String historyBreakRules = "";
|
||||
String vin = "";
|
||||
String plateNumber = "";
|
||||
String violationTotal = "0";
|
||||
String violationScore = "0";
|
||||
String violationDispose = "0";
|
||||
|
||||
void renderData() async {
|
||||
if (StorageService.to.hasVehicleInfo) {
|
||||
VehicleInfo? bean = StorageService.to.vehicleInfo;
|
||||
if (bean == null) {
|
||||
return;
|
||||
}
|
||||
vin = bean.vin;
|
||||
plateNumber = bean.plateNumber;
|
||||
}
|
||||
|
||||
showLoading("加载中");
|
||||
|
||||
try {
|
||||
await Future.wait([
|
||||
_fetchCompletionRate(), // 请求1:完成率
|
||||
_fetchAccidentCount(), // 请求2:事故数
|
||||
_fetchBreakRulesCount(), // 请求3:违章数
|
||||
]);
|
||||
} catch (e, stackTrace) {
|
||||
showErrorToast("加载数据失败,请稍后重试 $e");
|
||||
} finally {
|
||||
dismissLoading();
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchCompletionRate() async {
|
||||
final response = await HttpService.to.get(
|
||||
'appointment/orderAddHyd/driverAppointmentCompletionRate?phone=${StorageService.to.phone}',
|
||||
);
|
||||
|
||||
if (response != null) {
|
||||
final result = BaseModel.fromJson(response.data);
|
||||
if (result.code == 0 && result.data != null) {
|
||||
rate = result.data.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取历史事故数
|
||||
Future<void> _fetchAccidentCount() async {
|
||||
final response = await HttpService.to.get(
|
||||
'appointment/truck/historyTrafficAccidentCount?vin=${vin}',
|
||||
);
|
||||
if (response != null) {
|
||||
final result = BaseModel.fromJson(response.data);
|
||||
if (result.code == 0 && result.data != null) {
|
||||
accident = result.data.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取历史违章数
|
||||
Future<void> _fetchBreakRulesCount() async {
|
||||
final response = await HttpService.to.get(
|
||||
'appointment/truck/historyBreakRulesCount?vin=${vin}',
|
||||
);
|
||||
if (response != null) {
|
||||
final result = BaseModel.fromJson(response.data);
|
||||
if (result.code == 0 && result.data != null) {
|
||||
historyBreakRules = result.data.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void renderViolation() async {
|
||||
// 违章信息查询
|
||||
final originalHeaders = Map<String, dynamic>.from(HttpService.to.dio.options.headers);
|
||||
try {
|
||||
HttpService.to.setBaseUrl(AppTheme.jiaqing_service_url);
|
||||
HttpService.to.dio.options.headers['appId'] = '97ad10eeb6b346f79e0d6ffd81e4d3c3';
|
||||
|
||||
var responseData = await HttpService.to.get(
|
||||
"vehicleService/violation/queryViolationInfo_V2?plateNum=${plateNumber}",
|
||||
);
|
||||
|
||||
if (responseData == null || responseData.data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var result = BaseModel.fromJson(responseData.data);
|
||||
|
||||
if (result.code == 0 && result.data != null && result.data is List) {
|
||||
List<dynamic> violationList = result.data as List;
|
||||
int totalScore = 0;
|
||||
int disposeCount = 0;
|
||||
for (var item in violationList) {
|
||||
if (item is Map<String, dynamic>) {
|
||||
totalScore += (item['score'] as num?)?.toInt() ?? 0;
|
||||
if (item['isDispose'] == 1) {
|
||||
disposeCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
violationTotal = violationList.length.toString();
|
||||
violationScore = totalScore.toString();
|
||||
violationDispose = disposeCount.toString();
|
||||
}
|
||||
} catch (e) {
|
||||
} finally {
|
||||
HttpService.to.setBaseUrl(AppTheme.test_service_url);
|
||||
HttpService.to.dio.options.headers = originalHeaders;
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user