金诚优选前端代码
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.

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