index.vue 16 KB

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