index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. <template>
  2. <view class="container">
  3. <!-- 顶部logo and 搜索 start-->
  4. <view class="status_bar"></view>
  5. <view class="top-search flex">
  6. <view class="search-box flex" @click="clickSearch()">
  7. <image class="search" src="../../static/icon/search-h.png" mode=""></image>
  8. <view class="search-font">输入关键词搜索</view>
  9. </view>
  10. </view>
  11. <!-- 顶部logo and 搜索 end-->
  12. <view class="jg" style="background-color: #fff;"></view>
  13. <!-- 轮播图 start -->
  14. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  15. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  16. @click="bannerNavToUrl(item)">
  17. <image :src="item.pic" />
  18. </swiper-item>
  19. </swiper>
  20. <!-- 轮播图 end -->
  21. <view class="swiper-btm flex">
  22. <view class="btm-item flex">
  23. <image src="../../static/icon/index-gou.png" mode=""></image>
  24. <view class="">自用购物返利</view>
  25. </view>
  26. <view class="btm-item flex">
  27. <image src="../../static/icon/index-gou.png" mode=""></image>
  28. <view class="">分享好友赚钱</view>
  29. </view>
  30. <view class="btm-item flex">
  31. <image src="../../static/icon/index-gou.png" mode=""></image>
  32. <view class="">超值正品优惠</view>
  33. </view>
  34. </view>
  35. <!-- 分类 start -->
  36. <view class="cate-section flex">
  37. <view class="cate-item flex" @click="navto('/pages/index/artDetail')" >
  38. <view class="img-wrapper flex">
  39. <image src="../../static/icon/in1.png" mode=""></image>
  40. </view>
  41. <view class="item-title">全部商品</view>
  42. </view>
  43. <view class="cate-item flex" @click="navto('/pages/user/team')">
  44. <view class="img-wrapper flex">
  45. <image src="../../static/icon/in2.png" mode=""></image>
  46. </view>
  47. <view class="item-title">我的团队</view>
  48. </view>
  49. <view class="cate-item flex" @click="openKf">
  50. <view class="img-wrapper flex">
  51. <image src="../../static/icon/in3.png" mode=""></image>
  52. </view>
  53. <view class="item-title">联系客服</view>
  54. </view>
  55. <view class="cate-item flex" @click="navto('/pages/user/shareQrCode',1)">
  56. <view class="img-wrapper flex">
  57. <image src="../../static/icon/in4.png" mode=""></image>
  58. </view>
  59. <view class="item-title">邀请好友</view>
  60. </view>
  61. </view>
  62. <!-- 分类 ed -->
  63. <view class="jg">
  64. </view>
  65. <!-- 商品列表 start -->
  66. <view class="product-box">
  67. <view class="product-tit flex">
  68. <view class="hx">
  69. </view>
  70. <view class="tit">
  71. 精选TOP榜
  72. </view>
  73. <view class="hx">
  74. </view>
  75. </view>
  76. <!-- <view class="product-tit flex">
  77. <image src="../../static/img/top-bd.png" mode=""></image>
  78. </view> -->
  79. <image src="../../static/img/in-ban.png" mode="" class="in-ban"></image>
  80. <view class="hotgoods">
  81. <view class="hotgoods-item" v-for="item in goodList" :key="item.id"
  82. @click="navto('/pages/product/product?id=' + item.id)" style="height: 520rpx;">
  83. <view class="image-wrapper">
  84. <image class="image" :src="item.image" mode="scaleToFill"></image>
  85. </view>
  86. <view class="flex" style="flex-direction: column;justify-content: space-between;align-items: flex-start;height: 170rpx;">
  87. <view class="title clamp2">{{item.store_name}}</view>
  88. <view class="hot-price">
  89. <view class="price">
  90. <text class="font-size-sm"></text>
  91. ¥{{ item.price * 1 }}
  92. </view>
  93. <view class="yuanPrice" v-if="item.ot_price*1 > item.price*1">¥{{ item.ot_price*1 }}</view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <uni-load-more :status="loadingType"></uni-load-more>
  99. </view>
  100. <!-- 商品列表 ed-->
  101. <uni-popup ref="popupkf" type="center">
  102. <view class="popup-box">
  103. <view class="img">
  104. <image src="../../static/img/img009.png" mode=""></image>
  105. </view>
  106. <view class="mian">
  107. <view class="delivery">
  108. <view class="title">已经为您定制专属客服</view>
  109. <image src="../../static/img/img010.png" mode=""></image>
  110. </view>
  111. <view class="nocancel">客服VX:{{ text }}</view>
  112. <view class="comfirm-box">
  113. <view class="cancel" @click="cancel">取消</view>
  114. <view class="comfirm" @click="comfirm(text)">复制微信</view>
  115. </view>
  116. </view>
  117. </view>
  118. </uni-popup>
  119. </view>
  120. </template>
  121. <script>
  122. import {
  123. loadIndexs,
  124. groom1
  125. } from '@/api/index.js';
  126. import {
  127. getUserInfo,
  128. spread
  129. } from '@/api/user.js';
  130. import {
  131. getBargainList,
  132. getProducts,
  133. goodsDetail,
  134. poster
  135. } from '@/api/product.js';
  136. import {
  137. saveUrl,
  138. interceptor
  139. } from '@/utils/loginUtils';
  140. import {
  141. mapState,
  142. mapMutations
  143. } from 'vuex';
  144. // #ifdef H5
  145. import {
  146. weixindata,
  147. shareLoad
  148. } from '@/utils/wxAuthorized';
  149. // #endif
  150. export default {
  151. data() {
  152. return {
  153. text: '', //客服微信
  154. page: 1,
  155. limitt: 20,
  156. loadingType: 'more',
  157. current: 0,
  158. shareShow: false, //分享海报
  159. pageProportion: 0, //保存页面基于750宽度的比例
  160. swiperHeight: 0,
  161. checkid: 0,
  162. titleNViewBackground: '',
  163. swiperCurrent: 0,
  164. swiperLength: 0,
  165. carouselList: [], //轮播列表
  166. page: 1,
  167. limit: 5,
  168. firstList: [],
  169. goodList: [], //商品列表
  170. shopList: [],
  171. period: 1,
  172. shareImage: '',
  173. fgList: '',//复购商品
  174. };
  175. },
  176. computed: {
  177. ...mapState('user', ['hasLogin', 'userInfo'])
  178. },
  179. onShareAppMessage(options) {
  180. // 设置菜单中的转发按钮触发转发事件时的转发内容
  181. let pages = getCurrentPages(); //获取加载的页面
  182. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  183. let url = currentPage.route; //当前页面url
  184. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  185. let shareObj = {}
  186. if (this.userInfo.uid) {
  187. shareObj = {
  188. title: this.userInfo.nickname + '邀请您加入盛广大健康', // 默认是小程序的名称(可以写slogan等)
  189. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  190. imageUrl: '',
  191. success: function(res) {
  192. // 转发成功之后的回调
  193. if (res.errMsg == 'shareAppMessage:ok') {}
  194. },
  195. fail: function() {
  196. // 转发失败之后的回调
  197. if (res.errMsg == 'shareAppMessage:fail cancel') {
  198. // 用户取消转发
  199. } else if (res.errMsg == 'shareAppMessage:fail') {
  200. // 转发失败,其中 detail message 为详细失败信息
  201. }
  202. }
  203. };
  204. } else {
  205. shareObj = {
  206. title: '盛广大健康', // 默认是小程序的名称(可以写slogan等)
  207. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  208. imageUrl: '',
  209. success: function(res) {
  210. // 转发成功之后的回调
  211. if (res.errMsg == 'shareAppMessage:ok') {}
  212. },
  213. fail: function() {
  214. // 转发失败之后的回调
  215. if (res.errMsg == 'shareAppMessage:fail cancel') {
  216. // 用户取消转发
  217. } else if (res.errMsg == 'shareAppMessage:fail') {
  218. // 转发失败,其中 detail message 为详细失败信息
  219. }
  220. }
  221. };
  222. }
  223. return shareObj;
  224. },
  225. onReachBottom() {
  226. console.log('到底')
  227. this.getGoodList()
  228. },
  229. onLoad: function(option) {
  230. // #ifdef MP
  231. if (option.scene) {
  232. // 存储小程序邀请人
  233. uni.setStorage({
  234. key: 'spread_code',
  235. data: option.scene
  236. });
  237. }
  238. // #endif
  239. },
  240. onShow: function() {
  241. this.getGoodList()
  242. this.loadData();
  243. this.groom1()
  244. },
  245. methods: {
  246. //获取复购商品
  247. groom1() {
  248. groom1().then(res => {
  249. console.log(res)
  250. this.fgList = res.data.list
  251. })
  252. },
  253. getGoodList() {
  254. let obj = this
  255. if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  256. return
  257. }
  258. obj.loadingType = 'loading'
  259. getProducts({
  260. page: 1,
  261. limit: 50,
  262. }).then(res => {
  263. obj.goodList = res.data
  264. if (obj.limit == res.data.length) {
  265. obj.loadingType = 'more'
  266. } else {
  267. obj.loadingType = 'noMore'
  268. }
  269. })
  270. },
  271. navto(url, type = 0) {
  272. if (type == 1) {
  273. if (!this.hasLogin) {
  274. // 保存地址
  275. saveUrl();
  276. // 登录拦截
  277. interceptor();
  278. } else {
  279. uni.navigateTo({
  280. url,
  281. fail() {
  282. uni.switchTab({
  283. url
  284. })
  285. }
  286. })
  287. }
  288. } else {
  289. uni.navigateTo({
  290. url,
  291. fail() {
  292. uni.switchTab({
  293. url
  294. })
  295. }
  296. })
  297. }
  298. },
  299. navTo(url) {
  300. if (url == '') {
  301. this.$api.msg('暂未开通,敬请期待');
  302. } else {
  303. this.navto(url)
  304. }
  305. },
  306. // 點擊搜索框
  307. clickSearch() {
  308. uni.navigateTo({
  309. url: '/pages/product/search'
  310. });
  311. },
  312. // 监听图片加载完成
  313. onImageError(key, index) {
  314. this[key][index].image = '/static/error/errorImage.jpg';
  315. },
  316. // 请求载入数据
  317. async loadData() {
  318. loadIndexs({})
  319. .then(({
  320. data
  321. }) => {
  322. let goods = data.info;
  323. console.log(goods, '商品信息');
  324. this.carouselList = data.banner;
  325. this.swiperLength = this.carouselList.length;
  326. this.bastList = data.giftInfo; //会员礼包
  327. data.info.firstList.forEach(e => {
  328. e.isVip = e.store_type ? "3" : "0"
  329. })
  330. this.firstList = data.info.firstList //首页商品
  331. uni.stopPullDownRefresh();
  332. })
  333. .catch(e => {
  334. uni.stopPullDownRefresh();
  335. });
  336. },
  337. //轮播图切换修改背景色
  338. swiperChange(e) {
  339. const index = e.detail.current;
  340. this.swiperCurrent = index;
  341. this.titleNViewBackground = this.carouselList[index].background;
  342. },
  343. // 轮播图跳转
  344. bannerNavToUrl(item) {
  345. // #ifdef H5
  346. console.log(item.wap_url.indexOf('http'), 'banner');
  347. if (item.wap_url.indexOf('http') >= 0) {
  348. window.location.href = item.wap_url;
  349. }
  350. // #endif
  351. //测试数据没有写id,用title代替
  352. uni.navigateTo({
  353. url: item.wap_url
  354. });
  355. },
  356. comfirm(text) {
  357. console.log(text);
  358. const result = this.uniCopy(text);
  359. if (result === false) {
  360. uni.showToast({
  361. title: '不支持'
  362. });
  363. } else {
  364. uni.showToast({
  365. title: '复制成功',
  366. icon: 'none'
  367. });
  368. }
  369. this.$refs.popupkf.close();
  370. },
  371. uniCopy(content) {
  372. /**
  373. * 小程序端 和 app端的复制逻辑
  374. */
  375. //#ifndef H5
  376. uni.setClipboardData({
  377. data: content,
  378. success: function() {
  379. console.log('success');
  380. return true;
  381. }
  382. });
  383. //#endif
  384. /**
  385. * H5端的复制逻辑
  386. */
  387. // #ifdef H5
  388. if (!document.queryCommandSupported('copy')) {
  389. //为了兼容有些浏览器 queryCommandSupported 的判断
  390. // 不支持
  391. return false;
  392. }
  393. let textarea = document.createElement('textarea');
  394. textarea.value = content;
  395. textarea.readOnly = 'readOnly';
  396. document.body.appendChild(textarea);
  397. textarea.select(); // 选择对象
  398. textarea.setSelectionRange(0, content.length); //核心
  399. let result = document.execCommand('copy'); // 执行浏览器复制命令
  400. textarea.remove();
  401. return result;
  402. // #endif
  403. },
  404. // 打开客服
  405. openKf() {
  406. this.$refs.popupkf.open();
  407. },
  408. // 关闭客服
  409. cancel() {
  410. this.$refs.popupkf.close();
  411. },
  412. }
  413. };
  414. </script>
  415. <style lang="scss">
  416. page {
  417. background: #ffff;
  418. min-height: 100%;
  419. height: auto;
  420. }
  421. // 顶部搜索
  422. .top-search {
  423. height: 80rpx;
  424. padding: 0 20rpx;
  425. background-color: #fff;
  426. .top-logo {
  427. width: 50rpx;
  428. // height: 50rpx;
  429. margin-right: 10rpx;
  430. image {
  431. width: 48rpx;
  432. }
  433. }
  434. .search-box {
  435. justify-content: center;
  436. width: 698rpx;
  437. height: 60rpx;
  438. background: #EEEEEE;
  439. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  440. border-radius: 30rpx;
  441. .search {
  442. width: 34rpx;
  443. height: 34rpx;
  444. }
  445. .search-font {
  446. margin-left: 14rpx;
  447. font-size: 28rpx;
  448. font-family: PingFang SC;
  449. font-weight: 500;
  450. color: #CBCBCB;
  451. }
  452. }
  453. }
  454. // 顶部轮播图
  455. .top-swiper {
  456. width: 750rpx;
  457. height: 360rpx;
  458. // margin: 20rpx 0 0;
  459. image {
  460. width: 750rpx;
  461. height: 360rpx;
  462. }
  463. }
  464. .swiper-btm {
  465. height: 60rpx;
  466. width: 750rpx;
  467. background-color: #fff;
  468. margin-bottom: 20rpx;
  469. font-size: 26rpx;
  470. font-weight: 500;
  471. color: #333333;
  472. .btm-item {
  473. flex-grow: 1;
  474. justify-content: center;
  475. image {
  476. width: 25rpx;
  477. height: 25rpx;
  478. margin-right: 14rpx;
  479. }
  480. }
  481. }
  482. .jg {
  483. height: 20rpx;
  484. background: #F8F8F8;
  485. }
  486. // 分类
  487. .cate-section {
  488. justify-content: space-around;
  489. background-color: #fff;
  490. padding: 0rpx 0 30rpx;
  491. .cate-item {
  492. flex-grow: 0;
  493. width: 20%;
  494. flex-direction: column;
  495. text-align: center;
  496. align-items: center;
  497. justify-content: center;
  498. .img-wrapper {
  499. width: 90rpx;
  500. height: 90rpx;
  501. border-radius: 20rpx;
  502. position: relative;
  503. image {
  504. width: 90rpx;
  505. height: 90rpx;
  506. position: absolute;
  507. left: 50%;
  508. top: 50%;
  509. transform: translate(-50%, -50%);
  510. }
  511. }
  512. .item-title {
  513. margin-top: 15rpx;
  514. font-size: 32rpx;
  515. font-weight: 500;
  516. color: #000;
  517. }
  518. }
  519. }
  520. .product-box {
  521. margin-top: 20rpx;
  522. background: #ffffff;
  523. padding: 26rpx 0 20rpx;
  524. .product-tit {
  525. justify-content: center;
  526. image {
  527. width: 609rpx;
  528. height: 31rpx;
  529. }
  530. .hx {
  531. width: 120rpx;
  532. height: 1rpx;
  533. background: #e4bc8f;
  534. }
  535. .tit {
  536. margin: 0 70rpx;
  537. font-size: 36rpx;
  538. font-weight: 500;
  539. color: #e4bc8f;
  540. }
  541. }
  542. .in-ban {
  543. margin-top: 40rpx;
  544. width: 750rpx;
  545. height: 220rpx;
  546. }
  547. }
  548. .hotgoods {
  549. margin-top: 38rpx;
  550. width: 100%;
  551. display: flex;
  552. flex-wrap: wrap;
  553. padding: 0 20rpx 30rpx;
  554. justify-content: space-between;
  555. .hotgoods-item {
  556. width: 345rpx;
  557. background-color: #ffffff;
  558. border-radius: 12rpx;
  559. box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
  560. margin-bottom: 15rpx;
  561. .image-wrapper {
  562. width: 345rpx;
  563. height: 345rpx;
  564. border-radius: 3px;
  565. overflow: hidden;
  566. position: relative;
  567. .image-bg {
  568. position: absolute;
  569. top: 0;
  570. left: 0;
  571. right: 0;
  572. bottom: 0;
  573. width: 100%;
  574. height: 100%;
  575. opacity: 1;
  576. border-radius: 12rpx 12rpx 0 0;
  577. z-index: 2;
  578. }
  579. .image {
  580. width: 100%;
  581. height: 100%;
  582. opacity: 1;
  583. border-radius: 12rpx 12rpx 0 0;
  584. }
  585. }
  586. .title {
  587. margin-top: 24rpx;
  588. padding: 0 20rpx;
  589. font-size: 32rpx;
  590. font-weight: 500;
  591. color: #333333;
  592. }
  593. .hot-price {
  594. display: flex;
  595. justify-content: flex-start;
  596. align-items: center;
  597. // padding: 14rpx 0 30rpx;
  598. .hotPrice-box {
  599. padding: 2rpx 6rpx;
  600. background: linear-gradient(90deg, #c79a4c, #f9df7f);
  601. border-radius: 5rpx;
  602. text-align: center;
  603. line-height: 28rpx;
  604. font-size: 20rpx;
  605. font-family: Source Han Sans CN;
  606. font-weight: 400;
  607. color: #ffffff;
  608. }
  609. .price {
  610. margin-left: 10rpx;
  611. font-size: 40rpx;
  612. color: #ff0000;
  613. font-weight: 500;
  614. .jf {
  615. font-size: 20rpx;
  616. }
  617. }
  618. .yuanPrice {
  619. margin-left: 10rpx;
  620. font-size: 20rpx;
  621. font-family: PingFang SC;
  622. font-weight: 500;
  623. text-decoration: line-through;
  624. color: #999999;
  625. }
  626. .cart-icon {
  627. image {
  628. width: 44rpx;
  629. height: 44rpx;
  630. }
  631. }
  632. }
  633. }
  634. }
  635. .popup-box {
  636. width: 522rpx;
  637. height: 605rpx;
  638. background-color: #ffffff;
  639. border-radius: 20rpx;
  640. position: relative;
  641. .img {
  642. position: relative;
  643. top: -56rpx;
  644. left: 0;
  645. width: 522rpx;
  646. height: 132rpx;
  647. display: flex;
  648. justify-content: center;
  649. image {
  650. border-radius: 20rpx 20rpx 0 0;
  651. width: 450rpx;
  652. height: 132rpx;
  653. }
  654. }
  655. .mian {
  656. margin-top: -44rpx;
  657. display: flex;
  658. flex-direction: column;
  659. align-items: center;
  660. // padding: 32rpx 32rpx;
  661. background-color: #ffffff;
  662. border-radius: 0 0 20rpx 20rpx;
  663. text-align: center;
  664. .delivery {
  665. font-size: 40rpx;
  666. color: #333333;
  667. display: flex;
  668. align-items: center;
  669. flex-direction: column;
  670. image {
  671. margin-top: 48rpx;
  672. width: 172rpx;
  673. height: 160rpx;
  674. }
  675. }
  676. .nocancel {
  677. font-size: 32rpx;
  678. color: #333333;
  679. margin-top: 14rpx;
  680. }
  681. .comfirm-box {
  682. margin-top: 52rpx;
  683. display: flex;
  684. // margin-bottom: 32rpx;
  685. // justify-content: space-around;
  686. .cancel {
  687. display: flex;
  688. align-items: center;
  689. justify-content: center;
  690. width: 197rpx;
  691. height: 74rpx;
  692. border: 1px solid #dcc786;
  693. border-radius: 38rpx;
  694. font-size: 32rpx;
  695. color: #605128;
  696. }
  697. .comfirm {
  698. margin-left: 32rpx;
  699. display: flex;
  700. align-items: center;
  701. justify-content: center;
  702. width: 197rpx;
  703. height: 74rpx;
  704. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  705. border-radius: 38px;
  706. font-size: 32rpx;
  707. color: #605128;
  708. }
  709. }
  710. }
  711. }
  712. </style>