index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. <recommend :data='bastList'></recommend>
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. getProducts
  69. } from '@/api/product.js';
  70. import goldenBean from './child/goldenBean.vue';
  71. import wholesale from './child/wholesale.vue';
  72. import recommend from './child/recommend.vue';
  73. import {
  74. loadIndexs
  75. } from '@/api/index.js';
  76. import {
  77. getUserInfo
  78. } from '@/api/user.js';
  79. import {
  80. setCoupons
  81. } from '@/api/functionalUnit.js';
  82. import {
  83. saveUrl,
  84. interceptor
  85. } from '@/utils/loginUtils';
  86. import {
  87. mapState
  88. } from 'vuex';
  89. export default {
  90. components: {
  91. goldenBean,
  92. wholesale,
  93. recommend
  94. },
  95. data() {
  96. return {
  97. shareShow: false, //分享海报
  98. pageProportion: 0, //保存页面基于750宽度的比例
  99. swiperHeight: 0,
  100. checkid: 0,
  101. titleNViewBackground: '',
  102. swiperCurrent: 0,
  103. swiperLength: 0,
  104. carouselList: [], //轮播列表
  105. bastList: [], //商品
  106. jdList: [], //金豆商品
  107. page: 1,
  108. limit: 3,
  109. };
  110. },
  111. computed: {
  112. ...mapState(['loginInterceptor']),
  113. ...mapState('user', ['hasLogin', 'userInfo'])
  114. },
  115. onLoad: function(option) {
  116. // #ifndef MP
  117. if (option.spread) {
  118. // 存储其他邀请人
  119. uni.setStorageSync('spread', option.spread);
  120. }
  121. // #endif
  122. // #ifdef MP
  123. if (option.scene) {
  124. // 存储小程序邀请人
  125. uni.setStorage({
  126. key: 'spread_code',
  127. data: option.scene
  128. });
  129. }
  130. // #endif
  131. },
  132. onShow: function() {
  133. // 判断是否强制登录
  134. if (this.loginInterceptor && !this.hasLogin) {
  135. saveUrl()
  136. // 登录拦截
  137. // interceptor();
  138. return
  139. }
  140. this.loadData();
  141. this.getBargainList();
  142. },
  143. //下拉刷新
  144. onPullDownRefresh() {
  145. this.loadData();
  146. },
  147. // #ifndef MP
  148. // 监听导航栏输入框点击事件
  149. onNavigationBarSearchInputClicked(e) {
  150. //跳转到搜索页面
  151. this.clickSearch();
  152. },
  153. //点击导航栏 buttons 时触发
  154. onNavigationBarButtonTap(e) {
  155. const index = e.index;
  156. if (index === 0) {
  157. this.$api.msg('点击了扫描');
  158. } else if (index === 1) {
  159. // #ifdef APP-PLUS
  160. const pages = getCurrentPages();
  161. const page = pages[pages.length - 1];
  162. const currentWebview = page.$getAppWebview();
  163. currentWebview.hideTitleNViewButtonRedDot({
  164. index
  165. });
  166. // #endif
  167. uni.navigateTo({
  168. url: '/pages/user/notice'
  169. });
  170. }
  171. },
  172. // #endif
  173. methods: {
  174. getUserInfo() {
  175. getUserInfo().then(res => {
  176. console.log(res)
  177. this.setUserInfo(res.data);
  178. })
  179. },
  180. getBargainList() {
  181. let that = this;
  182. getProducts({
  183. page: that.page,
  184. limit: that.limit,
  185. is_gold: 1
  186. })
  187. .then(function(res) {
  188. that.jdList = res.data
  189. })
  190. .catch(res => {});
  191. },
  192. // 點擊搜索框
  193. clickSearch() {
  194. uni.navigateTo({
  195. url: '/pages/product/search'
  196. });
  197. },
  198. // 监听图片加载完成
  199. onImageError(key, index) {
  200. this[key][index].image = '/static/error/errorImage.jpg';
  201. },
  202. // 请求载入数据
  203. async loadData() {
  204. loadIndexs({})
  205. .then(({
  206. data
  207. }) => {
  208. let goods = data.info;
  209. this.carouselList = data.banner;
  210. this.swiperLength = this.carouselList.length;
  211. this.bastList = goods.bastList; //精品推荐
  212. uni.stopPullDownRefresh();
  213. })
  214. .catch(e => {
  215. uni.stopPullDownRefresh();
  216. });
  217. },
  218. //轮播图切换修改背景色
  219. swiperChange(e) {
  220. const index = e.detail.current;
  221. this.swiperCurrent = index;
  222. this.titleNViewBackground = this.carouselList[index].background;
  223. },
  224. //详情页
  225. navToDetailPage(item) {
  226. let id = item.id;
  227. uni.navigateTo({
  228. url: '/pages/product/product?id=' + id
  229. });
  230. },
  231. }
  232. };
  233. </script>
  234. <style lang="scss">
  235. .Mask {
  236. width: 100%;
  237. height: 100vh;
  238. position: fixed;
  239. z-index: 99999;
  240. background-color: rgba(0, 0, 0, 0.7);
  241. top: 0;
  242. image {
  243. width: 100%;
  244. height: 100vh;
  245. }
  246. }
  247. /* #ifdef MP */
  248. .mp-height {
  249. height: 44px;
  250. }
  251. .input-box {
  252. position: fixed;
  253. top: 0;
  254. left: 0;
  255. width: 100%;
  256. padding: 25rpx;
  257. background-color: #ffffff;
  258. z-index: 999;
  259. height: 44px;
  260. .iconsearch {
  261. font-size: 50rpx;
  262. }
  263. .input-content {
  264. border-radius: 99rpx;
  265. flex-grow: 1;
  266. padding: 10rpx 30rpx;
  267. background-color: rgba(231, 231, 231, 0.7);
  268. .input {
  269. flex-grow: 1;
  270. input {
  271. font-size: $font-lg;
  272. }
  273. }
  274. }
  275. .input-button {
  276. padding-left: 20rpx;
  277. font-size: $font-lg;
  278. height: 100%;
  279. }
  280. }
  281. page {
  282. .cate-section {
  283. position: relative;
  284. z-index: 5;
  285. border-radius: 16rpx 16rpx 0 0;
  286. margin-top: -20rpx;
  287. }
  288. .carousel-section {
  289. padding: 0;
  290. .titleNview-placing {
  291. padding-top: 0;
  292. height: 0;
  293. }
  294. .carousel {
  295. .carousel-item {
  296. padding: 0;
  297. }
  298. }
  299. .swiper-dots {
  300. left: 45rpx;
  301. bottom: 40rpx;
  302. }
  303. }
  304. }
  305. /* #endif */
  306. page {
  307. background: #f7f8f7;
  308. }
  309. .m-t {
  310. margin-top: 16rpx;
  311. }
  312. /* 头部 轮播图 */
  313. .carousel-section {
  314. position: relative;
  315. padding-top: 10px;
  316. overflow: hidden;
  317. .titleNview-placing {
  318. height: var(--status-bar-height);
  319. padding-top: 44px;
  320. box-sizing: content-box;
  321. }
  322. .titleNview-background {
  323. position: absolute;
  324. top: 0;
  325. left: 0;
  326. width: 100%;
  327. height: 426rpx;
  328. transition: 0.4s;
  329. }
  330. .carousel {
  331. width: 100%;
  332. height: 240rpx;
  333. .carousel-item {
  334. width: 100%;
  335. height: 100%;
  336. padding: 0 28rpx;
  337. overflow: hidden;
  338. }
  339. image {
  340. width: 100%;
  341. height: 100%;
  342. border-radius: $border-radius-sm;
  343. }
  344. }
  345. }
  346. .swiper-dots {
  347. display: flex;
  348. position: absolute;
  349. left: 60rpx;
  350. bottom: 15rpx;
  351. width: 72rpx;
  352. height: 36rpx;
  353. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJk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wWxHrAiFgT4fEGsB/CwIhYE+AeBAAdPLOcV8HRmWRDAiQVcO7GcV8CLM8uCAE4sQCDAlHcQ7x+ABQEEAggEEAggEEAggEAAgQACASAQQCCAQACBAAIBBAIIBBAIIBBAIABe4e9iAe/xd7EAJxYgEGDeO4j3EODp/cOCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
  354. background-size: 100% 100%;
  355. .num {
  356. width: 36rpx;
  357. height: 36rpx;
  358. border-radius: 50px;
  359. font-size: 24rpx;
  360. color: #fff;
  361. text-align: center;
  362. line-height: 36rpx;
  363. }
  364. .sign {
  365. position: absolute;
  366. top: 0;
  367. left: 50%;
  368. line-height: 36rpx;
  369. font-size: 12rpx;
  370. color: #fff;
  371. transform: translateX(-50%);
  372. }
  373. }
  374. /* 分类 */
  375. .cate-section {
  376. background-color: #fff;
  377. display: flex;
  378. justify-content: space-around;
  379. align-items: center;
  380. flex-wrap: wrap;
  381. padding: 30rpx 22rpx;
  382. .cate-item {
  383. display: flex;
  384. flex-direction: column;
  385. align-items: center;
  386. font-size: $font-sm + 2rpx;
  387. color: $font-color-dark;
  388. }
  389. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  390. image {
  391. width: 140rpx;
  392. height: 140rpx;
  393. // margin-bottom: 5rpx;
  394. border-radius: 50%;
  395. opacity: 0.7;
  396. }
  397. }
  398. /*公用边框样式*/
  399. %icon {
  400. margin-right: 10rpx;
  401. display: inline-block;
  402. padding: 2rpx 10rpx;
  403. border: 1rpx solid $color-yellow;
  404. color: $color-yellow;
  405. line-height: 1;
  406. font-size: $font-base;
  407. border-radius: 10rpx;
  408. }
  409. </style>