更新眠花糖慢病管理
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/pojo/city.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
||||
import 'package:vbvs_app/enum/APPPackageType.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
|
||||
part 'people_info_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
@@ -25,6 +29,7 @@ class PeopleInfoModel {
|
||||
String? contact;
|
||||
List peopleList = [];
|
||||
List<CityModel> cityModels = [];
|
||||
List selectedDiseaseIds = [];
|
||||
PeopleInfoModel();
|
||||
|
||||
factory PeopleInfoModel.fromJson(Map<String, dynamic> json) {
|
||||
@@ -46,6 +51,8 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
||||
}
|
||||
|
||||
final CityModelController cityController = Get.find<CityModelController>();
|
||||
RxList diseaseList = [].obs;
|
||||
|
||||
|
||||
@override
|
||||
Future<void> onInit() async {
|
||||
@@ -113,29 +120,32 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
||||
if (!cityController.isDataLoaded) {
|
||||
await cityController.loadAndSetCityData();
|
||||
}
|
||||
|
||||
|
||||
// 清空现有的城市模型列表
|
||||
model.cityModels = [];
|
||||
|
||||
|
||||
// 遍历peopleList中的每个人,查找对应的城市数据
|
||||
for (var person in model.peopleList) {
|
||||
if (person is Map<String, dynamic>) {
|
||||
// 获取person中的city_id
|
||||
final cityId = person['city_id']?.toString();
|
||||
|
||||
|
||||
if (cityId != null && cityId.isNotEmpty) {
|
||||
ef.log("开始查找city_id: $cityId");
|
||||
|
||||
|
||||
// 使用cityController查找完整的城市数据
|
||||
final CityModel? completeCityData = cityController.findCityById(cityId);
|
||||
|
||||
final CityModel? completeCityData =
|
||||
cityController.findCityById(cityId);
|
||||
|
||||
if (completeCityData != null) {
|
||||
// 将找到的城市数据添加到cityModels列表中
|
||||
model.cityModels.add(completeCityData);
|
||||
ef.log("成功添加城市数据: ${completeCityData.displayName} for person: ${person['name'] ?? 'Unknown'}");
|
||||
ef.log(
|
||||
"成功添加城市数据: ${completeCityData.displayName} for person: ${person['name'] ?? 'Unknown'}");
|
||||
} else {
|
||||
// 如果找不到对应的城市数据,添加一个空的CityModel,但保留city_id
|
||||
final CityModel emptyCityModel = CityModel(id: int.tryParse(cityId));
|
||||
final CityModel emptyCityModel =
|
||||
CityModel(id: int.tryParse(cityId));
|
||||
model.cityModels.add(emptyCityModel);
|
||||
ef.log("未找到对应城市数据,创建默认CityModel for city_id: $cityId");
|
||||
}
|
||||
@@ -146,16 +156,17 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 确保cityModels列表长度与peopleList一致
|
||||
while (model.cityModels.length < model.peopleList.length) {
|
||||
model.cityModels.add(CityModel());
|
||||
}
|
||||
|
||||
|
||||
// 更新UI
|
||||
updateAll();
|
||||
|
||||
ef.log("初始化城市数据完成,peopleList长度: ${model.peopleList.length}, cityModels长度: ${model.cityModels.length}");
|
||||
|
||||
ef.log(
|
||||
"初始化城市数据完成,peopleList长度: ${model.peopleList.length}, cityModels长度: ${model.cityModels.length}");
|
||||
} catch (e) {
|
||||
ef.log("初始化城市数据失败: $e");
|
||||
}
|
||||
@@ -176,4 +187,52 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
||||
updateAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse> getDiseaseData() async {
|
||||
try {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "请求失败".tr);
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.disease_list;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
String? language = "";
|
||||
if (AppConstants().ent_type == APPPackageType.MHT.code) {
|
||||
if (mhLanguageController.selectLanguage != null) {
|
||||
language = mhLanguageController.selectLanguage.value!.language_code;
|
||||
}
|
||||
} else {
|
||||
if (languageController.selectLanguage != null) {
|
||||
language = languageController.selectLanguage.value!.language_code;
|
||||
}
|
||||
}
|
||||
if (language != null && language.isNotEmpty) {
|
||||
if (queryUrl.contains("?")) {
|
||||
queryUrl += "&lang=$language";
|
||||
} else {
|
||||
queryUrl += "?lang=$language";
|
||||
}
|
||||
}
|
||||
var response = await EasyDartModule.dio.get(queryUrl);
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res =
|
||||
ApiResponse.fromJson(responseData, (object) => object);
|
||||
MyUtils.formatResponse(res, "请求成功".tr, "请求失败".tr);
|
||||
if (res.code == HttpStatusCodes.ok) {
|
||||
// bindDeviceNum.value = res.total!;
|
||||
diseaseList.value = res.data!;
|
||||
updateAll();
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
return ApiResponse(code: -1, msg: "失败".tr);
|
||||
}
|
||||
return apiResponse;
|
||||
} catch (e) {
|
||||
EasyDartModule.logger.info("疾病请求列表: $e");
|
||||
DailyLogUtils.writeLog("疾病请求列表: $e");
|
||||
}
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user