index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <view class="container">
  3. <!-- 背景 -->
  4. <view class="bg"><image src="../../static/img/index-bg.png" mode="widthFix"></image></view>
  5. <!-- 商品1 -->
  6. <view class="good-wrap">
  7. <view class="good-tit">
  8. <view class="good-tit-bg"><image src="../../static/img/index-title.png" mode=""></image></view>
  9. <view class="good-tit-font">美盟汇·盟主礼包</view>
  10. </view>
  11. <view class="item-wrap" v-for="(item, index) in productList">
  12. <view class="item-wrap-bg"><image src="../../static/img/index-product.png" mode=""></image></view>
  13. <view class="item-title">{{ item.store_name }}</view>
  14. <view class="item-img"><image :src="item.image" mode=""></image></view>
  15. <view class="item-btm">
  16. <view class="item-price flex">
  17. <view class="price-tit">特惠价</view>
  18. <view class="price-logo">¥</view>
  19. <view class="price-val">{{ item.price }}</view>
  20. </view>
  21. <view class="item-btn" @click="navToLevelDetailPage(item)">立刻购买</view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import seckill from '../../components/seckill/seckill.vue';
  29. import { getUserInfo } from '@/api/user.js';
  30. import { upgrade } from '@/api/product.js';
  31. import { interceptor } from '@/utils/loginUtils';
  32. import { mapState } from 'vuex';
  33. import weixinObj from '@/plugin/jweixin-module/index.js';
  34. // #ifdef H5
  35. import { weixindata, weixinlocation, shareLoad } from '@/utils/wxAuthorized';
  36. // #endif
  37. export default {
  38. components: {
  39. seckill
  40. },
  41. watch: {
  42. //自适应swiper高度
  43. checkid(newValue, oldValue) {
  44. let obj = this;
  45. if (newValue == 0) {
  46. let bHeight = Math.ceil(obj.bastList.length / 2);
  47. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  48. }
  49. if (newValue == 1) {
  50. let bHeight = Math.ceil(obj.goodsList.length / 2);
  51. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  52. }
  53. if (newValue == 2) {
  54. let bHeight = Math.ceil(obj.bastBanner.length / 2);
  55. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  56. }
  57. }
  58. },
  59. data() {
  60. return {
  61. productList: [], //常规商品
  62. shareShow: false, //分享海报
  63. pageProportion: 0, //保存页面基于750宽度的比例
  64. swiperHeight: 0,
  65. checkid: 0,
  66. titleNViewBackground: '',
  67. swiperCurrent: 0,
  68. swiperLength: 0,
  69. carouselList: [], //轮播列表
  70. page: 1,
  71. limit: 5,
  72. userServant: [
  73. {
  74. image: ''
  75. }
  76. ], //用户推广服务
  77. actTime: new Date()
  78. };
  79. },
  80. computed: {
  81. ...mapState(['loginInterceptor', 'baseURL']),
  82. ...mapState('user', ['hasLogin', 'userInfo'])
  83. },
  84. onLoad: function(option) {
  85. // #ifndef MP
  86. if (option.spread) {
  87. // 存储其他邀请人
  88. uni.setStorageSync('spread', option.spread);
  89. }
  90. // #endif
  91. // #ifdef MP
  92. if (option.scene) {
  93. // 存储小程序邀请人
  94. uni.setStorage({
  95. key: 'spread_code',
  96. data: option.scene
  97. });
  98. }
  99. // #endif
  100. },
  101. onShow: function() {
  102. // 判断是否强制登录
  103. if (this.loginInterceptor && !this.hasLogin) {
  104. // 登录拦截
  105. interceptor();
  106. }
  107. weixinObj.hideAllNonBaseMenuItem();
  108. this.getProducts();
  109. if (this.userInfo) {
  110. weixinObj.showAllNonBaseMenuItem();
  111. console.log('fx');
  112. this.IndexShare();
  113. }
  114. },
  115. //下拉刷新
  116. onPullDownRefresh() {
  117. this.loadData();
  118. },
  119. methods: {
  120. IndexShare() {
  121. let obj = this;
  122. let pages = getCurrentPages();
  123. // 获取当前页面
  124. let page = pages[pages.length - 1];
  125. let path = '/#/pages/index/index' + '?';
  126. // 保存传值
  127. // for (let i in page.options) {
  128. // path += i + '=' + page.options[i] + '&';
  129. // }
  130. // console.log(obj.Path)
  131. // 保存邀请人
  132. path += 'spread=' + this.userInfo.uid;
  133. let data = {
  134. link: this.baseURL + path,
  135. title: this.userInfo.nickname + '邀请您进入科粉社',
  136. desc: '欢迎加入科粉社',
  137. imgUrl: this.baseURL + '/static/icon/logo.jpg'
  138. };
  139. console.log(data, '分享数据');
  140. shareLoad(data);
  141. },
  142. getProducts() {
  143. upgrade({ pages: 1, limit: 10 }).then(({ data }) => {
  144. this.productList = data;
  145. });
  146. },
  147. openSubscribe: function(e) {
  148. let page = e;
  149. // #ifndef MP
  150. uni.navigateTo({
  151. url: page
  152. });
  153. // #endif
  154. // #ifdef MP
  155. uni.showLoading({
  156. title: '正在加载'
  157. });
  158. openBargainSubscribe()
  159. .then(res => {
  160. uni.hideLoading();
  161. uni.navigateTo({
  162. url: page
  163. });
  164. })
  165. .catch(err => {
  166. uni.hideLoading();
  167. });
  168. // #endif
  169. },
  170. Mask() {
  171. this.MaskShow = false;
  172. this.shareShow = true;
  173. uni.setStorage({
  174. key: 'FirstEntry',
  175. data: true,
  176. success: function() {
  177. console.log(uni.getStorageSync('FirstEntry'), 'Mask');
  178. }
  179. });
  180. },
  181. Toshare() {
  182. if (this.userInfo == '') {
  183. getUserInfo({})
  184. .then(({ data }) => {
  185. this.setUserInfo(data);
  186. this.userInfo = data;
  187. })
  188. .catch(e => {});
  189. } else {
  190. this.shareShow = false;
  191. uni.navigateTo({
  192. url: '/pages/user/shareQrCode?spread=' + this.userInfo.uid
  193. });
  194. }
  195. },
  196. Tocancel() {
  197. this.shareShow = false;
  198. },
  199. // 监听切换事件
  200. listChange(e) {
  201. this.checkid = e.detail.current;
  202. },
  203. // 點擊搜索框
  204. clickSearch() {
  205. uni.navigateTo({
  206. url: '/pages/product/search'
  207. });
  208. },
  209. // 请求载入数据
  210. async loadData() {
  211. loadIndexs({})
  212. .then(({ data }) => {
  213. let goods = data.info;
  214. this.carouselList = data.banner;
  215. this.swiperLength = this.carouselList.length;
  216. this.menusList = data.menus;
  217. this.goodsList = goods.firstList; //最新商品
  218. this.bastList = goods.bastList; //精品推荐
  219. this.bastBanner = data.benefit; //促销单品
  220. this.$set(this, 'couponArray', data.couponList); //保存卡包券
  221. uni.stopPullDownRefresh();
  222. })
  223. .catch(e => {
  224. uni.stopPullDownRefresh();
  225. });
  226. },
  227. //详情页
  228. navToDetailPage(item) {
  229. let id = item.id;
  230. uni.navigateTo({
  231. url: '/pages/product/product?id=' + id
  232. });
  233. },
  234. navToGiftDetailPage(item) {
  235. let id = item.id;
  236. console.log(item);
  237. uni.navigateTo({
  238. url: '/pages/product/product?id=' + id + '&gtype=0'
  239. });
  240. },
  241. navToLevelDetailPage(item) {
  242. let id = item.id;
  243. console.log(item);
  244. uni.navigateTo({
  245. url: '/pages/product/product?id=' + id + '&gtype=1'
  246. });
  247. },
  248. // 轮播图跳转
  249. bannerNavToUrl(item) {
  250. // #ifdef H5
  251. if (item.wap_url.indexOf('http') > 0) {
  252. window.location.href = item.wap_url;
  253. }
  254. // #endif
  255. //测试数据没有写id,用title代替
  256. uni.navigateTo({
  257. url: item.wap_url
  258. });
  259. }
  260. }
  261. };
  262. </script>
  263. <style lang="scss">
  264. .Mask {
  265. width: 100%;
  266. height: 100vh;
  267. position: fixed;
  268. z-index: 99999;
  269. background-color: rgba(0, 0, 0, 0.7);
  270. top: 0;
  271. image {
  272. width: 100%;
  273. height: 100vh;
  274. }
  275. }
  276. .bg {
  277. position: absolute;
  278. top: 0;
  279. left: 0;
  280. right: 0;
  281. width: 750rpx;
  282. height: 1654rpx;
  283. image {
  284. width: 100%;
  285. height: 100%;
  286. }
  287. }
  288. page {
  289. background: #9e7457;
  290. }
  291. .m-t {
  292. margin-top: 16rpx;
  293. }
  294. /*公用边框样式*/
  295. %icon {
  296. margin-right: 10rpx;
  297. display: inline-block;
  298. padding: 2rpx 10rpx;
  299. border: 1rpx solid $color-yellow;
  300. color: $color-yellow;
  301. line-height: 1;
  302. font-size: $font-base;
  303. border-radius: 10rpx;
  304. }
  305. .f-header {
  306. display: flex;
  307. align-items: center;
  308. height: 92rpx;
  309. padding: 6rpx 30rpx 8rpx;
  310. image {
  311. flex-shrink: 0;
  312. width: 80rpx;
  313. height: 80rpx;
  314. margin-right: 20rpx;
  315. }
  316. .tit-box {
  317. @extend %font-title-box;
  318. }
  319. .tit {
  320. @extend %font-title;
  321. }
  322. .iconenter {
  323. font-size: $font-lg + 2rpx;
  324. color: $font-color-light;
  325. }
  326. .f-left-icon {
  327. @extend %f-left-icon;
  328. }
  329. .iconfont {
  330. font-size: $font-sm - 2rpx;
  331. }
  332. }
  333. // 列表
  334. .list-box-h {
  335. height: 1550rpx;
  336. }
  337. .good-wrap {
  338. padding-top: 898rpx;
  339. .good-tit {
  340. position: relative;
  341. .good-tit-bg {
  342. position: absolute;
  343. top: 0;
  344. left: 0;
  345. right: 0;
  346. width: 750rpx;
  347. height: 86rpx;
  348. image {
  349. width: 100%;
  350. height: 100%;
  351. }
  352. }
  353. .good-tit-font {
  354. text-align: center;
  355. line-height: 86rpx;
  356. position: relative;
  357. z-index: 2;
  358. font-size: 36rpx;
  359. font-family: Source Han Serif SC;
  360. font-weight: 800;
  361. color: #fff4e5;
  362. }
  363. }
  364. .item-wrap {
  365. margin: 20rpx auto;
  366. width: 708rpx;
  367. height: 606rpx;
  368. border-radius: 12rpx;
  369. padding: 26rpx;
  370. position: relative;
  371. z-index: 2;
  372. .item-wrap-bg {
  373. position: absolute;
  374. top: 0;
  375. left: 0;
  376. right: 0;
  377. width: 708rpx;
  378. height: 606rpx;
  379. image {
  380. width: 100%;
  381. height: 100%;
  382. }
  383. }
  384. .item-title {
  385. padding-top: 20rpx;
  386. text-align: center;
  387. position: relative;
  388. z-index: 2;
  389. font-size: 36rpx;
  390. font-family: Source Han Serif SC;
  391. font-weight: 600;
  392. color: #653600;
  393. text-shadow: 0px 2rpx 2rpx rgba(206, 173, 129, 0.75);
  394. }
  395. .item-img {
  396. position: relative;
  397. z-index: 2;
  398. margin-top: 20rpx;
  399. width: 665rpx;
  400. height: 339rpx;
  401. background: #f0d4ac;
  402. border-radius: 6rpx 6rpx 6rpx 6rpx;
  403. display: flex;
  404. justify-content: center;
  405. align-items: center;
  406. image {
  407. width: 98%;
  408. height: 96%;
  409. border-radius: 6rpx 6rpx 6rpx 6rpx;
  410. }
  411. }
  412. .item-btm {
  413. position: relative;
  414. z-index: 2;
  415. display: flex;
  416. height: 100rpx;
  417. justify-content: space-between;
  418. align-items: center;
  419. // position: relative;
  420. .item-price {
  421. font-size: 27rpx;
  422. font-family: Source Han Serif SC;
  423. font-weight: bold;
  424. color: rgba(153, 0, 0, 1);
  425. justify-content: flex-start;
  426. align-items: flex-end;
  427. .price-tit {
  428. color: rgba(84, 50, 11, 1);
  429. }
  430. .price-logo {
  431. display: inline-block;
  432. padding: 0 5rpx 0 15rpx;
  433. }
  434. .price-val {
  435. font-size: 54rpx;
  436. position: relative;
  437. top: 8rpx;
  438. }
  439. }
  440. .item-btn {
  441. width: 154rpx;
  442. height: 50rpx;
  443. background: #910704;
  444. border-radius: 25rpx;
  445. text-align: center;
  446. line-height: 50rpx;
  447. font-size: 22rpx;
  448. font-family: Source Han Sans CN;
  449. font-weight: 400;
  450. color: #ffffff;
  451. }
  452. }
  453. }
  454. }
  455. </style>