search.vue 5.8 KB

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