mall.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="indexBox">
  3. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  4. <swiper-item v-for="item in imagelist" class="carousel-item" @click="navTo(item.url)">
  5. <image class="imageitem" :src="item.pic" />
  6. </swiper-item>
  7. </swiper>
  8. <view class="hot-list-box">
  9. <view class="list-box">
  10. <view class="list" v-for="(item,index) in navList.orderList" @click="navTo('/pages/product/product?id=' + item.id)">
  11. <view class="list-image-box">
  12. <image class="list-image" :src="item.image" mode="widthFix"></image>
  13. </view>
  14. <view class="list-content">
  15. <view class="list-title clamp2">
  16. {{item.store_name}}
  17. </view>
  18. <view class="list-money flex flex-start">
  19. <view class="money">
  20. ¥{{item.price*1}}
  21. </view>
  22. <view class="money old">
  23. ¥{{item.ot_price*1}}
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <uni-load-more :status="navList.loadingType"></uni-load-more>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. mapState,
  36. mapMutations
  37. } from 'vuex';
  38. import {
  39. loadIndexs
  40. } from '@/api/index.js';
  41. import {
  42. groomList
  43. } from '@/api/product.js';
  44. import {
  45. share
  46. } from '@/api/wx';
  47. export default {
  48. data() {
  49. return {
  50. //轮播图
  51. imagelist: [],
  52. // 推荐商品
  53. navList: {
  54. loadingType: 'more',
  55. orderList: [],
  56. page: 1, //当前页数
  57. limit: 10, //每次信息条数
  58. },
  59. // 热门商品
  60. rmList: []
  61. };
  62. },
  63. onLoad: function(option) {
  64. this.getPage();
  65. },
  66. onShow() {
  67. this.loadIndexs();
  68. },
  69. onReady() {},
  70. // 滚动到底部
  71. onReachBottom() {
  72. this.getPage();
  73. },
  74. methods: {
  75. share() {
  76. // console.log('加载分享');
  77. const that = this;
  78. // 请求获取默认数据
  79. share({}).then(({
  80. data
  81. }) => {
  82. // console.log('分享回调', data);
  83. that.shareData = data.data
  84. });
  85. },
  86. // 首页初始化
  87. loadIndexs() {
  88. const that = this;
  89. // 轮播图
  90. loadIndexs().then(
  91. (res) => {
  92. that.imagelist=res.data.banner
  93. console.log(res,'index');
  94. }
  95. ).catch(
  96. (res) => {
  97. console.log(res);
  98. }
  99. )
  100. },
  101. // 获取数据
  102. getPage(source){
  103. //这里是将订单挂载到tab列表下
  104. let navItem = this.navList;
  105. let state = navItem.state;
  106. if (source === 'tabChange' && navItem.loaded === true) {
  107. //tab切换只有第一次需要加载数据
  108. return;
  109. }
  110. if (navItem.loadingType === 'loading') {
  111. //防止重复加载
  112. return;
  113. }
  114. if (navItem.loadingType === 'noMore') {
  115. //防止重复加载
  116. return;
  117. }
  118. // 修改当前对象状态为加载中
  119. navItem.loadingType = 'loading';
  120. groomList({
  121. page: navItem.page,
  122. limit: navItem.limit
  123. },3)
  124. .then(({
  125. data
  126. }) => {
  127. let arr = data.list.map(e => {
  128. return e;
  129. });
  130. navItem.orderList = navItem.orderList.concat(arr);
  131. // console.log(navItem.orderList);
  132. navItem.page++;
  133. if (navItem.limit == data.length) {
  134. //判断是否还有数据, 有改为 more, 没有改为noMore
  135. navItem.loadingType = 'more';
  136. return;
  137. } else {
  138. //判断是否还有数据, 有改为 more, 没有改为noMore
  139. navItem.loadingType = 'noMore';
  140. }
  141. uni.hideLoading();
  142. this.$set(navItem, 'loaded', true);
  143. })
  144. .catch(e => {
  145. console.log(e);
  146. });
  147. },
  148. // 获取模板列表
  149. navTo(url) {
  150. if (url) {
  151. if (url.indexOf('http') > -1) {
  152. // #ifdef H5
  153. window.location.href = url
  154. // #endif
  155. // #ifdef APP
  156. plus.runtime.openURL(url)
  157. // #endif
  158. } else {
  159. uni.navigateTo({
  160. url: url
  161. })
  162. }
  163. }
  164. }
  165. },
  166. };
  167. </script>
  168. <style lang="scss">
  169. page,
  170. .indexBox {
  171. height: auto;
  172. min-height: 100%;
  173. }
  174. .indexBox {
  175. padding-bottom: 50rpx;
  176. }
  177. .top-swiper {
  178. margin: auto;
  179. width: 750rpx;
  180. height: 273rpx;
  181. .carousel-item {
  182. .imageitem {
  183. width: 750rpx;
  184. height: 273rpx;
  185. }
  186. }
  187. }
  188. .hot-list-box {
  189. padding: $page-row-spacing;
  190. background-color: #FFFFFF;
  191. padding-bottom: 0;
  192. .list-box {
  193. display: flex;
  194. flex-wrap: wrap;
  195. justify-content: space-between;
  196. align-items: flex-start;
  197. padding-top: 30rpx;
  198. padding-bottom: 20rpx;
  199. .list {
  200. box-shadow: 0px 0px 20rpx 0px rgba(50,50,52,0.06);
  201. border-radius: 15rpx;
  202. width: 330rpx;
  203. margin-bottom: 30rpx;
  204. .list-image-box {
  205. height:330rpx;
  206. overflow: hidden;
  207. .list-image {
  208. width: 100%;
  209. }
  210. }
  211. .list-content{
  212. padding: 20rpx;
  213. line-height: 1;
  214. .list-title {
  215. color: $font-color-dark;
  216. font-size: $font-base;
  217. margin-bottom: 20rpx;
  218. }
  219. .list-money {
  220. .money {
  221. font: $font-lg;
  222. color: #FF3342;
  223. &.old{
  224. font-size: $font-sm;
  225. color: $font-color-light;
  226. text-decoration:line-through ;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. </style>