index.vue 14 KB

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