index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. <navigator url="/pages/product/newPeople">
  35. <view class="cate-item">
  36. <image src="/static/img/index-nav1.png"></image>
  37. <text>新人专区</text>
  38. </view>
  39. </navigator>
  40. <navigator url="/pages/product/exchange">
  41. <view class="cate-item">
  42. <image src="/static/img/index-nav2.png"></image>
  43. <text>兑换专区</text>
  44. </view>
  45. </navigator>
  46. <navigator url="/pages/product/store">
  47. <view class="cate-item">
  48. <image src="/static/img/index-nav3.png"></image>
  49. <text>附近门店</text>
  50. </view>
  51. </navigator>
  52. <navigator url="/pages/index/sign">
  53. <view class="cate-item">
  54. <image src="/static/img/index-nav4.png"></image>
  55. <text>邀请有礼</text>
  56. </view>
  57. </navigator>
  58. </view>
  59. <!-- 金豆专区 -->
  60. <golden-bean :data='jdList'></golden-bean>
  61. <!-- 批发专区 -->
  62. <wholesale></wholesale>
  63. <!-- 为你推荐 -->
  64. <recommend :data='bastList'></recommend>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. getProducts
  70. } from '@/api/product.js';
  71. import goldenBean from './child/goldenBean.vue';
  72. import wholesale from './child/wholesale.vue';
  73. import recommend from './child/recommend.vue';
  74. import {
  75. loadIndexs
  76. } from '@/api/index.js';
  77. import {
  78. getUserInfo
  79. } from '@/api/user.js';
  80. import {
  81. setCoupons
  82. } from '@/api/functionalUnit.js';
  83. import {
  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. // 登录拦截
  136. interceptor();
  137. }
  138. this.loadData();
  139. this.getBargainList();
  140. },
  141. //下拉刷新
  142. onPullDownRefresh() {
  143. this.loadData();
  144. },
  145. // #ifndef MP
  146. // 监听导航栏输入框点击事件
  147. onNavigationBarSearchInputClicked(e) {
  148. //跳转到搜索页面
  149. this.clickSearch();
  150. },
  151. //点击导航栏 buttons 时触发
  152. onNavigationBarButtonTap(e) {
  153. const index = e.index;
  154. if (index === 0) {
  155. this.$api.msg('点击了扫描');
  156. } else if (index === 1) {
  157. // #ifdef APP-PLUS
  158. const pages = getCurrentPages();
  159. const page = pages[pages.length - 1];
  160. const currentWebview = page.$getAppWebview();
  161. currentWebview.hideTitleNViewButtonRedDot({
  162. index
  163. });
  164. // #endif
  165. uni.navigateTo({
  166. url: '/pages/user/notice'
  167. });
  168. }
  169. },
  170. // #endif
  171. methods: {
  172. getUserInfo() {
  173. getUserInfo().then(res => {
  174. console.log(res)
  175. this.setUserInfo(res.data);
  176. })
  177. },
  178. getBargainList() {
  179. let that = this;
  180. getProducts({
  181. page: that.page,
  182. limit: that.limit,
  183. is_gold: 1
  184. })
  185. .then(function(res) {
  186. that.jdList = res.data
  187. })
  188. .catch(res => {});
  189. },
  190. // 點擊搜索框
  191. clickSearch() {
  192. uni.navigateTo({
  193. url: '/pages/product/search'
  194. });
  195. },
  196. // 监听图片加载完成
  197. onImageError(key, index) {
  198. this[key][index].image = '/static/error/errorImage.jpg';
  199. },
  200. // 请求载入数据
  201. async loadData() {
  202. loadIndexs({})
  203. .then(({
  204. data
  205. }) => {
  206. let goods = data.info;
  207. this.carouselList = data.banner;
  208. this.swiperLength = this.carouselList.length;
  209. this.bastList = goods.bastList; //精品推荐
  210. uni.stopPullDownRefresh();
  211. })
  212. .catch(e => {
  213. uni.stopPullDownRefresh();
  214. });
  215. },
  216. //轮播图切换修改背景色
  217. swiperChange(e) {
  218. const index = e.detail.current;
  219. this.swiperCurrent = index;
  220. this.titleNViewBackground = this.carouselList[index].background;
  221. },
  222. //详情页
  223. navToDetailPage(item) {
  224. let id = item.id;
  225. uni.navigateTo({
  226. url: '/pages/product/product?id=' + id
  227. });
  228. },
  229. }
  230. };
  231. </script>
  232. <style lang="scss">
  233. .Mask {
  234. width: 100%;
  235. height: 100vh;
  236. position: fixed;
  237. z-index: 99999;
  238. background-color: rgba(0, 0, 0, 0.7);
  239. top: 0;
  240. image {
  241. width: 100%;
  242. height: 100vh;
  243. }
  244. }
  245. /* #ifdef MP */
  246. .mp-height {
  247. height: 44px;
  248. }
  249. .input-box {
  250. position: fixed;
  251. top: 0;
  252. left: 0;
  253. width: 100%;
  254. padding: 25rpx;
  255. background-color: #ffffff;
  256. z-index: 999;
  257. height: 44px;
  258. .iconsearch {
  259. font-size: 50rpx;
  260. }
  261. .input-content {
  262. border-radius: 99rpx;
  263. flex-grow: 1;
  264. padding: 10rpx 30rpx;
  265. background-color: rgba(231, 231, 231, 0.7);
  266. .input {
  267. flex-grow: 1;
  268. input {
  269. font-size: $font-lg;
  270. }
  271. }
  272. }
  273. .input-button {
  274. padding-left: 20rpx;
  275. font-size: $font-lg;
  276. height: 100%;
  277. }
  278. }
  279. page {
  280. .cate-section {
  281. position: relative;
  282. z-index: 5;
  283. border-radius: 16rpx 16rpx 0 0;
  284. margin-top: -20rpx;
  285. }
  286. .carousel-section {
  287. padding: 0;
  288. .titleNview-placing {
  289. padding-top: 0;
  290. height: 0;
  291. }
  292. .carousel {
  293. .carousel-item {
  294. padding: 0;
  295. }
  296. }
  297. .swiper-dots {
  298. left: 45rpx;
  299. bottom: 40rpx;
  300. }
  301. }
  302. }
  303. /* #endif */
  304. page {
  305. background: #f7f8f7;
  306. }
  307. .m-t {
  308. margin-top: 16rpx;
  309. }
  310. /* 头部 轮播图 */
  311. .carousel-section {
  312. position: relative;
  313. padding-top: 10px;
  314. overflow: hidden;
  315. .titleNview-placing {
  316. height: var(--status-bar-height);
  317. padding-top: 44px;
  318. box-sizing: content-box;
  319. }
  320. .titleNview-background {
  321. position: absolute;
  322. top: 0;
  323. left: 0;
  324. width: 100%;
  325. height: 426rpx;
  326. transition: 0.4s;
  327. }
  328. .carousel {
  329. width: 100%;
  330. height: 240rpx;
  331. .carousel-item {
  332. width: 100%;
  333. height: 100%;
  334. padding: 0 28rpx;
  335. overflow: hidden;
  336. }
  337. image {
  338. width: 100%;
  339. height: 100%;
  340. border-radius: $border-radius-sm;
  341. }
  342. }
  343. }
  344. .swiper-dots {
  345. display: flex;
  346. position: absolute;
  347. left: 60rpx;
  348. bottom: 15rpx;
  349. width: 72rpx;
  350. height: 36rpx;
  351. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpE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rAiFgT4fEGsB/CwIhYE+AeBAAdPLOcV8HRmWRDAiQVcO7GcV8CLM8uCAE4sQCDAlHcQ7x+ABQEEAggEEAggEEAggEAAgQACASAQQCCAQACBAAIBBAIIBBAIIBBAIABe4e9iAe/xd7EAJxYgEGDeO4j3EODp/cOCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
  352. background-size: 100% 100%;
  353. .num {
  354. width: 36rpx;
  355. height: 36rpx;
  356. border-radius: 50px;
  357. font-size: 24rpx;
  358. color: #fff;
  359. text-align: center;
  360. line-height: 36rpx;
  361. }
  362. .sign {
  363. position: absolute;
  364. top: 0;
  365. left: 50%;
  366. line-height: 36rpx;
  367. font-size: 12rpx;
  368. color: #fff;
  369. transform: translateX(-50%);
  370. }
  371. }
  372. /* 分类 */
  373. .cate-section {
  374. background-color: #fff;
  375. display: flex;
  376. justify-content: space-around;
  377. align-items: center;
  378. flex-wrap: wrap;
  379. padding: 30rpx 22rpx;
  380. .cate-item {
  381. display: flex;
  382. flex-direction: column;
  383. align-items: center;
  384. font-size: $font-sm + 2rpx;
  385. color: $font-color-dark;
  386. }
  387. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  388. image {
  389. width: 140rpx;
  390. height: 140rpx;
  391. // margin-bottom: 5rpx;
  392. border-radius: 50%;
  393. opacity: 0.7;
  394. }
  395. }
  396. /*公用边框样式*/
  397. %icon {
  398. margin-right: 10rpx;
  399. display: inline-block;
  400. padding: 2rpx 10rpx;
  401. border: 1rpx solid $color-yellow;
  402. color: $color-yellow;
  403. line-height: 1;
  404. font-size: $font-base;
  405. border-radius: 10rpx;
  406. }
  407. </style>