search.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view>
  3. <uni-nav-bar id="nav-bar" status-bar="true" backgroundColor="#FFF"
  4. @clickLeft="onBack()" @clickRight="onSearch()" fixed="true" :border="false">
  5. <view slot="left" >
  6. <view class="flex align-center " style="margin-left: 20rpx;">
  7. <image class="p-left-arrow" src="/static/p-left-arrow.png"></image>
  8. </view>
  9. </view>
  10. <view slot='middle' style=" margin-left: -65rpx; flex: 1.5;">
  11. <view class="cu-bar ">
  12. <view class="search-form round" style="margin: 0 10rpx;">
  13. <text class="cuIcon-search"></text>
  14. <input @input="onKeyInput" @focus="InputFocus" @blur="InputBlur" :adjust-position="false" type="text"
  15. placeholder="输入名字,搜索好友" confirm-type="search"></input>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- @clickRight="onNavFcGame()" -->
  20. <view slot="right" >
  21. <view style="position: relative; border: 1rpx solid #FFFFFF;">
  22. <view class="text-16px make-text-bPurple" style="line-height: 32rpx;">搜索</view>
  23. </view>
  24. </view>
  25. </uni-nav-bar>
  26. <!-- <view class="cu-bar search bg-white">
  27. <view class=" flex align-center margin-left" @click="onBack()">
  28. <image class="p-left-arrow" src="/static/p-left-arrow.png"></image>
  29. </view>
  30. <view class="search-form round">
  31. <text class="cuIcon-search"></text>
  32. <input @input="onKeyInput" @focus="InputFocus" @blur="InputBlur" :adjust-position="false" type="text"
  33. placeholder="输入名字,搜索好友" confirm-type="search"></input>
  34. </view>
  35. <view class="action">
  36. <view class="text-16px make-text-bPurple" style="line-height: 32rpx;" @click="onSearch()">搜索</view>
  37. </view>
  38. </view> -->
  39. <view class="cu-list menu-avatar ">
  40. <view class="cu-item card-view" style="height: 180rpx;" v-for="(item, index) in friends" :key="index">
  41. <view class="cu-avatar round lg"
  42. :style="[{ backgroundImage:'url('+item.avatarUrl+')' }]">
  43. <view class="cu-tag badge-bottom" >
  44. <image v-if="item.gender == 0" style="height: 32rpx;width: 32rpx;" src="../../../static/friend/boy.png"></image>
  45. <image v-if="item.gender == 1" style="height: 32rpx;width: 32rpx;" src="../../../static/friend/girl.png"></image>
  46. </view>
  47. </view>
  48. <view class="content" style="width: 360rpx;">
  49. <view class="text-grey">{{item.username}}</view>
  50. <view class="text-gray text-sm flex">
  51. <view class="text-cut">
  52. <text class="cuIcon-infofill text-red margin-right-xs"></text>
  53. {{item.signature}}
  54. </view>
  55. </view>
  56. <!-- <view class="text-gray text-sm flex">
  57. <view class="text-cut">
  58. <text class="cuIcon-infofill text-red margin-right-xs"></text>
  59. 我已天理为凭,踏入这片荒芜,不再受凡人的枷锁遏制。我已天理为凭,踏入这片荒芜,不再受凡人的枷锁遏制。
  60. </view>
  61. </view> -->
  62. </view>
  63. <view class="action" style="width: 160rpx; ">
  64. <button v-if="!item.isFriend" class="cu-btn round make-lines-bPurple"
  65. style="width: 146rpx; right: 30rpx;" @click="onAddFriend(item)">
  66. 添加</button>
  67. <button v-else class="cu-btn round bg-grey" style="width: 146rpx; right: 30rpx;">
  68. 已关注</button>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import config from '../../../common/config.js';
  76. import reqUtil from '../../../util/util-js/requstUtil.js';
  77. export default {
  78. data() {
  79. return {
  80. friends: [],
  81. inputValue:''
  82. }
  83. },
  84. methods: {
  85. onBack() {
  86. uni.navigateBack({
  87. delta: 1
  88. })
  89. },
  90. onKeyInput: function(event) {
  91. this.inputValue = event.target.value
  92. },
  93. onSearch() {
  94. if(this.inputValue.length < 1){
  95. uni.showToast({
  96. title:'请输入名字',
  97. duration:1000,
  98. icon:'none',
  99. mask:true
  100. })
  101. return;
  102. }
  103. reqUtil.requestData(config.URL.SEARCHFIRENDLIST, {
  104. username: this.inputValue
  105. }).then(
  106. res => {
  107. // console.log(JSON.stringify(res));
  108. this.friends = res.data.friends;
  109. },
  110. e => {
  111. console.log(e);
  112. }
  113. );
  114. },
  115. onAddFriend(data) {
  116. uni.showToast({
  117. title: '添加中..',
  118. duration: 1000,
  119. icon: 'loading',
  120. mask: true
  121. })
  122. reqUtil.requestData(config.URL.ADDFIRENDINFO, {
  123. friendId: data.friendId
  124. }).then(
  125. res => {
  126. console.log(JSON.stringify(res));
  127. // this.friends = res.data.friends;
  128. if (0 === res.code) {
  129. data.isFriend = true;
  130. uni.showToast({
  131. title: '添加成功',
  132. duration: 1000,
  133. mask: true
  134. })
  135. }
  136. },
  137. e => {
  138. console.log(e);
  139. }
  140. );
  141. }
  142. }
  143. }
  144. </script>
  145. <style>
  146. </style>