index.vue 15 KB

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