search.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="container">
  3. <view id="topnav" class="topnav flex-start" :style="{'height':`${topbarOffsetHeight-statusBarHeight}px`,'padding-top':`${statusBarHeight}px`}">
  4. <image :src="`${assetsUrl}back.png`" mode="widthFix" class="back" @click="back" ></image>
  5. </view>
  6. <view class="search-box flex-start" :style="{'padding-top':`${topbarOffsetHeight+5}px`}">
  7. <view class="input-box flex-start">
  8. <image :src="`${assetsUrl}search-input-serch.png`" mode="aspectFill" class="search-img"></image>
  9. <input :focus="inputFocus" type="text" placeholder="输入昵称进行搜索" placeholder-style="font-size:24rpx;color:#7D7DA4;" class="search-input font24 fw400" v-model="inputText" confirm-type="search" @confirm="search" @input="search">
  10. </view>
  11. <!-- <view class="cancel font28 fw400" @click="search" v-if="users.length===0||user">
  12. 搜索
  13. </view>
  14. <view class="cancel font28 fw400" @click="cancel" v-else>
  15. 取消
  16. </view> -->
  17. </view>
  18. <view class="his-input" v-if="inputText===null" :style="{'padding-top':`${topbarOffsetHeight+56}px`}">
  19. <view class="his-item flex-between" v-for="(item,index) in searchs" :key="index">
  20. <view class="his-left flex-start" @click="chooseHisItem(index)">
  21. <image :src="`${assetsUrl}search-time.png`" mode="aspectFill" class="his-icon"></image>
  22. <text class="his-text font28 fw400">{{item}}</text>
  23. </view>
  24. <image :src="`${assetsUrl}search-close.png`" mode="aspectFill" class="his-close" @click="closeHisItem(index)"></image>
  25. </view>
  26. <view class="tip font24 fw400" v-if="searchs.length>0" @click="clearAll">
  27. 清空搜索记录
  28. </view>
  29. </view>
  30. <view :style="{'padding-top':`${topbarOffsetHeight+56}px`}" v-if="users&&users.length>0">
  31. <view class="list-item flex-start" v-for="(item,index) in users" :key="index" @click="toDetail(item.id)">
  32. <view class="list-head-box">
  33. <image :src="item.iconThumbnail" mode="aspectFill" class="list-head-img"></image>
  34. <view class="list-head-dot" style="background-color: #38E825;" v-if="item.lastActiveTime<=30"></view>
  35. <view class="list-head-dot" style="background-color: #0ABDEF;" v-else-if="item.lastActiveTime>30&&item.lastActiveTime<=1440"></view>
  36. </view>
  37. <view class="list-info-box">
  38. <view class="name-box flex-between">
  39. <view class="name flex-start">
  40. <view class="name-text font28 fw600">
  41. {{item.nick}}
  42. </view>
  43. <image :src="`${assetsUrl}friends-vip.png`" mode="aspectFill" class="name-img" v-if="item.vip"></image>
  44. <image :src="`${assetsUrl}friends-godness.png`" mode="aspectFill" class="name-img-godness" v-if="item.goddess"></image>
  45. <image :src="`${assetsUrl}friends-real.png`" mode="aspectFill" class="name-img" v-else-if="item.realMan"></image>
  46. </view>
  47. <view class="distance font22 fw400" v-if="item.distance&&item.distance!=='NaNm'">
  48. {{item.distance}}
  49. </view>
  50. </view>
  51. <view class="sex-box flex-center" :style="{'background-color':`${item.sex==='Male'?'rgba(108,82,244,0.21)':''}`}">
  52. <image :src="`${assetsUrl}friends-female.png`" mode="aspectFill" class="sex-img" v-if="item.sex==='Famale'"></image>
  53. <image :src="`${assetsUrl}friends-male.png`" mode="aspectFill" class="sex-img" v-if="item.sex==='Male'"></image>
  54. <view class="el font20 fw500 sex-text1" v-if="item.sex==='Famale'">
  55. {{item.ageInfo.age}}
  56. </view>
  57. <view class="el font20 fw500 sex-text2" v-if="item.sex==='Male'">
  58. {{item.ageInfo.age}}
  59. </view>
  60. </view>
  61. <view class="tip-box font28 fw400 el" v-if="item.desc">
  62. 签名:{{item.desc}}
  63. </view>
  64. <view class="tip-box font28 fw400 el" v-else>
  65. 签名:暂无介绍
  66. </view>
  67. </view>
  68. <view class="img-box flex-between" v-if="item.lastNews">
  69. <image :src="item.lastNews.mediaUrls[0]" mode="aspectFill" class="ib1"></image>
  70. <image :src="item.lastNews.mediaUrls[1]" mode="aspectFill" class="ib2"></image>
  71. <image :src="item.lastNews.mediaUrls[2]" mode="aspectFill" class="ib3"></image>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="no-more font24 fw400" v-if="users!==null">没有更多了</view>
  76. <Status type="noData" text="暂无数据" v-if="showNoData"></Status>
  77. </view>
  78. </template>
  79. <script>
  80. import Status from '@/components/Status/Status.vue';
  81. import wxMap from '@/static/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js';
  82. const wxMapSdk=new wxMap({key:'E5SBZ-T2YC3-CBL3F-YGFQQ-26PP2-ERFII'});
  83. export default {
  84. components: {
  85. Status
  86. },
  87. data() {
  88. return {
  89. assetsUrl: this.$util.assetsUrl,
  90. inputText:null,
  91. searchOptions:{
  92. completeUser:{},
  93. geo:{
  94. lat:0,
  95. lon:0
  96. },
  97. listType:'',
  98. page:{
  99. index:1,
  100. size:20,
  101. sortValues:[]
  102. },
  103. prefer:{
  104. cityCode:null,
  105. femaleGoddess:false,
  106. femaleNew:false,
  107. maleNew:false,
  108. maleVip:false,
  109. maxAge:null,
  110. minAge:null,
  111. nick:'',
  112. onlineIn24Hour:null,
  113. onlineIn30Min:null,
  114. sortType:'Recommend'
  115. }
  116. },
  117. users:null,
  118. searchs:[],
  119. inputFocus:true,
  120. showNoData:false
  121. };
  122. },
  123. onLoad() {
  124. this.searchs=uni.getStorageSync('searchHistory')||[];
  125. },
  126. computed: {
  127. statusBarHeight() {
  128. return this.$store.state.statusBarHeight;
  129. },
  130. topbarOffsetHeight() {
  131. return this.$store.state.topbarOffsetHeight;
  132. },
  133. userInfo(){
  134. return this.$store.state.userInfo||JSON.parse(uni.getStorageSync('userInfo'))
  135. }
  136. },
  137. methods:{
  138. back(){
  139. uni.navigateBack({
  140. delta:1
  141. })
  142. },
  143. search(){
  144. if(this.inputText===null){
  145. this.users=null;
  146. return;
  147. }
  148. if(this.inputText===''){
  149. this.users=null;
  150. this.inputText=null;
  151. return;
  152. }
  153. this.searchs=uni.getStorageSync('searchHistory')||[];
  154. if(this.searchs.includes(this.inputText)){
  155. this.searchs.splice(this.searchs.indexOf(this.inputText),1);
  156. }
  157. if(this.searchs.length>=10){
  158. this.searchs.shift();
  159. }
  160. this.searchs.unshift(this.inputText);
  161. uni.setStorageSync('searchHistory',this.searchs);
  162. let user=JSON.parse(uni.getStorageSync('user'))
  163. this.searchOptions.listType=user.sex==='male'?'MaleReco':'FaMaleReco';
  164. this.searchOptions.geo.lat=this.$store.state.latitude;
  165. this.searchOptions.geo.lon=this.$store.state.longitude;
  166. this.searchOptions.prefer.nick=this.inputText;
  167. this.searchOptions.completeUser=user;
  168. this.$api.public.search(this.searchOptions).then(res=>{
  169. if(res.status==='Succ'){
  170. for(let i=0;i<res.data.users.length;i++){
  171. res.data.users[i].lastActiveTime=this.$moment(new Date()).diff(res.data.users[i].lastActive,'minutes');
  172. }
  173. console.log(res.data.users);
  174. this.users=res.data.users;
  175. this.showNoData=this.users.length===0?true:false;
  176. }
  177. })
  178. },
  179. cancel(){
  180. this.users=null;
  181. this.inputText=null;
  182. },
  183. chooseHisItem(index){
  184. this.inputText=this.searchs[index];
  185. this.$nextTick(()=>{
  186. this.inputFocus=true;
  187. })
  188. this.search();
  189. },
  190. closeHisItem(index){
  191. this.searchs.splice(index,1);
  192. uni.setStorageSync('searchHistory',this.searchs);
  193. },
  194. clearAll(){
  195. uni.setStorageSync('searchHistory',[]);
  196. this.searchs=[]
  197. },
  198. toDetail(id){
  199. uni.showLoading({})
  200. let user=JSON.parse(uni.getStorageSync('user'));
  201. this.$api.public.userDetail({getAlbum:true,completeUser:user,uponUserId:id}).then(res=>{
  202. if(res.data.frozen){
  203. uni.showToast({
  204. title:'该用户已被冻结',
  205. icon:'none'
  206. });
  207. return;
  208. }
  209. if(res.data.sex===user.sex){
  210. uni.showToast({
  211. title:'同性用户不能查看主页',
  212. icon:'none'
  213. })
  214. }
  215. else{
  216. this.otherInfo=res.data;
  217. uni.setStorageSync('otherInfo',JSON.stringify(res.data));
  218. uni.hideLoading();
  219. uni.navigateTo({
  220. url:`/pages/friends/user?id=${id}`
  221. })
  222. }
  223. })
  224. },
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .container {
  230. width: 100vw;
  231. min-height: 100vh;
  232. background-color: $bgcolor1;
  233. overflow: hidden;
  234. .topnav {
  235. margin: 0 32rpx;
  236. width: 100vw;
  237. align-items: center;
  238. position: fixed;
  239. background-color: $bgcolor1;
  240. z-index: 11;
  241. padding-bottom: 10rpx;
  242. .back{
  243. width: 40rpx;
  244. height: 40rpx;
  245. margin-right: 16rpx;
  246. }
  247. }
  248. .search-box{
  249. margin: 0 32rpx;
  250. height: 96rpx;
  251. width: 686rpx;
  252. align-items: center;
  253. position: fixed;
  254. background-color: $bgcolor1;
  255. z-index: 10;
  256. padding-bottom: 10rpx;
  257. .input-box{
  258. flex: 1;
  259. margin: 20rpx 0rpx;
  260. height: 80rpx;
  261. background-color: #332D4C;
  262. padding: 0rpx 24rpx;
  263. border-radius: 40rpx;
  264. .search-img{
  265. width: 40rpx;
  266. height: 40rpx;
  267. }
  268. .search-input{
  269. flex: 1;
  270. color: $fontcolor5;
  271. margin-left: 5rpx;
  272. }
  273. }
  274. .cancel{
  275. color: #D4D4F1;
  276. margin-left: 16rpx;
  277. }
  278. }
  279. .his-input{
  280. margin: 0 32rpx;
  281. margin-top: 24rpx;
  282. .his-item{
  283. padding: 28rpx 0rpx;
  284. .his-left{
  285. flex: 1;
  286. .his-icon{
  287. width: 40rpx;
  288. height: 40rpx;
  289. }
  290. .his-text{
  291. color: #D4D4F1;
  292. margin-left: 16rpx;
  293. }
  294. }
  295. .his-close{
  296. width: 32rpx;
  297. height: 32rpx;
  298. padding: 8rpx;
  299. }
  300. }
  301. .tip{
  302. color: #D4D4F1;
  303. text-align: center;
  304. text-decoration: underline;
  305. }
  306. }
  307. .list-item{
  308. margin: 0 32rpx;
  309. flex-wrap: wrap;
  310. padding: 40rpx 0rpx;
  311. .list-head-box{
  312. width: 136rpx;
  313. height: 136rpx;
  314. position: relative;
  315. .list-head-img{
  316. width: 136rpx;
  317. height: 136rpx;
  318. background-color: #ffffff;
  319. border-radius: 136rpx;
  320. }
  321. .list-head-dot{
  322. width: 24rpx;
  323. height: 24rpx;
  324. border-radius: 24rpx;
  325. position: absolute;
  326. background-color: aqua;
  327. bottom: 2rpx;
  328. right: 2rpx;
  329. border: 2rpx solid $bgcolor2;
  330. }
  331. }
  332. .list-info-box{
  333. box-sizing: border-box;
  334. width: 544rpx;
  335. padding-left: 32rpx;
  336. height: 136rpx;
  337. flex-direction: column;
  338. display: flex;
  339. justify-content: flex-start;
  340. align-items: flex-start;
  341. .name-box{
  342. width: 100%;
  343. .name{
  344. .name-text{
  345. color: $fontcolor5;
  346. }
  347. .name-img{
  348. width: 68rpx;
  349. height: 32rpx;
  350. margin-left: 8rpx;
  351. }
  352. .name-img-godness{
  353. width: 76rpx;
  354. height: 40rpx;
  355. margin-left: 8rpx;
  356. transform: translateY(-5rpx);
  357. }
  358. }
  359. .distance{
  360. color: $fontcolor3;
  361. }
  362. }
  363. .sex-box{
  364. padding: 0 15rpx;
  365. height: 32rpx;
  366. background: rgba(226, 53, 104, 0.2);
  367. border-radius: 25rpx;
  368. margin-top: 12rpx;
  369. .sex-img{
  370. width: 24rpx;
  371. height: 24rpx;
  372. }
  373. .sex-text1{
  374. color:#E23568;
  375. margin-left: 4rpx;
  376. }
  377. .sex-text2{
  378. color:#6C52F4;
  379. margin-left: 4rpx;
  380. }
  381. }
  382. .tip-box{
  383. color: $fontcolor3;
  384. width: 100%;
  385. margin-top: 10rpx;
  386. }
  387. }
  388. .img-box{
  389. width: 544rpx;
  390. height: 168rpx;
  391. margin-left: 168rpx;
  392. margin-top: 24rpx;
  393. .ib1{
  394. width: 168rpx;
  395. height: 168rpx;
  396. border-radius: 16rpx 0rpx 0rpx 16rpx;
  397. background: $fontcolor5;
  398. }
  399. .ib2{
  400. width: 168rpx;
  401. height: 168rpx;
  402. background: $fontcolor5;
  403. }
  404. .ib3{
  405. width: 168rpx;
  406. height: 168rpx;
  407. border-radius: 0rpx 16rpx 16rpx 0rpx;
  408. background: $fontcolor5;
  409. }
  410. }
  411. }
  412. }
  413. </style>