index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <view class="container">
  3. <!-- 小程序头部兼容 -->
  4. <!-- #ifdef MP -->
  5. <view class="input-box flex" @click="clickSearch">
  6. <view class=" input-content flex">
  7. <view class="iconfont iconsearch"></view>
  8. <view class="input"><input type="text" disabled placeholder="请输入搜索内容" /></view>
  9. </view>
  10. </view>
  11. <view class="mp-height"></view>
  12. <!-- #endif -->
  13. <!-- 头部轮播 -->
  14. <view class="carousel-section">
  15. <!-- 标题栏和状态栏占位符 -->
  16. <view class="titleNview-placing"></view>
  17. <!-- 背景色区域 -->
  18. <view class="titleNview-background" :style="{ backgroundColor: '#5DBC7C' }"></view>
  19. <swiper class="carousel" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  20. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item">
  21. <image :src="item.pic" />
  22. </swiper-item>
  23. </swiper>
  24. <!-- 自定义swiper指示器 -->
  25. <!-- <view class="swiper-dots">
  26. <text class="num">{{ swiperCurrent + 1 }}</text>
  27. <text class="sign">/</text>
  28. <text class="num">{{ swiperLength }}</text>
  29. </view> -->
  30. </view>
  31. <!-- 分类 -->
  32. <view class="cate-section">
  33. <navigator url="/pages/product/newPeople" v-if="userInfo.is_whole == 0">
  34. <view class="cate-item">
  35. <image src="/static/img/index-nav1.png"></image>
  36. <text>新人专区</text>
  37. </view>
  38. </navigator>
  39. <navigator url="/pages/product/exchange">
  40. <view class="cate-item">
  41. <image src="/static/img/index-nav2.png"></image>
  42. <text>兑换专区</text>
  43. </view>
  44. </navigator>
  45. <navigator url="/pages/product/store">
  46. <view class="cate-item">
  47. <image src="/static/img/index-nav3.png"></image>
  48. <text>附近门店</text>
  49. </view>
  50. </navigator>
  51. <navigator url="/pages/user/shareQrCode">
  52. <view class="cate-item">
  53. <image src="/static/img/index-nav4.png"></image>
  54. <text>邀请有礼</text>
  55. </view>
  56. </navigator>
  57. </view>
  58. <!-- 金豆专区 -->
  59. <golden-bean :data='jdList'></golden-bean>
  60. <!-- 批发专区 -->
  61. <wholesale></wholesale>
  62. <!-- 公司简介 -->
  63. <view class="jj-tit" v-if="gsjjList.length > 0">
  64. <view class="left">
  65. <image src="../../static/icon/gsjj.png" mode="" class="jj-log"></image>
  66. <view class="jj-title">
  67. 公司简介
  68. </view>
  69. </view>
  70. <view class="right">
  71. <view class="jj-more-tit">
  72. 更多
  73. </view>
  74. <image src="../../static/img/img39.png" mode="" class="jj-more"></image>
  75. </view>
  76. </view>
  77. <view class="jj-wrap" v-if="gsjjList.length > 0">
  78. <view class="jj" v-for="item in 1">
  79. <view class="jj-img"></view>
  80. <view class="jj-info">
  81. <view class="jj-tit-tit clamp">
  82. 哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈
  83. </view>
  84. <view class="jj-val clamp2">
  85. 体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 产品简介 -->
  91. <view class="jj-tit" style="margin-top: 20rpx;" v-if="cpjjList.length > 0">
  92. <view class="left">
  93. <image src="../../static/icon/cpjj.png" mode="" class="jj-log"></image>
  94. <view class="jj-title">
  95. 产品简介
  96. </view>
  97. </view>
  98. <view class="right">
  99. <view class="jj-more-tit">
  100. 更多
  101. </view>
  102. <image src="../../static/img/img39.png" mode="" class="jj-more"></image>
  103. </view>
  104. </view>
  105. <view class="jj-wrap" v-if="cpjjList.length > 0">
  106. <view class="jj" v-for="item in 1">
  107. <view class="jj-img"></view>
  108. <view class="jj-info">
  109. <view class="jj-tit-tit clamp">
  110. 哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈
  111. </view>
  112. <view class="jj-val clamp2">
  113. 体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴体贴
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. import topTitle from '../../components/top-title/top-title.vue';
  122. import {
  123. getProducts
  124. } from '@/api/product.js';
  125. import goldenBean from './child/goldenBean.vue';
  126. import wholesale from './child/wholesale.vue';
  127. import recommend from './child/recommend.vue';
  128. import {
  129. loadIndexs
  130. } from '@/api/index.js';
  131. import {
  132. getUserInfo
  133. } from '@/api/user.js';
  134. import {
  135. setCoupons
  136. } from '@/api/functionalUnit.js';
  137. import {
  138. saveUrl,
  139. interceptor
  140. } from '@/utils/loginUtils';
  141. import {
  142. mapState
  143. } from 'vuex';
  144. export default {
  145. components: {
  146. goldenBean,
  147. wholesale,
  148. recommend,
  149. topTitle
  150. },
  151. data() {
  152. return {
  153. shareShow: false, //分享海报
  154. pageProportion: 0, //保存页面基于750宽度的比例
  155. swiperHeight: 0,
  156. checkid: 0,
  157. titleNViewBackground: '',
  158. swiperCurrent: 0,
  159. swiperLength: 0,
  160. carouselList: [], //轮播列表
  161. bastList: [], //商品
  162. jdList: [], //金豆商品
  163. page: 1,
  164. limit: 3,
  165. gsjjList: [],
  166. cpjjList: []
  167. };
  168. },
  169. computed: {
  170. ...mapState(['loginInterceptor']),
  171. ...mapState('user', ['hasLogin', 'userInfo'])
  172. },
  173. onLoad: function(option) {
  174. // #ifndef MP
  175. if (option.spread) {
  176. // 存储其他邀请人
  177. uni.setStorageSync('spread', option.spread);
  178. }
  179. // #endif
  180. // #ifdef MP
  181. if (option.scene) {
  182. // 存储小程序邀请人
  183. uni.setStorage({
  184. key: 'spread_code',
  185. data: option.scene
  186. });
  187. }
  188. // #endif
  189. },
  190. onShow: function() {
  191. // 判断是否强制登录
  192. if (this.loginInterceptor && !this.hasLogin) {
  193. saveUrl()
  194. // 登录拦截
  195. // interceptor();
  196. return
  197. }
  198. this.loadData();
  199. this.getBargainList();
  200. },
  201. //下拉刷新
  202. onPullDownRefresh() {
  203. this.loadData();
  204. },
  205. // #ifndef MP
  206. // 监听导航栏输入框点击事件
  207. onNavigationBarSearchInputClicked(e) {
  208. //跳转到搜索页面
  209. this.clickSearch();
  210. },
  211. //点击导航栏 buttons 时触发
  212. onNavigationBarButtonTap(e) {
  213. const index = e.index;
  214. if (index === 0) {
  215. this.$api.msg('点击了扫描');
  216. } else if (index === 1) {
  217. // #ifdef APP-PLUS
  218. const pages = getCurrentPages();
  219. const page = pages[pages.length - 1];
  220. const currentWebview = page.$getAppWebview();
  221. currentWebview.hideTitleNViewButtonRedDot({
  222. index
  223. });
  224. // #endif
  225. uni.navigateTo({
  226. url: '/pages/user/notice'
  227. });
  228. }
  229. },
  230. // #endif
  231. methods: {
  232. getUserInfo() {
  233. getUserInfo().then(res => {
  234. console.log(res)
  235. this.setUserInfo(res.data);
  236. })
  237. },
  238. getBargainList() {
  239. let that = this;
  240. getProducts({
  241. page: that.page,
  242. limit: that.limit,
  243. is_gold: 1
  244. })
  245. .then(function(res) {
  246. that.jdList = res.data
  247. })
  248. .catch(res => {});
  249. },
  250. // 點擊搜索框
  251. clickSearch() {
  252. uni.navigateTo({
  253. url: '/pages/product/search'
  254. });
  255. },
  256. // 监听图片加载完成
  257. onImageError(key, index) {
  258. this[key][index].image = '/static/error/errorImage.jpg';
  259. },
  260. // 请求载入数据
  261. async loadData() {
  262. loadIndexs({})
  263. .then(({
  264. data
  265. }) => {
  266. let goods = data.info;
  267. this.carouselList = data.banner;
  268. this.swiperLength = this.carouselList.length;
  269. this.bastList = goods.bastList; //精品推荐
  270. uni.stopPullDownRefresh();
  271. })
  272. .catch(e => {
  273. uni.stopPullDownRefresh();
  274. });
  275. },
  276. //轮播图切换修改背景色
  277. swiperChange(e) {
  278. const index = e.detail.current;
  279. this.swiperCurrent = index;
  280. this.titleNViewBackground = this.carouselList[index].background;
  281. },
  282. //详情页
  283. navToDetailPage(item) {
  284. let id = item.id;
  285. uni.navigateTo({
  286. url: '/pages/product/product?id=' + id
  287. });
  288. },
  289. }
  290. };
  291. </script>
  292. <style lang="scss">
  293. .Mask {
  294. width: 100%;
  295. height: 100vh;
  296. position: fixed;
  297. z-index: 99999;
  298. background-color: rgba(0, 0, 0, 0.7);
  299. top: 0;
  300. image {
  301. width: 100%;
  302. height: 100vh;
  303. }
  304. }
  305. /* #ifdef MP */
  306. .mp-height {
  307. height: 44px;
  308. }
  309. .input-box {
  310. position: fixed;
  311. top: 0;
  312. left: 0;
  313. width: 100%;
  314. padding: 25rpx;
  315. background-color: #ffffff;
  316. z-index: 999;
  317. height: 44px;
  318. .iconsearch {
  319. font-size: 50rpx;
  320. }
  321. .input-content {
  322. border-radius: 99rpx;
  323. flex-grow: 1;
  324. padding: 10rpx 30rpx;
  325. background-color: rgba(231, 231, 231, 0.7);
  326. .input {
  327. flex-grow: 1;
  328. input {
  329. font-size: $font-lg;
  330. }
  331. }
  332. }
  333. .input-button {
  334. padding-left: 20rpx;
  335. font-size: $font-lg;
  336. height: 100%;
  337. }
  338. }
  339. page {
  340. .cate-section {
  341. position: relative;
  342. z-index: 5;
  343. border-radius: 16rpx 16rpx 0 0;
  344. margin-top: -20rpx;
  345. }
  346. .carousel-section {
  347. padding: 0;
  348. .titleNview-placing {
  349. padding-top: 0;
  350. height: 0;
  351. }
  352. .carousel {
  353. .carousel-item {
  354. padding: 0;
  355. }
  356. }
  357. .swiper-dots {
  358. left: 45rpx;
  359. bottom: 40rpx;
  360. }
  361. }
  362. }
  363. /* #endif */
  364. page {
  365. background: #f7f8f7;
  366. }
  367. .m-t {
  368. margin-top: 16rpx;
  369. }
  370. /* 头部 轮播图 */
  371. .carousel-section {
  372. position: relative;
  373. padding-top: 10px;
  374. overflow: hidden;
  375. .titleNview-placing {
  376. height: var(--status-bar-height);
  377. padding-top: 44px;
  378. box-sizing: content-box;
  379. }
  380. .titleNview-background {
  381. position: absolute;
  382. top: 0;
  383. left: 0;
  384. width: 100%;
  385. height: 426rpx;
  386. transition: 0.4s;
  387. }
  388. .carousel {
  389. width: 100%;
  390. height: 240rpx;
  391. .carousel-item {
  392. width: 100%;
  393. height: 100%;
  394. padding: 0 28rpx;
  395. overflow: hidden;
  396. }
  397. image {
  398. width: 100%;
  399. height: 100%;
  400. border-radius: $border-radius-sm;
  401. }
  402. }
  403. }
  404. .swiper-dots {
  405. display: flex;
  406. position: absolute;
  407. left: 60rpx;
  408. bottom: 15rpx;
  409. width: 72rpx;
  410. height: 36rpx;
  411. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9y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XFAJE4s4NQA3K/8Y6DzO4g40P7UcmIBJxbEesCKWBDg8wWxHrAiFgT4fEGsB/CwIhYE+AeBAAdPLOcV8HRmWRDAiQVcO7GcV8CLM8uCAE4sQCDAlHcQ7x+ABQEEAggEEAggEEAggEAAgQACASAQQCCAQACBAAIBBAIIBBAIIBBAIABe4e9iAe/xd7EAJxYgEGDeO4j3EODp/cOCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
  412. background-size: 100% 100%;
  413. .num {
  414. width: 36rpx;
  415. height: 36rpx;
  416. border-radius: 50px;
  417. font-size: 24rpx;
  418. color: #fff;
  419. text-align: center;
  420. line-height: 36rpx;
  421. }
  422. .sign {
  423. position: absolute;
  424. top: 0;
  425. left: 50%;
  426. line-height: 36rpx;
  427. font-size: 12rpx;
  428. color: #fff;
  429. transform: translateX(-50%);
  430. }
  431. }
  432. /* 分类 */
  433. .cate-section {
  434. background-color: #fff;
  435. display: flex;
  436. justify-content: space-around;
  437. align-items: center;
  438. flex-wrap: wrap;
  439. padding: 30rpx 22rpx;
  440. .cate-item {
  441. display: flex;
  442. flex-direction: column;
  443. align-items: center;
  444. font-size: $font-sm + 2rpx;
  445. color: $font-color-dark;
  446. }
  447. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  448. image {
  449. width: 140rpx;
  450. height: 140rpx;
  451. // margin-bottom: 5rpx;
  452. border-radius: 50%;
  453. opacity: 0.7;
  454. }
  455. }
  456. /*公用边框样式*/
  457. %icon {
  458. margin-right: 10rpx;
  459. display: inline-block;
  460. padding: 2rpx 10rpx;
  461. border: 1rpx solid $color-yellow;
  462. color: $color-yellow;
  463. line-height: 1;
  464. font-size: $font-base;
  465. border-radius: 10rpx;
  466. }
  467. .jj-tit {
  468. display: flex;
  469. // height: 50rpx;
  470. justify-content: space-between;
  471. background-color: #fff;
  472. padding-top: 20rpx;
  473. .left {
  474. padding-left: 20rpx;
  475. display: flex;
  476. .jj-log {
  477. width: 45rpx;
  478. height: 45rpx;
  479. }
  480. .jj-title {
  481. font-weight: bold;
  482. font-size: 32rpx;
  483. padding-left: 15rpx;
  484. }
  485. }
  486. .right {
  487. display: flex;
  488. width: 200rpx;
  489. font-size: 22rpx;
  490. // justify-content: sp;
  491. justify-content: flex-end;
  492. align-items: center;
  493. padding-right: 20rpx;
  494. color: #999;
  495. .jj-more {
  496. margin-left: 10rpx;
  497. width: 15rpx;
  498. height: 22rpx;
  499. }
  500. }
  501. }
  502. .jj-wrap {
  503. background-color: #fff;
  504. // margin: 20rpx 0;
  505. .jj {
  506. margin: auto;
  507. width: 689rpx;
  508. height: 202rpx;
  509. border-bottom: 1px solid #999;
  510. padding: 20rpx;
  511. padding-left: 0;
  512. display: flex;
  513. &:last-of-type {
  514. border-bottom: none;
  515. }
  516. .jj-img {
  517. flex-shrink: 0;
  518. width: 222rpx;
  519. height: 158rpx;
  520. background-color: #bfa;
  521. border-radius: 10rpx;
  522. }
  523. .jj-info {
  524. width: 450rpx;
  525. // flex-shrink: 0;
  526. padding: 10rpx;
  527. font-size: 32rpx;
  528. font-weight: bold;
  529. .jj-tit-tit {
  530. }
  531. .jj-val {
  532. padding-top: 20rpx;
  533. font-size: 28rpx;
  534. font-weight: 500;
  535. }
  536. }
  537. }
  538. }
  539. </style>