search.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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="h5能否自动获取焦点取决于浏览器的实现"
  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. });
  136. break;
  137. case '2':
  138. that.list = that.firendItem.filter(v => {
  139. let flag = false
  140. if(v.members.length>0){
  141. v.members.forEach(m=>{
  142. if(m.nickName.includes(keyword)
  143. ||pinyin.getCamelChars(m.nickName).includes(keyword)
  144. ||pinyin.getFullChars(m.nickName).includes(keyword)){
  145. flag = true
  146. }
  147. })
  148. }
  149. return flag
  150. });
  151. break;
  152. case '3':
  153. that.$socket.getFriendMessageByCondition(this.chatId, that.userData.user.operId, this.pageNum, keyword, res => {
  154. if (res.success) {
  155. that.list = res.response.data;
  156. }
  157. });
  158. case '4':
  159. that.$socket.getGroupMessageByCondition(this.chatId, that.userData.user.operId, this.pageNum, keyword, res => {
  160. if (res.success) {
  161. that.list = res.response.data;
  162. }
  163. });
  164. break;
  165. default:
  166. }
  167. },
  168. linkTo(chat) {
  169. this.$u.vuex('chatObj',chat);
  170. this.$u.route({
  171. url: 'pages/chat/chat',
  172. params: {}
  173. });
  174. }
  175. },
  176. onShow() {},
  177. onLoad({ searchType, chatId }) {
  178. this.searchType = searchType;
  179. this.chatId = chatId;
  180. }
  181. };
  182. </script>
  183. <style lang="scss" scoped>
  184. .status_bar {
  185. height: var(--status-bar-height);
  186. width: 100%;
  187. }
  188. .content_search {
  189. padding: 16rpx;
  190. background-color: #F6F7F8;
  191. }
  192. .content {
  193. .item {
  194. width: 750rpx;
  195. display: flex;
  196. align-items: center;
  197. // padding: 20rpx;
  198. image {
  199. width: 76rpx;
  200. height: 76rpx;
  201. margin: 20rpx;
  202. border-radius: 12rpx;
  203. flex: 0 0 76rpx;
  204. }
  205. .right {
  206. overflow: hidden;
  207. flex: 1 0;
  208. padding: 20rpx 20rpx 20rpx 0;
  209. &_top {
  210. display: flex;
  211. justify-content: space-between;
  212. &_name {
  213. font-size: 28rpx;
  214. color: $u-main-color;
  215. flex: 0 0 450rpx;
  216. overflow: hidden;
  217. }
  218. &_time {
  219. font-size: 22rpx;
  220. color: $u-light-color;
  221. }
  222. }
  223. &_btm {
  224. display: flex;
  225. justify-content: space-between;
  226. align-items: center;
  227. font-size: 22rpx;
  228. color: $u-tips-color;
  229. padding-top: 10rpx;
  230. }
  231. }
  232. }
  233. .bg_view {
  234. background-color: #fafafa;
  235. }
  236. .slot-wrap {
  237. display: flex;
  238. align-items: center;
  239. padding: 0 30rpx;
  240. }
  241. }
  242. .content1 {
  243. height: 100%;
  244. .list-cell {
  245. display: flex;
  246. box-sizing: border-box;
  247. width: 100%;
  248. padding: 10px 24rpx;
  249. overflow: hidden;
  250. color: #323233;
  251. font-size: 28rpx;
  252. line-height: 48rpx;
  253. background-color: #fff;
  254. align-items: center;
  255. image {
  256. width: 76rpx;
  257. height: 76rpx;
  258. border-radius: 12rpx;
  259. flex: 0 0 76rpx;
  260. }
  261. &-name {
  262. padding-left: 20rpx;
  263. }
  264. }
  265. }
  266. </style>