Browse Source

优化读卡器逻辑

gavin.chen 1 year ago
parent
commit
25205422f8

+ 25 - 22
lib/pages/patient/card_reader/controller.dart

@@ -1,6 +1,7 @@
 import 'dart:math';
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:get/get.dart';
+import 'package:idread/model/id_card_info_model.dart';
 import 'package:vitalapp/architecture/utils/prompt_box.dart';
 import 'package:idread/idread.dart';
 
@@ -15,7 +16,9 @@ class CardReaderController extends GetxController {
       bool start = await Idread.startRead();
       if (start) {
         Idread.dataStreamListen((data) {
-          print(data.toString());
+          if (data is IdCardInfoModel) {
+            onReadInfo(data);
+          }
         });
       }
     }
@@ -29,7 +32,9 @@ class CardReaderController extends GetxController {
       bool start = await Idread.startRead();
       if (start) {
         Idread.dataStreamListen((data) {
-          print(data.toString());
+          if (data is IdCardInfoModel) {
+            onReadInfo(data);
+          }
         });
       }
     } else {
@@ -41,16 +46,17 @@ class CardReaderController extends GetxController {
 
   /// 读取到数据的回调
   /// TODO addListener 监听读卡器读到数据
-  void onReadInfo(String mockData) {
+  void onReadInfo(IdCardInfoModel data) {
+    print("读卡器读到数据:$data");
+    print("读卡器读到数据:${data.birthDay}");
     final result = CardReaderResult(
       success: true,
-      cardNo: "123456789012345678",
-      name: "张三",
-      nation: "汉族",
-      gender: GenderEnum.Female,
+      cardNo: data.idCard,
+      name: data.peopleName,
+      nation: data.people,
+      gender: data.sex == '男' ? GenderEnum.Male : GenderEnum.Female,
       birthday: DateTime(1990, 1, 1),
-      address: "北京市朝阳区",
-      censusRegister: "北京市朝阳区",
+      address: data.address,
     );
     Get.back(
       result: result,
@@ -97,19 +103,16 @@ class CardReaderResult {
   /// 出生日期
   DateTime birthday;
 
-  /// 现住地址
+  /// 地址
   String address;
 
-  /// 户籍地址
-  String censusRegister;
-
-  CardReaderResult(
-      {required this.success,
-      required this.cardNo,
-      required this.name,
-      required this.gender,
-      required this.nation,
-      required this.birthday,
-      required this.address,
-      required this.censusRegister});
+  CardReaderResult({
+    required this.success,
+    required this.cardNo,
+    required this.name,
+    required this.gender,
+    required this.nation,
+    required this.birthday,
+    required this.address,
+  });
 }

+ 1 - 1
lib/pages/patient/card_reader/widgets/card_reader_view.dart

@@ -33,7 +33,7 @@ class CardReaderView extends GetView<CardReaderController> {
         ElevatedButton(
           onPressed: () {
             // FIXME 模拟读取到数据
-            controller.onReadInfo("mockData");
+            // controller.onReadInfo("mockData");
           },
           child: const Text(
             '取消',

+ 1 - 2
lib/pages/patient/create/controller.dart

@@ -113,14 +113,13 @@ class CreatePatientController extends FControllerBase with HomeNavMixin {
       const CardReaderDialog(),
     );
     if (result != null && result.success) {
-      print("读卡成功,身份证号:${result.cardNo}");
+      PromptBox.toast("读取成功");
       state.cardNo = result.cardNo; // 回填身份证号
       state.name = result.name; // 回填姓名
       state.gender = result.gender; // 回填性别
       state.nation = result.nation; // 回填民族
       state.birthday = result.birthday; // 回填出生日期
       state.address = result.address; // 回填现住地址
-      state.censusRegister = result.censusRegister; // 回填户籍地址
     } else {
       print("读卡取消");
     }