更新分享
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
|
||||
part 'person_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
|
||||
@JsonSerializable()
|
||||
class PersonModel {
|
||||
int read = 1;
|
||||
|
||||
DateTime? birthday;
|
||||
double? weight;
|
||||
int? read = 1;
|
||||
// String? name;
|
||||
|
||||
PersonModel();
|
||||
|
||||
@@ -30,5 +36,152 @@ class PersonModel {
|
||||
class PersonController extends GetControllerEx<PersonModel> {
|
||||
PersonController() {
|
||||
attr = GetModel(PersonModel()).obs;
|
||||
}
|
||||
}
|
||||
}
|
||||
RxList selectedDiseaseIds = [].obs;
|
||||
// RxList diseaseList = [
|
||||
// {'id': 1, 'name': '高血压'},
|
||||
// {'id': 2, 'name': '糖尿病'},
|
||||
// {'id': 3, 'name': '冠心病'},
|
||||
// {'id': 4, 'name': '哮喘'},
|
||||
// {'id': 5, 'name': '脑卒中'},
|
||||
// {'id': 6, 'name': '慢性肾病'},
|
||||
// {'id': 7, 'name': '慢阻肺'},
|
||||
// {'id': 8, 'name': '类风湿关节炎'},
|
||||
// {'id': 9, 'name': '类风湿关节炎类风湿关节炎'},
|
||||
// {'id': 10, 'name': '类风湿关节炎类风湿关节炎类风湿关节炎'},
|
||||
// ].obs;
|
||||
|
||||
RxString currentPersonId = "".obs;
|
||||
RxString name = "".obs;
|
||||
RxInt gender = 1.obs;
|
||||
RxString birthday = "".obs;
|
||||
RxInt weight = 65.obs;
|
||||
DateTime? dateTime; //选择时间
|
||||
RxList diseaseList = [].obs;
|
||||
|
||||
//保存人员资料
|
||||
// void savePersonData() {
|
||||
// print("id->" + currentPersonId.value);
|
||||
// print("name->" + name.value);
|
||||
// print("gender->${gender.value}");
|
||||
// print("生日->${birthday.value}");
|
||||
// print("体重->${weight.value}");
|
||||
// print("慢病->${selectedDiseaseIds.value}");
|
||||
// }
|
||||
|
||||
Future<ApiResponse> savePersonData() async {
|
||||
try {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "蓝牙绑定.绑定失败".tr);
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.person_info;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
if (name.value.isEmpty) {
|
||||
apiResponse.msg = "请输入姓名".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (birthday.value.isEmpty) {
|
||||
apiResponse.msg = "请选择生日".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (weight.value == 0) {
|
||||
apiResponse.msg = "请输入体重".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
var data = {
|
||||
"id": currentPersonId.value,
|
||||
"name": name.value,
|
||||
"gender": gender.value,
|
||||
"birthday": birthday.value,
|
||||
"weight": weight.value,
|
||||
"disease": selectedDiseaseIds.value,
|
||||
};
|
||||
var response =
|
||||
await EasyDartModule.dio.put(queryUrl, data: jsonEncode(data));
|
||||
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) {
|
||||
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
|
||||
}
|
||||
|
||||
Future<ApiResponse> updatePersonName(person, deviceId) async {
|
||||
try {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "请求失败".tr);
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.person_info;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
if (name.value.isEmpty) {
|
||||
apiResponse.msg = "请输入姓名".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
person['name'] = name.value;
|
||||
person['id'] = deviceId;
|
||||
var response =
|
||||
await EasyDartModule.dio.put(queryUrl, data: jsonEncode(person));
|
||||
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) {
|
||||
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
|
||||
}
|
||||
|
||||
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}";
|
||||
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