index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <template>
  2. <view class="container">
  3. <view class="vheigh"></view>
  4. <!-- 小程序头部兼容 -->
  5. <!-- 顶部logo and 搜索 start-->
  6. <view class="top-search flex">
  7. <view class="search-box flex" @click="clickSearch()">
  8. <image class="search" src="../../static/icon/search-h.png" mode=""></image>
  9. <view class="search-font"><input type="text" placeholder="输入关键词搜索" v-model="productname" /></view>
  10. </view>
  11. </view>
  12. <!-- 顶部logo and 搜索 end-->
  13. <!-- 轮播图 start -->
  14. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  15. <!-- <view class="carousel-item"><image src="../../static/img/index.png" /></view> -->
  16. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"><image :src="item.pic" /></swiper-item>
  17. </swiper>
  18. <!-- 轮播图 end -->
  19. <view class="swiper-btm flex">
  20. <view class="btm-item flex">
  21. <image src="../../static/icon/index-gou.png" mode=""></image>
  22. <view class="">自用购物返利</view>
  23. </view>
  24. <view class="btm-item flex">
  25. <image src="../../static/icon/index-gou.png" mode=""></image>
  26. <view class="">分享好友赚钱</view>
  27. </view>
  28. <view class="btm-item flex">
  29. <image src="../../static/icon/index-gou.png" mode=""></image>
  30. <view class="">超值正品优惠</view>
  31. </view>
  32. </view>
  33. <!-- 分类 -->
  34. <!-- <view class="cate-section">
  35. <navigator url="/pages/product/classify?type=2">
  36. <view class="cate-item">
  37. <image src="/static/icon/c3.png"></image>
  38. <text>报单商品</text>
  39. </view>
  40. </navigator>
  41. <navigator url="/pages/product/list?fid=5&sid=5&tid=6&isFu=1">
  42. <view class="cate-item">
  43. <image src="/static/icon/c5.png"></image>
  44. <text>复购专区</text>
  45. </view>
  46. </navigator>
  47. <view @click="navTo('/pages/user/shareQrCode')">
  48. <view class="cate-item">
  49. <image src="/static/icon/c8.png"></image>
  50. <text>邀请好友</text>
  51. </view>
  52. </view>
  53. </view> -->
  54. <!-- 精品 商品 -->
  55. <view class="guess-section-box">
  56. <view class="guess-section-title"><image src="../../static/img/title.png" mode=""></image></view>
  57. <view class="guess-section">
  58. <view v-for="(item, index) in bastList" :key="index" class="guess-item" @click="navToDetailPage(item)">
  59. <view class="image-wrapper"><image :src="item.image" mode="scaleToFill"></image></view>
  60. <text class="title clamp margin-c-20">{{ item.store_name }}</text>
  61. <view class="cmy-hr"></view>
  62. <view class="price margin-c-20 flex">
  63. <view>
  64. <text class="font-size-sm "></text>
  65. {{ item.price }}
  66. </view>
  67. <!-- <view class="font-size-sm">
  68. <text class="font-color-gray">{{ item.sales }}人购买</text>
  69. </view> -->
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import { loadIndexs } from '@/api/index.js';
  78. import { getUserInfo } from '@/api/user.js';
  79. import { getProducts } from '@/api/product.js';
  80. import { saveUrl, interceptor } from '@/utils/loginUtils.js';
  81. import { mapState } from 'vuex';
  82. export default {
  83. watch: {
  84. //自适应swiper高度
  85. checkid(newValue, oldValue) {
  86. let obj = this;
  87. if (newValue == 0) {
  88. let bHeight = Math.ceil(obj.bastList.length / 2);
  89. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  90. }
  91. if (newValue == 1) {
  92. let bHeight = Math.ceil(obj.goodsList.length / 2);
  93. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  94. }
  95. if (newValue == 2) {
  96. let bHeight = Math.ceil(obj.bastBanner.length / 2);
  97. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  98. }
  99. }
  100. // 初次加载页面高度时修改页面高度
  101. // bastList(newValue, oldValue) {
  102. // let obj = this;
  103. // let bHeight = Math.ceil(newValue.length / 2);
  104. // obj.$nextTick(function() {
  105. // uni.createSelectorQuery()
  106. // .select('#list-box')
  107. // .fields(
  108. // {
  109. // size: true
  110. // },
  111. // function(data) {
  112. // obj.pageProportion = data.width / 750;
  113. // obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight);
  114. // }
  115. // )
  116. // .exec();
  117. // });
  118. // }
  119. },
  120. data() {
  121. return {
  122. pageProportion: 0, //保存页面基于750宽度的比例
  123. productname: '',
  124. swiperHeight: 0,
  125. checkid: 0,
  126. titleNViewBackground: '',
  127. carouselList: [], //轮播列表
  128. bastList: [], //精品推荐列表
  129. page: 1,
  130. limit: 10,
  131. loadingType: 'more' //加载更多状态
  132. };
  133. },
  134. computed: {
  135. ...mapState(['loginInterceptor']),
  136. ...mapState('user', ['hasLogin', 'userInfo'])
  137. },
  138. onLoad: function(option) {
  139. // #ifndef MP
  140. if (option.spread) {
  141. // 存储其他邀请人
  142. uni.setStorageSync('spread', option.spread);
  143. }
  144. // #endif
  145. // #ifdef MP
  146. if (option.scene) {
  147. // 存储小程序邀请人
  148. uni.setStorage({
  149. key: 'spread_code',
  150. data: option.scene
  151. });
  152. }
  153. // #endif
  154. },
  155. onReachBottom() {
  156. this.loadData();
  157. },
  158. onShow: function() {
  159. // 判断是否强制登录
  160. if (this.loginInterceptor && !this.hasLogin) {
  161. // 登录拦截
  162. interceptor();
  163. }
  164. this.productname = '';
  165. this.loadingType = 'more';
  166. this.page = 1;
  167. this.bastList = []; //精品推荐列表
  168. this.loadData();
  169. },
  170. //下拉刷新
  171. onPullDownRefresh() {
  172. this.loadData();
  173. },
  174. methods: {
  175. navTo(url) {
  176. if (!this.hasLogin) {
  177. // 保存地址
  178. saveUrl();
  179. // 登录拦截
  180. interceptor();
  181. } else {
  182. uni.navigateTo({
  183. url
  184. });
  185. }
  186. },
  187. // 监听切换事件
  188. listChange(e) {
  189. this.checkid = e.detail.current;
  190. },
  191. // 點擊搜索框
  192. clickSearch() {
  193. this.bastList = [];
  194. this.page = 1;
  195. this.limit = 10;
  196. this.loadingType = 'more';
  197. this.loadData();
  198. },
  199. // 请求载入数据
  200. async loadData() {
  201. let obj = this;
  202. loadIndexs({})
  203. .then(({ data }) => {
  204. let goods = data.info;
  205. this.carouselList = data.banner;
  206. this.swiperLength = this.carouselList.length;
  207. if (obj.loadingType == 'nomore' || obj.loadingType == 'loading') {
  208. return;
  209. }
  210. obj.loadingType = 'loading';
  211. getProducts({
  212. page: obj.page,
  213. limit: obj.limit,
  214. set_vip: 1,
  215. keyword: obj.productname
  216. })
  217. .then(({ data }) => {
  218. obj.bastList = obj.bastList.concat(data);
  219. //判断是否还有下一页,有是more 没有是nomore
  220. if (obj.limit == data.length) {
  221. obj.page++;
  222. obj.loadingType = 'more';
  223. } else {
  224. obj.loadingType = 'nomore';
  225. }
  226. uni.stopPullDownRefresh();
  227. })
  228. .catch(e => {
  229. console.log(e);
  230. });
  231. })
  232. .catch(e => {
  233. uni.stopPullDownRefresh();
  234. });
  235. },
  236. //轮播图切换修改背景色
  237. swiperChange(e) {
  238. const index = e.detail.current;
  239. this.swiperCurrent = index;
  240. this.titleNViewBackground = this.carouselList[index].background;
  241. },
  242. //详情页
  243. navToDetailPage(item) {
  244. let id = item.id;
  245. uni.navigateTo({
  246. url: '/pages/product/product?id=' + id + '&isPao=1'
  247. });
  248. },
  249. // 轮播图跳转
  250. bannerNavToUrl(item) {
  251. // #ifdef H5
  252. if (item.wap_url.indexOf('http') > 0) {
  253. window.location.href = item.wap_url;
  254. }
  255. // #endif
  256. //测试数据没有写id,用title代替
  257. uni.navigateTo({
  258. url: item.wap_url
  259. });
  260. }
  261. }
  262. };
  263. </script>
  264. <style lang="scss">
  265. page {
  266. .cate-section {
  267. position: relative;
  268. z-index: 5;
  269. border-radius: 16rpx 16rpx 0 0;
  270. margin-top: -20rpx;
  271. }
  272. }
  273. page {
  274. background: #f7f8f7;
  275. }
  276. .top-search {
  277. height: 80rpx;
  278. padding: 0 20rpx;
  279. background-color: #fff;
  280. .search-box {
  281. justify-content: center;
  282. width: 698rpx;
  283. height: 60rpx;
  284. background: #eeeeee;
  285. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  286. border-radius: 30rpx;
  287. .search {
  288. width: 34rpx;
  289. height: 34rpx;
  290. }
  291. .search-font {
  292. width: 500rpx;
  293. margin-left: 14rpx;
  294. font-size: 28rpx;
  295. font-family: PingFang SC;
  296. font-weight: 500;
  297. color: #cbcbcb;
  298. }
  299. }
  300. }
  301. // 顶部轮播图
  302. .top-swiper {
  303. width: 750rpx;
  304. height: 360rpx;
  305. // margin: 20rpx 0 0;
  306. image {
  307. width: 750rpx;
  308. height: 360rpx;
  309. }
  310. }
  311. .swiper-btm {
  312. height: 60rpx;
  313. width: 750rpx;
  314. background-color: #fff;
  315. margin-bottom: 20rpx;
  316. font-size: 21rpx;
  317. font-weight: 500;
  318. color: #333333;
  319. .btm-item {
  320. flex-grow: 1;
  321. justify-content: center;
  322. image {
  323. width: 25rpx;
  324. height: 25rpx;
  325. margin-right: 14rpx;
  326. }
  327. }
  328. }
  329. /* 分类 */
  330. .cate-section {
  331. display: flex;
  332. justify-content: space-around;
  333. align-items: center;
  334. flex-wrap: wrap;
  335. padding: 30rpx 22rpx;
  336. .cate-item {
  337. display: flex;
  338. flex-direction: column;
  339. align-items: center;
  340. font-size: $font-sm + 2rpx;
  341. color: $font-color-dark;
  342. }
  343. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  344. image {
  345. width: 88rpx;
  346. height: 88rpx;
  347. margin-bottom: 14rpx;
  348. border-radius: 50%;
  349. opacity: 0.7;
  350. }
  351. }
  352. /*公用边框样式*/
  353. %icon {
  354. margin-right: 10rpx;
  355. display: inline-block;
  356. padding: 2rpx 10rpx;
  357. border: 1rpx solid $color-yellow;
  358. color: $color-yellow;
  359. line-height: 1;
  360. font-size: $font-base;
  361. border-radius: 10rpx;
  362. }
  363. .vheigh {
  364. height: var(--status-bar-height);
  365. }
  366. /* 猜你喜欢 */
  367. .guess-section {
  368. display: flex;
  369. flex-wrap: wrap;
  370. padding: 0 30rpx;
  371. .guess-item {
  372. overflow: hidden;
  373. display: flex;
  374. flex-direction: column;
  375. width: 48%;
  376. margin-bottom: 4%;
  377. border-radius: $border-radius-sm;
  378. background-color: white;
  379. box-shadow: $box-shadow;
  380. &:nth-child(2n + 1) {
  381. margin-right: 4%;
  382. }
  383. }
  384. .image-wrapper {
  385. width: 100%;
  386. height: 330rpx;
  387. border-radius: 3px;
  388. overflow: hidden;
  389. image {
  390. width: 100%;
  391. height: 100%;
  392. opacity: 1;
  393. }
  394. }
  395. .title {
  396. font-size: $font-base;
  397. color: $font-color-dark;
  398. font-weight: bold;
  399. line-height: 80rpx;
  400. }
  401. .price {
  402. font-size: $font-lg;
  403. color: $font-color-base;
  404. font-weight: bold;
  405. line-height: 1;
  406. line-height: 80rpx;
  407. }
  408. .icon {
  409. @extend %icon;
  410. }
  411. .detail {
  412. line-height: 1;
  413. }
  414. .tip {
  415. color: white;
  416. background-color: $color-yellow;
  417. line-height: 1.5;
  418. font-size: $font-sm;
  419. padding-left: 20rpx;
  420. }
  421. }
  422. // 推荐
  423. .recommend {
  424. width: 95%;
  425. height: 155rpx;
  426. margin: 0rpx auto;
  427. padding-top: 30rpx;
  428. font-size: 26rpx;
  429. text-align: center;
  430. color: #333333;
  431. align-items: flex-start;
  432. .recommend_list {
  433. width: 33%;
  434. }
  435. .re_title {
  436. font-size: 32rpx;
  437. font-weight: bold;
  438. }
  439. .re_name {
  440. color: #999999;
  441. padding-top: 10rpx;
  442. }
  443. .selected_icon {
  444. width: 25rpx;
  445. height: 10rpx;
  446. margin: 0px auto;
  447. display: none;
  448. image {
  449. width: 100%;
  450. height: 100%;
  451. }
  452. }
  453. .active {
  454. display: block;
  455. }
  456. .active_color {
  457. color: #dc4d46 !important;
  458. }
  459. }
  460. // 列表
  461. .list-box-h {
  462. height: 1550rpx;
  463. }
  464. // 优惠券
  465. .coupon-list {
  466. display: inline-block;
  467. }
  468. .row {
  469. border-radius: 15rpx;
  470. margin: 25rpx;
  471. height: 155rpx;
  472. // width: 552rpx;
  473. overflow: hidden;
  474. background-color: #ffffff;
  475. padding-right: 25rpx;
  476. .list-interval {
  477. border: 1px dashed $border-color-light;
  478. height: 100%;
  479. .top,
  480. .bottom {
  481. border-radius: 100rpx;
  482. width: 30rpx;
  483. height: 30rpx;
  484. position: absolute;
  485. background-color: $page-color-base;
  486. right: -15rpx;
  487. }
  488. .top {
  489. top: -18rpx;
  490. }
  491. .bottom {
  492. bottom: -18rpx;
  493. }
  494. }
  495. .list-money {
  496. height: 100%;
  497. min-width: 155rpx;
  498. text-align: center;
  499. image {
  500. height: 100%;
  501. width: 20rpx;
  502. }
  503. .list-money-text {
  504. flex-grow: 1;
  505. padding: 0 25rpx;
  506. .tit {
  507. text-align: center;
  508. padding: 15rpx 0rpx;
  509. font-size: 55rpx;
  510. color: $color-red;
  511. font-weight: bold;
  512. &.noAction {
  513. color: $font-color-light;
  514. }
  515. }
  516. .price {
  517. padding-bottom: 25rpx;
  518. color: $font-color-light;
  519. }
  520. }
  521. }
  522. .row_list_right {
  523. // flex-grow: 1;
  524. min-width: 200rpx;
  525. padding-left: 25rpx;
  526. line-height: 1;
  527. .right_time {
  528. padding: 10rpx 0rpx;
  529. color: $font-color-light;
  530. font-size: $font-sm;
  531. }
  532. .right_top {
  533. margin: 15rpx 0;
  534. .right_name {
  535. font-size: $font-base;
  536. color: #bc253a;
  537. font-weight: bold;
  538. }
  539. .right_title {
  540. font-size: $font-base;
  541. color: $font-base;
  542. font-weight: bold;
  543. &.noAction {
  544. color: $font-color-light;
  545. }
  546. }
  547. }
  548. }
  549. .right_use {
  550. margin: 15rpx 0;
  551. padding: 10rpx;
  552. width: 160rpx;
  553. text-align: center;
  554. color: #fff;
  555. background-color: #bc253a;
  556. border-radius: 50rpx;
  557. font-size: $font-sm;
  558. &.noAction {
  559. background-color: $font-color-light;
  560. }
  561. }
  562. .iconlocation {
  563. font-size: 36rpx;
  564. color: $font-color-light;
  565. }
  566. }
  567. .guess-section-box {
  568. margin-top: 20rpx;
  569. width: 750rpx;
  570. background: #fff;
  571. padding-top: 30rpx;
  572. .guess-section-title {
  573. width: 450rpx;
  574. height: 30rpx;
  575. margin: 0 auto 36rpx;
  576. image {
  577. width: 100%;
  578. height: 100%;
  579. }
  580. }
  581. }
  582. </style>