controller.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:get/get.dart';
  2. import 'package:url_launcher/url_launcher.dart';
  3. import '../../../../common/api/index.dart';
  4. import '../../../../common/models/orgs/index.dart';
  5. import '../../../../common/utils/index.dart';
  6. import '../../../../common/values/index.dart';
  7. import '../../im/im_chat/index.dart';
  8. import 'index.dart';
  9. class PersonController extends GetxController {
  10. PersonController();
  11. final state = PersonState();
  12. /// 在 widget 内存中分配后立即调用。
  13. @override
  14. void onInit() {
  15. super.onInit();
  16. }
  17. /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  18. @override
  19. void onReady() {
  20. final map = Get.arguments;
  21. if (map != null && map["id"] != null && map["id"] is String) {
  22. String id = map["id"] as String;
  23. loadPersonInfo(id);
  24. } else {
  25. OLogger.e('参数异常,没有人员 id');
  26. Get.back();
  27. }
  28. super.onReady();
  29. }
  30. /// 查询人员信息
  31. loadPersonInfo(String id) async {
  32. Loading.show();
  33. final person = await OrganizationControlService.to.person(id);
  34. if (person != null) {
  35. Loading.dismiss();
  36. if (person.superior != null && person.superior?.isNotEmpty == true) {
  37. loadSuperiorName(person.superior!);
  38. }
  39. state.person.value = person;
  40. // 隐藏手机号码
  41. if (O2ContactPermissionManager.instance
  42. .isHiddenMobile(person.distinguishedName!)) {
  43. person.showMobile = O2.hiddenMobileNumber;
  44. }
  45. if (person.woIdentityList != null) {
  46. state.departmentNames =
  47. person.woIdentityList!.map((e) => e.unitName!).toList().join('、');
  48. }
  49. loadPersonAttribute(person.woPersonAttributeList ?? []);
  50. } else {
  51. OLogger.e('人员 id $id 查询人员信息失败!');
  52. Get.back();
  53. }
  54. }
  55. /// 汇报对象人员名称
  56. loadSuperiorName(String id) async {
  57. final person = await OrganizationControlService.to.person(id);
  58. if (person != null) {
  59. state.superiorName = person.name ?? '';
  60. }
  61. }
  62. /// 加载人员属性
  63. loadPersonAttribute(List<O2PersonAttribute> woPersonAttributeList) async {
  64. if (woPersonAttributeList.isEmpty) {
  65. return;
  66. }
  67. List<O2PersonAttribute> personAttributeList = [];
  68. Map<String, dynamic> extendParam = ProgramCenterService.to.extendParam();
  69. Map<String, dynamic>? personAttributeMobile = extendParam['personAttributeMobile'];
  70. if (personAttributeMobile == null) {
  71. Map<String, dynamic>? config = await O2ApiManager.instance.getWebConfigJson();
  72. if (config != null ) {
  73. personAttributeMobile = config['personAttributeMobile'];
  74. }
  75. }
  76. List<String> showList =
  77. personAttributeMobile?['showList']?.cast<String>() ?? [];
  78. List<String> hiddenList =
  79. personAttributeMobile?['hiddenList']?.cast<String>() ?? [];
  80. if (showList.isEmpty && hiddenList.isEmpty) {
  81. personAttributeList.addAll(woPersonAttributeList);
  82. } else {
  83. for (O2PersonAttribute attribute in woPersonAttributeList) {
  84. if ((showList.isNotEmpty && showList.contains(attribute.name)) ||
  85. (hiddenList.isNotEmpty && !hiddenList.contains(attribute.name))) {
  86. personAttributeList.add(attribute);
  87. }
  88. }
  89. }
  90. state.personAttributeList.addAll(personAttributeList);
  91. }
  92. void mailTo(String mail) async {
  93. if (mail.isNotEmpty) {
  94. Uri uri = Uri(scheme: 'mailto', path: mail);
  95. if (await canLaunchUrl(uri)) {
  96. await launchUrl(uri);
  97. }
  98. }
  99. }
  100. void telTo(String phone) async {
  101. if (phone.isNotEmpty) {
  102. Uri uri = Uri(scheme: 'tel', path: phone);
  103. if (await canLaunchUrl(uri)) {
  104. await launchUrl(uri);
  105. }
  106. }
  107. }
  108. /// 发起聊天
  109. Future<void> startSingleChat() async {
  110. var person = state.person.value;
  111. if (person != null && person.distinguishedName != null) {
  112. final conv = await MessageCommunicationService.to.createConversation(
  113. O2.imConversationTypeSingle, [person.distinguishedName!]);
  114. if (conv != null) {
  115. await ImChatPage.open(conv.id!);
  116. }
  117. }
  118. }
  119. }