index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view style="width: 750rpx;">
  5. <official-account></official-account>
  6. </view>
  7. <!-- #endif -->
  8. <!-- 兼容小程序搜索 -->
  9. <!-- #ifdef MP -->
  10. <navigator url="/pages/product/search">
  11. <view class="input-box flex">
  12. <view class=" input-content flex">
  13. <view class="iconfont iconsearch"></view>
  14. <view class="input"><input disabled placeholder="请输入搜索内容" /></view>
  15. </view>
  16. </view>
  17. </navigator>
  18. <!-- #endif -->
  19. <!-- 头部轮播 -->
  20. <view class="carousel-section">
  21. <view class="carousel-box">
  22. <swiper class="carousel" autoplay="true" duration="400" interval="5000" style="height: 312rpx;">
  23. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  24. @click="nav(item)">
  25. <image :src="item.pic" />
  26. </swiper-item>
  27. </swiper>
  28. </view>
  29. </view>
  30. <!-- 新手教程 -->
  31. <view class="award-box" @click="navTo('/pages/index/study')">
  32. <image src="../../static/img/study.png" mode=""></image>
  33. </view>
  34. <!-- 分类 -->
  35. <view class="cate-section">
  36. <view class="cate-item" @click="navTo('/pages/category/category')">
  37. <image src="https://zhibo.liuniu946.com/img/cate003.png"></image>
  38. <text>全部分类</text>
  39. </view>
  40. <view class="cate-item" @click="navTo('/pages/recommend/hotgoods')">
  41. <image src="https://zhibo.liuniu946.com/img/cate001.png"></image>
  42. <text>热销产品</text>
  43. </view>
  44. <view class="cate-item" @click="navTo('/pages/freeShop/apply')">
  45. <image src="https://zhibo.liuniu946.com/img/cate004.png"></image>
  46. <text>免费网店</text>
  47. </view>
  48. <view class="cate-item" @click="navTo('/pages/user/share')">
  49. <image src="https://zhibo.liuniu946.com/img/cate002.png"></image>
  50. <text>邀请好友</text>
  51. </view>
  52. </view>
  53. <!-- 正价商品 -->
  54. <view class="recommend-box">
  55. <view class="f-header">
  56. <view class="f-left-icon">为你推荐</view>
  57. <view class="tit-box"><text class="tit">超级好物 立即抢购</text></view>
  58. <view @click="navTo('/pages/recommend/recommend')"><text class="iconfont iconenter">更多</text></view>
  59. </view>
  60. <view class="guess-section">
  61. <view v-for="(item, index) in commgoods" :key="index" class="guess-item" @click="navToDetailPage(item)">
  62. <view class="image-wrapper">
  63. <image :src="item.image" mode="scaleToFill"></image>
  64. </view>
  65. <view class="info-wrapper">
  66. <text class="title">{{ item.store_name }}</text>
  67. <view class="price-box">
  68. <view class="price-left">
  69. <view class="ot_price">
  70. <text class="price-tip">¥</text>
  71. {{ item.ot_price }}
  72. </view>
  73. <view class="price">
  74. <text class="price-tip">¥</text>
  75. {{ item.price }}
  76. </view>
  77. </view>
  78. <view class="price-right">
  79. <!-- <view class="people">{{item.sales}}人购买</view> -->
  80. <view class="buyNow">马上购</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 热销产品 -->
  88. <view class="hotgoodsheader">
  89. <image src="https://zhibo.liuniu946.com/img/img001.png" mode=""></image>
  90. </view>
  91. <view class="hotgoods" style="padding-bottom: 0;">
  92. <view class="hotgoods-item" v-for="item in firstList" :key="item.id" @click="navToDetailPage(item)">
  93. <view class="image-wrapper">
  94. <image :src="item.image" mode="scaleToFill"></image>
  95. </view>
  96. <view class="title clamp margin-c-20">{{ item.store_name }}</view>
  97. <view class="hot-price">
  98. <view class="price">
  99. <text class="font-size-sm">¥</text>
  100. {{ item.price }}
  101. </view>
  102. <view class="cart-icon">
  103. <image src="https://zhibo.liuniu946.com/img/img002.png" mode=""></image>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <!-- 热销推荐 -->
  109. <u-tabbar v-if="mystore" v-model="current" :list="tabbar" active-color="#FF0000"
  110. inactive-color="#f19c99"></u-tabbar>
  111. <u-tabbar v-else v-model="current" :list="tabbar1" active-color="#FF0000" inactive-color="#f19c99"></u-tabbar>
  112. </view>
  113. </template>
  114. <script>
  115. import {
  116. loadIndexs
  117. } from '@/api/index.js';
  118. import {
  119. mapState,
  120. mapMutations
  121. } from 'vuex';
  122. import {
  123. saveUrl,
  124. interceptor
  125. } from '@/utils/loginUtils.js';
  126. import {
  127. tabbar,
  128. tabbar1
  129. } from '@/utils/tabbar.js';
  130. export default {
  131. // #ifdef MP
  132. onShareAppMessage: function(res) {
  133. console.log(res);
  134. console.log('是否从按钮进入');
  135. if (res.from === 'button' || res.from === 'menu') {
  136. // 来自页面内分享按钮
  137. let pages = getCurrentPages();
  138. // 获取当前页面
  139. let page = pages[pages.length - 1];
  140. let path = '/' + page.route + '?';
  141. // 保存传值
  142. for (let i in page.options) {
  143. path += i + '=' + page.options[i] + '&';
  144. }
  145. // 保存邀请人
  146. path += 'spread=' + this.userInfo.uid;
  147. let data = {
  148. path: path,
  149. imageUrl: 'http://zhibo.liuniu946.com/uploads/attach/2021/06/20210621/f24e2d3028d95db57944e1816ec464fc.jpg',
  150. title: this.userInfo.nickname + '邀请您进入台州智播项目'
  151. };
  152. return data;
  153. } else {
  154. console.log('else');
  155. }
  156. },
  157. // #endif
  158. data() {
  159. return {
  160. mystore: '',
  161. tabbar: tabbar,
  162. tabbar1: tabbar1,
  163. current: 0,
  164. carouselList: [],
  165. swiperLength: 0,
  166. swiperCurrent: 0,
  167. commgoods: [], // 为你推荐
  168. firstList: [], // 热销产品
  169. indexTop: 0, // 顶部缩进
  170. contentTop: 0, // 缩进
  171. pzTop: 0, // 拼中顶部缩进
  172. searchHeight: 0, //搜索框高度
  173. searchBoxHei: 0 // 高度
  174. };
  175. },
  176. onShow() {
  177. let value = uni.getStorageSync('mystore');
  178. console.log(value);
  179. // if (value) {
  180. this.mystore = value;
  181. console.log('首页this.mystore', this.mystore);
  182. // }
  183. },
  184. onLoad(option) {
  185. let res = uni.getSystemInfoSync();
  186. // #ifdef MP
  187. let menuButtonObject = wx.getMenuButtonBoundingClientRect();
  188. let navBarHeight = menuButtonObject.height + (menuButtonObject.top - res.statusBarHeight) * 2; // 导航栏高度
  189. this.searchBoxHei = navBarHeight; // 搜索框外框高度
  190. this.searchHeight = menuButtonObject.height; // 搜索框高度
  191. // #endif
  192. this.indexTop = res.statusBarHeight + 40; // 状态栏高度
  193. this.contentTop = this.searchBoxHei + this.indexTop + 40; // content padding-top 高度
  194. this.pzTop = this.contentTop + 10; // 拼中top高度
  195. // console.log('--option--', option);
  196. if (option.spread) {
  197. // 存储邀请人
  198. this.spread = option.spread;
  199. uni.setStorageSync('spread', option.spread);
  200. }
  201. if (option.scene) {
  202. // 存储邀请人
  203. this.spread = option.scene;
  204. uni.setStorageSync('spread_code', option.scene);
  205. }
  206. if (option.bingding) {
  207. this.bingding = option.bingding;
  208. uni.setStorageSync('bingding', option.bingding);
  209. }
  210. this.loadData();
  211. },
  212. computed: {
  213. ...mapState(['userInfo', 'baseURL', 'hasLogin', 'urlFile'])
  214. },
  215. methods: {
  216. // openQr(){
  217. // uni.scanCode({
  218. // success(e){
  219. // uni.showModal({
  220. // title: '掃碼內容',
  221. // content: JSON.stringify(e),
  222. // });
  223. // }
  224. // })
  225. // },
  226. // 获取首页数据
  227. loadData() {
  228. loadIndexs({}).then(({
  229. data
  230. }) => {
  231. // uni.setStorageSync('mystore',userInfo.store_info.id);
  232. console.log('--store_switch---', data.store_switch);
  233. // if( data.store_switch == 0){
  234. // console.log('== 0');
  235. // uni.setStorageSync('mystore','');
  236. // const value = uni.getStorageSync('mystore');
  237. // this.mystore = value;
  238. // console.log('请求数据mystore', this.mystore);
  239. // } else {
  240. // console.log('== 1');
  241. // }
  242. this.carouselList = data.banner;
  243. this.commgoods = data.info.bastList; // 为你推荐
  244. this.firstList = data.info.firstList; // 热销产品
  245. });
  246. },
  247. //轮播图跳转页面
  248. nav(item) {
  249. if (!this.hasLogin) {
  250. uni.showModal({
  251. title: '登录',
  252. content: '您未登录,是否马上登陆?',
  253. success: e => {
  254. if (e.confirm) {
  255. interceptor();
  256. }
  257. },
  258. fail: e => {
  259. console.log(e);
  260. }
  261. });
  262. return;
  263. }
  264. console.log(item);
  265. if (item.url != '/') {
  266. console.log('11111');
  267. uni.navigateTo({
  268. url: '/' + item.url,
  269. fail(error) {
  270. console.log(error);
  271. }
  272. });
  273. }
  274. },
  275. // 点击跳转页面
  276. navTo(url) {
  277. if (!this.hasLogin) {
  278. uni.showModal({
  279. title: '登录',
  280. content: '您未登录,是否马上登陆?',
  281. success: e => {
  282. if (e.confirm) {
  283. interceptor();
  284. }
  285. },
  286. fail: e => {
  287. console.log(e);
  288. }
  289. });
  290. return;
  291. }
  292. uni.navigateTo({
  293. url,
  294. fail(error) {
  295. uni.switchTab({
  296. url
  297. });
  298. }
  299. });
  300. },
  301. // 监听导航栏输入框点击事件
  302. onNavigationBarSearchInputClicked(e) {
  303. //跳转到搜索页面
  304. this.clickSearch();
  305. },
  306. // 點擊搜索框
  307. clickSearch() {
  308. uni.navigateTo({
  309. url: '/pages/product/search'
  310. });
  311. },
  312. // 跳转普通商品
  313. navToDetailPage(item) {
  314. uni.navigateTo({
  315. url: '/pages/product/product?id=' + item.id
  316. });
  317. },
  318. IndexShare() {
  319. let obj = this;
  320. let data = obj.onShareAppMessage();
  321. let item = {
  322. link: data.path, // 分享链接
  323. imgUrl: data.imgUrl,
  324. title: data.title
  325. };
  326. console.log('分享加', item);
  327. weixindata(item);
  328. }
  329. }
  330. };
  331. </script>
  332. <style lang="scss">
  333. /* #ifdef MP || APP-PLUS*/
  334. .input-box {
  335. padding: 25rpx;
  336. /* #ifdef APP-PLUS */
  337. margin-top: var(--status-bar-height);
  338. /* #endif */
  339. background-color: #fe8119;
  340. height: 44px;
  341. .iconsearch {
  342. font-size: 50rpx;
  343. }
  344. .input-content {
  345. border-radius: 99rpx;
  346. flex-grow: 1;
  347. padding: 5rpx 30rpx;
  348. // background-color: rgba(231, 231, 231, 0.7);
  349. background: #ffffff;
  350. .input {
  351. flex-grow: 1;
  352. input {
  353. font-size: $font-base;
  354. }
  355. }
  356. }
  357. .input-button {
  358. padding-left: 20rpx;
  359. font-size: $font-base;
  360. height: 100%;
  361. }
  362. }
  363. /* #endif */
  364. /* 头部 轮播图 */
  365. .carousel-section {
  366. background-color: #ffffff;
  367. width: 100%;
  368. height: 320rpx;
  369. .carousel-box {
  370. display: flex;
  371. justify-content: center;
  372. background-color: #fe8119;
  373. width: 100%;
  374. height: 260rpx;
  375. border-radius: 0 0 100rpx 100rpx;
  376. }
  377. .titleNview-placing {
  378. height: var(--status-bar-height);
  379. padding-top: 44px;
  380. box-sizing: content-box;
  381. }
  382. .carousel {
  383. width: 92%;
  384. height: 240rpx;
  385. .carousel-item {
  386. width: 100%;
  387. height: 100%;
  388. }
  389. image {
  390. width: 100%;
  391. height: 100%;
  392. border-radius: $border-radius-sm;
  393. }
  394. }
  395. }
  396. /* 分类 */
  397. .cate-section {
  398. display: flex;
  399. justify-content: space-around;
  400. align-items: center;
  401. flex-wrap: wrap;
  402. padding: 30rpx 22rpx;
  403. background-color: #ffffff;
  404. .cate-item {
  405. display: flex;
  406. flex-direction: column;
  407. align-items: center;
  408. font-size: $font-sm + 2rpx;
  409. color: $font-color-dark;
  410. }
  411. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  412. image {
  413. width: 88rpx;
  414. height: 88rpx;
  415. margin-bottom: 14rpx;
  416. border-radius: 50%;
  417. opacity: 0.7;
  418. }
  419. }
  420. // 为你推荐
  421. .recommend-box {
  422. background: linear-gradient(180deg, #ffffff, #f8f8f8);
  423. width: 100%;
  424. padding: 0 32rpx;
  425. }
  426. .f-header {
  427. display: flex;
  428. align-items: center;
  429. height: 92rpx;
  430. padding: 6rpx 30rpx 8rpx;
  431. border-radius: 12rpx 12rpx 0 0;
  432. color: #ffffff;
  433. background: linear-gradient(180deg, #fd4646, #ff3535);
  434. .tit-box {
  435. @extend %font-title-box;
  436. font-size: 20rpx;
  437. color: #ffffff;
  438. margin-left: 20rpx;
  439. }
  440. .iconenter {
  441. font-size: $font-lg + 2rpx;
  442. color: #ffffff;
  443. }
  444. .f-left-icon {
  445. font-size: 34rpx;
  446. border-right: 1rpx solid #ffffff;
  447. padding-right: 18rpx;
  448. }
  449. .iconfont {
  450. font-size: 26rpx;
  451. }
  452. }
  453. .guess-section {
  454. width: 100%;
  455. display: flex;
  456. flex-direction: column;
  457. background-color: #ffffff;
  458. border-radius: 0 0 12rpx 12rpx;
  459. .guess-item {
  460. display: flex;
  461. width: 100%;
  462. padding: 24rpx;
  463. border-bottom: 1rpx solid #f0f0f0;
  464. &:nth-last-child(1) {
  465. border-bottom: none;
  466. }
  467. }
  468. .image-wrapper {
  469. width: 168rpx;
  470. height: 168rpx;
  471. border-radius: 3px;
  472. image {
  473. width: 168rpx;
  474. height: 168rpx;
  475. opacity: 1;
  476. }
  477. }
  478. .info-wrapper {
  479. width: 100%;
  480. display: flex;
  481. flex-direction: column;
  482. margin-left: 20rpx;
  483. }
  484. .title {
  485. font-size: 32rpx;
  486. color: $font-color-dark;
  487. word-break: break-all;
  488. display: -webkit-box;
  489. -webkit-line-clamp: 1;
  490. -webkit-box-orient: vertical;
  491. overflow: hidden;
  492. }
  493. .price-box {
  494. margin-top: 10rpx;
  495. display: flex;
  496. justify-content: space-between;
  497. .price-left {
  498. display: flex;
  499. flex-direction: column;
  500. .price {
  501. margin-top: 8rpx;
  502. line-height: 30rpx;
  503. color: #ff0000;
  504. font-size: 40rpx;
  505. font-weight: 700;
  506. .price-tip {
  507. font-size: 28rpx;
  508. }
  509. }
  510. .ot_price {
  511. margin-top: 50rpx;
  512. line-height: 24rpx;
  513. font-size: 28rpx;
  514. margin-left: 4rpx;
  515. text-decoration: line-through;
  516. color: #aaaaaa;
  517. .price-tip {
  518. font-size: 22rpx;
  519. }
  520. }
  521. }
  522. .price-right {
  523. display: flex;
  524. flex-direction: column;
  525. .people {
  526. margin-top: 32rpx;
  527. font-weight: 700;
  528. color: #999999;
  529. font-size: 22rpx;
  530. text-align: right;
  531. margin-right: 4rpx;
  532. }
  533. .buyNow {
  534. margin-top: 68rpx;
  535. background: linear-gradient(180deg, #fd4646, #ff3535);
  536. border-radius: 26rpx;
  537. padding: 6rpx 18rpx;
  538. font-size: 26rpx;
  539. font-weight: 400;
  540. color: #ffffff;
  541. }
  542. }
  543. }
  544. }
  545. // 热销产品
  546. .hotgoodsheader {
  547. width: 100%;
  548. display: flex;
  549. justify-content: center;
  550. align-items: center;
  551. padding: 32rpx 0 24rpx;
  552. image {
  553. width: 374rpx;
  554. height: 34rpx;
  555. }
  556. }
  557. .hotgoods {
  558. width: 100%;
  559. display: flex;
  560. flex-wrap: wrap;
  561. padding: 0 32rpx 108rpx;
  562. .hotgoods-item {
  563. width: 48%;
  564. background-color: #ffffff;
  565. border-radius: 12rpx;
  566. margin-bottom: 24rpx;
  567. &:nth-child(2n + 1) {
  568. margin-right: 24rpx;
  569. }
  570. .image-wrapper {
  571. width: 100%;
  572. height: 330rpx;
  573. border-radius: 3px;
  574. overflow: hidden;
  575. image {
  576. width: 100%;
  577. height: 100%;
  578. opacity: 1;
  579. border-radius: 12rpx 12rpx 0 0;
  580. }
  581. }
  582. .title {
  583. font-size: $font-base;
  584. color: $font-color-dark;
  585. font-weight: bold;
  586. line-height: 80rpx;
  587. }
  588. .hot-price {
  589. display: flex;
  590. justify-content: space-between;
  591. padding: 0 16rpx 12rpx;
  592. .price {
  593. font-size: 40rpx;
  594. color: #ff0000;
  595. font-weight: 500;
  596. }
  597. .cart-icon {
  598. image {
  599. width: 44rpx;
  600. height: 44rpx;
  601. }
  602. }
  603. }
  604. }
  605. }
  606. .award-box {
  607. width: 100%;
  608. padding: 24rpx 24rpx 0;
  609. background: #ffffff;
  610. image {
  611. width: 100%;
  612. height: 170rpx;
  613. }
  614. }
  615. </style>