index.vue 17 KB

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