index.vue 17 KB

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