friend-add.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="page friend-add">
  3. <nav-bar back>添加好友</nav-bar>
  4. <view class="nav-bar">
  5. <view class="nav-search">
  6. <uni-search-bar v-model="searchText" radius="100" :focus="true" @confirm="onSearch()"
  7. @cancel="onCancel()" placeholder="用户名/昵称"></uni-search-bar>
  8. </view>
  9. </view>
  10. <view class="user-items">
  11. <scroll-view class="scroll-bar" scroll-with-animation="true" scroll-y="true">
  12. <view v-for="(user) in users" :key="user.id" v-show="user.id != userStore.userInfo.id">
  13. <view class="user-item">
  14. <head-image :id="user.id" :name="user.nickName" :online="user.online"
  15. :url="user.headImage"></head-image>
  16. <view class="user-info">
  17. <view class="nick-name">
  18. <view>{{ user.nickName }}</view>
  19. <uni-tag v-if="user.status == 1" circle type="error" text="已注销" size="small"></uni-tag>
  20. </view>
  21. <view class="user-name">用户名:{{ `${user.userName}`}}</view>
  22. </view>
  23. <view class="user-btns">
  24. <button type="primary" v-show="!isFriend(user.id)" size="mini"
  25. @click.stop="onAddFriend(user)">加为好友</button>
  26. <button type="default" v-show="isFriend(user.id)" size="mini" disabled>已添加</button>
  27. </view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. searchText: "",
  39. users: []
  40. }
  41. },
  42. methods: {
  43. onCancel() {
  44. uni.navigateBack();
  45. },
  46. onSearch() {
  47. this.$http({
  48. url: "/user/findByName?name=" + this.searchText,
  49. method: "GET"
  50. }).then((data) => {
  51. this.users = data;
  52. })
  53. },
  54. onAddFriend(user) {
  55. this.$http({
  56. url: "/friend/add?friendId=" + user.id,
  57. method: "POST"
  58. }).then((data) => {
  59. let friend = {
  60. id: user.id,
  61. nickName: user.nickName,
  62. headImage: user.headImageThumb,
  63. online: user.online,
  64. delete: false
  65. }
  66. this.friendStore.addFriend(friend);
  67. uni.showToast({
  68. title: "添加成功,对方已成为您的好友",
  69. icon: "none"
  70. })
  71. })
  72. },
  73. onShowUserInfo(user) {
  74. uni.navigateTo({
  75. url: "/pages/common/user-info?id=" + user.id
  76. })
  77. },
  78. isFriend(userId) {
  79. return this.friendStore.isFriend(userId);
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. .friend-add {
  86. position: relative;
  87. display: flex;
  88. flex-direction: column;
  89. .user-items {
  90. position: relative;
  91. flex: 1;
  92. overflow: hidden;
  93. .user-item {
  94. height: 100rpx;
  95. display: flex;
  96. margin-bottom: 1rpx;
  97. position: relative;
  98. padding: 18rpx 20rpx;
  99. align-items: center;
  100. background-color: white;
  101. white-space: nowrap;
  102. .user-info {
  103. flex: 1;
  104. display: flex;
  105. flex-direction: column;
  106. padding-left: 20rpx;
  107. font-size: $im-font-size;
  108. white-space: nowrap;
  109. overflow: hidden;
  110. .nick-name {
  111. display: flex;
  112. flex: 1;
  113. font-size: $im-font-size-large;
  114. white-space: nowrap;
  115. overflow: hidden;
  116. align-items: center;
  117. .uni-tag {
  118. text-align: center;
  119. margin-left: 5rpx;
  120. padding: 1px 5px;
  121. }
  122. }
  123. .user-name {
  124. display: flex;
  125. font-size: $im-font-size-smaller;
  126. color: $im-text-color-lighter;
  127. padding-top: 8rpx;
  128. }
  129. }
  130. }
  131. .scroll-bar {
  132. height: 100%;
  133. }
  134. }
  135. }
  136. </style>