金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

597 lines
16 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <lf-nav :spreadOut="true" title="发现" @changeHeight="e => nav_height = e"></lf-nav>
  4. <view>
  5. <u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="true" :current="tab_current" @change="tabChange"></u-tabs>
  6. </view>
  7. <swiper :style="{height: autoHeight}" :current="tab_current" @change="swiperChange">
  8. <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
  9. <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher"
  10. @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh" :scroll-top="scrollTop" @scroll="scroll">
  11. <view v-for="(item,index) of tab.list" :key="index">
  12. <view class="lf-p-32">
  13. <view class="lf-flex" @click="$url('/pages/user/my/my?user_id='+item.user_id)">
  14. <view class="tag-father">
  15. <image :src="item.user.avatar" v-if="item.user.avatar" mode="widthFix" class="head-img"></image>
  16. <image src="/static/images/empty.png" v-else mode="widthFix" class="head-img"></image>
  17. <view class="head-tag">V</view>
  18. </view>
  19. <view class="lf-flex-column lf-m-l-20">
  20. <view class="lf-flex" style="align-items: center;">
  21. <view class="lf-font-32 lf-color-black lf-font-bold" v-if="item.user.nick_name">{{item.user.nick_name}}</view>
  22. <view class="lf-font-32 lf-color-black lf-font-bold" v-else>{{item.user.mobile_replace}}</view>
  23. <text class="lf-iconfont icon-xiangyou lf-color-777 lf-m-l-10 lf-text-vertical" style="font-size: 18rpx;"></text>
  24. </view>
  25. <view class="lf-font-24 lf-color-777 lf-m-t-15">{{item.created_at}}</view>
  26. </view>
  27. </view>
  28. <view class="lf-font-28 lf-color-333 lf-m-t-20" @click="goDetails(item.id)">
  29. {{item.content}}
  30. </view>
  31. <view class="lf-flex-wrap lf-m-t-20">
  32. <image v-for="(picture,index2) in item.attachs" @click.stop="checkPicture(item.attachs,index2)" :key="index2" class="qzone-img" :src="picture.url" mode="aspectFill"></image>
  33. </view>
  34. <view class="lf-m-t-30 lf-row-between lf-p-l-50 lf-p-r-50">
  35. <view class="lf-row-center" @click.stop="addLike(item.id)">
  36. <text class="lf-iconfont icon-xihuanlike lf-color-price lf-font-40" v-if="item.is_like"></text>
  37. <text class="lf-iconfont icon-xihuan lf-font-40" v-else></text>
  38. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.likes_count}}</text>
  39. </view>
  40. <view class="lf-row-center">
  41. <text class="lf-iconfont icon-chakan lf-font-40"></text>
  42. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.view_count}}</text>
  43. </view>
  44. <view class="lf-row-center" @click="goDetails(item.id)">
  45. <text class="lf-iconfont icon-pinglun- lf-font-40"></text>
  46. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.comments_count}}</text>
  47. </view>
  48. </view>
  49. </view>
  50. <self-line/>
  51. </view>
  52. <!-- 空数据的情况 -->
  53. <view class="loading-more">
  54. <text v-if="tab.list.length"
  55. :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  56. <lf-nocontent src="/static/images/empty.png" v-else></lf-nocontent>
  57. </view>
  58. </scroll-view>
  59. </swiper-item>
  60. </swiper>
  61. <view class="fixed-right">
  62. <view class="fixed-btn" hover-class="lf-opacity" @click="$url('/pages/discover/publish')">
  63. <text class="lf-iconfont icon-fabu lf-font-50"></text>
  64. </view>
  65. </view>
  66. <view class="fixed-right2" v-if="showTotop">
  67. <view class="fixed-btn" hover-class="lf-opacity" @click="goTop()">
  68. <text class="lf-iconfont icon-zhiding lf-font-50"></text>
  69. </view>
  70. </view>
  71. <!-- 悬浮购物车入口 -->
  72. <view class="fixed-right1">
  73. <view class="fixed-cart" hover-class="lf-opacity" @click="$url('/pages/store/cart/cart')">
  74. <text class="lf-iconfont icon-gouwulan icon-text"></text>
  75. <text class="tips">购物车</text>
  76. <block v-if="$isRight(car_num)">
  77. <view class="angle-mark" v-if="car_num<99">{{car_num || 0}}</view>
  78. <view class="angle-mark" v-else>99+</view>
  79. </block>
  80. </view>
  81. </view>
  82. <!-- <view style="height: 30rpx;"></view> -->
  83. <lf-tabbar></lf-tabbar>
  84. </view>
  85. </template>
  86. <script>
  87. import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
  88. export default {
  89. components: {
  90. lfTabbar
  91. },
  92. data() {
  93. let _public = {
  94. page: 1,
  95. isPage: true,
  96. loadingClass: true,
  97. loadingText: '正在加载中'
  98. }
  99. return {
  100. scrollTop: 0,
  101. oldScrollTop:0,
  102. showTotop: false,
  103. tab_list: [
  104. {name: '最新',type: 'created_at',list:[],..._public},
  105. {name: '最热',type: 'view_count',list:[],..._public},
  106. {name: '已关注',type: 'view_count',list:[],..._public}
  107. ],
  108. tab_current: 0,
  109. scrollH: 0,
  110. nav_height: 0,
  111. isRefresher: true,
  112. pageSize: 10,
  113. car_num: 0
  114. }
  115. },
  116. computed: {
  117. autoHeight(){
  118. return `calc(${this.scrollH}px - ${this.nav_height}px - 130rpx - 86rpx)`;
  119. }
  120. },
  121. onShow() {
  122. this.getHotActivity()
  123. },
  124. onLoad(){
  125. let info = uni.getSystemInfoSync();
  126. this.scrollH = info.screenHeight;
  127. this.getHotActivity();
  128. this.getcarNum();
  129. },
  130. methods: {
  131. getcarNum() {
  132. this.$http
  133. .get({
  134. api: 'api/shopping/cart/count',
  135. header: {
  136. Authorization: this.$cookieStorage.get('user_token')
  137. },
  138. })
  139. .then(res => {
  140. if (res.data.code == 200) {
  141. if(res.data.data == null) {
  142. this.car_num = 0;
  143. }else {
  144. this.car_num = res.data.data;
  145. }
  146. } else {
  147. wx.showModal({
  148. content: '请下拉页面刷新重试',
  149. showCancel: false
  150. });
  151. }
  152. })
  153. .catch(() => {
  154. wx.stopPullDownRefresh();
  155. wx.hideLoading();
  156. wx.showModal({
  157. content: '请求失败',
  158. showCancel: false
  159. });
  160. });
  161. },
  162. scroll (e) {
  163. //记录scroll 位置
  164. this.oldScrollTop = e.detail.scrollTop;
  165. if(this.oldScrollTop > 900) {
  166. this.showTotop = true;
  167. }else {
  168. this.showTotop = false;
  169. }
  170. },
  171. goTop(e) {
  172. //视图会发生重新渲染
  173. this.scrollTop = this.oldScrollTop;
  174. //当视图渲染结束 重新设置为0
  175. this.$nextTick(() =>{
  176. this.scrollTop = 0;
  177. });
  178. },
  179. checkPicture(image_list,current) {
  180. if(image_list.length <= 0) return;
  181. let list = [];
  182. image_list.forEach((item,index) => {
  183. list.push(item.url)
  184. })
  185. this.$u.throttle(() => {
  186. uni.previewImage({
  187. urls: list,
  188. current: current
  189. });
  190. }, 500);
  191. },
  192. getCurrentPageUrlWithArgs() {
  193. var pages = getCurrentPages() //获取加载的页面
  194. var currentPage = pages[pages.length-1] //获取当前页面的对象
  195. var url = currentPage.route //当前页面url
  196. var options = currentPage.options //如果要获取url中所带的参数可以查看options
  197. //拼接url的参数
  198. var urlWithArgs = url + '?'
  199. for(var key in options){
  200. var value = options[key]
  201. urlWithArgs += key + '=' + value + '&'
  202. }
  203. urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length-1)
  204. return encodeURIComponent(urlWithArgs)
  205. },
  206. goDetails(id) {
  207. let token = this.$cookieStorage.get('user_token');
  208. if(!token) {
  209. var url = this.getCurrentPageUrlWithArgs();
  210. wx.showModal({
  211. content:'请重新登录',
  212. duration:1500,
  213. showCancel: false,
  214. success:(res)=>{
  215. if (res.confirm) {
  216. // wx.navigateTo 邓平艺 于2021.09.24修改,
  217. // 原因:未登录点击后跳转到登录页,当登录成功,
  218. // 再次跳转回来时,用户点击页面返回,原有页面和弹窗还存在
  219. uni.redirectTo({
  220. url:`/pages/user/register/register?url=${url}`
  221. })
  222. return;
  223. }
  224. },
  225. cancel:()=>{
  226. uni.redirectTo({
  227. url:`/pages/user/register/register?url=${url}`
  228. })
  229. return;
  230. }
  231. })
  232. }else {
  233. this.$url('/pages/discover/discoverdetails?discover_id='+id)
  234. }
  235. },
  236. addLike(id) {
  237. this.$http
  238. .post({
  239. api: 'api/discover/like',
  240. data: {
  241. discover_id: id
  242. },
  243. header: {
  244. Authorization: this.$cookieStorage.get('user_token')
  245. },
  246. })
  247. .then(res => {
  248. if (res.data.code == 200) {
  249. if (res.data.status) {
  250. this.getHotActivity();
  251. } else {
  252. wx.showModal({
  253. content: res.data.message || '请下拉页面刷新重试',
  254. showCancel: false
  255. });
  256. }
  257. } else {
  258. wx.showModal({
  259. content: res.data.message || '请下拉页面刷新重试',
  260. showCancel: false
  261. });
  262. }
  263. wx.hideLoading();
  264. })
  265. .catch(() => {
  266. wx.hideLoading();
  267. });
  268. },
  269. getMyAttention(options = {}) {
  270. let tab_item = this.tab_list[this.tab_current];
  271. this.$http
  272. .get({
  273. api: 'api/discover/follow',
  274. data: {
  275. page: tab_item.page,
  276. page_size: this.pageSize,
  277. },
  278. header: {
  279. Authorization: this.$cookieStorage.get('user_token')
  280. },
  281. })
  282. .then(res => {
  283. if (res.data.code == 200) {
  284. let isPage;
  285. if(res.data.data.per_page == res.data.data.data.length) {
  286. isPage = true;
  287. }else {
  288. isPage = false;
  289. }
  290. if(!isPage) {
  291. tab_item.loadingClass = false;
  292. tab_item.loadingText = '没有更多数据啦~';
  293. }
  294. if(options.type == 'pageRefresh') {
  295. uni.stopPullDownRefresh();
  296. }else if(options.type == 'scrollRefresh') {
  297. this.isRefresher = false;
  298. }
  299. if(tab_item.page == 1) {
  300. tab_item.list = res.data.data.data;
  301. }else {
  302. tab_item.list.push(...res.data.data.data);
  303. }
  304. } else {
  305. wx.showModal({
  306. content: '请下拉页面刷新重试',
  307. showCancel: false
  308. });
  309. }
  310. wx.hideLoading();
  311. })
  312. .catch(() => {
  313. wx.hideLoading();
  314. });
  315. },
  316. // 页面触底,加载下一页
  317. onScrolltolower(){
  318. let tab_item = this.tab_list[this.tab_current];
  319. if(tab_item.isPage){
  320. tab_item.page = tab_item.page + 1;
  321. if(this.tab_current == 2) {
  322. this.getMyAttention();
  323. }else {
  324. this.getHotActivity();
  325. }
  326. }
  327. },
  328. // 下拉刷新处理
  329. refreshFn(options){
  330. let tab_item = this.tab_list[this.tab_current];
  331. tab_item.page = 1;
  332. tab_item.isPage = true;
  333. tab_item.loadingClass = true;
  334. tab_item.list = []
  335. tab_item.loadingText = '正在加载中';
  336. if(this.tab_current == 2) {
  337. this.getMyAttention(options);
  338. }else {
  339. this.getHotActivity(options);
  340. }
  341. },
  342. // scroll-view 下拉刷新
  343. onRefresherrefresh(){
  344. this.isRefresher = true;
  345. this.refreshFn({type: 'scrollRefresh'});
  346. },
  347. tabChange(event){
  348. this.tab_current = event;
  349. if(this.tab_current == 2) {
  350. this.getMyAttention();
  351. }else {
  352. this.getHotActivity();
  353. }
  354. },
  355. swiperChange(event){
  356. this.tab_current = event.detail.current;
  357. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  358. if(this.tab_current == 2) {
  359. this.getMyAttention();
  360. }else {
  361. this.getHotActivity();
  362. }
  363. },
  364. getHotActivity(options = {}) {
  365. let discover_type;
  366. let tab_item = this.tab_list[this.tab_current];
  367. if(this.tab_current == 0) {
  368. discover_type = 'created_at';
  369. }else {
  370. discover_type = 'view_count';
  371. }
  372. this.$http
  373. .get({
  374. api: 'api/discover',
  375. data:{
  376. page: tab_item.page,
  377. page_size: this.pageSize,
  378. order: discover_type
  379. },
  380. header: {
  381. Authorization: this.$cookieStorage.get('user_token')
  382. },
  383. })
  384. .then(res => {
  385. if (res.data.code == 200) {
  386. if (res.data.status) {
  387. let isPage;
  388. if(res.data.data.per_page == res.data.data.data.length) {
  389. isPage = true;
  390. }else {
  391. isPage = false;
  392. }
  393. tab_item.isPage = isPage;
  394. if(!isPage) {
  395. tab_item.loadingClass = false;
  396. tab_item.loadingText = '没有更多数据啦~';
  397. }
  398. if(options.type == 'pageRefresh') {
  399. uni.stopPullDownRefresh();
  400. }else if(options.type == 'scrollRefresh') {
  401. this.isRefresher = false;
  402. }
  403. if(tab_item.page == 1) {
  404. tab_item.list = res.data.data.data;
  405. }else {
  406. tab_item.list.push(...res.data.data.data);
  407. }
  408. } else {
  409. wx.showModal({
  410. content: res.message || '请下拉页面刷新重试',
  411. showCancel: false
  412. });
  413. }
  414. } else {
  415. wx.showModal({
  416. content: '请下拉页面刷新重试',
  417. showCancel: false
  418. });
  419. }
  420. wx.hideLoading();
  421. })
  422. .catch(() => {
  423. wx.hideLoading();
  424. });
  425. }
  426. }
  427. }
  428. </script>
  429. <style>
  430. page {
  431. background-color: white;
  432. }
  433. </style>
  434. <style lang="scss" scoped>
  435. .fixed-right1{
  436. position: fixed;
  437. right: 32rpx;
  438. bottom: 450rpx;
  439. width: max-content;
  440. height: max-content;
  441. z-index: 9;
  442. .fixed-cart{
  443. width: 110rpx;
  444. height: 110rpx;
  445. border-radius: 50%;
  446. background-color: #FFFFFF;
  447. border: 1rpx solid #DEDEDE;
  448. display: flex;
  449. justify-content: center;
  450. align-items: center;
  451. flex-direction: column;
  452. color: #333333;
  453. position: relative;
  454. margin-top: 30rpx;
  455. .icon-text{
  456. font-size: 50rpx;
  457. line-height: 1;
  458. }
  459. .tips{
  460. font-size: 20rpx;
  461. color: #333333;
  462. }
  463. .angle-mark{
  464. position: absolute;
  465. right: 4rpx;
  466. top: 4rpx;
  467. width: 40rpx;
  468. height: 40rpx;
  469. background-color: #15716E;
  470. border-radius: 50%;
  471. font-size: 20rpx;
  472. display: flex;
  473. justify-content: center;
  474. align-items: center;
  475. color: #FFFFFF;
  476. }
  477. }
  478. .fixed-live{
  479. background: #15716E;
  480. border-radius: 100rpx 5rpx 100rpx 100rpx;
  481. border: none;
  482. color: #FFFFFF;
  483. // animation: bounceIn 1s .2s ease both;
  484. backface-visibility:visible;
  485. transform-origin:center center;
  486. animation: demo 2s 0s infinite ease normal none ;
  487. // &>text:nth-child(1){
  488. // animation: fadeInRightBig 1s .1s ease both;
  489. // }
  490. .tips{
  491. color: #FFFFFF;
  492. }
  493. }
  494. }
  495. .tag-father {
  496. position: relative;
  497. }
  498. .head-tag {
  499. color: white;
  500. display: flex;
  501. align-items: center;
  502. justify-content: center;
  503. text-align: center;
  504. font-size: 24rpx;
  505. width: 36rpx;
  506. height: 36rpx;
  507. border-radius: 50%;
  508. background-color: #15716E;
  509. border: 1rpx solid #FFFFFF;
  510. position: absolute;
  511. left: 66rpx;
  512. top: 70rpx;
  513. z-index: 99;
  514. }
  515. .qzone-img {
  516. width: 220rpx;
  517. height: 220rpx;
  518. border-radius: 10rpx;
  519. margin-right: 12rpx;
  520. &:nth-child(3n) {
  521. margin-right: 0;
  522. }
  523. &:nth-child(n + 4) {
  524. margin-top: 12rpx;
  525. }
  526. }
  527. .head-img {
  528. width: 100rpx;
  529. height: 100rpx;
  530. border-radius: 50%;
  531. }
  532. .fixed-right{
  533. position: fixed;
  534. right: 32rpx;
  535. bottom: 188rpx;
  536. width: max-content;
  537. height: max-content;
  538. padding-bottom: constant(safe-area-inset-bottom);
  539. padding-bottom: env(safe-area-inset-bottom);
  540. .fixed-btn{
  541. width: 110rpx;
  542. height: 110rpx;
  543. border-radius: 50%;
  544. background-color: #15716E;
  545. display: flex;
  546. justify-content: center;
  547. align-items: center;
  548. color: #FFFFFF;
  549. }
  550. }
  551. .fixed-right2{
  552. position: fixed;
  553. right: 32rpx;
  554. bottom: 440rpx;
  555. width: max-content;
  556. height: max-content;
  557. padding-bottom: constant(safe-area-inset-bottom);
  558. padding-bottom: env(safe-area-inset-bottom);
  559. .fixed-btn{
  560. width: 110rpx;
  561. height: 110rpx;
  562. border-radius: 50%;
  563. background-color: #15716E;
  564. display: flex;
  565. justify-content: center;
  566. align-items: center;
  567. color: #FFFFFF;
  568. }
  569. }
  570. // tab样式
  571. /deep/.u-scroll-box {
  572. display: flex;
  573. justify-content: center;
  574. align-items: center;
  575. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  576. }
  577. /deep/.u-scroll-box .u-tab-bar {
  578. background-color: #15716E!important;
  579. width: 80rpx!important;
  580. position: absolute;
  581. left: 0;
  582. bottom: -14rpx;
  583. }
  584. /deep/ .u-tab-item {
  585. font-size: 28rpx!important;
  586. }
  587. </style>