addressbook.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="main">
  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. userService.list({
  67. current: 1,
  68. size: 10000
  69. }).then((res) => {
  70. this.userList = res.records
  71. this.officeList = this.forItem(data)
  72. this.total = res.total
  73. }).catch((e) => {
  74. throw e
  75. })
  76. })
  77. userService.list({
  78. current: 1,
  79. size: 10000
  80. }).then((data) => {
  81. this.userList = data.records
  82. this.total = data.total
  83. }).catch((e) => {
  84. throw e
  85. })
  86. },
  87. // computed: {
  88. // list () {
  89. // let resultList = this.userList.filter((item)=>{
  90. // if(item.name.indexOf(this.searchUserName) >= 0){
  91. // return true
  92. // }
  93. // })
  94. // return this.pySegSort(resultList)
  95. // }
  96. // },
  97. methods: {
  98. // 排序
  99. pySegSort(arr) {
  100. if (!String.prototype.localeCompare)
  101. return null;
  102. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  103. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  104. var segs = [];
  105. var curr;
  106. letters.forEach((item, i) => {
  107. curr = {
  108. letter: item,
  109. data: []
  110. };
  111. arr.forEach((item2) => {
  112. if ((!zh[i - 1] || zh[i - 1].localeCompare(item2.name) <= 0) && item2.name
  113. .localeCompare(zh[i]) == -1) {
  114. curr.data.push(item2);
  115. }
  116. });
  117. if (curr.data.length) {
  118. segs.push(curr);
  119. this.indexList.push(curr.letter)
  120. curr.data.sort((a, b) => {
  121. return a.name.localeCompare(b.name);
  122. });
  123. }
  124. });
  125. return segs;
  126. },
  127. // 遍历
  128. forItem(list) {
  129. for (let i = 0; i < list.length; i++) {
  130. let b = []
  131. if(list[i].icon) continue;
  132. b = this.userList.filter(item => item.officeDTO && item.officeDTO.id == list[i].id)
  133. if (b.length > 0) {
  134. b.forEach(item => {
  135. this.$set(item, "icon", "/static/img/flat-avatar.png");
  136. })
  137. if (list[i].children) {
  138. list[i].children = list[i].children.concat(b);
  139. this.forItem(list[i].children)
  140. } else {
  141. this.$set(list[i], "children", b);
  142. }
  143. } else {
  144. if (list[i].children && list[i].children.length > 0) {
  145. this.forItem(list[i].children)
  146. } else {
  147. let no = [{
  148. id: "no001",
  149. name: '暂无人员'
  150. }]
  151. this.$set(list[i], "children", no);
  152. }
  153. }
  154. }
  155. return list;
  156. },
  157. }
  158. }
  159. </script>
  160. <style lang="scss">
  161. .list {
  162. &__item {
  163. @include flex;
  164. padding: 6px 12px;
  165. align-items: center;
  166. &__avatar {
  167. height: 35px;
  168. width: 35px;
  169. border-radius: 3px;
  170. }
  171. &__user-name {
  172. font-size: 16px;
  173. margin-left: 10px;
  174. color: $u-main-color;
  175. }
  176. }
  177. &__footer {
  178. color: $u-tips-color;
  179. font-size: 14px;
  180. text-align: center;
  181. margin: 15px 0;
  182. }
  183. }
  184. </style>