index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <template>
  2. <view class="container">
  3. <view class="vheigh"></view>
  4. <view class="top" @click="clickSearch()">
  5. <view class="top-icon"><image src="../../static/icon/icon.png" mode=""></image></view>
  6. <view class="top-main">输入你要查找的内容</view>
  7. </view>
  8. <swiper class="banner" autoplay="true" duration="400" interval="5000">
  9. <swiper-item class="banner-item" v-for="(item, index) in carouselList"><image :src="item.pic" /></swiper-item>
  10. </swiper>
  11. <view class="navbar flex">
  12. <view class="navbar-item" @click="navTo('/pages/category/category')">
  13. <view class="navbar-image"><image src="../../static/icon/index1.png" mode=""></image></view>
  14. <view class="navbar-font">全部商品</view>
  15. </view>
  16. <view class="navbar-item" @click="navTo('/pages/index/detail?id=2')">
  17. <view class="navbar-image"><image src="../../static/icon/index2.png" mode=""></image></view>
  18. <view class="navbar-font">公司介绍</view>
  19. </view>
  20. <view class="navbar-item" @click="kfOpen">
  21. <view class="navbar-image"><image src="../../static/icon/index3.png" mode=""></image></view>
  22. <view class="navbar-font">联系客服</view>
  23. </view>
  24. <view class="navbar-item" @click="navTo('/pages/user/shareQrCode')">
  25. <view class="navbar-image"><image src="../../static/icon/index4.png" mode=""></image></view>
  26. <view class="navbar-font">邀请好友</view>
  27. </view>
  28. </view>
  29. <view class="xian"></view>
  30. <view class="hot-box">
  31. <view class="hot-title flex">
  32. <view class="hot-title-item flex">
  33. <view class="hot-title-image"><image src="../../static/icon/fire.png" mode=""></image></view>
  34. <view class="hot-title-font">好货上新</view>
  35. </view>
  36. <view class="hot-title-item flex" @click="navTo('/pages/product/classify?type=3')">
  37. <view class="hot-title-more">更多</view>
  38. <view class="hot-title-jt"><image src="../../static/icon/jt.png" mode=""></image></view>
  39. </view>
  40. </view>
  41. <view class="hot-main flex">
  42. <view class="hot-main-item" v-for="(item, index) in hotList" @click="navToDetailPage(item)">
  43. <view class="hot-main-image"><image :src="item.image" mode=""></image></view>
  44. <view class="hot-name clamp">{{ item.store_name }}</view>
  45. <view class="hot-price">
  46. ¥{{ item.price * 1 }}
  47. <!-- <text class="yuan-price">¥{{ item.ot_price * 1 }}</text> -->
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="xian"></view>
  53. <view class="guess-section-box">
  54. <view class="guess-section-title">
  55. <view class="guess-section-xian"></view>
  56. <view class="guess-section-title-font">爆款推荐</view>
  57. <view class="guess-section-xian"></view>
  58. </view>
  59. <view class="guess-section">
  60. <view v-for="(item, index) in bastList" :key="index" class="guess-item" @click="navToDetailPage(item)">
  61. <view class="image-wrapper"><image :src="item.image" mode="scaleToFill"></image></view>
  62. <text class="title clamp margin-c-20">{{ item.store_name }}</text>
  63. <view class="cmy-hr"></view>
  64. <view class="price margin-c-20 flex">
  65. <view>
  66. ¥{{ item.price }}
  67. <text class="yuan-price">¥{{ item.ot_price }}</text>
  68. </view>
  69. <!-- <view class="font-size-sm">
  70. <text class="font-color-gray">{{ item.sales }}人购买</text>
  71. </view> -->
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="zb" @click="navTo('/pages/user/living')"><image src="../../static/img/living.png" mode=""></image></view>
  77. <uni-popup ref="popupkf" type="center">
  78. <view class="popup-box">
  79. <view class="img"><image src="../../static/img/img009.png" mode=""></image></view>
  80. <view class="mian">
  81. <view class="delivery">
  82. <view class="title">已经为您定制专属客服</view>
  83. <image src="../../static/img/img010.png" mode=""></image>
  84. </view>
  85. <view class="nocancel">客服VX:{{ text }}</view>
  86. <view class="comfirm-box">
  87. <view class="cancel" @click="kfClose()">取消</view>
  88. <view class="comfirm" @click="comfirm(text)">复制微信</view>
  89. </view>
  90. </view>
  91. </view>
  92. </uni-popup>
  93. </view>
  94. </template>
  95. <script>
  96. import { loadIndexs } from '@/api/index.js';
  97. import { getUserInfo } from '@/api/user.js';
  98. import { setCoupons } from '@/api/functionalUnit.js';
  99. import { getBargainList } from '@/api/product.js';
  100. import { interceptor } from '@/utils/loginUtils';
  101. import uniCopy from '@/js_sdk/xb-copy/uni-copy.js';
  102. import { mapState } from 'vuex';
  103. export default {
  104. data() {
  105. return {
  106. carouselList: [''],
  107. hotList: [],
  108. text: '1111',
  109. bastList: []
  110. };
  111. },
  112. // #ifdef MP
  113. onShareAppMessage: function(res) {
  114. console.log(res);
  115. console.log('是否从按钮进入');
  116. if (res.from === 'button' || res.from === 'menu') {
  117. // 来自页面内分享按钮
  118. let pages = getCurrentPages();
  119. // 获取当前页面
  120. let page = pages[pages.length - 1];
  121. let path = '/' + page.route + '?';
  122. // 保存传值
  123. for (let i in page.options) {
  124. path += i + '=' + page.options[i] + '&';
  125. }
  126. // 保存邀请人
  127. path += 'spread=' + this.userInfo.uid;
  128. let data = {
  129. path: path,
  130. imageUrl: this.bastList[0].pic,
  131. title: this.userInfo.nickname ? this.userInfo.nickname : '' + '邀请您进入亲家母优选'
  132. };
  133. return data;
  134. } else {
  135. console.log('else');
  136. }
  137. },
  138. // #endif
  139. computed: {
  140. ...mapState('user', ['hasLogin', 'userInfo'])
  141. },
  142. onLoad: function(option) {
  143. // #ifndef MP
  144. if (option.spread) {
  145. // 存储其他邀请人
  146. uni.setStorageSync('spread', option.spread);
  147. }
  148. // #endif
  149. // #ifdef MP
  150. if (option.scene) {
  151. // 存储小程序邀请人
  152. uni.setStorage({
  153. key: 'spread_code',
  154. data: option.scene
  155. });
  156. }
  157. // #endif
  158. },
  159. onShow: function() {
  160. // 判断是否强制登录
  161. if (this.loginInterceptor && !this.hasLogin) {
  162. // 登录拦截
  163. interceptor();
  164. }
  165. this.loadData();
  166. },
  167. //下拉刷新
  168. onPullDownRefresh() {
  169. this.loadData();
  170. },
  171. methods: {
  172. kfOpen() {
  173. this.$refs.popupkf.open();
  174. },
  175. kfClose() {
  176. this.$refs.popupkf.close();
  177. },
  178. navTo(url) {
  179. uni.navigateTo({
  180. url,
  181. fail() {
  182. uni.switchTab({
  183. url
  184. });
  185. }
  186. });
  187. },
  188. comfirm(text) {
  189. console.log(text);
  190. const result = uniCopy(text);
  191. if (result === false) {
  192. uni.showToast({
  193. title: '不支持'
  194. });
  195. } else {
  196. uni.showToast({
  197. title: '复制成功',
  198. icon: 'none'
  199. });
  200. }
  201. this.$refs.popupkf.close();
  202. },
  203. cs() {
  204. uni.scanCode({
  205. success: function(res) {
  206. console.log('条码类型:' + res.scanType);
  207. console.log('条码内容:' + res.result);
  208. }
  209. });
  210. },
  211. // 點擊搜索框
  212. clickSearch() {
  213. uni.navigateTo({
  214. url: '/pages/product/search'
  215. });
  216. },
  217. // 请求载入数据
  218. async loadData() {
  219. loadIndexs({})
  220. .then(({ data }) => {
  221. let goods = data.info;
  222. this.carouselList = data.banner;
  223. this.swiperLength = this.carouselList.length;
  224. this.hotList = goods.firstList; //最新商品
  225. this.bastList = data.likeInfo; //爆款推荐
  226. uni.stopPullDownRefresh();
  227. })
  228. .catch(e => {
  229. uni.stopPullDownRefresh();
  230. });
  231. },
  232. //轮播图切换修改背景色
  233. swiperChange(e) {
  234. const index = e.detail.current;
  235. this.swiperCurrent = index;
  236. this.titleNViewBackground = this.carouselList[index].background;
  237. },
  238. //详情页
  239. navToDetailPage(item) {
  240. let id = item.id;
  241. uni.navigateTo({
  242. url: '/pages/product/product?id=' + id
  243. });
  244. },
  245. // 轮播图跳转
  246. bannerNavToUrl(item) {
  247. // #ifdef H5
  248. if (item.wap_url.indexOf('http') > 0) {
  249. window.location.href = item.wap_url;
  250. }
  251. // #endif
  252. //测试数据没有写id,用title代替
  253. uni.navigateTo({
  254. url: item.wap_url
  255. });
  256. }
  257. }
  258. };
  259. </script>
  260. <style lang="scss">
  261. .vheigh {
  262. height: var(--status-bar-height);
  263. background-color: #ffffff;
  264. }
  265. .container,
  266. page {
  267. height: auto;
  268. min-height: 100%;
  269. background: #ffffff;
  270. }
  271. .top {
  272. width: 689rpx;
  273. height: 58rpx;
  274. background: #ededed;
  275. border-radius: 29rpx;
  276. margin: 20rpx auto 0;
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. .top-icon {
  281. width: 32rpx;
  282. height: 32rpx;
  283. image {
  284. width: 100%;
  285. height: 100%;
  286. }
  287. }
  288. .top-main {
  289. margin-left: 20rpx;
  290. font-size: 28rpx;
  291. font-family: PingFang SC;
  292. font-weight: 500;
  293. color: #cbcbcb;
  294. }
  295. }
  296. .banner {
  297. margin: 20rpx auto 0;
  298. width: 690rpx;
  299. height: 350rpx;
  300. .banner-item {
  301. width: 690rpx;
  302. height: 350rpx;
  303. image {
  304. width: 100%;
  305. height: 100%;
  306. }
  307. }
  308. }
  309. .navbar {
  310. justify-content: space-around;
  311. margin-top: 50rpx;
  312. .navbar-item {
  313. display: flex;
  314. flex-direction: column;
  315. align-items: center;
  316. .navbar-image {
  317. width: 90rpx;
  318. height: 90rpx;
  319. border-radius: 50%;
  320. image {
  321. width: 100%;
  322. height: 100%;
  323. border-radius: 50%;
  324. }
  325. }
  326. .navbar-font {
  327. margin-top: 24rpx;
  328. font-size: 24rpx;
  329. font-family: PingFang SC;
  330. font-weight: 500;
  331. color: #666666;
  332. }
  333. }
  334. }
  335. .xian {
  336. margin-top: 50rpx;
  337. width: 750rpx;
  338. height: 20rpx;
  339. background: #efefef;
  340. opacity: 0.61;
  341. }
  342. .hot-box {
  343. padding: 0 30rpx;
  344. .hot-title {
  345. padding-top: 50rpx;
  346. .hot-title-item {
  347. justify-content: flex-start;
  348. .hot-title-image {
  349. width: 36rpx;
  350. height: 36rpx;
  351. image {
  352. width: 100%;
  353. height: 100%;
  354. }
  355. }
  356. .hot-title-font {
  357. margin-left: 7rpx;
  358. font-size: 32rpx;
  359. font-family: PingFang SC;
  360. font-weight: 800;
  361. color: #303030;
  362. }
  363. .hot-title-more {
  364. margin-right: 10rpx;
  365. font-size: 24rpx;
  366. font-family: PingFang SC;
  367. font-weight: 500;
  368. color: #999999;
  369. }
  370. .hot-title-jt {
  371. width: 10rpx;
  372. height: 19rpx;
  373. position: relative;
  374. top: -8rpx;
  375. image {
  376. width: 100%;
  377. height: 100%;
  378. }
  379. }
  380. }
  381. }
  382. .hot-main {
  383. margin-top: 25rpx;
  384. .hot-main-item {
  385. width: 220rpx;
  386. background: #ffffff;
  387. border: 4rpx solid #f0e7d2;
  388. border-radius: 10rpx;
  389. padding: 0 0 34rpx;
  390. .hot-main-image {
  391. width: 212rpx;
  392. height: 212rpx;
  393. image {
  394. width: 100%;
  395. height: 100%;
  396. }
  397. }
  398. .hot-name {
  399. padding: 20rpx 12rpx 0;
  400. font-size: 28rpx;
  401. font-family: PingFang SC;
  402. font-weight: 500;
  403. color: #0a122b;
  404. }
  405. .hot-price {
  406. padding: 0 12rpx;
  407. font-size: 32rpx;
  408. font-family: PingFang SC;
  409. font-weight: 800;
  410. color: #ff4c4c;
  411. .yuan-price {
  412. display: inline-block;
  413. margin-left: 10rpx;
  414. font-size: 24rpx;
  415. font-family: PingFang SC;
  416. font-weight: 500;
  417. text-decoration: line-through;
  418. color: #969696;
  419. }
  420. }
  421. }
  422. }
  423. }
  424. .guess-section-box {
  425. margin-top: 20rpx;
  426. width: 750rpx;
  427. background: #fff;
  428. padding-top: 30rpx;
  429. .guess-section-title {
  430. display: flex;
  431. justify-content: center;
  432. align-items: center;
  433. .guess-section-xian {
  434. width: 120rpx;
  435. height: 1px;
  436. background: #999999;
  437. }
  438. .guess-section-title-font {
  439. margin: 0 70rpx;
  440. font-size: 30rpx;
  441. font-family: PingFang SC;
  442. font-weight: 500;
  443. color: #363636;
  444. }
  445. }
  446. }
  447. .guess-section {
  448. margin-top: 40rpx;
  449. display: flex;
  450. flex-wrap: wrap;
  451. padding: 0 30rpx;
  452. .guess-item {
  453. padding-bottom: 35rpx;
  454. overflow: hidden;
  455. display: flex;
  456. flex-direction: column;
  457. width: 48%;
  458. margin-bottom: 4%;
  459. border-radius: $border-radius-sm;
  460. background-color: white;
  461. box-shadow: $box-shadow;
  462. &:nth-child(2n + 1) {
  463. margin-right: 4%;
  464. }
  465. }
  466. .image-wrapper {
  467. width: 100%;
  468. height: 330rpx;
  469. border-radius: 3px;
  470. overflow: hidden;
  471. image {
  472. width: 100%;
  473. height: 100%;
  474. opacity: 1;
  475. }
  476. }
  477. .title {
  478. margin-top: 28rpx;
  479. font-size: $font-base;
  480. color: $font-color-dark;
  481. font-weight: bold;
  482. }
  483. .price {
  484. margin-top: 34rpx;
  485. font-size: 32rpx;
  486. font-family: PingFang SC;
  487. font-weight: 800;
  488. color: #ff4c4c;
  489. line-height: 1;
  490. .yuan-price {
  491. display: inline-block;
  492. margin-left: 10rpx;
  493. font-size: 24rpx;
  494. font-family: PingFang SC;
  495. font-weight: 500;
  496. text-decoration: line-through;
  497. color: #969696;
  498. }
  499. }
  500. .icon {
  501. @extend %icon;
  502. }
  503. .detail {
  504. line-height: 1;
  505. }
  506. .tip {
  507. color: white;
  508. background-color: $color-yellow;
  509. line-height: 1.5;
  510. font-size: $font-sm;
  511. padding-left: 20rpx;
  512. }
  513. }
  514. /*公用边框样式*/
  515. %icon {
  516. margin-right: 10rpx;
  517. display: inline-block;
  518. padding: 2rpx 10rpx;
  519. border: 1rpx solid $color-yellow;
  520. color: $color-yellow;
  521. line-height: 1;
  522. font-size: $font-base;
  523. border-radius: 10rpx;
  524. }
  525. .popup-box {
  526. width: 640rpx;
  527. height: 605rpx;
  528. background-color: #ffffff;
  529. border-radius: 20rpx;
  530. position: relative;
  531. .img {
  532. position: relative;
  533. top: -56rpx;
  534. left: 0;
  535. width: 640rpx;
  536. height: 132rpx;
  537. display: flex;
  538. justify-content: center;
  539. image {
  540. border-radius: 20rpx 20rpx 0 0;
  541. width: 450rpx;
  542. height: 132rpx;
  543. }
  544. }
  545. .mian {
  546. margin-top: -44rpx;
  547. display: flex;
  548. flex-direction: column;
  549. align-items: center;
  550. // padding: 32rpx 32rpx;
  551. background-color: #ffffff;
  552. border-radius: 0 0 20rpx 20rpx;
  553. text-align: center;
  554. .delivery {
  555. font-size: 40rpx;
  556. color: #333333;
  557. display: flex;
  558. align-items: center;
  559. flex-direction: column;
  560. .title {
  561. }
  562. image {
  563. margin-top: 48rpx;
  564. width: 172rpx;
  565. height: 160rpx;
  566. }
  567. }
  568. .nocancel {
  569. font-size: 32rpx;
  570. color: #333333;
  571. margin-top: 14rpx;
  572. }
  573. .comfirm-box {
  574. margin-top: 52rpx;
  575. display: flex;
  576. // margin-bottom: 32rpx;
  577. // justify-content: space-around;
  578. .cancel {
  579. display: flex;
  580. align-items: center;
  581. justify-content: center;
  582. width: 260rpx;
  583. height: 88rpx;
  584. border: 2rpx solid #dcc786;
  585. border-radius: 10rpx;
  586. font-size: 32rpx;
  587. font-family: PingFang SC;
  588. font-weight: 500;
  589. color: #605128;
  590. }
  591. .comfirm {
  592. margin-left: 32rpx;
  593. display: flex;
  594. align-items: center;
  595. justify-content: center;
  596. width: 260rpx;
  597. height: 88rpx;
  598. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  599. border-radius: 10rpx;
  600. font-size: 32rpx;
  601. color: #605128;
  602. }
  603. }
  604. }
  605. }
  606. .zb {
  607. position: fixed;
  608. right: 20rpx;
  609. bottom: 20%;
  610. width: 136rpx;
  611. height: 136rpx;
  612. image {
  613. width: 100%;
  614. height: 100%;
  615. }
  616. }
  617. </style>