index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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" @click="bannerNavToUrl(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='bastList'></golden-bean>
  58. <!-- 批发专区 -->
  59. <wholesale></wholesale>
  60. <!-- 为你推荐 -->
  61. <recommend :data='bastList'></recommend>
  62. </view>
  63. </template>
  64. <script>
  65. import goldenBean from './child/goldenBean.vue'
  66. import wholesale from './child/wholesale.vue'
  67. import recommend from './child/recommend.vue'
  68. import seckill from '../../components/seckill/seckill.vue';
  69. import { loadIndexs } from '@/api/index.js';
  70. import { getUserInfo } from '@/api/user.js';
  71. import { setCoupons } from '@/api/functionalUnit.js';
  72. import { getBargainList } from '@/api/product.js';
  73. import { interceptor } from '@/utils/loginUtils';
  74. import { mapState } from 'vuex';
  75. export default {
  76. components: {
  77. seckill,
  78. goldenBean,
  79. wholesale,
  80. recommend
  81. },
  82. watch: {
  83. //自适应swiper高度
  84. checkid(newValue, oldValue) {
  85. let obj = this;
  86. if (newValue == 0) {
  87. let bHeight = Math.ceil(obj.bastList.length / 2);
  88. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  89. }
  90. if (newValue == 1) {
  91. let bHeight = Math.ceil(obj.goodsList.length / 2);
  92. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  93. }
  94. if (newValue == 2) {
  95. let bHeight = Math.ceil(obj.bastBanner.length / 2);
  96. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  97. }
  98. },
  99. // 初次加载页面高度时修改页面高度
  100. // bastList(newValue, oldValue) {
  101. // let obj = this;
  102. // let bHeight = Math.ceil(newValue.length / 2);
  103. // obj.$nextTick(function() {
  104. // uni.createSelectorQuery()
  105. // .select('#list-box')
  106. // .fields(
  107. // {
  108. // size: true
  109. // },
  110. // function(data) {
  111. // obj.pageProportion = data.width / 750;
  112. // obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  113. // }
  114. // )
  115. // .exec();
  116. // });
  117. // }
  118. },
  119. data() {
  120. return {
  121. shareShow: false, //分享海报
  122. pageProportion: 0, //保存页面基于750宽度的比例
  123. swiperHeight: 0,
  124. checkid: 0,
  125. titleNViewBackground: '',
  126. swiperCurrent: 0,
  127. swiperLength: 0,
  128. bargainlist: [], //砍价商品
  129. carouselList: [], //轮播列表
  130. goodsList: [], //最新商品列表
  131. bastList: [], //精品推荐列表
  132. bastBanner: [], //促销商品列表
  133. menusList: [], //头部菜单
  134. page: 1,
  135. limit: 5,
  136. userServant: [
  137. {
  138. image: ''
  139. }
  140. ], //用户推广服务
  141. couponArray: [], //可领取优惠券
  142. recommend: [
  143. {
  144. id: 0,
  145. re_title: '精选',
  146. re_name: '为你推荐'
  147. },
  148. {
  149. id: 1,
  150. re_title: '最新',
  151. re_name: '最新好货优选'
  152. },
  153. {
  154. id: 2,
  155. re_title: '便宜好货',
  156. re_name: '90天便宜好货'
  157. }
  158. ],
  159. actTime: new Date()
  160. };
  161. },
  162. computed: {
  163. ...mapState(['loginInterceptor']),
  164. ...mapState('user', ['hasLogin','userInfo'])
  165. },
  166. onLoad: function(option) {
  167. // #ifndef MP
  168. if (option.spread) {
  169. // 存储其他邀请人
  170. uni.setStorageSync('spread', option.spread);
  171. }
  172. // #endif
  173. // #ifdef MP
  174. if (option.scene) {
  175. // 存储小程序邀请人
  176. uni.setStorage({
  177. key: 'spread_code',
  178. data: option.scene
  179. });
  180. }
  181. // #endif
  182. },
  183. onShow: function() {
  184. // 判断是否强制登录
  185. if (this.loginInterceptor && !this.hasLogin) {
  186. // 登录拦截
  187. interceptor();
  188. }
  189. this.loadData();
  190. this.getBargainList();
  191. },
  192. //下拉刷新
  193. onPullDownRefresh() {
  194. this.loadData();
  195. },
  196. // #ifndef MP
  197. // 监听导航栏输入框点击事件
  198. onNavigationBarSearchInputClicked(e) {
  199. //跳转到搜索页面
  200. this.clickSearch();
  201. },
  202. //点击导航栏 buttons 时触发
  203. onNavigationBarButtonTap(e) {
  204. const index = e.index;
  205. if (index === 0) {
  206. this.$api.msg('点击了扫描');
  207. } else if (index === 1) {
  208. // #ifdef APP-PLUS
  209. const pages = getCurrentPages();
  210. const page = pages[pages.length - 1];
  211. const currentWebview = page.$getAppWebview();
  212. currentWebview.hideTitleNViewButtonRedDot({
  213. index
  214. });
  215. // #endif
  216. uni.navigateTo({
  217. url: '/pages/user/notice'
  218. });
  219. }
  220. },
  221. // #endif
  222. methods: {
  223. //砍价商品推荐详情页
  224. navToDetailPages(item) {
  225. let id = item.product_id;
  226. //let type = 2;
  227. uni.navigateTo({
  228. url: '/pages/product/product?id=' + id
  229. });
  230. },
  231. openSubscribe: function(e) {
  232. let page = e;
  233. // #ifndef MP
  234. uni.navigateTo({
  235. url: page
  236. });
  237. // #endif
  238. // #ifdef MP
  239. uni.showLoading({
  240. title: '正在加载'
  241. });
  242. openBargainSubscribe()
  243. .then(res => {
  244. uni.hideLoading();
  245. uni.navigateTo({
  246. url: page
  247. });
  248. })
  249. .catch(err => {
  250. uni.hideLoading();
  251. });
  252. // #endif
  253. },
  254. getBargainList() {
  255. let that = this;
  256. getBargainList({
  257. page: that.page,
  258. limit: that.limit
  259. })
  260. .then(function(res) {
  261. that.$set(that, 'bargainlist', res.data.slice(0, 2));
  262. })
  263. .catch(res => {
  264. console.log(res, 'getBargainList');
  265. });
  266. },
  267. Mask() {
  268. this.MaskShow = false;
  269. this.shareShow = true;
  270. uni.setStorage({
  271. key: 'FirstEntry',
  272. data: true,
  273. success: function() {
  274. console.log(uni.getStorageSync('FirstEntry'), 'Mask');
  275. }
  276. });
  277. },
  278. Toshare() {
  279. if (this.userInfo == '') {
  280. getUserInfo({})
  281. .then(({ data }) => {
  282. this.setUserInfo(data);
  283. this.userInfo = data;
  284. })
  285. .catch(e => {});
  286. } else {
  287. this.shareShow = false;
  288. uni.navigateTo({
  289. url: '/pages/user/shareQrCode?spread=' + this.userInfo.uid
  290. });
  291. }
  292. },
  293. Tocancel() {
  294. this.shareShow = false;
  295. },
  296. // 监听切换事件
  297. listChange(e) {
  298. this.checkid = e.detail.current;
  299. },
  300. // 點擊搜索框
  301. clickSearch() {
  302. uni.navigateTo({
  303. url: '/pages/product/search'
  304. });
  305. },
  306. // 点击触发领取优惠券
  307. setCoupons(item) {
  308. // 判断是否已经领取了优惠券
  309. let obj = this;
  310. uni.showModal({
  311. title: '领取提示',
  312. content: '是否领取优惠券',
  313. success(e) {
  314. if (e.confirm) {
  315. setCoupons({ couponId: item.id }).then(e => {
  316. item.is_use = true;
  317. uni.showToast({
  318. title: '领取成功',
  319. type: 'top',
  320. duration: 2000
  321. });
  322. });
  323. }
  324. }
  325. });
  326. },
  327. //商品种类切换
  328. change(item) {
  329. let id = item;
  330. this.checkid = id;
  331. if (this.checkid == 1) {
  332. // console.log(1);
  333. this.detail = this.selected_detail;
  334. } else if (this.checkid == 2) {
  335. // console.log(2);
  336. this.detail = this.new_product;
  337. } else {
  338. this.detail = this.cheap_good;
  339. }
  340. },
  341. // 监听图片加载完成
  342. onImageError(key, index) {
  343. this[key][index].image = '/static/error/errorImage.jpg';
  344. },
  345. // 请求载入数据
  346. async loadData() {
  347. loadIndexs({})
  348. .then(({ data }) => {
  349. let goods = data.info;
  350. this.carouselList = data.banner;
  351. this.swiperLength = this.carouselList.length;
  352. this.menusList = data.menus;
  353. this.goodsList = goods.firstList; //最新商品
  354. this.bastList = goods.bastList; //精品推荐
  355. this.bastBanner = data.benefit; //促销单品
  356. this.$set(this, 'couponArray', data.couponList); //保存卡包券
  357. uni.stopPullDownRefresh();
  358. })
  359. .catch(e => {
  360. uni.stopPullDownRefresh();
  361. });
  362. },
  363. //轮播图切换修改背景色
  364. swiperChange(e) {
  365. const index = e.detail.current;
  366. this.swiperCurrent = index;
  367. this.titleNViewBackground = this.carouselList[index].background;
  368. },
  369. //详情页
  370. navToDetailPage(item) {
  371. let id = item.id;
  372. uni.navigateTo({
  373. url: '/pages/product/product?id=' + id
  374. });
  375. },
  376. // 轮播图跳转
  377. bannerNavToUrl(item) {
  378. // #ifdef H5
  379. if (item.wap_url.indexOf('http') > 0) {
  380. window.location.href = item.wap_url;
  381. }
  382. // #endif
  383. //测试数据没有写id,用title代替
  384. uni.navigateTo({
  385. url: item.wap_url
  386. });
  387. }
  388. }
  389. };
  390. </script>
  391. <style lang="scss">
  392. .Mask {
  393. width: 100%;
  394. height: 100vh;
  395. position: fixed;
  396. z-index: 99999;
  397. background-color: rgba(0, 0, 0, 0.7);
  398. top: 0;
  399. image {
  400. width: 100%;
  401. height: 100vh;
  402. }
  403. }
  404. /* #ifdef MP */
  405. .mp-height {
  406. height: 44px;
  407. }
  408. .input-box {
  409. position: fixed;
  410. top: 0;
  411. left: 0;
  412. width: 100%;
  413. padding: 25rpx;
  414. background-color: #ffffff;
  415. z-index: 999;
  416. height: 44px;
  417. .iconsearch {
  418. font-size: 50rpx;
  419. }
  420. .input-content {
  421. border-radius: 99rpx;
  422. flex-grow: 1;
  423. padding: 10rpx 30rpx;
  424. background-color: rgba(231, 231, 231, 0.7);
  425. .input {
  426. flex-grow: 1;
  427. input {
  428. font-size: $font-lg;
  429. }
  430. }
  431. }
  432. .input-button {
  433. padding-left: 20rpx;
  434. font-size: $font-lg;
  435. height: 100%;
  436. }
  437. }
  438. page {
  439. .cate-section {
  440. position: relative;
  441. z-index: 5;
  442. border-radius: 16rpx 16rpx 0 0;
  443. margin-top: -20rpx;
  444. }
  445. .carousel-section {
  446. padding: 0;
  447. .titleNview-placing {
  448. padding-top: 0;
  449. height: 0;
  450. }
  451. .carousel {
  452. .carousel-item {
  453. padding: 0;
  454. }
  455. }
  456. .swiper-dots {
  457. left: 45rpx;
  458. bottom: 40rpx;
  459. }
  460. }
  461. }
  462. /* #endif */
  463. page {
  464. background: #f7f8f7;
  465. }
  466. .m-t {
  467. margin-top: 16rpx;
  468. }
  469. /* 头部 轮播图 */
  470. .carousel-section {
  471. position: relative;
  472. padding-top: 10px;
  473. overflow: hidden;
  474. .titleNview-placing {
  475. height: var(--status-bar-height);
  476. padding-top: 44px;
  477. box-sizing: content-box;
  478. }
  479. .titleNview-background {
  480. position: absolute;
  481. top: 0;
  482. left: 0;
  483. width: 100%;
  484. height: 426rpx;
  485. transition: 0.4s;
  486. }
  487. .carousel {
  488. width: 100%;
  489. height: 240rpx;
  490. .carousel-item {
  491. width: 100%;
  492. height: 100%;
  493. padding: 0 28rpx;
  494. overflow: hidden;
  495. }
  496. image {
  497. width: 100%;
  498. height: 100%;
  499. border-radius: $border-radius-sm;
  500. }
  501. }
  502. }
  503. .swiper-dots {
  504. display: flex;
  505. position: absolute;
  506. left: 60rpx;
  507. bottom: 15rpx;
  508. width: 72rpx;
  509. height: 36rpx;
  510. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8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QNhY8kgWyL/WDtwujjI8hoE8rKLqb5CDJaRMJHokC6yKgSCR9JAukmokIknCQJpLOIrJFwMsBJELFcKHwM9BFkLBMKFxNcBCHlQ+FhoocgpVwwnv0Xn30QBJGMC0QcaBVJiAMiec/dcwKuL4j1QMsVCXFAJE4s4NQA3K/8Y6DzO4g40P7UcmIBJxbEesCKWBDg8wWxHrAiFgT4fEGsB/CwIhYE+AeBAAdPLOcV8HRmWRDAiQVcO7GcV8CLM8uCAE4sQCDAlHcQ7x+ABQEEAggEEAggEEAggEAAgQACASAQQCCAQACBAAIBBAIIBBAIIBBAIABe4e9iAe/xd7EAJxYgEGDeO4j3EODp/cOCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
  511. background-size: 100% 100%;
  512. .num {
  513. width: 36rpx;
  514. height: 36rpx;
  515. border-radius: 50px;
  516. font-size: 24rpx;
  517. color: #fff;
  518. text-align: center;
  519. line-height: 36rpx;
  520. }
  521. .sign {
  522. position: absolute;
  523. top: 0;
  524. left: 50%;
  525. line-height: 36rpx;
  526. font-size: 12rpx;
  527. color: #fff;
  528. transform: translateX(-50%);
  529. }
  530. }
  531. /* 分类 */
  532. .cate-section {
  533. background-color: #fff;
  534. display: flex;
  535. justify-content: space-around;
  536. align-items: center;
  537. flex-wrap: wrap;
  538. padding: 30rpx 22rpx;
  539. .cate-item {
  540. display: flex;
  541. flex-direction: column;
  542. align-items: center;
  543. font-size: $font-sm + 2rpx;
  544. color: $font-color-dark;
  545. }
  546. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  547. image {
  548. width: 140rpx;
  549. height: 140rpx;
  550. // margin-bottom: 5rpx;
  551. border-radius: 50%;
  552. opacity: 0.7;
  553. }
  554. }
  555. /*公用边框样式*/
  556. %icon {
  557. margin-right: 10rpx;
  558. display: inline-block;
  559. padding: 2rpx 10rpx;
  560. border: 1rpx solid $color-yellow;
  561. color: $color-yellow;
  562. line-height: 1;
  563. font-size: $font-base;
  564. border-radius: 10rpx;
  565. }
  566. </style>