index.vue 13 KB

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