addressbook.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="main">
  3. <cu-custom bgColor="bg-blue">
  4. <block slot="content">通讯录</block>
  5. </cu-custom>
  6. <view class="tree">
  7. <ly-tree :tree-data="officeList" :props="props" node-key="id" :checkOnClickNode="true" :showRadio="false"
  8. :show-checkbox="false" :checkOnlyLeaf="false" ref="officeTree" />
  9. </view>
  10. <u-overlay :show="loading">
  11. <view class="warp">
  12. <view class="rect"><u-button plain loading loadingText="加载中"></u-button></view>
  13. </view>
  14. </u-overlay>
  15. </view>
  16. </template>
  17. <script>
  18. import userService from '@/api/sys/userService'
  19. import officeService from "@/api/sys/officeService"
  20. export default {
  21. data() {
  22. return {
  23. loading:true,
  24. indexList: [],
  25. officeList: [],
  26. userList: [],
  27. total: 0,
  28. searchUserName: ''
  29. }
  30. },
  31. props: {
  32. props: {
  33. type: Object,
  34. default: () => {
  35. return {
  36. children: 'children',
  37. label: 'name'
  38. }
  39. }
  40. }
  41. },
  42. created() {
  43. officeService.treeData().then(data => {
  44. // this.officeList = data
  45. userService.list({
  46. current: 1,
  47. size: 10000
  48. }).then((res) => {
  49. this.userList = res.records
  50. this.officeList = this.forItem(data)
  51. this.total = res.total
  52. this.loading=false
  53. }).catch((e) => {
  54. throw e
  55. })
  56. })
  57. userService.list({
  58. current: 1,
  59. size: 10000
  60. }).then((data) => {
  61. this.userList = data.records
  62. this.total = data.total
  63. }).catch((e) => {
  64. throw e
  65. })
  66. },
  67. // computed: {
  68. // list () {
  69. // let resultList = this.userList.filter((item)=>{
  70. // if(item.name.indexOf(this.searchUserName) >= 0){
  71. // return true
  72. // }
  73. // })
  74. // return this.pySegSort(resultList)
  75. // }
  76. // },
  77. methods: {
  78. // 排序
  79. pySegSort(arr) {
  80. if (!String.prototype.localeCompare)
  81. return null;
  82. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  83. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  84. var segs = [];
  85. var curr;
  86. letters.forEach((item, i) => {
  87. curr = {
  88. letter: item,
  89. data: []
  90. };
  91. arr.forEach((item2) => {
  92. if ((!zh[i - 1] || zh[i - 1].localeCompare(item2.name) <= 0) && item2.name
  93. .localeCompare(zh[i]) == -1) {
  94. curr.data.push(item2);
  95. }
  96. });
  97. if (curr.data.length) {
  98. segs.push(curr);
  99. this.indexList.push(curr.letter)
  100. curr.data.sort((a, b) => {
  101. return a.name.localeCompare(b.name);
  102. });
  103. }
  104. });
  105. return segs;
  106. },
  107. // 遍历
  108. forItem(list) {
  109. for (let i = 0; i < list.length; i++) {
  110. let b = []
  111. if(list[i].icon) continue;
  112. b = this.userList.filter(item => item.officeDTO && item.officeDTO.id == list[i].id)
  113. if (b.length > 0) {
  114. b.forEach(item => {
  115. this.$set(item, "icon", "/static/img/flat-avatar.png");
  116. })
  117. if (list[i].children) {
  118. list[i].children = list[i].children.concat(b);
  119. this.forItem(list[i].children)
  120. } else {
  121. this.$set(list[i], "children", b);
  122. }
  123. } else {
  124. if (list[i].children && list[i].children.length > 0) {
  125. this.forItem(list[i].children)
  126. } else {
  127. let no = [{
  128. id: "no001",
  129. name: '暂无人员'
  130. }]
  131. this.$set(list[i], "children", no);
  132. }
  133. }
  134. }
  135. return list;
  136. },
  137. }
  138. }
  139. </script>
  140. <style lang="scss">
  141. .warp {
  142. display: flex;
  143. align-items: center;
  144. justify-content: center;
  145. height: 100%;
  146. }
  147. .list {
  148. &__item {
  149. @include flex;
  150. padding: 6px 12px;
  151. align-items: center;
  152. &__avatar {
  153. height: 35px;
  154. width: 35px;
  155. border-radius: 3px;
  156. }
  157. &__user-name {
  158. font-size: 16px;
  159. margin-left: 10px;
  160. color: $u-main-color;
  161. }
  162. }
  163. &__footer {
  164. color: $u-tips-color;
  165. font-size: 14px;
  166. text-align: center;
  167. margin: 15px 0;
  168. }
  169. }
  170. </style>