index.vue 17 KB

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