search.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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||!users||users===[]"></Status>
  77. </view>
  78. </template>
  79. <script>
  80. import Status from '@/components/Status/Status.vue';
  81. export default {
  82. components: {
  83. Status
  84. },
  85. data() {
  86. return {
  87. assetsUrl: this.$util.assetsUrl,
  88. inputText:null,
  89. searchOptions:{
  90. completeUser:{},
  91. geo:{
  92. lat:0,
  93. lon:0
  94. },
  95. listType:'',
  96. page:{
  97. index:1,
  98. size:20,
  99. sortValues:[]
  100. },
  101. prefer:{
  102. cityCode:null,
  103. femaleGoddess:false,
  104. femaleNew:false,
  105. maleNew:false,
  106. maleVip:false,
  107. maxAge:null,
  108. minAge:null,
  109. nick:'',
  110. onlineIn24Hour:null,
  111. onlineIn30Min:null,
  112. sortType:'Recommend'
  113. }
  114. },
  115. users:null,
  116. searchs:[],
  117. inputFocus:true,
  118. showNoData:true
  119. };
  120. },
  121. onLoad() {
  122. this.searchs=uni.getStorageSync('searchHistory')||[];
  123. },
  124. computed: {
  125. statusBarHeight() {
  126. return this.$store.state.statusBarHeight;
  127. },
  128. topbarOffsetHeight() {
  129. return this.$store.state.topbarOffsetHeight;
  130. },
  131. userInfo(){
  132. return this.$store.state.userInfo||JSON.parse(uni.getStorageSync('userInfo'))
  133. }
  134. },
  135. methods:{
  136. back(){
  137. uni.navigateBack({
  138. delta:1
  139. })
  140. },
  141. search(){
  142. if(this.inputText===null){
  143. this.users=null;
  144. return;
  145. }
  146. if(this.inputText===''){
  147. this.users=null;
  148. this.inputText=null;
  149. return;
  150. }
  151. this.searchs=uni.getStorageSync('searchHistory')||[];
  152. if(this.searchs.includes(this.inputText)){
  153. this.searchs.splice(this.searchs.indexOf(this.inputText),1);
  154. }
  155. if(this.searchs.length>=10){
  156. this.searchs.shift();
  157. }
  158. this.searchs.unshift(this.inputText);
  159. uni.setStorageSync('searchHistory',this.searchs);
  160. let user=JSON.parse(uni.getStorageSync('user'))
  161. this.searchOptions.listType=user.sex==='male'?'MaleReco':'FaMaleReco';
  162. this.searchOptions.geo.lat=this.$store.state.latitude;
  163. this.searchOptions.geo.lon=this.$store.state.longitude;
  164. this.searchOptions.prefer.nick=this.inputText;
  165. this.searchOptions.completeUser=user;
  166. this.$api.public.search(this.searchOptions).then(res=>{
  167. if(res.status==='Succ'){
  168. this.users=res.data.users;
  169. this.showNoData=this.users.length===0?true:false;
  170. }
  171. })
  172. },
  173. cancel(){
  174. this.users=null;
  175. this.inputText=null;
  176. },
  177. chooseHisItem(index){
  178. this.inputText=this.searchs[index];
  179. this.$nextTick(()=>{
  180. this.inputFocus=true;
  181. })
  182. this.search();
  183. },
  184. closeHisItem(index){
  185. this.searchs.splice(index,1);
  186. uni.setStorageSync('searchHistory',this.searchs);
  187. },
  188. clearAll(){
  189. uni.setStorageSync('searchHistory',[]);
  190. this.searchs=[]
  191. },
  192. toDetail(id){
  193. uni.showLoading({})
  194. let user=JSON.parse(uni.getStorageSync('user'));
  195. this.$api.public.userDetail({getAlbum:true,completeUser:user,uponUserId:id}).then(res=>{
  196. if(res.data.frozen){
  197. uni.showToast({
  198. title:'该用户已被冻结',
  199. icon:'none'
  200. });
  201. return;
  202. }
  203. if(res.data.sex===user.sex){
  204. uni.showToast({
  205. title:'同性用户不能查看主页',
  206. icon:'none'
  207. })
  208. }
  209. else{
  210. this.otherInfo=res.data;
  211. uni.hideLoading();
  212. uni.navigateTo({
  213. url:`/pages/friends/user?id=${id}`
  214. })
  215. }
  216. })
  217. },
  218. }
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. .container {
  223. width: 100vw;
  224. min-height: 100vh;
  225. background-color: $bgcolor1;
  226. overflow: hidden;
  227. .topnav {
  228. margin: 0 32rpx;
  229. width: 100vw;
  230. align-items: center;
  231. position: fixed;
  232. background-color: $bgcolor1;
  233. z-index: 11;
  234. padding-bottom: 10rpx;
  235. .back{
  236. width: 40rpx;
  237. height: 40rpx;
  238. margin-right: 16rpx;
  239. }
  240. }
  241. .search-box{
  242. margin: 0 32rpx;
  243. height: 96rpx;
  244. width: 686rpx;
  245. align-items: center;
  246. position: fixed;
  247. background-color: $bgcolor1;
  248. z-index: 10;
  249. padding-bottom: 10rpx;
  250. .input-box{
  251. flex: 1;
  252. margin: 20rpx 0rpx;
  253. height: 80rpx;
  254. background-color: #332D4C;
  255. padding: 0rpx 24rpx;
  256. border-radius: 40rpx;
  257. .search-img{
  258. width: 40rpx;
  259. height: 40rpx;
  260. }
  261. .search-input{
  262. flex: 1;
  263. color: $fontcolor5;
  264. margin-left: 5rpx;
  265. }
  266. }
  267. .cancel{
  268. color: #D4D4F1;
  269. margin-left: 16rpx;
  270. }
  271. }
  272. .his-input{
  273. margin: 0 32rpx;
  274. margin-top: 24rpx;
  275. .his-item{
  276. padding: 28rpx 0rpx;
  277. .his-left{
  278. flex: 1;
  279. .his-icon{
  280. width: 40rpx;
  281. height: 40rpx;
  282. }
  283. .his-text{
  284. color: #D4D4F1;
  285. margin-left: 16rpx;
  286. }
  287. }
  288. .his-close{
  289. width: 32rpx;
  290. height: 32rpx;
  291. padding: 8rpx;
  292. }
  293. }
  294. .tip{
  295. color: #D4D4F1;
  296. text-align: center;
  297. text-decoration: underline;
  298. }
  299. }
  300. .list-item{
  301. margin: 0 32rpx;
  302. flex-wrap: wrap;
  303. padding: 40rpx 0rpx;
  304. .list-head-box{
  305. width: 136rpx;
  306. height: 136rpx;
  307. position: relative;
  308. .list-head-img{
  309. width: 136rpx;
  310. height: 136rpx;
  311. background-color: #ffffff;
  312. border-radius: 136rpx;
  313. }
  314. .list-head-dot{
  315. width: 24rpx;
  316. height: 24rpx;
  317. border-radius: 24rpx;
  318. position: absolute;
  319. background-color: aqua;
  320. bottom: 2rpx;
  321. right: 2rpx;
  322. border: 2rpx solid $bgcolor2;
  323. }
  324. }
  325. .list-info-box{
  326. box-sizing: border-box;
  327. width: 544rpx;
  328. padding-left: 32rpx;
  329. height: 136rpx;
  330. flex-direction: column;
  331. display: flex;
  332. justify-content: flex-start;
  333. align-items: flex-start;
  334. .name-box{
  335. width: 100%;
  336. .name{
  337. .name-text{
  338. color: $fontcolor5;
  339. }
  340. .name-img{
  341. width: 68rpx;
  342. height: 32rpx;
  343. margin-left: 8rpx;
  344. }
  345. .name-img-godness{
  346. width: 76rpx;
  347. height: 40rpx;
  348. margin-left: 8rpx;
  349. transform: translateY(-5rpx);
  350. }
  351. }
  352. .distance{
  353. color: $fontcolor3;
  354. }
  355. }
  356. .sex-box{
  357. padding: 0 15rpx;
  358. height: 32rpx;
  359. background: rgba(226, 53, 104, 0.2);
  360. border-radius: 25rpx;
  361. margin-top: 12rpx;
  362. .sex-img{
  363. width: 24rpx;
  364. height: 24rpx;
  365. }
  366. .sex-text1{
  367. color:#E23568;
  368. margin-left: 4rpx;
  369. }
  370. .sex-text2{
  371. color:#6C52F4;
  372. margin-left: 4rpx;
  373. }
  374. }
  375. .tip-box{
  376. color: $fontcolor3;
  377. width: 100%;
  378. margin-top: 10rpx;
  379. }
  380. }
  381. .img-box{
  382. width: 544rpx;
  383. height: 168rpx;
  384. margin-left: 168rpx;
  385. margin-top: 24rpx;
  386. .ib1{
  387. width: 168rpx;
  388. height: 168rpx;
  389. border-radius: 16rpx 0rpx 0rpx 16rpx;
  390. background: $fontcolor5;
  391. }
  392. .ib2{
  393. width: 168rpx;
  394. height: 168rpx;
  395. background: $fontcolor5;
  396. }
  397. .ib3{
  398. width: 168rpx;
  399. height: 168rpx;
  400. border-radius: 0rpx 16rpx 16rpx 0rpx;
  401. background: $fontcolor5;
  402. }
  403. }
  404. }
  405. }
  406. </style>