index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false" :border-bottom="false"><view class="navbar-tit">交友</view></u-navbar>
  4. <view class="home-head">
  5. <view class="homeTab">
  6. <u-tabs :list="tabList" :current="current" @change="change" :show-bar="false" active-color="#333"
  7. inactive-color="#c4c0c0"></u-tabs>
  8. </view>
  9. <view class="homeAdd" v-if="current == '0'" @click="showClick">
  10. <u-icon custom-prefix="custom-icon" name="filter-2-fill"></u-icon>
  11. <span>筛选</span>
  12. </view>
  13. <view class="homeAdd" v-if="current == '1'" @click="refreshClick">
  14. <u-icon custom-prefix="custom-icon" name="refresh-line"></u-icon>
  15. <span>刷新</span>
  16. </view>
  17. </view>
  18. <u-popup v-model="show" mode="bottom" :closeable="true" border-radius="20" close-icon-pos="top-left">
  19. <view class="screenTit">
  20. <h4>条件筛选</h4>
  21. <span @click="reset">重置</span>
  22. </view>
  23. <view class="screenCon">
  24. <view class="screenCon-row">
  25. <span>只看异性</span>
  26. <u-switch v-model="checked" active-color="#FF5E5E"></u-switch>
  27. </view>
  28. <view class="screenCon-item">
  29. <view class="screenCon-tit">
  30. <span>年龄</span><p>{{rangeValues[0]}}~{{rangeValues[1]}}</p>
  31. </view>
  32. <view class="screenCon-con">
  33. <view class="screenCon-slider">
  34. <RangeSlider
  35. :width="slideWidth"
  36. :height="slideHeight"
  37. :blockSize="slideBlockSize"
  38. :min="slideMin"
  39. :max="slideMax"
  40. :values="rangeValues"
  41. :step="step"
  42. :liveMode="isLiveMode"
  43. @rangechange="onRangeChange"
  44. ref="refsValues"
  45. >
  46. <view slot="minBlock" class="range-slider-block"></view>
  47. <!-- 左边滑块的内容 -->
  48. <view slot="maxBlock" class="range-slider-block"></view>
  49. <!-- 右边滑块的内容 -->
  50. </RangeSlider>
  51. <!-- <u-slider v-model="value"></u-slider> -->
  52. </view>
  53. </view>
  54. </view>
  55. <view class="screenCon-item">
  56. <view class="screenCon-tit">
  57. <span>身高</span><p>{{rangeValues2[0]}}~{{rangeValues2[1]}}</p>
  58. </view>
  59. <view class="screenCon-con">
  60. <view class="screenCon-slider">
  61. <RangeSlider
  62. :width="slideWidth"
  63. :height="slideHeight"
  64. :blockSize="slideBlockSize"
  65. :min="slideMin2"
  66. :max="slideMax2"
  67. :values="rangeValues2"
  68. :step="step"
  69. :liveMode="isLiveMode"
  70. @rangechange="onRangeChange2"
  71. ref="refsValues2"
  72. >
  73. <view slot="minBlock" class="range-slider-block"></view>
  74. <!-- 左边滑块的内容 -->
  75. <view slot="maxBlock" class="range-slider-block"></view>
  76. <!-- 右边滑块的内容 -->
  77. </RangeSlider>
  78. <!-- <u-slider v-model="value"></u-slider> -->
  79. </view>
  80. </view>
  81. </view>
  82. <view class="screenCon-item">
  83. <view class="screenCon-tit">
  84. <span>会员所属工会所在地</span>
  85. </view>
  86. <view class="screenCon-con">
  87. <view class="screenCon-choice">
  88. <view class="choice-item" :class="qyActiveClass == index ? 'active' : ''"
  89. v-for="(item ,index) in qyList" :key="item.id" @click="qyClick(item,index)">{{item.name}}</view>
  90. </view>
  91. </view>
  92. </view>
  93. <view class="screenCon-item">
  94. <view class="screenCon-tit">
  95. <span>学历</span>
  96. </view>
  97. <view class="screenCon-con">
  98. <view class="screenCon-choice">
  99. <view class="choice-item" :class="xlActiveClass == index ? 'active' : ''"
  100. v-for="(item ,index) in xlList" :key="item.id" @click="xlClick(item,index)">{{item.name}}</view>
  101. </view>
  102. </view>
  103. </view>
  104. <view class="screenCon-item">
  105. <view class="screenCon-tit">
  106. <span>婚姻状况</span>
  107. </view>
  108. <view class="screenCon-con">
  109. <view class="screenCon-choice">
  110. <view class="choice-item" :class="hyqkActiveClass == index ? 'active' : ''"
  111. v-for="(item ,index) in hyqkList" :key="item.id" @click="hyqkClick(item,index)">{{item.name}}</view>
  112. </view>
  113. </view>
  114. </view>
  115. <view class="screenCon-item">
  116. <view class="screenCon-tit">
  117. <span>子女状况</span>
  118. </view>
  119. <view class="screenCon-con">
  120. <view class="screenCon-choice">
  121. <view class="choice-item" :class="znqkActiveClass == index ? 'active' : ''"
  122. v-for="(item ,index) in znqkList" :key="item.id" @click="znqkClick(item,index)">{{item.name}}</view>
  123. </view>
  124. </view>
  125. </view>
  126. <view class="screenCon-item">
  127. <view class="screenCon-tit">
  128. <span>兴趣爱好(可多选)</span>
  129. </view>
  130. <view class="screenCon-con">
  131. <view class="screenCon-choice">
  132. <view class="choice-item" :class="item.hobbyChecked ? 'active' : ''"
  133. v-for="(item ,index) in interests" :key="item.id" @tap="selectInterest(index)">{{item.name}}</view>
  134. </view>
  135. </view>
  136. </view>
  137. <view class="screenCon-btn">
  138. <u-button type="error" shape="circle" :custom-style="customStyle" @click="sure">确定</u-button>
  139. </view>
  140. </view>
  141. </u-popup>
  142. <view class="friendList">
  143. <view class="friendList-item" v-for="(item ,index) in friendList" :key="item.id" @click="gotoUrl('pages/friend/personal?id='+item.id)">
  144. <u-image class="friendList-img" :src="item.faceImage+'?x-oss-process=image/resize,m_fill,w_256,h_256'" height="160" width="160" border-radius="10">
  145. </u-image>
  146. <view class="friendList-text">
  147. <view class="friendList-name">
  148. <span>{{showName(item.realName)}}</span>
  149. <u-icon v-if="item.gender" custom-prefix="custom-icon" name="women-line" color="#FF695B"></u-icon>
  150. <u-icon v-else custom-prefix="custom-icon" name="men-line" color="#1677FF"></u-icon>
  151. </view>
  152. <view class="friendList-info">
  153. <span>{{item.age}}岁 · {{item.height}}cm{{item.weight?' · '+item.weight+'kg':''}}</span>
  154. </view>
  155. <view class="friendList-label">
  156. <view class="friendList-label-item">
  157. <u-icon custom-prefix="custom-icon" name="map-pin-2-fill"></u-icon>
  158. <span>{{item.orgAreaName}}</span>
  159. </view>
  160. <view class="friendList-label-item">
  161. <span>{{item.educationN}}</span>
  162. </view>
  163. <view class="friendList-label-item">
  164. <span>{{item.industryN}}</span>
  165. </view>
  166. </view>
  167. </view>
  168. </view>
  169. <u-divider v-if="friendList.length == recordsTotal" color="#B6BDC3" style="margin-top:20px;" bg-color="#f4f0f0">已经到底了</u-divider>
  170. </view>
  171. </view>
  172. </template>
  173. <script>
  174. import * as friendApi from '@/apis/friend.js'
  175. import * as loginApi from '@/apis/login.js'
  176. import RangeSlider from '../../components/range-slider/range-slider.vue';
  177. export default {
  178. data() {
  179. return {
  180. rangeValues: [22, 35],
  181. slideWidth: 600,
  182. slideHeight: 80,
  183. slideBlockSize: 30,
  184. //年龄
  185. slideMin: 18,
  186. slideMax: 80,
  187. //身高
  188. slideMin2: 140,
  189. slideMax2: 220,
  190. isLiveMode: true,
  191. rangeValues2: [170, 180],
  192. step:1,
  193. type: '', //全部0,猜你喜欢1(不传默认查全部)
  194. memberId: '', //未登录不传,登陆了传当前用户ID
  195. pageIndex: 1,
  196. pageSize: 20,
  197. recordsTotal: 0,
  198. list: [],
  199. friendList: [],
  200. qyList: [], //所属区域
  201. xlList: [], //学历
  202. hyqkList: [], //婚姻情况
  203. znqkList: [], //子女情况
  204. hobbyInfoList: [], //兴趣爱好
  205. interests: [],
  206. qyActiveClass: 0,
  207. xlActiveClass: 0,
  208. hyqkActiveClass: 0,
  209. znqkActiveClass: 0,
  210. form: {
  211. oppositeSex: '', //只看异性1,不传值为查看所有
  212. ageStart: '', //年龄起
  213. ageEnd: '', //年龄止
  214. heightStart: '', //身高起
  215. heightEnd: '', //身高止
  216. qy: '', //籍贯(单位所属区域)
  217. xl: '', //学历
  218. hyqk: '', //婚姻情况
  219. znqk: '', //子女情况
  220. hobbys: '', //兴趣爱好
  221. },
  222. tabList: [{
  223. name: '全部'
  224. }, {
  225. name: '猜你喜欢'
  226. }],
  227. current: 0,
  228. randomList: [],
  229. show: false,
  230. checked: true,
  231. customStyle:{
  232. background: '#FF5E5E'
  233. },
  234. value: 30,
  235. }
  236. },
  237. components: {
  238. RangeSlider
  239. },
  240. onLoad(op) {
  241. if(this.carhelp.getPersonInfo().id != null) {
  242. this.memberId = this.carhelp.getPersonInfo().id;
  243. this.form.memberId = this.carhelp.getPersonInfo().id;
  244. }
  245. this.getFriendList();
  246. this.getConditionList();
  247. },
  248. onReachBottom() {
  249. if (this.friendList.length < this.recordsTotal) {
  250. this.myLoadmore();
  251. }
  252. },
  253. methods: {
  254. showClick() {
  255. if(this.memberId != null) {
  256. this.show = true;
  257. } else {
  258. uni.showToast({
  259. title: "请用户先登录",
  260. icon: "none"
  261. })
  262. }
  263. },
  264. reset() {
  265. this.checked = true;
  266. this.rangeValues = [22,35];
  267. this.$refs.refsValues.originalMinValue=22
  268. this.$refs.refsValues.originalMaxValue=35
  269. this.rangeValues2 = [170, 180];
  270. this.$refs.refsValues2.originalMinValue=170
  271. this.$refs.refsValues2.originalMaxValue=180
  272. this.qyClick(this.qyList[0],0);
  273. this.xlClick(this.xlList[0],0);
  274. this.hyqkClick(this.hyqkList[0],0);
  275. this.znqkClick(this.znqkList[0],0);
  276. for(let i=0;i<this.interests.length;i++) {
  277. this.interests[i].hobbyChecked = false;
  278. }
  279. },
  280. pad: function(num, n) {
  281. return Array(n - ('' + num).length + 1).join(0) + num;
  282. },
  283. onRangeChange: function(e) {
  284. this.rangeValues = [e.minValue, e.maxValue];
  285. },
  286. onRangeChange2: function(e) {
  287. this.rangeValues2 = [e.minValue, e.maxValue];
  288. },
  289. formatTimeBySliderValue(value) {
  290. //按比例,将滑块上面的数值进行转换为时间形式
  291. //转换为分钟数
  292. let minutes = (24 * 60 * value) / this.slideMax;
  293. //转换为小时数
  294. let hours = parseInt(minutes / 60);
  295. //剩余分钟数
  296. let minutes_min = parseInt(minutes % 60);
  297. return '' + this.pad(hours, 2) + ':' + this.pad(minutes_min, 2) + ':' + '00';
  298. },
  299. qyClick(item,index) {
  300. this.qyActiveClass = index;
  301. this.form.qy = item.value;
  302. },
  303. xlClick(item,index) {
  304. this.xlActiveClass = index;
  305. this.form.xl = item.value;
  306. },
  307. hyqkClick(item,index) {
  308. this.hyqkActiveClass = index;
  309. this.form.hyqk = item.value;
  310. },
  311. znqkClick(item,index) {
  312. this.znqkActiveClass = index;
  313. this.form.znqk = item.value;
  314. },
  315. selectInterest(index) {
  316. let interest = this.interests;
  317. interest[index].hobbyChecked = !interest[index].hobbyChecked;
  318. this.interests= interest;
  319. },
  320. sure() {
  321. this.form.hobbys = '';
  322. this.friendList = [];
  323. if(this.checked) {
  324. this.form.oppositeSex = '1';
  325. }
  326. this.form.ageStart = this.rangeValues[0];
  327. this.form.ageEnd = this.rangeValues[1];
  328. this.form.heightStart = this.rangeValues2[0];
  329. this.form.heightEnd = this.rangeValues2[1];
  330. if(this.form.qy == ''){
  331. this.form.qy = this.qyList[0].value;
  332. }
  333. if(this.form.xl == ''){
  334. this.form.xl = this.xlList[0].value;
  335. }
  336. if(this.form.hyqk == ''){
  337. this.form.hyqk = this.hyqkList[0].value;
  338. }
  339. if(this.form.znqk == ''){
  340. this.form.znqk = this.znqkList[0].value;
  341. }
  342. for(let i=0;i<this.interests.length;i++)
  343. {
  344. if(this.interests[i].hobbyChecked)
  345. {
  346. if(this.form.hobbys.length>0)
  347. {
  348. this.form.hobbys+=','
  349. }
  350. this.form.hobbys += this.interests[i].id;
  351. }
  352. }
  353. this.list = this.form;
  354. uni.showLoading({
  355. title: "加载中",
  356. mask: true,
  357. })
  358. friendApi.findFriendsList(this.form).then((res) => {
  359. this.friendList = [
  360. ...this.friendList,
  361. ...res.data.data
  362. ];
  363. this.recordsTotal = res.data.recordsTotal;
  364. uni.hideLoading();
  365. }).catch(error => {
  366. uni.showToast({
  367. title: error,icon: "none"
  368. })
  369. })
  370. this.show = false;
  371. },
  372. change(index) {
  373. if(this.memberId != null) {
  374. this.current = index;
  375. this.type = index;
  376. if(this.type == '1') {
  377. this.refreshClick();
  378. } else {
  379. this.getFriendList(true);
  380. }
  381. } else {
  382. uni.showToast({
  383. title: "请用户先登录",
  384. icon: "none"
  385. })
  386. }
  387. },
  388. refreshClick() {
  389. this.friendList = [];
  390. let formList = [];
  391. for(var item in this.list) {
  392. var sgd = {};
  393. sgd[item] = this.list[item]
  394. formList.push(sgd);
  395. }
  396. let refreshList = [];
  397. for(var i=0; i<3; i++) {
  398. var num=Math.floor(Math.random()*9+0);
  399. refreshList.push(formList[num]);
  400. }
  401. refreshList.push({type: '1'});
  402. refreshList.push({memberId: this.memberId});
  403. if(refreshList.oppositeSex == null) {
  404. refreshList.push({oppositeSex: this.list.oppositeSex});
  405. }
  406. var obj = {};
  407. for(var m in refreshList) {
  408. for(var n in refreshList[m]) {
  409. obj[n] = refreshList[m][n];
  410. }
  411. }
  412. uni.showLoading({
  413. title: "加载中",
  414. mask: true,
  415. })
  416. friendApi.findFriendsList(obj).then((res) => {
  417. this.friendList = [
  418. ...this.friendList,
  419. ...res.data.data
  420. ];
  421. this.recordsTotal = res.data.recordsTotal;
  422. uni.hideLoading();
  423. }).catch(error => {
  424. uni.showToast({
  425. title: error,icon: "none"
  426. })
  427. })
  428. },
  429. myLoadmore() {
  430. this.pageIndex += 1;
  431. this.getFriendList()
  432. },
  433. getFriendList(bl) {
  434. uni.showLoading({
  435. title: "加载中",
  436. mask: true,
  437. })
  438. if (bl) {
  439. this.friendList = [];
  440. this.pageIndex = 1;
  441. }
  442. friendApi.findFriendsList({
  443. type: this.type,
  444. memberId: this.memberId,
  445. oppositeSex: '1',
  446. pageIndex: 1,
  447. pageSize: 20
  448. }).then((res) => {
  449. this.friendList = [
  450. ...this.friendList,
  451. ...res.data.data
  452. ];
  453. this.recordsTotal = res.data.recordsTotal;
  454. uni.hideLoading();
  455. }).catch(error => {
  456. uni.showToast({
  457. title: error,icon: "none"
  458. })
  459. })
  460. },
  461. getConditionList() {
  462. uni.showLoading({
  463. title: "加载中",
  464. mask: true,
  465. })
  466. loginApi.getBaseDictionary().then((res) => {
  467. this.qyList = res.data.qyList;
  468. this.xlList = res.data.xlList;
  469. this.hyqkList = res.data.hyqkList;
  470. this.znqkList = res.data.znqkList;
  471. this.xlList.splice(0,0,{id: '1',name:'不限',value:''});
  472. this.hyqkList.splice(0,0,{id: '1',name:'不限',value:''});
  473. this.znqkList.splice(0,0,{id: '1',name:'不限',value:''});
  474. this.hobbyInfoList = res.data.hobbyInfoList;
  475. if(this.hobbyInfoList){
  476. let hobbyList = [];
  477. hobbyList = this.hobbyInfoList;
  478. for(let i = 0;i< hobbyList.length;i++)
  479. {
  480. let hobby = {id:hobbyList[i].id,name:hobbyList[i].name,hobbyChecked:false};
  481. this.interests.push(hobby);
  482. }
  483. }
  484. uni.hideLoading();
  485. }).catch(error => {
  486. uni.showToast({
  487. title: error,icon: "none"
  488. })
  489. })
  490. },
  491. }
  492. }
  493. </script>
  494. <style>
  495. page {
  496. background-color: #f4f0f0;
  497. }
  498. </style>
  499. <style lang="scss" scoped>
  500. .screenCon-btn{
  501. padding: 15px;
  502. position: sticky;
  503. bottom: 0;
  504. background-color: white;
  505. box-shadow: 0px -4px 2px #FAFAFA;
  506. }
  507. .screenCon-slider{
  508. height: 24px;
  509. }
  510. .screenCon-choice{
  511. display: flex;
  512. flex-wrap: wrap;
  513. .choice-item{
  514. background-color: #F1F3F4;
  515. border-radius: 4px;
  516. padding:8px 0;
  517. color:#6C6A6A;
  518. width: 22%;
  519. text-align: center;
  520. margin-right: 10px;
  521. margin-bottom: 10px;
  522. }
  523. .active{
  524. background-color: #FF5E5E;
  525. color:#fff;
  526. }
  527. }
  528. .screenCon-item{
  529. padding: 10px 0;
  530. .screenCon-tit{
  531. display: flex;
  532. align-items: center;
  533. span{font-size: 16px;}
  534. p{font-size: 16px;color:#999;margin-left: 8px;}
  535. }
  536. .screenCon-con{
  537. margin-top: 12px;
  538. }
  539. }
  540. .screenCon-row{
  541. display: flex;
  542. justify-content: space-between;
  543. align-items: center;
  544. padding: 10px 0;
  545. span{
  546. font-size: 16px;
  547. }
  548. }
  549. .screenCon{
  550. height: 500px;
  551. padding: 0 15px;
  552. margin-top: 50px;
  553. }
  554. .screenTit{
  555. height: 50px;
  556. position:fixed;
  557. left: 0;
  558. top: 0;
  559. right: 0;
  560. background-color: #fff;
  561. z-index: 2;
  562. h4{
  563. position: absolute;
  564. font-weight: normal;
  565. left: 50%;
  566. top:12px;
  567. font-size: 16PX;
  568. margin-left: -32px;
  569. }
  570. span{
  571. position: absolute;
  572. color:#999;
  573. right: 15px;
  574. top: 15px;
  575. }
  576. }
  577. .navbar-tit{
  578. padding-left:15px;
  579. font-size: 24px;
  580. }
  581. .home-head {
  582. display: flex;
  583. justify-content: space-between;
  584. align-items: center;
  585. padding-right: 15px;
  586. z-index: 99;
  587. background-color: #FFF;
  588. .homeAdd {
  589. color: #FF5E5E;
  590. span {
  591. margin-left: 3px;
  592. }
  593. }
  594. }
  595. .friendList {
  596. padding: 15px;
  597. .friendList-item {
  598. display: flex;
  599. background-color: #fff;
  600. padding: 12px;
  601. border-radius: 12px;
  602. margin-bottom: 15px;
  603. .friendList-text {
  604. flex: 1;
  605. min-width: 0;
  606. margin-left: 12px;
  607. display: flex;
  608. flex-direction: column;
  609. justify-content: space-between;
  610. .friendList-name {
  611. font-weight: normal;
  612. span {
  613. font-size: 18px;
  614. margin-right: 8px;
  615. }
  616. }
  617. .friendList-info {
  618. color: #999;
  619. font-size: 12px;
  620. }
  621. .friendList-label {
  622. display: flex;
  623. align-items: center;
  624. .friendList-label-item {
  625. background: #F1F3F4;
  626. padding: 2px 8px;
  627. color: #A2A9B5;
  628. border-radius: 4px;
  629. font-size: 12px;
  630. margin-right: 8px;
  631. span {
  632. margin-left: 3px;
  633. }
  634. }
  635. }
  636. }
  637. }
  638. }
  639. </style>