index.vue 16 KB

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