addressbook.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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" v-model="searchUserName"></u-search>
  9. </view>
  10. <view style="padding: 20upx; background-color: white;">
  11. <u-search placeholder="部门" :clearabled="true" :showAction="false" v-model="officeName"></u-search>
  12. </view>
  13. <view style="padding: 20upx; background-color: white;">
  14. <u-search placeholder="手机号" :clearabled="true" :showAction="false" v-model="mobile"></u-search>
  15. </view>
  16. </u-sticky>
  17. <view>
  18. <u-index-list :indexList="indexList">
  19. <template v-for="(item, index) in list">
  20. <!-- #ifdef APP-NVUE -->
  21. <u-index-anchor :text="list[index].letter" :key="index"></u-index-anchor>
  22. <!-- #endif -->
  23. <u-index-item :key="index">
  24. <!-- #ifndef APP-NVUE -->
  25. <u-index-anchor :text="list[index].letter"></u-index-anchor>
  26. <!-- #endif -->
  27. <view class="list" v-for="(user, index1) in list[index].data" :key="index1">
  28. <!-- 检查user.name是否不等于"管理员" -->
  29. <view class="list__item" v-if="user.name !== '管理员'">
  30. <u-avatar shape="square" size="35" icon="account-fill" fontSize="26"
  31. randomBgColor></u-avatar>
  32. <!-- <view class="cu-avatar round " :style="'background-image:url('+(user.photo?user.photo:'/h5/static/user/flat-avatar.png')+');'"></view> -->
  33. <text class="list__item__user-name">{{ user.name }}</text>
  34. <!-- 新增的展示其他信息的元素 -->
  35. <!-- 使用条件渲染检查 user.officeDTO.name 是否为 null -->
  36. <text class="list__item__additional-info" v-if="user.officeDTO">{{ user.officeDTO.name
  37. }}</text>
  38. <!-- 新的电话号码信息 -->
  39. <text class="list__item__phone-number">{{ user.mobile }}</text>
  40. </view>
  41. <u-line v-if="user.name !== '管理员'"></u-line>
  42. </view>
  43. </u-index-item>
  44. </template>
  45. <view style="font-size: 15px; color: gray; text-align: center; margin-top: 15px;">共{{ total }}位好友</view>
  46. </u-index-list>
  47. <u-gap height="100" bgColor="#fff"></u-gap>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import userService from '@/api/sys/userService'
  53. export default {
  54. data() {
  55. return {
  56. indexList: [],
  57. userList: [],
  58. total: 0,
  59. searchUserName: '',
  60. officeName: '',
  61. mobile: ''
  62. }
  63. },
  64. created() {
  65. let params = { current: 1, size: 10000, tenantDTO: {} }
  66. if (this.userInfo.tenantDTO.id == "10009") {
  67. params.tenantDTO.id = this.userInfo.tenantDTO.id
  68. }
  69. userService.list(params).then((data) => {
  70. this.userList = data.records
  71. this.total = data.total
  72. }).catch((e) => {
  73. throw e
  74. })
  75. },
  76. computed: {
  77. userInfo() {
  78. return this.$store.state.user.userInfo
  79. },
  80. list() {
  81. let resultList = this.userList.filter((item) => {
  82. if (item.name.indexOf(this.searchUserName) >= 0) {
  83. return true
  84. }
  85. })
  86. resultList = resultList.filter((item) => {
  87. if (item.officeDTO && item.officeDTO.name) {
  88. if (item.officeDTO.name.indexOf(this.officeName) >= 0) {
  89. return true
  90. }
  91. }
  92. })
  93. resultList = resultList.filter((item) => {
  94. if (item.mobile) {
  95. if (item.mobile.indexOf(this.mobile) >= 0) {
  96. return true
  97. }
  98. }
  99. })
  100. this.total = resultList.length
  101. return this.pySegSort(resultList)
  102. }
  103. },
  104. methods: {
  105. // 排序
  106. pySegSort(arr) {
  107. if (!String.prototype.localeCompare)
  108. return null;
  109. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  110. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  111. var segs = [];
  112. this.indexList = [];
  113. var curr;
  114. letters.forEach((item, i) => {
  115. curr = { letter: item, data: [] };
  116. arr.forEach((item2) => {
  117. if ((!zh[i - 1] || zh[i - 1].localeCompare(item2.name) <= 0) && item2.name.localeCompare(zh[i]) == -1) {
  118. curr.data.push(item2);
  119. }
  120. });
  121. if (curr.data.length) {
  122. segs.push(curr);
  123. this.indexList.push(curr.letter)
  124. curr.data.sort((a, b) => {
  125. return a.name.localeCompare(b.name);
  126. });
  127. }
  128. });
  129. return segs;
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. .list {
  136. &__item {
  137. @include flex;
  138. padding: 6px 12px;
  139. align-items: center;
  140. &__avatar {
  141. height: 35px;
  142. width: 35px;
  143. border-radius: 3px;
  144. }
  145. &__user-name {
  146. font-size: 16px;
  147. margin-left: 10px;
  148. color: $u-main-color;
  149. }
  150. }
  151. &__footer {
  152. color: $u-tips-color;
  153. font-size: 14px;
  154. text-align: center;
  155. margin: 15px 0;
  156. }
  157. }
  158. .list__item__additional-info {
  159. position: relative;
  160. top: 10px;
  161. /* Adjust as needed */
  162. left: 15px;
  163. /* Adjust as needed */
  164. font-size: 12px;
  165. /* Adjust the font size as needed */
  166. color: #999;
  167. /* Adjust the color as needed */
  168. }
  169. .list__item__phone-number {
  170. position: relative;
  171. top: 10px;
  172. /* Adjust as needed */
  173. margin-left: 20px;
  174. /* 根据需要调整间距 */
  175. font-size: 12px;
  176. /* 根据需要调整字体大小 */
  177. color: #999;
  178. /* 根据需要调整颜色 */
  179. }
  180. </style>