search.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-WEIXIN -->
  4. <u-navbar title=" " :background="{ background: '#F6F7F8' }">
  5. <view class="slot-wrap">
  6. <u-search
  7. :focus="true"
  8. @custom="clickCancel"
  9. placeholder="搜索..."
  10. shape="square"
  11. :action-style="{ color: '#007aff' }"
  12. action-text="取消"
  13. :bg-color="'#ffffff'"
  14. v-model="searchWord"
  15. ></u-search>
  16. </view>
  17. </u-navbar>
  18. <!-- #endif -->
  19. <!-- #ifndef MP-WEIXIN -->
  20. <view class="status_bar"></view>
  21. <view class="content_search">
  22. <u-search
  23. :focus="true"
  24. @custom="clickCancel"
  25. @search="toSearch"
  26. placeholder="h5能否自动获取焦点取决于浏览器的实现"
  27. shape="square"
  28. :action-style="{ color: '#007aff' }"
  29. action-text="取消"
  30. :bg-color="'#ffffff'"
  31. v-model="searchWord"
  32. ></u-search>
  33. </view>
  34. <!-- #endif -->
  35. <view class="content1" v-if="'0' == searchType">
  36. <view v-for="(item, index) in list" :key="index">
  37. <chatItem @linkTo="toUserInfo" :value="item" :index="index"></chatItem>
  38. </view>
  39. </view>
  40. <view class="content" v-else-if="'1' == searchType">
  41. <template v-for="(item,index) in list">
  42. <chatItem @linkTo="linkTo" :value="item" :index="index"></chatItem>
  43. </template>
  44. </view>
  45. <view class="content1" v-else-if="'2' == searchType">
  46. <addressBook :list="list" :scrollTop="scrollTop" @linkTo="linkToCard"></addressBook>
  47. </view>
  48. <view class="content" v-else-if="'3' == searchType || '4' == searchType">
  49. <template v-for="(item, index) in list">
  50. <chatItem :value="item" :index="index"></chatItem>
  51. </template>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import chatItem from '@/components/chatItem.vue';
  57. import addressBook from '@/components/addressBook.vue'
  58. import { pinyin } from '../../public/Pinyin.js';
  59. export default {
  60. name:'search',
  61. components:{chatItem,addressBook},
  62. data() {
  63. return {
  64. chatId: '',
  65. pageNum: -1,
  66. searchType: '0',
  67. searchWord: '',
  68. list: [],
  69. scrollTop:0
  70. };
  71. },
  72. watch:{
  73. searchWord:function(v){
  74. this.toSearch(v)
  75. }
  76. },
  77. onPageScroll(e) {
  78. this.scrollTop = e.scrollTop;
  79. },
  80. methods: {
  81. toUserInfo(userInfo){
  82. this.$u.route({
  83. url: 'pages/businessCard/businessCard',
  84. params:{ ...userInfo, source: 2}
  85. })
  86. },
  87. clickCancel() {
  88. this.$u.route({
  89. type: 'navigateBack'
  90. });
  91. },
  92. linkToCard({ id }) {
  93. this.$u.route({
  94. url: 'pages/businessCard/businessCard',
  95. params:{ id: id, source: 0}
  96. });
  97. },
  98. toSearch(v) {
  99. let that = this;
  100. const keyword = v
  101. switch(that.searchType){
  102. case '0':
  103. that.$socket.findFriendRequestList(keyword, res => {
  104. if (res.success) {
  105. that.list = res.userList;
  106. }
  107. });
  108. break;
  109. case '1':
  110. that.$socket.queryChats(keyword, that.userData.user.operId, res => {
  111. if (res.success) {
  112. that.list = res.chats;
  113. }
  114. });
  115. break;
  116. case '2':
  117. that.list = that.firendItem.filter(v => {
  118. let flag = false
  119. if(v.members.length>0){
  120. v.members.forEach(m=>{
  121. if(m.nickName.includes(keyword)
  122. ||pinyin.getCamelChars(m.nickName).includes(keyword)
  123. ||pinyin.getFullChars(m.nickName).includes(keyword)){
  124. flag = true
  125. }
  126. })
  127. }
  128. return flag
  129. });
  130. break;
  131. case '3':
  132. that.$socket.getFriendMessageByCondition(this.chatId, that.userData.user.operId, this.pageNum, keyword, res => {
  133. if (res.success) {
  134. that.list = res.response.data;
  135. }
  136. });
  137. case '4':
  138. that.$socket.getGroupMessageByCondition(this.chatId, that.userData.user.operId, this.pageNum, keyword, res => {
  139. if (res.success) {
  140. that.list = res.response.data;
  141. }
  142. });
  143. break;
  144. default:
  145. }
  146. },
  147. linkTo(chat) {
  148. this.$u.vuex('chatObj',chat);
  149. this.$u.route({
  150. url: 'pages/chat/chat',
  151. params: {}
  152. });
  153. }
  154. },
  155. onShow() {},
  156. onLoad({ searchType, chatId }) {
  157. this.searchType = searchType;
  158. this.chatId = chatId;
  159. }
  160. };
  161. </script>
  162. <style lang="scss" scoped>
  163. .status_bar {
  164. height: var(--status-bar-height);
  165. width: 100%;
  166. }
  167. .content_search {
  168. padding: 16rpx;
  169. background-color: #F6F7F8;
  170. }
  171. .content {
  172. .item {
  173. width: 750rpx;
  174. display: flex;
  175. align-items: center;
  176. // padding: 20rpx;
  177. image {
  178. width: 76rpx;
  179. height: 76rpx;
  180. margin: 20rpx;
  181. border-radius: 12rpx;
  182. flex: 0 0 76rpx;
  183. }
  184. .right {
  185. overflow: hidden;
  186. flex: 1 0;
  187. padding: 20rpx 20rpx 20rpx 0;
  188. &_top {
  189. display: flex;
  190. justify-content: space-between;
  191. &_name {
  192. font-size: 28rpx;
  193. color: $u-main-color;
  194. flex: 0 0 450rpx;
  195. overflow: hidden;
  196. }
  197. &_time {
  198. font-size: 22rpx;
  199. color: $u-light-color;
  200. }
  201. }
  202. &_btm {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. font-size: 22rpx;
  207. color: $u-tips-color;
  208. padding-top: 10rpx;
  209. }
  210. }
  211. }
  212. .bg_view {
  213. background-color: #fafafa;
  214. }
  215. .slot-wrap {
  216. display: flex;
  217. align-items: center;
  218. padding: 0 30rpx;
  219. }
  220. }
  221. .content1 {
  222. height: 100%;
  223. .list-cell {
  224. display: flex;
  225. box-sizing: border-box;
  226. width: 100%;
  227. padding: 10px 24rpx;
  228. overflow: hidden;
  229. color: #323233;
  230. font-size: 28rpx;
  231. line-height: 48rpx;
  232. background-color: #fff;
  233. align-items: center;
  234. image {
  235. width: 76rpx;
  236. height: 76rpx;
  237. border-radius: 12rpx;
  238. flex: 0 0 76rpx;
  239. }
  240. &-name {
  241. padding-left: 20rpx;
  242. }
  243. }
  244. }
  245. </style>