view.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../../../common/models/index.dart';
  4. import '../../../common/style/index.dart';
  5. import '../../../common/widgets/index.dart';
  6. import 'index.dart';
  7. class ContactPage extends GetView<ContactController> {
  8. const ContactPage({Key? key}) : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. return GetBuilder<ContactController>(
  12. builder: (_) {
  13. return Scaffold(
  14. appBar: AppBar(title: Text('home_tab_contact'.tr)),
  15. body: SafeArea(
  16. child: Padding(
  17. padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
  18. child: Column(
  19. children: [
  20. searchBar(context),
  21. const SizedBox(height: 10),
  22. Expanded(
  23. flex: 1,
  24. child: Obx(() => ListView(children: [
  25. deptChildren('contact_my_department'.tr,
  26. controller.state.myDepartments, context),
  27. ...deptListToWidget(
  28. controller.state.topUnit, context)
  29. // const SizedBox(height: 10),
  30. // Obx(() => deptChildren('contact_structure'.tr,
  31. // controller.state.topUnit, context))
  32. ])),
  33. )
  34. ],
  35. )),
  36. ),
  37. );
  38. },
  39. );
  40. }
  41. List<Widget> deptListToWidget(List<O2Unit> topUnit, BuildContext context) {
  42. List<Widget> list = [];
  43. for (var element in topUnit) {
  44. list.add(const SizedBox(height: 10));
  45. list.add(deptChildren(
  46. element.name ?? '', element.subUnitList ?? [], context,
  47. personList: element.personList ?? []));
  48. }
  49. return list;
  50. }
  51. Widget deptChildren(String title, List<O2Unit> depts, BuildContext context,
  52. {List<O2Person> personList = const []}) {
  53. List<Widget> list = [];
  54. if (depts.isNotEmpty) {
  55. list.add(ListTile(
  56. title: Text(title, style: Theme.of(context).textTheme.titleSmall)));
  57. var dList = depts.map((e) {
  58. var orgName = e.name ?? '';
  59. var oneName = orgName;
  60. if (orgName.length > 1) {
  61. oneName = oneName.substring(0, 1);
  62. }
  63. return ListTile(
  64. leading: SizedBox(
  65. width: 32,
  66. height: 32,
  67. child: CircleAvatar(
  68. radius: 32,
  69. backgroundColor: Theme.of(context).colorScheme.primary,
  70. child: Text(oneName, style: const TextStyle(color: Colors.white)),
  71. ),
  72. ),
  73. title: Text(orgName),
  74. trailing: O2UI.rightArrow(),
  75. onTap: () => controller.openDept(e),
  76. );
  77. }).toList();
  78. list.addAll(dList);
  79. // 人员列表
  80. if (personList.isNotEmpty) {
  81. list.add(const SizedBox(height: 10));
  82. final pList = personList.map((e) {
  83. return ListTile(
  84. onTap: () => controller.clickEnterPerson(e),
  85. leading: SizedBox(
  86. width: 50,
  87. height: 50,
  88. child: O2UI.personAvatar(e.distinguishedName!, 25),
  89. ),
  90. title: Text(e.name ?? ''),
  91. trailing: O2UI.rightArrow(),
  92. );
  93. }).toList();
  94. list.addAll(pList);
  95. }
  96. }
  97. return Card(
  98. shape: const RoundedRectangleBorder(
  99. borderRadius: BorderRadius.all(Radius.circular(10))),
  100. child: Column(children: list));
  101. }
  102. Widget searchBar(BuildContext context) {
  103. return GestureDetector(
  104. onTap: controller.openSearchContact,
  105. child: Container(
  106. height: 36,
  107. decoration: BoxDecoration(
  108. color: Theme.of(context).colorScheme.background,
  109. borderRadius: BorderRadius.all(Radius.circular(18))),
  110. alignment: Alignment.centerLeft,
  111. child: Padding(
  112. padding: EdgeInsets.only(left: 10),
  113. child: Row(
  114. crossAxisAlignment: CrossAxisAlignment.center,
  115. children: [
  116. SizedBox(
  117. width: 22,
  118. height: 22,
  119. child: Icon(O2IconFont.search,
  120. color: Theme.of(context).colorScheme.primary),
  121. ),
  122. Padding(
  123. padding: EdgeInsets.only(left: 10),
  124. child: Text(
  125. "contact_person_search_placeholder".tr,
  126. style: Theme.of(context).textTheme.bodySmall,
  127. ))
  128. ],
  129. ),
  130. )));
  131. }
  132. }