index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <template>
  2. <view class="container">
  3. <!-- 头部轮播 -->
  4. <view class="carousel-section">
  5. <!-- 标题栏和状态栏占位符 -->
  6. <view class="titleNview-placing"></view>
  7. <swiper class="carousel" autoplay="true" duration="400" interval="5000">
  8. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item" @click="bannerNavToUrl(item)"><image :src="item.pic" /></swiper-item>
  9. </swiper>
  10. </view>
  11. <view class="tongz flex">
  12. <view>
  13. <view class="tongz-bg"><image src="../../static/img/xtxx.png" mode=""></image></view>
  14. <view class="tongz-left flex">
  15. <image class="image-left" src="../../static/icon/ld.png" mode=""></image>
  16. <u-notice-bar
  17. style="width: 100%;"
  18. mode="vertical"
  19. type="none"
  20. :volume-icon="false"
  21. :more-icon="true"
  22. :list="showTitle"
  23. @click="goDetails"
  24. @getMore="nav('/pages/user/addmen?id=2')"
  25. ></u-notice-bar>
  26. </view>
  27. </view>
  28. </view>
  29. <u-tabs :list="typeList" active-color="#4E6CFF" name="name" bg-color="transparent" :current="typeIndex" @change="changeType"></u-tabs>
  30. <swiper class="list-box" @change="listChange" :style="{ height: swiperHeight + 'px' }" :current="typeIndex">
  31. <swiper-item v-for="ls in typeList">
  32. <!-- <view class="guess-section">
  33. <view v-for="(item, index) in ls.list" :key="index" class="guess-item" @click="navToDetailPage(item)">
  34. <view class="image-wrapper"><image :src="item.image" mode="scaleToFill"></image></view>
  35. <text class="title clamp2 margin-c-20">{{ item.store_name }}</text>
  36. <view class="cmy-hr"></view>
  37. <view class="price margin-c-20 flex">
  38. <view>
  39. <image class="iconJf" src="../../static/icon/iconU1.png" mode="widthFix"></image>
  40. {{ item.price }}
  41. </view>
  42. <view class="font-size-sm">
  43. <text class="font-color-gray">{{ item.sales }}人购买</text>
  44. </view>
  45. </view>
  46. </view>
  47. </view> -->
  48. <view class="good-wrapper">
  49. <view class="good" v-for="(item, index) in ls.list" :key="index" @click="navToDetailPage(item)">
  50. <view class="image-wrapper"><image :src="item.image" mode="scaleToFill"></image></view>
  51. <view class="good-info">
  52. <view class="info-title clamp2">
  53. {{item.store_name}}
  54. </view>
  55. <view class="info-price">
  56. <image class="jff" src="../../static/icon/iconU1.png" mode="widthFix"></image>{{item.price}}
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <u-loadmore :status="ls.load" />
  62. </swiper-item>
  63. </swiper>
  64. </view>
  65. </template>
  66. <script>
  67. import { loadIndexs, article } from '@/api/index.js';
  68. import { getUserInfo } from '@/api/user.js';
  69. import { interceptor } from '@/utils/loginUtils';
  70. import { mapState } from 'vuex';
  71. import { getCategoryList, getProducts } from '@/api/product.js';
  72. export default {
  73. data() {
  74. return {
  75. shareShow: false, //分享海报
  76. pageProportion: 0, //保存页面基于750宽度的比例
  77. swiperHeight: 0,
  78. swiperLength: 0,
  79. carouselList: [], //轮播列表
  80. page: 1,
  81. limit: 5,
  82. // 商品分类数据
  83. typeList: [{}],
  84. //保存当前选中的分类
  85. typeIndex: 0,
  86. showList: [],
  87. showTitle: []
  88. };
  89. },
  90. computed: {
  91. ...mapState('user', ['hasLogin', 'userInfo'])
  92. },
  93. onLoad: function(option) {
  94. // #ifndef MP
  95. if (option.spread) {
  96. // 存储其他邀请人
  97. uni.setStorageSync('spread', option.spread);
  98. }
  99. // #endif
  100. this.init();
  101. this.getShowList()
  102. },
  103. //下拉刷新
  104. onPullDownRefresh() {
  105. this.init();
  106. },
  107. // #ifndef MP
  108. // 监听导航栏输入框点击事件
  109. onNavigationBarSearchInputClicked(e) {
  110. //跳转到搜索页面
  111. this.clickSearch();
  112. },
  113. // #endif
  114. onReachBottom() {
  115. this.getProducts(this.typeList[this.typeIndex]);
  116. },
  117. methods: {
  118. // 初始化页面数据
  119. init() {
  120. this.loadData();
  121. // 获取分类
  122. this.getType();
  123. // 获取页面初始比例
  124. this.getBl();
  125. },
  126. // 获取初始化页面比例
  127. getBl() {
  128. let obj = this;
  129. obj.$nextTick(function() {
  130. uni.createSelectorQuery()
  131. .select('.container')
  132. .fields(
  133. {
  134. size: true
  135. },
  136. function(data) {
  137. obj.pageProportion = data.width / 750;
  138. }
  139. )
  140. .exec();
  141. });
  142. },
  143. // 设置切换高度
  144. getlistHeight(item) {
  145. let obj = this;
  146. let bHeight = Math.ceil(item.length / 2);
  147. obj.swiperHeight = Math.ceil(obj.pageProportion * 520 * bHeight + 30);
  148. },
  149. // tabs切换
  150. changeType(e) {
  151. console.log(e, 'dianji');
  152. console.log(this.typeList[e])
  153. this.typeIndex = e;
  154. // 判断是否已经加载过数据
  155. const item = this.typeList[this.typeIndex];
  156. if (!item.loding) {
  157. this.getProducts(item);
  158. }
  159. },
  160. // sw切换
  161. listChange(e) {
  162. if (e.detail.current != this.typeIndex) {
  163. this.typeIndex = e.detail.current;
  164. // 判断是否已经加载过数据
  165. const item = this.typeList[this.typeIndex];
  166. if (!item.loding) {
  167. this.getProducts(item);
  168. }
  169. }
  170. },
  171. //商品详情页
  172. navToDetailPages(item) {
  173. let id = item.product_id;
  174. //let type = 2;
  175. uni.navigateTo({
  176. url: '/pages/product/product?id=' + id
  177. });
  178. },
  179. // 获取商品分类
  180. getType() {
  181. const obj = this;
  182. getCategoryList({})
  183. .then(({ data }) => {
  184. obj.typeList = data.map(function(s) {
  185. return {
  186. name: s.cate_name,
  187. id: s.id,
  188. page: 1,
  189. limit: 10,
  190. list: [],
  191. load: 'loadmore', //loadmore/loading / nomore
  192. isLoding: false //用于判断是否已经载入过分类
  193. };
  194. });
  195. // 加载商品
  196. obj.getProducts(this.typeList[this.typeIndex]);
  197. })
  198. .catch(err => {
  199. console.log(err);
  200. });
  201. },
  202. // 获取商品信息
  203. getProducts(item) {
  204. // 判断是否已经没有数据
  205. if (item.load == 'nomore') {
  206. return;
  207. }
  208. // 判断是否加载中
  209. if (item.load == 'loading') {
  210. return;
  211. }
  212. // 判断是否为初次加载
  213. if (!item.isLoding) {
  214. item.isLoding = true;
  215. }
  216. // 设置开始加载
  217. item.load = 'loading';
  218. getProducts({
  219. cid: item.id,
  220. page: item.page,
  221. limit: item.limit
  222. })
  223. .then(e => {
  224. item.list = item.list.concat(e.data);
  225. if (item.list.length == item.limit) {
  226. item.page++;
  227. item.load = 'loadmore';
  228. } else {
  229. item.load = 'nomore';
  230. }
  231. // 初始化高度
  232. this.getlistHeight(item.list);
  233. })
  234. .catch(e => {
  235. console.log(e);
  236. });
  237. },
  238. // 點擊搜索框
  239. clickSearch() {
  240. uni.navigateTo({
  241. url: '/pages/product/search'
  242. });
  243. },
  244. // 请求载入数据
  245. async loadData() {
  246. loadIndexs({})
  247. .then(({ data }) => {
  248. let goods = data.info;
  249. this.carouselList = data.banner;
  250. this.swiperLength = this.carouselList.length;
  251. this.menusList = data.menus;
  252. uni.stopPullDownRefresh();
  253. })
  254. .catch(e => {
  255. uni.stopPullDownRefresh();
  256. });
  257. },
  258. //详情页
  259. navToDetailPage(item) {
  260. let id = item.id;
  261. uni.navigateTo({
  262. url: '/pages/product/product?id=' + id
  263. });
  264. },
  265. // 轮播图跳转
  266. bannerNavToUrl(item) {
  267. // #ifdef H5
  268. if (item.wap_url.indexOf('http') > 0) {
  269. window.location.href = item.wap_url;
  270. }
  271. // #endif
  272. //测试数据没有写id,用title代替
  273. uni.navigateTo({
  274. url: item.wap_url
  275. });
  276. },
  277. //获取系统消息
  278. getShowList() {
  279. article({
  280. page: 1,
  281. limit: 3
  282. },2).then( ({data}) => {
  283. this.showList = data
  284. this.showTitle = data.map( item => {
  285. return item.title
  286. })
  287. })
  288. },
  289. //系统消息跳转详情
  290. goDetails(e) {
  291. console.log(e)
  292. uni.navigateTo({
  293. url: '/pages/user/addmenDetail?id=' + this.showList[e].id
  294. });
  295. },
  296. nav(url) {
  297. // console.log('dddddddddddddddddd')
  298. uni.navigateTo({
  299. url: url
  300. })
  301. }
  302. }
  303. };
  304. </script>
  305. <style lang="scss">
  306. page {
  307. background: #f7f8f7;
  308. }
  309. .m-t {
  310. margin-top: 16rpx;
  311. }
  312. .list-box {
  313. margin-top: 30rpx;
  314. }
  315. /* 头部 轮播图 */
  316. .carousel-section {
  317. position: relative;
  318. padding-top: 10px;
  319. overflow: hidden;
  320. background: url(../../static/img/indexBg.png) no-repeat;
  321. background-size: 100% 100%;
  322. .titleNview-placing {
  323. height: var(--status-bar-height);
  324. padding-top: 44px;
  325. box-sizing: content-box;
  326. }
  327. .titleNview-background {
  328. position: absolute;
  329. top: 0;
  330. left: 0;
  331. width: 100%;
  332. height: 426rpx;
  333. transition: 0.4s;
  334. }
  335. .carousel {
  336. width: 680rpx;
  337. height: 340rpx;
  338. margin: 0 auto;
  339. .carousel-item {
  340. width: 100%;
  341. height: 100%;
  342. overflow: hidden;
  343. }
  344. image {
  345. width: 100%;
  346. height: 100%;
  347. border-radius: $border-radius-sm;
  348. }
  349. }
  350. }
  351. /*公用边框样式*/
  352. %icon {
  353. margin-right: 10rpx;
  354. display: inline-block;
  355. padding: 2rpx 10rpx;
  356. border: 1rpx solid $color-yellow;
  357. color: $color-yellow;
  358. line-height: 1;
  359. font-size: $font-base;
  360. border-radius: 10rpx;
  361. }
  362. .f-header {
  363. display: flex;
  364. align-items: center;
  365. height: 92rpx;
  366. padding: 6rpx 30rpx 8rpx;
  367. image {
  368. flex-shrink: 0;
  369. width: 80rpx;
  370. height: 80rpx;
  371. margin-right: 20rpx;
  372. }
  373. .tit-box {
  374. @extend %font-title-box;
  375. }
  376. .tit {
  377. @extend %font-title;
  378. }
  379. .iconenter {
  380. font-size: $font-lg + 2rpx;
  381. color: $font-color-light;
  382. }
  383. .f-left-icon {
  384. @extend %f-left-icon;
  385. }
  386. .iconfont {
  387. font-size: $font-sm - 2rpx;
  388. }
  389. }
  390. /* 商品列表 */
  391. .guess-section {
  392. display: flex;
  393. flex-wrap: wrap;
  394. padding: 0 30rpx;
  395. .guess-item {
  396. overflow: hidden;
  397. display: flex;
  398. flex-direction: column;
  399. width: 48%;
  400. margin-bottom: 4%;
  401. border-radius: $border-radius-sm;
  402. background-color: white;
  403. box-shadow: $box-shadow;
  404. &:nth-child(2n + 1) {
  405. margin-right: 4%;
  406. }
  407. }
  408. .image-wrapper {
  409. width: 100%;
  410. height: 330rpx;
  411. border-radius: 3px;
  412. overflow: hidden;
  413. image {
  414. width: 100%;
  415. height: 100%;
  416. opacity: 1;
  417. }
  418. }
  419. .title {
  420. padding-top: 10rpx;
  421. font-size: $font-base;
  422. color: $font-color-dark;
  423. font-weight: bold;
  424. line-height: 1.5;
  425. }
  426. .price {
  427. font-size: $font-lg;
  428. color: $base-color;
  429. font-weight: bold;
  430. line-height: 1;
  431. line-height: 80rpx;
  432. .iconJf {
  433. width: 23rpx;
  434. margin-right: 5rpx;
  435. }
  436. }
  437. .icon {
  438. @extend %icon;
  439. }
  440. .detail {
  441. line-height: 1;
  442. }
  443. .tip {
  444. color: white;
  445. background-color: $color-yellow;
  446. line-height: 1.5;
  447. font-size: $font-sm;
  448. padding-left: 20rpx;
  449. }
  450. }
  451. // 列表
  452. .list-box-h {
  453. height: 1550rpx;
  454. }
  455. .row {
  456. border-radius: 15rpx;
  457. margin: 25rpx;
  458. height: 155rpx;
  459. // width: 552rpx;
  460. overflow: hidden;
  461. background-color: #ffffff;
  462. padding-right: 25rpx;
  463. .list-interval {
  464. border: 1px dashed $border-color-light;
  465. height: 100%;
  466. .top,
  467. .bottom {
  468. border-radius: 100rpx;
  469. width: 30rpx;
  470. height: 30rpx;
  471. position: absolute;
  472. background-color: $page-color-base;
  473. right: -15rpx;
  474. }
  475. .top {
  476. top: -18rpx;
  477. }
  478. .bottom {
  479. bottom: -18rpx;
  480. }
  481. }
  482. .list-money {
  483. height: 100%;
  484. min-width: 155rpx;
  485. text-align: center;
  486. image {
  487. height: 100%;
  488. width: 20rpx;
  489. }
  490. .list-money-text {
  491. flex-grow: 1;
  492. padding: 0 25rpx;
  493. .tit {
  494. text-align: center;
  495. padding: 15rpx 0rpx;
  496. font-size: 55rpx;
  497. color: $color-red;
  498. font-weight: bold;
  499. &.noAction {
  500. color: $font-color-light;
  501. }
  502. }
  503. .price {
  504. padding-bottom: 25rpx;
  505. color: $font-color-light;
  506. }
  507. }
  508. }
  509. .row_list_right {
  510. // flex-grow: 1;
  511. min-width: 200rpx;
  512. padding-left: 25rpx;
  513. line-height: 1;
  514. .right_time {
  515. padding: 10rpx 0rpx;
  516. color: $font-color-light;
  517. font-size: $font-sm;
  518. }
  519. .right_top {
  520. margin: 15rpx 0;
  521. .right_name {
  522. font-size: $font-base;
  523. color: #bc253a;
  524. font-weight: bold;
  525. }
  526. .right_title {
  527. font-size: $font-base;
  528. color: $font-base;
  529. font-weight: bold;
  530. &.noAction {
  531. color: $font-color-light;
  532. }
  533. }
  534. }
  535. }
  536. .right_use {
  537. margin: 15rpx 0;
  538. padding: 10rpx;
  539. width: 160rpx;
  540. text-align: center;
  541. color: #fff;
  542. background-color: #bc253a;
  543. border-radius: 50rpx;
  544. font-size: $font-sm;
  545. &.noAction {
  546. background-color: $font-color-light;
  547. }
  548. }
  549. .iconlocation {
  550. font-size: 36rpx;
  551. color: $font-color-light;
  552. }
  553. }
  554. .xtxx {
  555. width: 100%;
  556. height: 70rpx;
  557. position: relative;
  558. margin: 22rpx 0 20rpx;
  559. .bg {
  560. display: inline-block;
  561. width: 690rpx;
  562. position: absolute;
  563. right: 0;
  564. left: 0;
  565. margin: 0 auto;
  566. }
  567. .ld {
  568. width: 28rpx;
  569. height: 34rpx;
  570. position: absolute;
  571. top: 18rpx;
  572. left: 55rpx;
  573. }
  574. }
  575. .tongz {
  576. width: 690rpx;
  577. height: 70rpx;
  578. margin: 48rpx auto 0;
  579. padding: 18rpx 30rpx 18rpx 24rpx;
  580. align-items: center;
  581. position: relative;
  582. .tongz-bg {
  583. position: absolute;
  584. top: 0;
  585. right: 0;
  586. left: 0;
  587. width: 690rpx;
  588. height: 70rpx;
  589. image {
  590. width: 100%;
  591. height: 100%;
  592. }
  593. }
  594. .tongz-left {
  595. width: 640rpx;
  596. .image-left {
  597. width: 28rpx;
  598. height: 34rpx;
  599. }
  600. .tongz-font {
  601. margin-left: 22rpx;
  602. font-size: 28rpx;
  603. font-family: Source Han Sans CN;
  604. font-weight: 400;
  605. color: #0f253a;
  606. }
  607. }
  608. .tongz-right {
  609. position: relative;
  610. z-index: 11;
  611. width: 12rpx;
  612. height: 26rpx;
  613. image {
  614. width: 100%;
  615. height: 100%;
  616. }
  617. }
  618. }
  619. .good-wrapper {
  620. padding: 0 30rpx;
  621. .good {
  622. width: 681rpx;
  623. height: 257rpx;
  624. background: #FFFFFF;
  625. box-shadow: 0px 0px 15rpx 0px rgba(10, 13, 47, 0.14);
  626. border-radius: 14rpx;
  627. margin: 0 auto 20rpx;
  628. padding: 18rpx 19rpx 17rpx;
  629. display: flex;
  630. .image-wrapper {
  631. width: 222rpx;
  632. height: 222rpx;
  633. border-radius: 14rpx;
  634. flex-shrink: 0;
  635. // background-color: red;
  636. image {
  637. width: 100%;
  638. height: 100%;
  639. opacity: 1;
  640. border-radius: 14rpx;
  641. }
  642. }
  643. .good-info {
  644. padding-left: 22rpx;
  645. position: relative;
  646. .info-title {
  647. padding-top: 20rpx;
  648. font-size: 32rpx;
  649. font-family: PingFang SC;
  650. font-weight: bold;
  651. color: #333333;
  652. }
  653. .info-price {
  654. font-size: 36rpx;
  655. font-family: PingFang SC;
  656. font-weight: bold;
  657. color: #FFC000;
  658. line-height: 35px;
  659. position: absolute;
  660. bottom: 0;
  661. left: 22rpx;
  662. display: flex;
  663. align-items: center;
  664. }
  665. }
  666. }
  667. }
  668. </style>