index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <view class="center">
  3. <!-- 小程序头部兼容 -->
  4. <!-- #ifdef MP -->
  5. <navigator url="/pages/product/search">
  6. <view class="input-box flex">
  7. <view class=" input-content flex">
  8. <view class="iconfont iconsearch"></view>
  9. <view class="input"><input disabled placeholder="请输入搜索内容" /></view>
  10. </view>
  11. </view>
  12. </navigator>
  13. <!-- #endif -->
  14. <view class="top"></view>
  15. <view class="carousel">
  16. <swiper autoplay="true" duration="400" interval="5000" @change="swiperChange" class="bor">
  17. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"><image :src="item.pic" /></swiper-item>
  18. </swiper>
  19. </view>
  20. <view class="swiper-dot">
  21. <template v-for="item in swiperLength">
  22. <view class="swiper-dots-item" :key="item" :class="{ action: swiperCurrent + 1 === item }"></view>
  23. </template>
  24. </view>
  25. <view class="cate-section">
  26. <view class="cate-item" @click="nav('/pages/category/category')">
  27. <image src="/static/icon/c3.png"></image>
  28. <view class="cate-font">品牌故事</view>
  29. </view>
  30. <view class="cate-item" @click="nav('/pages/category/articleList')">
  31. <image src="/static/icon/c5.png"></image>
  32. <view class="cate-font">使用案例</view>
  33. </view>
  34. <view class="cate-item" @click="showPopup()">
  35. <image src="/static/icon/c7.png"></image>
  36. <view class="cate-font">康复天地</view>
  37. </view>
  38. <view class="cate-item">
  39. <image src="/static/icon/c8.png" @click="nav('/pages/index/vip')"></image>
  40. <view class="cate-font">成为会员</view>
  41. </view>
  42. </view>
  43. <view class="xian"></view>
  44. <view class="main">
  45. <view class="main-top flex">
  46. <view class="main-left">
  47. <view class="shu"></view>
  48. <view class="main-title">热销推荐</view>
  49. <view class="main-tip">在售精品</view>
  50. </view>
  51. </view>
  52. <view class="list-box-h">
  53. <view v-for="(item, index) in dataList" :key="index" class="guess-item" @click="navToDetailPage(item)">
  54. <image :src="item.image"></image>
  55. <view class="guess-box">
  56. <view class="title clamp2">{{ item.store_name }}</view>
  57. <view class="price-box flex">
  58. <view class="yuanprice">{{ item.ot_price }}</view>
  59. <image src="../../static/img/jiantou.png" mode=""></image>
  60. <view class="jiang">直降{{ (item.ot_price - item.price).toFixed(2) }}元</view>
  61. </view>
  62. <view class="price">¥{{ item.price }}</view>
  63. <view class="btn">立即购买</view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <uni-popup ref="popup" type="center">
  69. <view class="popup">
  70. <view class="popup-dox">
  71. <image class="popup-logo" src="../../static/img/img009.png"></image>
  72. <view class="pop-title">已为您定制专属客服</view>
  73. <view>{{ weixin }}</view>
  74. <image class="popup-text" @longtap="bc_code" :src="erweima"></image>
  75. <view class="btn" @click="copy(weixin)">复制微信号</view>
  76. <view class="pop-tip flex">
  77. <view class="weixin"><image src="../../static/img/weixin.png" mode=""></image></view>
  78. <view>长按保存二维码</view>
  79. </view>
  80. </view>
  81. </view>
  82. <view class="close_icon" @click="close"><image src="../../static/img/Close.png"></image></view>
  83. </uni-popup>
  84. </view>
  85. </template>
  86. <script>
  87. import { loadIndexs } from '@/api/index.js';
  88. import { mapState } from 'vuex';
  89. import { saveUrl, interceptor } from '@/utils/loginUtils.js';
  90. import { service } from '@/api/user.js';
  91. // #ifdef H5
  92. import { weixindata, weixinlocation, shareLoad } from '@/utils/wxAuthorized';
  93. import weixinObj from '@/plugin/jweixin-module/index.js';
  94. // #endif
  95. export default {
  96. data() {
  97. return {
  98. carouselList: [], //轮播图
  99. swiperCurrent: 0,
  100. dataList: [],
  101. erweima: '',
  102. weixin: '', //客服微信
  103. swiperLength: 1 //图片数量
  104. };
  105. },
  106. onLoad: function(option) {
  107. // #ifndef MP
  108. if (option.spread) {
  109. // 存储其他邀请人
  110. uni.setStorageSync('spread', option.spread);
  111. }
  112. // #endif
  113. // #ifdef MP
  114. if (option.scene) {
  115. // 存储小程序邀请人
  116. uni.setStorage({
  117. key: 'spread_code',
  118. data: option.scene
  119. });
  120. }
  121. // #endif
  122. // #ifdef H5
  123. if (this.hasLogin) {
  124. console.log('显示');
  125. weixinObj.hideAllNonBaseMenuItem();
  126. this.IndexShare();
  127. } else {
  128. console.log('隐藏');
  129. weixinObj.hideAllNonBaseMenuItem();
  130. }
  131. //#endif
  132. },
  133. computed: {
  134. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
  135. ...mapState(['baseURL'])
  136. },
  137. onShow: function() {
  138. // 判断是否强制登录
  139. if (!this.hasLogin) {
  140. // 登录拦截
  141. uni.showModal({
  142. title: '登录',
  143. content: '您未登录,是否马上登陆?',
  144. success: e => {
  145. if (e.confirm) {
  146. interceptor();
  147. }
  148. },
  149. fail: e => {
  150. console.log(e);
  151. }
  152. });
  153. }
  154. this.loadData();
  155. },
  156. //下拉刷新
  157. onPullDownRefresh() {
  158. this.loadData();
  159. },
  160. // #ifndef MP
  161. // 监听导航栏输入框点击事件
  162. onNavigationBarSearchInputClicked(e) {
  163. //跳转到搜索页面
  164. this.clickSearch();
  165. },
  166. //点击导航栏 buttons 时触发
  167. onNavigationBarButtonTap(e) {
  168. uni.navigateTo({
  169. url: '/pages/user/notice'
  170. });
  171. },
  172. // #endif
  173. methods: {
  174. // #ifdef H5
  175. IndexShare() {
  176. let obj = this;
  177. let pages = getCurrentPages();
  178. // 获取当前页面
  179. let page = pages[pages.length - 1];
  180. let path = '/#/' + page.route + '?';
  181. // 保存传值
  182. for (let i in page.options) {
  183. path += i + '=' + page.options[i] + '&';
  184. }
  185. console.log(obj.Path);
  186. // 保存邀请人
  187. path += 'spread=' + this.userInfo.uid;
  188. let data = {
  189. link: this.baseURL + '/index/' + path,
  190. title: this.userInfo.nickname + '邀请您进入鼎立足行',
  191. desc: '欢迎加入鼎立足行',
  192. imgUrl: 'https://dlzx.liuniu946.com/index/static/img/logo.png'
  193. };
  194. shareLoad(data);
  195. },
  196. // #endif
  197. // 监听切换事件
  198. listChange(e) {
  199. this.checkid = e.detail.current;
  200. },
  201. // 點擊搜索框
  202. clickSearch() {
  203. uni.navigateTo({
  204. url: '/pages/product/search'
  205. });
  206. },
  207. nav(url) {
  208. uni.navigateTo({
  209. url,
  210. fail: () => {
  211. console.log(1);
  212. uni.switchTab({
  213. url
  214. });
  215. }
  216. });
  217. },
  218. showPopup() {
  219. this.$refs.popup.open();
  220. },
  221. close() {
  222. this.$refs.popup.close();
  223. },
  224. //轮播图切换修改背景色
  225. swiperChange(e) {
  226. const index = e.detail.current;
  227. this.swiperCurrent = index;
  228. },
  229. copy(content) {
  230. /**
  231. * 小程序端 和 app端的复制逻辑
  232. */
  233. //#ifndef H5
  234. uni.setClipboardData({
  235. data: content,
  236. success: function() {
  237. console.log('success');
  238. return true;
  239. }
  240. });
  241. //#endif
  242. /**
  243. * H5端的复制逻辑
  244. */
  245. // #ifdef H5
  246. if (!document.queryCommandSupported('copy')) {
  247. //为了兼容有些浏览器 queryCommandSupported 的判断
  248. // 不支持
  249. return false;
  250. }
  251. let textarea = document.createElement('textarea');
  252. textarea.value = content;
  253. textarea.readOnly = 'readOnly';
  254. document.body.appendChild(textarea);
  255. textarea.select(); // 选择对象
  256. textarea.setSelectionRange(0, content.length); //核心
  257. let result = document.execCommand('copy'); // 执行浏览器复制命令
  258. textarea.remove();
  259. return result;
  260. // #endif
  261. },
  262. comfirm(text) {
  263. console.log(text);
  264. const result = this.uniCopy(text);
  265. if (result === false) {
  266. uni.showToast({
  267. title: '不支持'
  268. });
  269. } else {
  270. uni.showToast({
  271. title: '复制成功',
  272. icon: 'none'
  273. });
  274. }
  275. this.$refs.popup.close();
  276. },
  277. bc_code() {
  278. let that = this;
  279. console.log('保存二维码', this.erweima);
  280. uni.downloadFile({
  281. //获得二维码的临时地址
  282. url: this.erweima,
  283. success: res => {
  284. //console.log('获取url',res)
  285. if (res.statusCode == 200) {
  286. uni.saveImageToPhotosAlbum({
  287. filePath: res.tempFilePath, //传入临时地址
  288. success() {
  289. that.$api.msg('保存成功'); //封装的提示
  290. },
  291. fail() {
  292. that.$api.msg('保存失败');
  293. }
  294. });
  295. }
  296. }
  297. });
  298. },
  299. // 请求载入数据
  300. async loadData() {
  301. loadIndexs({})
  302. .then(({ data }) => {
  303. console.log(data);
  304. this.carouselList = data.banner;
  305. this.swiperLength = this.carouselList.length;
  306. this.dataList = data.likeInfo; //最新商品
  307. uni.stopPullDownRefresh();
  308. })
  309. .catch(e => {
  310. uni.stopPullDownRefresh();
  311. });
  312. service({}).then(({ data }) => {
  313. this.erweima = data.service_qr;
  314. this.weixin = data.service_wechat;
  315. });
  316. },
  317. //详情页
  318. navToDetailPage(item) {
  319. let id = item.id;
  320. uni.navigateTo({
  321. url: '/pages/product/product?id=' + id
  322. });
  323. }
  324. }
  325. };
  326. </script>
  327. <style lang="scss">
  328. page,
  329. .center {
  330. height: auto;
  331. min-height: 100%;
  332. background-color: #ffffff;
  333. }
  334. /* #ifdef MP || APP-PLUS*/
  335. .input-box {
  336. padding: 25rpx;
  337. /* #ifdef APP-PLUS */
  338. margin-top: var(--status-bar-height);
  339. /* #endif */
  340. background-color: #0fc8e4;
  341. height: 44px;
  342. .iconsearch {
  343. font-size: 50rpx;
  344. }
  345. .input-content {
  346. border-radius: 99rpx;
  347. flex-grow: 1;
  348. padding: 5rpx 30rpx;
  349. // background-color: rgba(231, 231, 231, 0.7);
  350. background: #ffffff;
  351. .input {
  352. flex-grow: 1;
  353. input {
  354. font-size: $font-base;
  355. }
  356. }
  357. }
  358. .input-button {
  359. padding-left: 20rpx;
  360. font-size: $font-base;
  361. height: 100%;
  362. }
  363. }
  364. /* #endif */
  365. .top {
  366. width: 1000rpx;
  367. height: 240rpx;
  368. background: linear-gradient(180deg, #08c4e6, #50ead2);
  369. overflow: hidden;
  370. text-align: center;
  371. border-bottom-left-radius: 50%;
  372. border-bottom-right-radius: 50%;
  373. margin-left: -125rpx;
  374. }
  375. .carousel {
  376. width: 700rpx;
  377. height: 300rpx;
  378. border-radius: 14rpx;
  379. margin: 0 auto;
  380. margin-top: calc(-260rpx + var(--status-bar-height));
  381. .bor {
  382. border-radius: 14rpx;
  383. .carousel-item {
  384. image {
  385. width: 100%;
  386. height: 100%;
  387. border-radius: 14rpx;
  388. }
  389. }
  390. }
  391. }
  392. .swiper-dot {
  393. position: relative;
  394. z-index: 10;
  395. margin-top: -40rpx;
  396. display: flex;
  397. justify-content: center;
  398. .swiper-dots-item {
  399. width: 14rpx;
  400. height: 14rpx;
  401. background: #aaaaaa;
  402. border-radius: 50%;
  403. margin: 0 16rpx;
  404. // z-index: 999;
  405. }
  406. .action {
  407. background-color: #ffffff;
  408. }
  409. }
  410. .cate-section {
  411. display: flex;
  412. justify-content: space-around;
  413. align-items: center;
  414. flex-wrap: wrap;
  415. padding: 40rpx 22rpx;
  416. .cate-item {
  417. display: flex;
  418. flex-direction: column;
  419. align-items: center;
  420. font-size: $font-sm + 4rpx;
  421. color: $font-color-dark;
  422. }
  423. .cate-font {
  424. margin-top: -26rpx;
  425. }
  426. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  427. image {
  428. width: 150rpx;
  429. height: 150rpx;
  430. margin-bottom: 14rpx;
  431. border-radius: 50%;
  432. }
  433. }
  434. .xian {
  435. width: 750rpx;
  436. height: 20rpx;
  437. background: #f5f5f5;
  438. }
  439. .main {
  440. margin-top: 40rpx;
  441. padding: 0 40rpx;
  442. .main-top {
  443. align-items: center;
  444. .main-left {
  445. display: flex;
  446. justify-content: flex-start;
  447. align-items: center;
  448. .shu {
  449. width: 8rpx;
  450. height: 38rpx;
  451. background: #05ab81;
  452. border-radius: 4rpx;
  453. }
  454. .main-title {
  455. margin-left: 10rpx;
  456. font-size: 36rpx;
  457. font-family: PingFang SC;
  458. font-weight: bold;
  459. color: #202739;
  460. }
  461. .main-tip {
  462. font-size: 22rpx;
  463. font-family: PingFang SC;
  464. font-weight: bold;
  465. color: #95a0b1;
  466. margin-left: 14rpx;
  467. }
  468. }
  469. }
  470. }
  471. .guess-item {
  472. display: flex;
  473. width: 710rpx;
  474. height: 290rpx;
  475. background: #ffffff;
  476. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  477. border-radius: 10rpx;
  478. padding: 15rpx;
  479. padding-bottom: 150rpx;
  480. margin: 20rpx auto 0;
  481. position: relative;
  482. image {
  483. width: 260rpx;
  484. height: 260rpx;
  485. border-radius: 10rpx;
  486. }
  487. .guess-box {
  488. padding: 12rpx 0 0 24rpx;
  489. width: 436rpx;
  490. .title {
  491. font-size: 30rpx;
  492. padding-left: 4rpx;
  493. font-family: PingFang SC;
  494. font-weight: 500;
  495. color: #333333;
  496. width: 368rpx;
  497. line-height: 36rpx;
  498. .tuanF {
  499. display: inline-block;
  500. margin-right: 4rpx;
  501. position: relative;
  502. top: -6rpx;
  503. .tuan {
  504. display: flex;
  505. align-items: center;
  506. padding: 10rpx;
  507. height: 36rpx;
  508. background: #ffebe9;
  509. border-radius: 18rpx;
  510. .tuan-image {
  511. width: 18rpx;
  512. height: 18rpx;
  513. }
  514. .tuan-font {
  515. display: inline;
  516. font-size: 20rpx;
  517. font-family: PingFang SC;
  518. font-weight: 500;
  519. color: #ff1135;
  520. margin-left: 2rpx;
  521. }
  522. }
  523. }
  524. }
  525. .ping-box {
  526. margin-top: 15rpx;
  527. justify-content: flex-start;
  528. .ping {
  529. margin-left: 10rpx;
  530. height: 39rpx;
  531. background: #fdf7eb;
  532. border-radius: 5rpx;
  533. font-size: 22rpx;
  534. font-family: PingFang SC;
  535. font-weight: 500;
  536. color: #ff911f;
  537. display: flex;
  538. align-items: center;
  539. padding: 0 10rpx;
  540. }
  541. }
  542. .price-box {
  543. margin-top: 80rpx;
  544. justify-content: flex-start;
  545. .yuanprice {
  546. font-size: 26rpx;
  547. font-family: PingFang SC;
  548. font-weight: 500;
  549. text-decoration: line-through;
  550. color: #999999;
  551. padding-right: 6rpx;
  552. }
  553. image {
  554. width: 14rpx;
  555. height: 16rpx;
  556. }
  557. .jiang {
  558. padding-left: 2rpx;
  559. font-size: 24rpx;
  560. font-family: PingFang SC;
  561. font-weight: bold;
  562. color: #b59467;
  563. }
  564. }
  565. .price {
  566. font-size: 36rpx;
  567. font-family: PingFang SC;
  568. font-weight: bold;
  569. color: #ff1135;
  570. }
  571. .btn {
  572. width: 137rpx;
  573. height: 56rpx;
  574. background: #16cc9f;
  575. border-radius: 28rpx;
  576. font-size: 28rpx;
  577. font-family: PingFang SC;
  578. font-weight: 500;
  579. color: #ffffff;
  580. line-height: 56rpx;
  581. text-align: center;
  582. position: absolute;
  583. bottom: 25rpx;
  584. right: 25rpx;
  585. }
  586. }
  587. }
  588. .popup {
  589. width: 640rpx;
  590. background-color: #ffffff;
  591. border-radius: 15rpx;
  592. text-align: center;
  593. .popup-dox {
  594. position: relative;
  595. top: -60rpx;
  596. .popup-logo {
  597. width: 460rpx;
  598. height: 132rpx;
  599. }
  600. .pop-title {
  601. font-size: 40rpx;
  602. font-weight: bold;
  603. color: #333333;
  604. padding: 25rpx 0rpx;
  605. margin-bottom: 50rpx;
  606. }
  607. .popup-text {
  608. width: 400rpx;
  609. height: 400rpx;
  610. margin-bottom: 50rpx;
  611. }
  612. .btn {
  613. width: 300rpx;
  614. height: 50rpx;
  615. line-height: 50rpx;
  616. background: #96e4f2;
  617. margin: 0 auto;
  618. color: #ffffff;
  619. border-radius: 25rpx;
  620. }
  621. .pop-tip {
  622. font-size: 30rpx;
  623. font-weight: 500;
  624. color: #333333;
  625. justify-content: center;
  626. margin-top: 20rpx;
  627. .weixin {
  628. width: 48rpx;
  629. height: 40rpx;
  630. margin-right: 14rpx;
  631. image {
  632. width: 48rpx;
  633. height: 40rpx;
  634. }
  635. }
  636. }
  637. }
  638. }
  639. .close_icon {
  640. width: 60rpx;
  641. height: 60rpx;
  642. margin: 88rpx auto 0;
  643. image {
  644. width: 100%;
  645. height: 100%;
  646. }
  647. }</style>