addressbook.vue 4.1 KB

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