index.vue 15 KB

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