index.vue 10 KB

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