index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. <!-- #ifdef APP-PLUS -->
  35. <video src="../../static/video/v1.mp4" controls class="gsjs" :muted="muted" ref="inv" id="myVideo"></video>
  36. <!-- #endif -->
  37. <!-- #ifdef H5 -->
  38. <video src="https://chat.yiqushangshi.com/wap/video/v1.mp4" controls class="gsjs" :muted="muted" ref="inv" id="myVideo"></video>
  39. <!-- #endif -->
  40. <!-- 商品列表 start -->
  41. <!-- <view class="hot-wrap">
  42. <view class="hot-top flex">
  43. <image src="../../static/icon/hhh.png" mode=""></image>
  44. <view class="">
  45. 礼包商品
  46. </view>
  47. </view>
  48. <view class="hot-list">
  49. <view class="good" v-for="item in goodList" @click="navTo('/pages/product/product?id=' + item.id)">
  50. <image :src="item.image" mode="" class="good-img"></image>
  51. <view class="good-tit">
  52. {{item.store_name}}
  53. </view>
  54. <view class="good-cz flex">
  55. <view class="price">
  56. <text class="xy">¥</text> <text>{{item.price}}</text><text class="old-price">¥{{item.ot_price}}</text>
  57. </view>
  58. <view class="cz-btn">
  59. 立即抢购
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view> -->
  65. <!-- 商品列表 ed-->
  66. <uni-popup ref="popupkf" type="center">
  67. <view class="popup-box">
  68. <view class="img">
  69. <image src="../../static/img/img009.png" mode=""></image>
  70. </view>
  71. <view class="mian">
  72. <view class="delivery">
  73. <view class="title">已经为您定制专属客服</view>
  74. <image src="../../static/img/img010.png" mode=""></image>
  75. </view>
  76. <view class="nocancel">客服VX:{{ text }}</view>
  77. <view class="comfirm-box">
  78. <view class="cancel" @click="cancel">取消</view>
  79. <view class="comfirm" @click="comfirm(text)">复制微信</view>
  80. </view>
  81. </view>
  82. </view>
  83. </uni-popup>
  84. </view>
  85. </template>
  86. <script>
  87. import {
  88. loadIndexs,
  89. groom1
  90. } from '@/api/index.js';
  91. import {
  92. getUserInfo,
  93. spread
  94. } from '@/api/user.js';
  95. import {
  96. getBargainList,
  97. getProducts,
  98. goodsDetail,
  99. poster
  100. } from '@/api/product.js';
  101. import {
  102. saveUrl,
  103. interceptor
  104. } from '@/utils/loginUtils';
  105. import {
  106. mapState,
  107. mapMutations
  108. } from 'vuex';
  109. // #ifdef H5
  110. import {
  111. weixindata,
  112. shareLoad
  113. } from '@/utils/wxAuthorized';
  114. // #endif
  115. export default {
  116. data() {
  117. return {
  118. muted: false,
  119. cateList: [
  120. {
  121. path: '/pages/index/gift',
  122. img: '../../static/icon/inx1.png',
  123. tit: 'VIP商品'
  124. },
  125. {
  126. path: '/pages/index/zero',
  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. onHide() {
  262. console.log('滴答滴答滴答滴答滴答滴答的')
  263. let video = uni.createVideoContext('myVideo', this);
  264. console.log(video,'video')
  265. try{
  266. video.pause()
  267. }catch(e){
  268. //TODO handle the exception
  269. console.log('err',e)
  270. }
  271. // this.$refs.inv.pause()
  272. },
  273. methods: {
  274. gogogo(item) {
  275. if(!item.path) {
  276. uni.navigateTo({
  277. url: '/pages/index/dkf'
  278. })
  279. }else {
  280. uni.navigateTo({
  281. url: item.path + '&tit=' + item.tit,
  282. fail() {
  283. uni.navigateTo({
  284. url: item.path
  285. }) }
  286. })
  287. }
  288. },
  289. getGoodList() {
  290. let obj = this
  291. if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  292. return
  293. }
  294. obj.loadingType = 'loading'
  295. getProducts({
  296. is_pack: 1,
  297. page: 1,
  298. limit: 50,
  299. }).then(res => {
  300. obj.goodList = res.data
  301. if (obj.limit == res.data.length) {
  302. obj.loadingType = 'more'
  303. } else {
  304. obj.loadingType = 'noMore'
  305. }
  306. })
  307. },
  308. navto(url, type = 0) {
  309. if (type == 1) {
  310. if (!this.hasLogin) {
  311. // 保存地址
  312. saveUrl();
  313. // 登录拦截
  314. interceptor();
  315. } else {
  316. uni.navigateTo({
  317. url,
  318. fail() {
  319. uni.switchTab({
  320. url
  321. })
  322. }
  323. })
  324. }
  325. } else {
  326. uni.navigateTo({
  327. url,
  328. fail() {
  329. uni.switchTab({
  330. url
  331. })
  332. }
  333. })
  334. }
  335. },
  336. navTo(url) {
  337. if (url == '') {
  338. this.$api.msg('暂未开通,敬请期待');
  339. } else {
  340. this.navto(url)
  341. }
  342. },
  343. // 點擊搜索框
  344. clickSearch() {
  345. uni.navigateTo({
  346. url: '/pages/product/search'
  347. });
  348. },
  349. // 监听图片加载完成
  350. onImageError(key, index) {
  351. this[key][index].image = '/static/error/errorImage.jpg';
  352. },
  353. // 请求载入数据
  354. async loadData() {
  355. loadIndexs({})
  356. .then(({
  357. data
  358. }) => {
  359. let goods = data.info;
  360. console.log(goods, '商品信息');
  361. this.carouselList = data.banner;
  362. this.swiperLength = this.carouselList.length;
  363. this.bastList = data.giftInfo; //会员礼包
  364. data.info.firstList.forEach(e => {
  365. e.isVip = e.store_type ? "3" : "0"
  366. })
  367. this.firstList = data.info.firstList //首页商品
  368. uni.stopPullDownRefresh();
  369. })
  370. .catch(e => {
  371. uni.stopPullDownRefresh();
  372. });
  373. },
  374. //轮播图切换修改背景色
  375. swiperChange(e) {
  376. const index = e.detail.current;
  377. this.swiperCurrent = index;
  378. this.titleNViewBackground = this.carouselList[index].background;
  379. },
  380. // 轮播图跳转
  381. bannerNavToUrl(item) {
  382. // #ifdef H5
  383. console.log(item.wap_url.indexOf('http'), 'banner');
  384. if (item.wap_url.indexOf('http') >= 0) {
  385. window.location.href = item.wap_url;
  386. }
  387. // uni.navigateTo({
  388. // url: '/pages/zero/order'
  389. // })
  390. // #endif
  391. //测试数据没有写id,用title代替
  392. uni.navigateTo({
  393. url: item.wap_url
  394. });
  395. },
  396. comfirm(text) {
  397. console.log(text);
  398. const result = this.uniCopy(text);
  399. if (result === false) {
  400. uni.showToast({
  401. title: '不支持'
  402. });
  403. } else {
  404. uni.showToast({
  405. title: '复制成功',
  406. icon: 'none'
  407. });
  408. }
  409. this.$refs.popupkf.close();
  410. },
  411. uniCopy(content) {
  412. /**
  413. * 小程序端 和 app端的复制逻辑
  414. */
  415. //#ifndef H5
  416. uni.setClipboardData({
  417. data: content,
  418. success: function() {
  419. console.log('success');
  420. return true;
  421. }
  422. });
  423. //#endif
  424. /**
  425. * H5端的复制逻辑
  426. */
  427. // #ifdef H5
  428. if (!document.queryCommandSupported('copy')) {
  429. //为了兼容有些浏览器 queryCommandSupported 的判断
  430. // 不支持
  431. return false;
  432. }
  433. let textarea = document.createElement('textarea');
  434. textarea.value = content;
  435. textarea.readOnly = 'readOnly';
  436. document.body.appendChild(textarea);
  437. textarea.select(); // 选择对象
  438. textarea.setSelectionRange(0, content.length); //核心
  439. let result = document.execCommand('copy'); // 执行浏览器复制命令
  440. textarea.remove();
  441. return result;
  442. // #endif
  443. },
  444. // 打开客服
  445. openKf() {
  446. this.$refs.popupkf.open();
  447. },
  448. // 关闭客服
  449. cancel() {
  450. this.$refs.popupkf.close();
  451. },
  452. }
  453. };
  454. </script>
  455. <style lang="scss">
  456. page {
  457. min-height: 100%;
  458. height: auto;
  459. }
  460. // 顶部搜索
  461. .top-search {
  462. height: 80rpx;
  463. padding: 0 20rpx;
  464. position: relative;
  465. .top-logo {
  466. width: 50rpx;
  467. // height: 50rpx;
  468. margin-right: 10rpx;
  469. image {
  470. width: 48rpx;
  471. }
  472. }
  473. .search-box {
  474. justify-content: center;
  475. width: 698rpx;
  476. height: 60rpx;
  477. background: rgba(255,255,255,0.5);
  478. color: #fff;
  479. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  480. border-radius: 30rpx;
  481. .search {
  482. width: 34rpx;
  483. height: 34rpx;
  484. }
  485. .search-font {
  486. margin-left: 14rpx;
  487. font-size: 28rpx;
  488. font-weight: 500;
  489. }
  490. }
  491. }
  492. // 顶部轮播图
  493. .top-swiper {
  494. background-color: #fff;
  495. width: 690rpx;
  496. height: 320rpx;
  497. margin: auto;
  498. .carousel-item {
  499. image {
  500. width: 100%;
  501. height: 100%;
  502. border-radius: 20rpx;
  503. }
  504. }
  505. // margin: 20rpx 0 0;
  506. }
  507. .swiper-btm {
  508. height: 60rpx;
  509. width: 750rpx;
  510. background-color: #fff;
  511. margin-bottom: 20rpx;
  512. font-size: 26rpx;
  513. font-weight: 500;
  514. color: #333333;
  515. .btm-item {
  516. flex-grow: 1;
  517. justify-content: center;
  518. image {
  519. width: 25rpx;
  520. height: 25rpx;
  521. margin-right: 14rpx;
  522. }
  523. }
  524. }
  525. .jg {
  526. height: 20rpx;
  527. background: #F8F8F8;
  528. }
  529. // 分类
  530. .cate-section {
  531. justify-content: space-around;
  532. background-color: #fff;
  533. padding: 0 0 30rpx;
  534. flex-wrap: wrap;
  535. .cate-item {
  536. padding-top: 30rpx;
  537. flex-grow: 0;
  538. width: 25%;
  539. flex-direction: column;
  540. text-align: center;
  541. align-items: center;
  542. justify-content: center;
  543. .img-wrapper {
  544. width:123rpx;
  545. height: 123rpx;
  546. border-radius: 20rpx;
  547. position: relative;
  548. image {
  549. width: 100%;
  550. height: 100%;
  551. position: absolute;
  552. left: 50%;
  553. top: 50%;
  554. transform: translate(-50%, -50%);
  555. }
  556. }
  557. .item-title {
  558. margin-top: 15rpx;
  559. font-size: 26rpx;
  560. font-weight: 500;
  561. color: #333333;
  562. }
  563. }
  564. }
  565. .hot-wrap {
  566. .hot-top {
  567. width: 750rpx;
  568. height: 174rpx;
  569. background: linear-gradient(#FFFFFF, rgba(255,255,255,0));
  570. padding: 0rpx 22rpx 75rpx;
  571. justify-content: flex-start;
  572. font-size: 32rpx;
  573. font-weight: 800;
  574. color: #000000;
  575. image {
  576. width: 36rpx;
  577. height: 36rpx;
  578. margin-right: 12rpx;
  579. }
  580. }
  581. .hot-list {
  582. margin-top: -70rpx;
  583. .good {
  584. width: 704rpx;
  585. background: #FFFFFF;
  586. border-radius: 20rpx;
  587. margin:0 auto 30rpx;
  588. .good-img {
  589. width: 704rpx;
  590. height: 330rpx;
  591. background: #D4D4E1;
  592. border-radius: 20rpx 20rpx 0rpx 0rpx;
  593. }
  594. .good-tit {
  595. padding:10rpx 20rpx;
  596. font-size: 30rpx;
  597. font-weight: bold;
  598. color: #000000;
  599. }
  600. .good-cz {
  601. padding: 0 20rpx 23rpx 23rpx;
  602. .price {
  603. font-size: 42rpx;
  604. font-weight: bold;
  605. color: $base-color;
  606. .xy {
  607. font-size: 24rpx;
  608. }
  609. .old-price {
  610. font-size: 26rpx;
  611. font-weight: 500;
  612. text-decoration: line-through;
  613. color: #999999;
  614. margin-left: 18rpx;
  615. }
  616. }
  617. .cz-btn {
  618. width: 172rpx;
  619. line-height: 60rpx;
  620. background: $base-color;
  621. border-radius: 10rpx;
  622. font-size: 26rpx;
  623. font-weight: 500;
  624. color: #FFFFFF;
  625. text-align: center;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. .popup-box {
  632. width: 522rpx;
  633. height: 605rpx;
  634. background-color: #ffffff;
  635. border-radius: 20rpx;
  636. position: relative;
  637. .img {
  638. position: relative;
  639. top: -56rpx;
  640. left: 0;
  641. width: 522rpx;
  642. height: 132rpx;
  643. display: flex;
  644. justify-content: center;
  645. image {
  646. border-radius: 20rpx 20rpx 0 0;
  647. width: 450rpx;
  648. height: 132rpx;
  649. }
  650. }
  651. .mian {
  652. margin-top: -44rpx;
  653. display: flex;
  654. flex-direction: column;
  655. align-items: center;
  656. // padding: 32rpx 32rpx;
  657. background-color: #ffffff;
  658. border-radius: 0 0 20rpx 20rpx;
  659. text-align: center;
  660. .delivery {
  661. font-size: 40rpx;
  662. color: #333333;
  663. display: flex;
  664. align-items: center;
  665. flex-direction: column;
  666. image {
  667. margin-top: 48rpx;
  668. width: 172rpx;
  669. height: 160rpx;
  670. }
  671. }
  672. .nocancel {
  673. font-size: 32rpx;
  674. color: #333333;
  675. margin-top: 14rpx;
  676. }
  677. .comfirm-box {
  678. margin-top: 52rpx;
  679. display: flex;
  680. // margin-bottom: 32rpx;
  681. // justify-content: space-around;
  682. .cancel {
  683. display: flex;
  684. align-items: center;
  685. justify-content: center;
  686. width: 197rpx;
  687. height: 74rpx;
  688. border: 1px solid #dcc786;
  689. border-radius: 38rpx;
  690. font-size: 32rpx;
  691. color: #605128;
  692. }
  693. .comfirm {
  694. margin-left: 32rpx;
  695. display: flex;
  696. align-items: center;
  697. justify-content: center;
  698. width: 197rpx;
  699. height: 74rpx;
  700. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  701. border-radius: 38px;
  702. font-size: 32rpx;
  703. color: #605128;
  704. }
  705. }
  706. }
  707. }
  708. .top-bg {
  709. height: 450rpx;
  710. //#f53934
  711. background-image: linear-gradient(to bottom,#f53934,#fff);
  712. position: absolute;
  713. top: 0;
  714. width: 100%;
  715. }
  716. .gsjs {
  717. width: 100%;
  718. }
  719. </style>