index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. clickSearch() {
  171. uni.navigateTo({
  172. url: '/pages/product/search'
  173. });
  174. },
  175. // 监听图片加载完成
  176. onImageError(key, index) {
  177. this[key][index].image = '/static/error/errorImage.jpg';
  178. },
  179. // 请求载入数据
  180. async loadData() {
  181. loadIndexs({})
  182. .then(({ data }) => {
  183. let goods = data.info;
  184. this.carouselList = data.banner;
  185. this.swiperLength = this.carouselList.length;
  186. this.bastList = goods.bastList; //精品推荐
  187. uni.stopPullDownRefresh();
  188. })
  189. .catch(e => {
  190. uni.stopPullDownRefresh();
  191. });
  192. },
  193. //轮播图切换修改背景色
  194. swiperChange(e) {
  195. const index = e.detail.current;
  196. this.swiperCurrent = index;
  197. this.titleNViewBackground = this.carouselList[index].background;
  198. },
  199. //详情页
  200. navToDetailPage(item) {
  201. let id = item.id;
  202. uni.navigateTo({
  203. url: '/pages/product/product?id=' + id
  204. });
  205. }
  206. }
  207. };
  208. </script>
  209. <style lang="scss">
  210. .Mask {
  211. width: 100%;
  212. height: 100vh;
  213. position: fixed;
  214. z-index: 99999;
  215. background-color: rgba(0, 0, 0, 0.7);
  216. top: 0;
  217. image {
  218. width: 100%;
  219. height: 100vh;
  220. }
  221. }
  222. /* #ifdef MP */
  223. .mp-height {
  224. height: 44px;
  225. }
  226. .input-box {
  227. position: fixed;
  228. top: 0;
  229. left: 0;
  230. width: 100%;
  231. padding: 25rpx;
  232. background-color: #ffffff;
  233. z-index: 999;
  234. height: 44px;
  235. .iconsearch {
  236. font-size: 50rpx;
  237. }
  238. .input-content {
  239. border-radius: 99rpx;
  240. flex-grow: 1;
  241. padding: 10rpx 30rpx;
  242. background-color: rgba(231, 231, 231, 0.7);
  243. .input {
  244. flex-grow: 1;
  245. input {
  246. font-size: $font-lg;
  247. }
  248. }
  249. }
  250. .input-button {
  251. padding-left: 20rpx;
  252. font-size: $font-lg;
  253. height: 100%;
  254. }
  255. }
  256. page {
  257. .cate-section {
  258. position: relative;
  259. z-index: 5;
  260. border-radius: 16rpx 16rpx 0 0;
  261. margin-top: -20rpx;
  262. }
  263. .carousel-section {
  264. padding: 0;
  265. .titleNview-placing {
  266. padding-top: 0;
  267. height: 0;
  268. }
  269. .carousel {
  270. .carousel-item {
  271. padding: 0;
  272. }
  273. }
  274. .swiper-dots {
  275. left: 45rpx;
  276. bottom: 40rpx;
  277. }
  278. }
  279. }
  280. /* #endif */
  281. page {
  282. background: #f7f8f7;
  283. }
  284. .m-t {
  285. margin-top: 16rpx;
  286. }
  287. /* 头部 轮播图 */
  288. .carousel-section {
  289. position: relative;
  290. padding-top: 10px;
  291. overflow: hidden;
  292. .titleNview-placing {
  293. height: var(--status-bar-height);
  294. padding-top: 44px;
  295. box-sizing: content-box;
  296. }
  297. .titleNview-background {
  298. position: absolute;
  299. top: 0;
  300. left: 0;
  301. width: 100%;
  302. height: 426rpx;
  303. transition: 0.4s;
  304. }
  305. .carousel {
  306. width: 100%;
  307. height: 240rpx;
  308. .carousel-item {
  309. width: 100%;
  310. height: 100%;
  311. padding: 0 28rpx;
  312. overflow: hidden;
  313. }
  314. image {
  315. width: 100%;
  316. height: 100%;
  317. border-radius: $border-radius-sm;
  318. }
  319. }
  320. }
  321. .swiper-dots {
  322. display: flex;
  323. position: absolute;
  324. left: 60rpx;
  325. bottom: 15rpx;
  326. width: 72rpx;
  327. height: 36rpx;
  328. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC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EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
  329. background-size: 100% 100%;
  330. .num {
  331. width: 36rpx;
  332. height: 36rpx;
  333. border-radius: 50px;
  334. font-size: 24rpx;
  335. color: #fff;
  336. text-align: center;
  337. line-height: 36rpx;
  338. }
  339. .sign {
  340. position: absolute;
  341. top: 0;
  342. left: 50%;
  343. line-height: 36rpx;
  344. font-size: 12rpx;
  345. color: #fff;
  346. transform: translateX(-50%);
  347. }
  348. }
  349. /* 分类 */
  350. .cate-section {
  351. background-color: #fff;
  352. display: flex;
  353. justify-content: space-around;
  354. align-items: center;
  355. flex-wrap: wrap;
  356. padding: 30rpx 22rpx;
  357. .cate-item {
  358. display: flex;
  359. flex-direction: column;
  360. align-items: center;
  361. font-size: $font-sm + 2rpx;
  362. color: $font-color-dark;
  363. }
  364. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  365. image {
  366. width: 140rpx;
  367. height: 140rpx;
  368. // margin-bottom: 5rpx;
  369. border-radius: 50%;
  370. opacity: 0.7;
  371. }
  372. }
  373. /*公用边框样式*/
  374. %icon {
  375. margin-right: 10rpx;
  376. display: inline-block;
  377. padding: 2rpx 10rpx;
  378. border: 1rpx solid $color-yellow;
  379. color: $color-yellow;
  380. line-height: 1;
  381. font-size: $font-base;
  382. border-radius: 10rpx;
  383. }
  384. </style>