index.vue 11 KB

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