zmt.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-x="true" class="class-box flex b-t" :scroll-left="scrollLeft" :scroll-with-animation="true">
  4. <view @click="tabClass(idx)" class="item" :style="{ width: topNavWidth }" v-for="(item, idx) in navList" :key="idx">
  5. <view class="status" :class="{ action: idx == classIndex }">{{ item.title }}</view>
  6. </view>
  7. </scroll-view>
  8. <swiper :interval="3000" :duration="500" class="nav-swiper" :current="classIndex" :style="{'height':height}" disable-touch>
  9. <swiper-item v-for="navItem in navList">
  10. <scroll-view scroll-y="true" :style="{'height':height}" @scrolltolower="getZmtList()">
  11. <!-- 轮播图and搜索 start-->
  12. <view class="Search-box" @click="navTo('/pages/index/searchZmt')">
  13. <view class="Search-box-size">
  14. <image class="box-img" src="../../static/img/img01.png"></image>
  15. <input type="text" class="box-word" disabled placeholder="请输入关键字" v-model="keyword" />
  16. </view>
  17. <!-- <view class="Search-box-sort" @click="messagesearch">搜索</view> -->
  18. </view>
  19. <!-- <view class="top-swiper">
  20. <swiper :autoplay="true" :interval="3000" :duration="1000" class="banner-swiper">
  21. <swiper-item>
  22. <image src="../../static/error/emptyCart.png" mode="" class="swiper-img"></image>
  23. </swiper-item>
  24. <swiper-item>
  25. <image src="../../static/img/bargainBg.jpg" mode="" class="swiper-img"></image>
  26. </swiper-item>
  27. </swiper>
  28. <view class="input-box flex" @click="clickSearch">
  29. <view class=" input-content flex">
  30. <view class="iconfont iconsearch"></view>
  31. <view class="input"><input type="text" disabled placeholder="有什么新鲜事" /></view>
  32. </view>
  33. </view>
  34. </view> -->
  35. <!-- 轮播图and搜索 end-->
  36. <!-- 自媒体列表 start -->
  37. <view class="dy-wrap flex" v-for="item in navItem.list" @click="navTo('/pages/user/dydetail?id=' + item.id)">
  38. <view class="user-logo">
  39. <image :src="item.headimg" mode=""></image>
  40. </view>
  41. <view class="user-num">
  42. <view class="user-name">
  43. {{item.name}}
  44. </view>
  45. <view class="sub-num">
  46. 发表文章:{{item.count}}
  47. </view>
  48. <view class="read-num">
  49. 阅读量:{{item.visit}}
  50. </view>
  51. </view>
  52. <view class="flex flex_direction">
  53. <view class="dy-btn" :class="{'dying':item.is_sub == 1}" @click.stop="dingYue(item)">
  54. {{item.is_sub == 1?'已订阅':'订阅'}}
  55. </view>
  56. <!-- <view v-show="item.join" class="jr-btn" class="dying}">
  57. {{'已加入'}}
  58. </view> -->
  59. <view class="jr-btn" v-if="item.join" :class="{'dying':item.join == 1}" @click.stop='toJoin(item)'>
  60. 已加入
  61. </view>
  62. <view class="jr-btn" v-if="!item.joins&&!item.join" :class="dying" @click.stop='toJoin(item)'>
  63. 加入
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 自媒体列表 end -->
  68. </scroll-view>
  69. </swiper-item>
  70. </swiper>
  71. </view>
  72. </template>
  73. <script>
  74. import {
  75. loadIndexs
  76. } from '@/api/index.js';
  77. import {
  78. getUserInfo
  79. } from '@/api/user.js';
  80. import {
  81. interceptor
  82. } from '@/utils/loginUtils';
  83. import {
  84. mapState
  85. } from 'vuex';
  86. import { getZmtList, getQyType, dingYue } from '@/api/art.js'
  87. export default {
  88. data() {
  89. return {
  90. isDy:false,
  91. height: '',
  92. classIndex: 0,
  93. topNavWidth: '25%', //设置导航默认宽度
  94. navList: [{
  95. id: 0,
  96. title: '推荐',
  97. loadingType: 'more',
  98. list: [],
  99. page: 1, //当前页数
  100. limit: 10 //每次信息条数
  101. }
  102. ],
  103. pageProportion: 0, //保存页面基于750宽度的比例
  104. swiperHeight: 0,
  105. checkid: 0,
  106. titleNViewBackground: '',
  107. swiperCurrent: 0,
  108. swiperLength: 0,
  109. bargainlist: [], //砍价商品
  110. carouselList: [], //轮播列表
  111. goodsList: [], //最新商品列表
  112. bastList: [], //精品推荐列表
  113. bastBanner: [], //促销商品列表
  114. menusList: [], //头部菜单
  115. page: 1,
  116. limit: 5,
  117. userServant: [{
  118. image: ''
  119. }], //用户推广服务
  120. couponArray: [], //可领取优惠券
  121. recommend: [{
  122. id: 0,
  123. re_title: '精选',
  124. re_name: '为你推荐'
  125. },
  126. {
  127. id: 1,
  128. re_title: '最新',
  129. re_name: '最新好货优选'
  130. },
  131. {
  132. id: 2,
  133. re_title: '便宜好货',
  134. re_name: '90天便宜好货'
  135. }
  136. ],
  137. actTime: new Date(),
  138. keyword: '',
  139. merId:''
  140. };
  141. },
  142. computed: {
  143. ...mapState(['loginInterceptor']),
  144. ...mapState('user', ['hasLogin', 'userInfo']),
  145. // 计算左侧距离
  146. scrollLeft() {
  147. if (this.classIndex > 1) {
  148. return this.itemWidht * (this.classIndex - 1.5);
  149. } else {
  150. return 0;
  151. }
  152. }
  153. },
  154. onLoad: function(option) {
  155. let obj = this
  156. // #ifndef MP
  157. if (option.spread) {
  158. // 存储其他邀请人
  159. uni.setStorageSync('spread', option.spread);
  160. }
  161. // #endif
  162. // #ifdef MP
  163. if (option.scene) {
  164. // 存储小程序邀请人
  165. uni.setStorage({
  166. key: 'spread_code',
  167. data: option.scene
  168. });
  169. }
  170. // #endif
  171. this.getArtTypeList()
  172. getUserInfo({}).then(res=>{
  173. let userInfo=res.data
  174. if(userInfo.mer_id!=undefined && userInfo.mer_id!=null && userInfo.mer_id!=0 && userInfo.mer_id!=''){
  175. obj.merId=userInfo.mer_id
  176. }
  177. })
  178. },
  179. onShow: function() {
  180. // 判断是否强制登录
  181. if (this.loginInterceptor && !this.hasLogin) {
  182. // 登录拦截
  183. interceptor();
  184. }
  185. this.loadData();
  186. },
  187. //下拉刷新
  188. onPullDownRefresh() {
  189. this.loadData();
  190. },
  191. // #ifndef MP
  192. // 监听导航栏输入框点击事件
  193. onNavigationBarSearchInputClicked(e) {
  194. //跳转到搜索页面
  195. this.clickSearch();
  196. },
  197. //点击导航栏 buttons 时触发
  198. onNavigationBarButtonTap(e) {
  199. const index = e.index;
  200. if (index === 0) {
  201. this.$api.msg('点击了扫描');
  202. } else if (index === 1) {
  203. // #ifdef APP-PLUS
  204. const pages = getCurrentPages();
  205. const page = pages[pages.length - 1];
  206. const currentWebview = page.$getAppWebview();
  207. currentWebview.hideTitleNViewButtonRedDot({
  208. index
  209. });
  210. // #endif
  211. uni.navigateTo({
  212. url: '/pages/user/notice'
  213. });
  214. }
  215. },
  216. onReady(res) {
  217. var obj = this;
  218. uni.getSystemInfo({
  219. success: resu => {
  220. const query = uni.createSelectorQuery();
  221. query.select('.good-content').boundingClientRect();
  222. query.exec(function(res) {
  223. obj.height = resu.windowHeight - res[0].top + 'px';
  224. });
  225. },
  226. fail: res => {}
  227. });
  228. },
  229. // #endif
  230. // 计算页面剩余高度
  231. onReady(res) {
  232. var obj = this;
  233. uni.getSystemInfo({
  234. success: resu => {
  235. const query = uni.createSelectorQuery();
  236. query.select('.nav-swiper').boundingClientRect();
  237. query.exec(function(res) {
  238. obj.height = resu.windowHeight - res[0].top + 'px';
  239. });
  240. },
  241. fail: res => {}
  242. });
  243. },
  244. onReachBottom() {
  245. this.getZmtList()
  246. },
  247. methods: {
  248. // 获取项目宽度
  249. numClassWidht() {
  250. uni.createSelectorQuery()
  251. .select('.container')
  252. .fields(
  253. {
  254. size: true
  255. },
  256. data => {
  257. // 设置项目宽度
  258. this.itemWidht = Math.floor((data.width / 750) * 187.5);
  259. }
  260. )
  261. .exec();
  262. },
  263. navTo(url) {
  264. console.log(url)
  265. uni.navigateTo({
  266. url: url
  267. })
  268. },
  269. tabClass(ind) {
  270. // 保存当前选中的对象
  271. this.classIndex = ind;
  272. this.getZmtList('tab')
  273. },
  274. // 點擊搜索框
  275. clickSearch() {
  276. },
  277. // 监听图片加载完成
  278. onImageError(key, index) {
  279. this[key][index].image = '/static/error/errorImage.jpg';
  280. },
  281. // 请求载入数据
  282. async loadData() {
  283. loadIndexs({})
  284. .then(({
  285. data
  286. }) => {
  287. let goods = data.info;
  288. this.carouselList = data.banner;
  289. this.swiperLength = this.carouselList.length;
  290. this.menusList = data.menus;
  291. this.goodsList = goods.firstList; //最新商品
  292. this.bastList = goods.bastList; //精品推荐
  293. this.bastBanner = data.benefit; //促销单品
  294. this.$set(this, 'couponArray', data.couponList); //保存卡包券
  295. uni.stopPullDownRefresh();
  296. })
  297. .catch(e => {
  298. uni.stopPullDownRefresh();
  299. });
  300. },
  301. //轮播图切换修改背景色
  302. swiperChange(e) {
  303. const index = e.detail.current;
  304. this.swiperCurrent = index;
  305. this.titleNViewBackground = this.carouselList[index].background;
  306. },
  307. //详情页
  308. navToDetailPage(item) {
  309. let id = item.id;
  310. uni.navigateTo({
  311. url: '/pages/product/product?id=' + id
  312. });
  313. },
  314. // 轮播图跳转
  315. bannerNavToUrl(item) {
  316. // #ifdef H5
  317. if (item.wap_url.indexOf('http') > 0) {
  318. window.location.href = item.wap_url;
  319. }
  320. // #endif
  321. //测试数据没有写id,用title代替
  322. uni.navigateTo({
  323. url: item.wap_url
  324. });
  325. },
  326. // 获取企业分类
  327. getArtTypeList() {
  328. let obj = this
  329. getQyType().then(res => {
  330. console.log(res,'获取')
  331. // 获取头部nav
  332. let arr = res.data.map(e => {
  333. e.loadingType = 'more'
  334. e.page = 1
  335. e.limit = 10
  336. e.loaded = false
  337. e.list = []
  338. return e
  339. })
  340. obj.navList = obj.navList.concat(arr)
  341. console.log(obj.navList)
  342. obj.$nextTick(() => {
  343. obj.numClassWidht();
  344. });
  345. this.getZmtList()
  346. })
  347. },
  348. // 获取自媒体列表
  349. getZmtList(type) {
  350. let obj = this
  351. let index = obj.classIndex
  352. let navItem = obj.navList[index]
  353. if(type == 'tab' && navItem.loaded) {
  354. return
  355. }
  356. if(navItem.loadingType == 'loading' || navItem.loadingType == 'noMore') {
  357. return
  358. }
  359. navItem.loadingType = 'loading'
  360. let searchData = {}
  361. if(navItem.id == 0) {
  362. searchData = {
  363. page: navItem.page,
  364. rows: navItem.limit,
  365. }
  366. }else {
  367. searchData = {
  368. page: navItem.page,
  369. rows: navItem.limit,
  370. type: navItem.id
  371. }
  372. }
  373. getZmtList(searchData).then(res => {
  374. console.log(res)
  375. navItem.list = navItem.list.concat(res.data.list)
  376. navItem.page++
  377. if(res.data.list.length == navItem.limit) {
  378. navItem.loadingType = 'more'
  379. }else {
  380. navItem.loadingType = 'noMore'
  381. }
  382. navItem.loaded = true
  383. })
  384. },
  385. // 订阅
  386. dingYue(item) {
  387. let obj = this
  388. // is_sub 为1 时为关注状态
  389. if(item.is_sub == 1) {
  390. uni.showModal({
  391. title:'提示',
  392. content: '是否取消关注?',
  393. complete(e) {
  394. if(e.confirm) {
  395. // 取消关注
  396. dingYue({
  397. id:item.id
  398. }).then(res => {
  399. console.log(res)
  400. let s = obj.navList[obj.classIndex].list.indexOf(item);
  401. obj.navList[obj.classIndex].list[s].is_sub = 0
  402. obj.$api.msg('已取消关注')
  403. })
  404. }
  405. }
  406. })
  407. }else {
  408. // 关注
  409. dingYue({
  410. id:item.id
  411. }).then(res => {
  412. let s = obj.navList[obj.classIndex].list.indexOf(item);
  413. obj.navList[obj.classIndex].list[s].is_sub = 1
  414. obj.$api.msg('已关注')
  415. })
  416. }
  417. },
  418. //加入
  419. toJoin(item){
  420. if(!this.merId){
  421. this.navTo('/pages/user/joinMedia?id=' + item.id)
  422. }
  423. }
  424. }
  425. };
  426. </script>
  427. <style lang="scss">
  428. page {
  429. background: #f7f8f7;
  430. }
  431. .navbar {
  432. display: flex;
  433. height: 40px;
  434. padding: 0 5px;
  435. background: #fff;
  436. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  437. position: relative;
  438. z-index: 10;
  439. .nav-item {
  440. flex: 1;
  441. display: flex;
  442. justify-content: center;
  443. align-items: center;
  444. height: 100%;
  445. font-size: 15px;
  446. color: $font-color-dark;
  447. position: relative;
  448. &.current {
  449. color: #000;
  450. font-weight: bold;
  451. &:after {
  452. content: '';
  453. position: absolute;
  454. left: 50%;
  455. bottom: 0;
  456. transform: translateX(-50%);
  457. width: 44px;
  458. height: 0;
  459. border-bottom: 2px solid #E60012;
  460. }
  461. }
  462. }
  463. }
  464. .nav-swiper {
  465. background-color: #fff;
  466. }
  467. .top-swiper {
  468. position: relative;
  469. .banner-swiper {
  470. width: 750rpx;
  471. height: 390rpx;
  472. .swiper-img {
  473. display: block;
  474. width: 750rpx;
  475. height: 390rpx;
  476. }
  477. swiper-item {
  478. width: 750rpx;
  479. height: 390rpx;
  480. }
  481. }
  482. }
  483. // 头部时间段样式
  484. .class-box {
  485. white-space: nowrap;
  486. height: 40px;
  487. position: relative;
  488. background-color: #fff;
  489. .item {
  490. text-align: center;
  491. display: inline-block;
  492. color: $font-color-base;
  493. height: 100%;
  494. background-color: #ffffff;
  495. line-height: 1;
  496. .status {
  497. font-size:30rpx;
  498. margin: 0 auto;
  499. width: 60px;
  500. height: 100%;
  501. line-height: 40px;
  502. &.action {
  503. color: #000;
  504. font-weight: bold;
  505. position: relative;
  506. &:after {
  507. content: '';
  508. position: absolute;
  509. left: 50%;
  510. bottom:5px;
  511. transform: translateX(-50%);
  512. width: 33px;
  513. height: 0;
  514. border-bottom: 2px solid #E60012;
  515. }
  516. }
  517. }
  518. }
  519. }
  520. .dy-wrap {
  521. width: 707rpx;
  522. background: #fff;
  523. margin: auto;
  524. border-bottom: #E9E9E9 solid 1px;
  525. padding: 20rpx 0;
  526. .user-logo {
  527. flex-shrink: 0;
  528. height: 100rpx;
  529. width: 100rpx;
  530. border-radius: 50%;
  531. image {
  532. width: 100%;
  533. height: 100%;
  534. border-radius: 50%;
  535. }
  536. }
  537. .user-num {
  538. flex-grow: 1;
  539. padding-left: 10rpx;
  540. font-size: 24rpx;
  541. font-weight: 500;
  542. color: #999999;
  543. .user-name {
  544. font-size: 34rpx;
  545. font-weight: 600;
  546. color: #333333;
  547. padding-right: 20rpx;
  548. padding: 0 20rpx 20rpx 0;
  549. }
  550. }
  551. .dy-btn {
  552. flex-shrink: 0;
  553. text-align: center;
  554. width: 136rpx;
  555. line-height: 66rpx;
  556. border-radius: 10rpx;
  557. font-size: 28rpx;
  558. font-weight: 500;
  559. background: #E6645F;
  560. color: #fff;
  561. }
  562. .jr-btn {
  563. flex-shrink: 0;
  564. text-align: center;
  565. width: 136rpx;
  566. line-height: 66rpx;
  567. border-radius: 10rpx;
  568. font-size: 28rpx;
  569. font-weight: 500;
  570. margin-top: 20rpx;
  571. background: #E6645F;
  572. color: #fff;
  573. }
  574. .flex_direction{
  575. flex-direction: column;
  576. justify-content: center;
  577. }
  578. .dying {
  579. color: #999999;
  580. background: #E9E9E9;
  581. }
  582. }
  583. .input-box {
  584. width: 100%;
  585. padding: 25rpx;
  586. z-index: 999;
  587. height: 44px;
  588. .iconsearch {
  589. font-size: 50rpx;
  590. }
  591. .input-content {
  592. border-radius: 99rpx;
  593. flex-grow: 1;
  594. padding: 10rpx 30rpx;
  595. background-color: rgba(255, 255, 255, 0.7);
  596. border: 1px solid #000000;
  597. .input {
  598. flex-grow: 1;
  599. input {
  600. font-size: $font-lg;
  601. }
  602. }
  603. }
  604. .input-button {
  605. padding-left: 20rpx;
  606. font-size: $font-lg;
  607. height: 100%;
  608. }
  609. }
  610. .Search-box {
  611. padding-left: 20rpx;
  612. padding-right: 20rpx;
  613. height: 100rpx;
  614. background: #ffffff;
  615. display: flex;
  616. justify-content: center;
  617. align-items: center;
  618. .Search-box-sort {
  619. font-size: 30rpx;
  620. font-weight: 500;
  621. color: rgba(102, 102, 102, 1);
  622. .sort-text {
  623. width: 57rpx;
  624. height: 29rpx;
  625. font-size: 30rpx;
  626. font-weight: 500;
  627. color: rgba(51, 51, 51, 1);
  628. line-height: 58rpx;
  629. margin-right: 19rpx;
  630. }
  631. .sort-img {
  632. width: 21rpx;
  633. height: 11rpx;
  634. margin-bottom: 4rpx;
  635. }
  636. }
  637. .Search-box-size {
  638. width: 700rpx;
  639. height: 65rpx;
  640. border-radius: 32rpx;
  641. background-color: #f1f1f1;
  642. padding-left: 36rpx;
  643. display: flex;
  644. align-items: center;
  645. .box-img {
  646. height: 32rpx;
  647. width: 32rpx;
  648. margin-right: 16rpx;
  649. }
  650. .box-word {
  651. width: 100%;
  652. font-size: 22rpx;
  653. font-weight: 500;
  654. color: rgba(205, 203, 203, 1);
  655. line-height: 55rpx;
  656. }
  657. }
  658. }
  659. </style>