import 'package:fis_jsonrpc/rpc.dart'; import 'package:get/get.dart'; import 'package:vnoteapp/architecture/defines.dart'; import 'package:vnoteapp/architecture/utils/prompt_box.dart'; import 'package:vnoteapp/managers/interfaces/patient.dart'; import 'package:vnoteapp/pages/controllers/crowd_labels.dart'; import 'package:vnoteapp/pages/controllers/home_nav_mixin.dart'; import 'package:vnoteapp/pages/patient/create/state.dart'; import 'package:vnoteapp/pages/patient/list/controller.dart'; import 'package:vnoteapp/routes/nav_ids.dart'; class CreatePatientController extends FControllerBase with HomeNavMixin { final _patientManager = Get.find(); final state = CreatePatientState(); @override Future onLoad() { final params = Get.parameters; if (params.containsKey("from")) { if (params["from"] == "list") { state.isCreateOnly = true; } } return super.onLoad(); } /// 保存档案,调整签约 void gotoSignContract() async { setBusy("正在保存..."); final code = await _submitForm(); if (code == null) { busy = false; PromptBox.toast("保存失败"); return; } // final code = "13B95A2B2790464BBFD9B30A71F15C95"; busy = false; Future.delayed( const Duration(milliseconds: 800), () { state.reset(); // 重置状态 }, ); Get.toNamed( "/contract/package_list", parameters: {"patientCode": code}, ); // Get.find().switchNavByName("/patient/list"); // Future.delayed( // const Duration(milliseconds: 800), // () { // // TODO: // Get.find().gotoDetail(code); // busy = false; // }, // ); } /// 存为档案,调整到档案详情 void gotoPatientDetail() async { setBusy("正在保存..."); final code = await _submitForm(); if (code == null) { busy = false; PromptBox.toast("保存失败"); return; } else { Future.delayed( const Duration(milliseconds: 800), () { state.reset(); // 重置状态 busy = false; PromptBox.toast("保存成功"); }, ); } ///不跳转到详情页 // Get.find().switchNavByName("/patient/list"); Get.put(PatientListController()); Future.delayed( const Duration(milliseconds: 800), () { Get.find().gotoDetail(code); busy = false; }, ); } /// 保存并返回 void saveAndBack() async { setBusy("正在保存..."); final code = await _submitForm(); busy = false; if (code == null) { busy = false; return; } Get.back(result: code, id: NavIds.HOME); } /// 点击读卡事件 void onReadCardClicked() { Get.snackbar( "提示", "此功能尚未开发", duration: const Duration(seconds: 2), ); } /// 处理 “同户籍地址” 勾选变更事件 void onSyncAddressCheckChanged(bool isChecked) { state.isSyncAddresses = isChecked; if (isChecked) { // 同步户籍地址到现住地址 state.address = state.censusRegister; } else { state.address = ""; } } /// 处理户籍地址变更 void onCensusRegisterChanged(String value) { state.censusRegister = value; if (state.isSyncAddresses) { state.address = value; } } Future _submitForm() async { final validateMsg = await _validateForm(); if (validateMsg != null) { toast(validateMsg); return null; } final crowdLabelCodes = Get.find().state.selectedCodes; final request = CreatePatientRequest( patientName: state.name, phone: state.phoneNo, patientGender: state.gender, nationality: state.nation, birthday: state.birthday?.toUtc(), cardType: state.cardType, cardNo: state.cardNo, patientAddress: state.address, permanentResidenceAddress: state.censusRegister, crowdLabels: crowdLabelCodes, ); final result = await _patientManager.create(request); return result; } Future _validateForm() async { if (state.name.isEmpty) { return "请填写姓名"; } if (state.cardNo.isEmpty) { return "请填写证件号"; } final crowdLabelCodes = Get.find().state.selectedCodes; if (crowdLabelCodes.isEmpty) { return "请选择人群分类"; } return null; } }