index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <view class="content">
  3. <!-- 顶部logo and 搜索 start-->
  4. <!-- #ifdef APP -->
  5. <view class="status_bar"></view>
  6. <!-- #endif -->
  7. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000">
  8. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  9. @click="bannerNavToUrl(item)">
  10. <image :src="item.pic" />
  11. </swiper-item>
  12. </swiper>
  13. <!-- 轮播图 end -->
  14. <view class="tip flex" v-if="auth == 1 && prod.length> 0">
  15. <image src="../../static/index/hg.png" mode=""></image>
  16. <view class="">
  17. <text>/</text>礼包商品
  18. </view>
  19. </view>
  20. <view class="goods-list flex" v-if="auth == 1">
  21. <view class="goods" v-for="item in prod" @click="navTo('/pages/product/product?id=' + item.id)">
  22. <image :src="item.image" mode="" class="logo"></image>
  23. <view class="price flex">
  24. <view class="val">
  25. ¥{{item.price}}
  26. </view>
  27. <view class="more">
  28. 立即加入>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <template v-if="auth == 0">
  34. <view class="tip flex" >
  35. <image src="../../static/index/hg.png" mode=""></image>
  36. <view class="">
  37. <text>/</text>会员联盟
  38. </view>
  39. </view>
  40. <view class="goods-list flex" >
  41. <view class="goods" v-for="item in miniList" @click="navTo('/pages/product/product?id=' + item.id)">
  42. <image :src="item.image" mode="" class="logo"></image>
  43. <view class="price flex">
  44. <view class="val">
  45. ¥{{item.price}}
  46. </view>
  47. <view class="more">
  48. 立即加入>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="big-goods-list">
  54. <view class="big-good" v-for="item in bigList" @click="navTo('/pages/product/product?id=' + item.id)">
  55. <image :src="item.image" mode="" class="logo"></image>
  56. <view class="price flex">
  57. <view class="val">
  58. ¥{{item.price}}
  59. </view>
  60. <view class="more">
  61. 立即加入>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <image v-if="list.length> 0" :src="list[0].image_input[0]" mode="widthFix" style="display: block;margin: 38rpx 38rpx;width: 671rpx;"></image>
  67. </template>
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. xzwNotoce
  73. } from '@/components/xzw-notice/xzw-notice.vue'
  74. import {
  75. loadIndexs,
  76. getArtList,
  77. groom1,
  78. } from '@/api/index.js';
  79. import {
  80. getUserInfo,
  81. spread
  82. } from '@/api/user.js';
  83. import {
  84. getBargainList,
  85. getProducts,
  86. goodsDetail,
  87. poster
  88. } from '@/api/product.js';
  89. import {
  90. saveUrl,
  91. interceptor
  92. } from '@/utils/loginUtils';
  93. import {
  94. mapState,
  95. mapMutations
  96. } from 'vuex';
  97. // #ifdef H5
  98. import {
  99. weixindata,
  100. shareLoad
  101. } from '@/utils/wxAuthorized';
  102. // #endif
  103. export default {
  104. components: {
  105. xzwNotoce
  106. },
  107. data() {
  108. return {
  109. miniList: [],
  110. bigList: [],
  111. prod: [],
  112. auth: 1,
  113. list: [],
  114. muted: false,
  115. // page: 1,
  116. limitt: 20,
  117. loadingType: 'more',
  118. current: 0,
  119. shareShow: false, //分享海报
  120. titleNViewBackground: '',
  121. swiperCurrent: 0,
  122. swiperLength: 0,
  123. carouselList: [], //轮播列表
  124. page: 1,
  125. limit: 5,
  126. firstList: [],
  127. goodList: [], //商品列表
  128. shopList: [],
  129. period: 1,
  130. shareImage: '',
  131. fgList: '', //复购商品
  132. bastList:[],
  133. levelList:[],
  134. };
  135. },
  136. computed: {
  137. ...mapState('user', ['hasLogin', 'userInfo'])
  138. },
  139. onShareAppMessage(options) {
  140. // 设置菜单中的转发按钮触发转发事件时的转发内容
  141. let pages = getCurrentPages(); //获取加载的页面
  142. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  143. let url = currentPage.route; //当前页面url
  144. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  145. let shareObj = {}
  146. if (this.userInfo.uid) {
  147. shareObj = {
  148. title: this.userInfo.nickname + '邀请您加入阿格莱亚-馨美研', // 默认是小程序的名称(可以写slogan等)
  149. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  150. imageUrl: '',
  151. success: function(res) {
  152. // 转发成功之后的回调
  153. if (res.errMsg == 'shareAppMessage:ok') {}
  154. },
  155. fail: function() {
  156. // 转发失败之后的回调
  157. if (res.errMsg == 'shareAppMessage:fail cancel') {
  158. // 用户取消转发
  159. } else if (res.errMsg == 'shareAppMessage:fail') {
  160. // 转发失败,其中 detail message 为详细失败信息
  161. }
  162. }
  163. };
  164. } else {
  165. shareObj = {
  166. title: '阿格莱亚-馨美研', // 默认是小程序的名称(可以写slogan等)
  167. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  168. imageUrl: '',
  169. success: function(res) {
  170. // 转发成功之后的回调
  171. if (res.errMsg == 'shareAppMessage:ok') {}
  172. },
  173. fail: function() {
  174. // 转发失败之后的回调
  175. if (res.errMsg == 'shareAppMessage:fail cancel') {
  176. // 用户取消转发
  177. } else if (res.errMsg == 'shareAppMessage:fail') {
  178. // 转发失败,其中 detail message 为详细失败信息
  179. }
  180. }
  181. };
  182. }
  183. return shareObj;
  184. },
  185. onReachBottom() {
  186. },
  187. onLoad: function(option) {
  188. // #ifdef MP
  189. if (option.scene) {
  190. // 存储小程序邀请人
  191. uni.setStorage({
  192. key: 'spread_code',
  193. data: option.scene
  194. });
  195. }
  196. // #endif
  197. // #ifdef H5
  198. if (option.spread) {
  199. // 存储小程序邀请人
  200. uni.setStorage({
  201. key: 'spread',
  202. data: option.spread
  203. });
  204. }
  205. // #endif
  206. },
  207. onShow: function() {
  208. this.getGoodList()
  209. // this.getLevelList()
  210. this.loadData();
  211. this.getArtList();
  212. this.getProduct()
  213. },
  214. methods: {
  215. getProduct() {
  216. getProducts().then(res => {
  217. this.prod = res.data
  218. })
  219. },
  220. onload(e) {
  221. console.log("onload--广告加载完成");
  222. },
  223. onclose(e) {
  224. console.log("广告关闭: " + e);
  225. },
  226. onerror(e) {
  227. console.log('广告error:', e);
  228. },
  229. getArtList() {
  230. getArtList({
  231. page: 1,
  232. limit: 100
  233. }, 1).then(({
  234. data
  235. }) => {
  236. this.list = data;
  237. });
  238. },
  239. goItem(e) {
  240. console.log('bbbbbbbbbb', e);
  241. uni.navigateTo({
  242. url: '/pages/index/artDetail?id=' + e.id
  243. })
  244. },
  245. goMore() {
  246. console.log('dddddddddd');
  247. uni.navigateTo({
  248. url: '/pages/index/artList?id=2'
  249. })
  250. },
  251. gogogo(item) {
  252. if (!item.path) {
  253. uni.navigateTo({
  254. url: '/pages/index/dkf'
  255. })
  256. } else {
  257. uni.navigateTo({
  258. url: item.path + '&tit=' + item.tit,
  259. fail() {
  260. uni.navigateTo({
  261. url: item.path
  262. })
  263. }
  264. })
  265. }
  266. },
  267. getGoodList() {
  268. let obj = this
  269. getProducts({
  270. is_pack: 1,
  271. page: 1,
  272. limit: 50,
  273. }).then(res => {
  274. obj.goodList = res.data
  275. getProducts({
  276. is_level: 1,
  277. page: 1,
  278. limit: 50,
  279. }).then(res => {
  280. obj.goodList = obj.goodList.concat(res.data)
  281. obj.miniList = obj.goodList.slice(0,2)
  282. obj.bigList = obj.goodList.slice(2)
  283. console.log(obj.miniList,'obj.miniList')
  284. console.log(obj.bigList)
  285. })
  286. })
  287. },
  288. getLevelList() {
  289. let obj = this
  290. getProducts({
  291. is_level: 1,
  292. page: 1,
  293. limit: 50,
  294. }).then(res => {
  295. obj.levelList = res.data.sort((a, b) => a.price - b.price);
  296. })
  297. },
  298. navto(url, type = 0) {
  299. if (type == 1) {
  300. if (!this.hasLogin) {
  301. // 保存地址
  302. saveUrl();
  303. // 登录拦截
  304. interceptor();
  305. } else {
  306. uni.navigateTo({
  307. url,
  308. fail() {
  309. uni.switchTab({
  310. url
  311. })
  312. }
  313. })
  314. }
  315. } else {
  316. uni.navigateTo({
  317. url,
  318. fail() {
  319. uni.switchTab({
  320. url
  321. })
  322. }
  323. })
  324. }
  325. },
  326. navTo(url) {
  327. if (url == '') {
  328. this.$api.msg('暂未开通,敬请期待');
  329. } else {
  330. this.navto(url)
  331. }
  332. },
  333. // 點擊搜索框
  334. clickSearch() {
  335. uni.navigateTo({
  336. url: '/pages/product/search'
  337. });
  338. },
  339. // 监听图片加载完成
  340. onImageError(key, index) {
  341. this[key][index].image = '/static/error/errorImage.jpg';
  342. },
  343. // 请求载入数据
  344. async loadData() {
  345. loadIndexs({})
  346. .then(({
  347. data
  348. }) => {
  349. let goods = data.info;
  350. console.log(goods, '商品信息');
  351. this.auth = data.auth;
  352. this.carouselList = data.banner;
  353. this.swiperLength = this.carouselList.length;
  354. this.bastList = data.benefit;
  355. data.info.firstList.forEach(e => {
  356. e.isVip = e.store_type ? "3" : "0"
  357. })
  358. this.firstList = data.info.firstList //首页商品
  359. uni.stopPullDownRefresh();
  360. })
  361. .catch(e => {
  362. uni.stopPullDownRefresh();
  363. });
  364. },
  365. //轮播图切换修改背景色
  366. swiperChange(e) {
  367. const index = e.detail.current;
  368. this.swiperCurrent = index;
  369. this.titleNViewBackground = this.carouselList[index].background;
  370. },
  371. // 轮播图跳转
  372. bannerNavToUrl(item) {
  373. // #ifdef H5
  374. console.log(item.wap_url.indexOf('http'), 'banner');
  375. if (item.wap_url.indexOf('http') >= 0) {
  376. window.location.href = item.wap_url;
  377. }
  378. // uni.navigateTo({
  379. // url: '/pages/zero/order'
  380. // })
  381. // #endif
  382. //测试数据没有写id,用title代替
  383. uni.navigateTo({
  384. url: item.wap_url
  385. });
  386. },
  387. comfirm(text) {
  388. console.log(text);
  389. const result = this.uniCopy(text);
  390. if (result === false) {
  391. uni.showToast({
  392. title: '不支持'
  393. });
  394. } else {
  395. uni.showToast({
  396. title: '复制成功',
  397. icon: 'none'
  398. });
  399. }
  400. this.$refs.popupkf.close();
  401. },
  402. uniCopy(content) {
  403. /**
  404. * 小程序端 和 app端的复制逻辑
  405. */
  406. //#ifndef H5
  407. uni.setClipboardData({
  408. data: content,
  409. success: function() {
  410. console.log('success');
  411. return true;
  412. }
  413. });
  414. //#endif
  415. /**
  416. * H5端的复制逻辑
  417. */
  418. // #ifdef H5
  419. if (!document.queryCommandSupported('copy')) {
  420. //为了兼容有些浏览器 queryCommandSupported 的判断
  421. // 不支持
  422. return false;
  423. }
  424. let textarea = document.createElement('textarea');
  425. textarea.value = content;
  426. textarea.readOnly = 'readOnly';
  427. document.body.appendChild(textarea);
  428. textarea.select(); // 选择对象
  429. textarea.setSelectionRange(0, content.length); //核心
  430. let result = document.execCommand('copy'); // 执行浏览器复制命令
  431. textarea.remove();
  432. return result;
  433. // #endif
  434. },
  435. // 打开客服
  436. openKf() {
  437. this.$refs.popupkf.open();
  438. },
  439. // 关闭客服
  440. cancel() {
  441. this.$refs.popupkf.close();
  442. },
  443. }
  444. };
  445. </script>
  446. <style lang="scss">
  447. page {
  448. min-height: 100%;
  449. height: auto;
  450. background-color: #ebebeb;
  451. }
  452. // 顶部轮播图
  453. .top-swiper {
  454. width: 750rpx;
  455. height: 644rpx;
  456. margin: auto;
  457. .carousel-item {
  458. image {
  459. width: 100%;
  460. height: 100%;
  461. border-radius: 20rpx;
  462. }
  463. }
  464. }
  465. .status_bar {
  466. height: var(--status-bar-height);
  467. width: 100%;
  468. }
  469. .goods-list {
  470. padding: 0 38rpx;
  471. flex-wrap: wrap;
  472. .goods {
  473. width: 321rpx;
  474. height: 223rpx;
  475. border-radius: 20rpx;
  476. background-color: #fff;
  477. margin-bottom: 20rpx;
  478. .logo {
  479. display: block;
  480. width: 100%;
  481. height: 167rpx;
  482. border-radius: 20rpx;
  483. }
  484. .price {
  485. height: 66rpx;
  486. padding: 0 10rpx;
  487. .val {
  488. font-weight: bold;
  489. font-size: 32rpx;
  490. color: #7E0000;
  491. }
  492. .more {
  493. font-weight: bold;
  494. font-size: 18rpx;
  495. color: #000000;
  496. }
  497. }
  498. }
  499. }
  500. .tip {
  501. justify-content: flex-start;
  502. font-weight: bold;
  503. font-size: 36rpx;
  504. color: #000000;
  505. // margin-left: ;
  506. padding-left: 37rpx;
  507. margin: 38rpx 0;
  508. image {
  509. width: 44rpx;
  510. height: 40rpx;
  511. }
  512. text {
  513. color: #7E0000;
  514. padding: 0 8rpx;
  515. }
  516. }
  517. .goods-list {
  518. padding: 0 35rpx;
  519. flex-wrap: wrap;
  520. .good {
  521. width: 324rpx;
  522. height: 460rpx;
  523. background: #FFFFFF;
  524. border-radius: 25rpx;
  525. margin-bottom: 20rpx;
  526. position: relative;
  527. image {
  528. width: 324rpx;
  529. height: 324rpx;
  530. }
  531. &:last-of-type {
  532. margin-bottom: 0;
  533. }
  534. .pic {
  535. width: 324rpx;
  536. height: 324rpx;
  537. border-radius: 25rpx;
  538. }
  539. .store-name {
  540. width: 285rpx;
  541. margin: auto;
  542. font-weight: bold;
  543. color: #A42527;
  544. margin: 10rpx 0;
  545. padding-left: 20rpx;
  546. }
  547. .key {
  548. font-weight: 500;
  549. font-size: 17rpx;
  550. color: #654427;
  551. text-align: center;
  552. padding:20rpx 0 ;
  553. }
  554. .price {
  555. width: 268rpx;
  556. height: 52rpx;
  557. background-size: 100% 100%;
  558. position: absolute;
  559. left: 0;
  560. right: 0;
  561. bottom: 30rpx;
  562. // margin: auto;
  563. padding:0 16rpx;
  564. .val {
  565. font-weight: bold;
  566. font-size: 34rpx;
  567. color: #7E0000;
  568. text {
  569. padding-left: 10rpx;
  570. font-weight: 500;
  571. font-size: 24rpx;
  572. color: #9A9A9A;
  573. text-decoration-line: line-through;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. .big-goods-list {
  580. .big-good {
  581. width: 674rpx;
  582. height: 395rpx;
  583. margin: 20rpx auto;
  584. border-radius: 25rpx;
  585. background-color: #fff;
  586. }
  587. .logo {
  588. width: 674rpx;
  589. height: 313rpx;
  590. }
  591. .price {
  592. padding:10rpx 20rpx;
  593. .val {
  594. font-weight: bold;
  595. font-size: 39rpx;
  596. color: #7E0000;
  597. }
  598. .more {
  599. font-weight: bold;
  600. font-size: 22rpx;
  601. color: #000000;
  602. }
  603. }
  604. }
  605. </style>