时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
7.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <view class="lf-row-center lf-flex-column">
  3. <view class="ctab" v-if="tab_list.length">
  4. <u-tabs :list="tab_list" :is-scroll="true" :show-bar="false" :current="current" @change="change"></u-tabs>
  5. </view>
  6. <swiper :style="{height: 'calc('+ windowHeight +'px - 110rpx)', width: '750rpx'}" :current="current" @change="swiperChange">
  7. <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
  8. <scroll-view class="com" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  9. <view class="lf-row-between list" v-for="(item, index) in tab.list" :key="item.id" @click="toDetail(item)">
  10. <view class="left">
  11. <image :src="item.cover" mode="aspectFill"></image>
  12. </view>
  13. <view class="right">
  14. <view class="lf-line-2 title">{{ item.name }}</view>
  15. <view class="lf-flex tips">
  16. <view class="lf-row-between lf-flex-1" v-if="item.specs[0]">
  17. <view class="lf-flex">
  18. <view class="u-line-progress" v-if="item.specs[0].sold_percent">
  19. <u-line-progress :percent="item.specs[0].sold_percent" height="20" :striped="true" active-color="#FE9903" :show-percent="false" inactive-color="#F5F5F5"></u-line-progress>
  20. </view>
  21. <text class="progress lf-m-r-10">{{ item.specs[0].sold_percent_text }}</text>
  22. </view>
  23. <view>
  24. <text class="bought">{{ item.specs[0].sold_stock_text }}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="lf-row-between price">
  29. <lf-price :price="item.specs[0].selling_price" v-if="item.specs[0]"></lf-price>
  30. <text class="lf-font-24 original-price" v-if="item.specs[0]">{{ item.specs[0].original_price }}</text>
  31. <text v-else></text>
  32. <button>立即抢购</button>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 空数据的情况 -->
  37. <view class="loading-more">
  38. <text v-if="tab.list.length" :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  39. <my-nocontent v-else></my-nocontent>
  40. </view>
  41. <!-- 回到顶部 -->
  42. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  43. </scroll-view>
  44. </swiper-item>
  45. </swiper>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. tab_list: [],
  53. current: 0, // tab下表
  54. pageSize: 10,
  55. shareInfo: {},
  56. windowHeight: 0, // 屏幕可用高度
  57. isRefresher: false // scroll-view下拉刷新状态,当前默认没有触发
  58. }
  59. },
  60. onLoad() {
  61. this.windowHeight = getApp().globalData.windowHeight;
  62. this.getCategoryList();
  63. this.getShareInfo();
  64. },
  65. methods: {
  66. // 获取分享信息
  67. getShareInfo(){
  68. this.$http(this.API.API_SHARE_HOME).then(res => {
  69. this.shareInfo = res.data;
  70. });
  71. },
  72. // 切换tab
  73. change(index) {
  74. this.current = index;
  75. if(this.tab_list[index].list.length <= 0){
  76. this.getGoodsList(); // tab下没有数据,请求第一页
  77. }
  78. },
  79. // 滑块下标值变化
  80. swiperChange(event){
  81. this.current = event.detail.current;
  82. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  83. if(this.tab_list[event.detail.current].list.length <= 0){
  84. this.getGoodsList(); // tab下没有数据,请求第一页
  85. }
  86. },
  87. // 获取分类tab
  88. getCategoryList(options = {}){
  89. this.$http(this.API.API_CATEGORY_LIST).then(res => {
  90. let res_list = res.data || [];
  91. let tab_list = res_list.map(item => {
  92. return {
  93. id: item.id,
  94. name: item.name,
  95. type: item.type,
  96. list: [],
  97. loadingClass: true,
  98. loadingText: '正在加载中',
  99. page: 1,
  100. isPage: true
  101. }
  102. });
  103. if(options.type == 'pageRefresh'){
  104. uni.stopPullDownRefresh();
  105. }else if(options.type == 'scrollRefresh'){
  106. this.isRefresher = false;
  107. }
  108. this.tab_list = tab_list;
  109. this.getGoodsList();
  110. })
  111. },
  112. // 获取分类下的商品列表
  113. getGoodsList(){
  114. let per_page = this.pageSize;
  115. let tab_item = this.tab_list[this.current];
  116. this.$http(this.API.API_GOODS_LIST, {
  117. category_id: tab_item.id,
  118. type: tab_item.type,
  119. page: tab_item.page,
  120. per_page
  121. }).then(res => {
  122. let isPage = res.data.has_more_page;
  123. tab_item.isPage = isPage;
  124. if(!isPage){
  125. tab_item.loadingClass = false;
  126. tab_item.loadingText = '没有更多数据啦~';
  127. }
  128. if(tab_item.page == 1){
  129. tab_item.list = res.data.items;
  130. }else{
  131. tab_item.list.push(...res.data.items);
  132. }
  133. })
  134. },
  135. // 去到详情页
  136. toDetail(item){
  137. this.$url('/pages/goodsDetail/index?id='+ item.id);
  138. },
  139. // 页面触底,加载下一页
  140. onScrolltolower(){
  141. let tab_item = this.tab_list[this.current];
  142. if(tab_item.isPage){
  143. tab_item.page = tab_item.page + 1;
  144. this.getGoodsList();
  145. }
  146. },
  147. // scroll-view 下拉刷新
  148. onRefresherrefresh(){
  149. this.isRefresher = true;
  150. this.getCategoryList({type: 'scrollRefresh'});
  151. }
  152. },
  153. // page 下拉刷新
  154. onPullDownRefresh(){
  155. // 新版逻辑,刷新则整个数据全部重新获取
  156. this.getCategoryList({type: 'pageRefresh'});
  157. // 旧版逻辑,刷新只刷tab下的商品列表
  158. // let tab_item = this.tab_list[this.current];
  159. // tab_item.page = 1;
  160. // tab_item.isPage = true;
  161. // tab_item.loadingClass = true;
  162. // tab_item.loadingText = '正在加载中';
  163. // this.getGoodsList();
  164. },
  165. onShareAppMessage(){
  166. let shareInfo = {
  167. title: this.shareInfo.title || '欢迎使用时空网小程序',
  168. path: '/pages/route/index?route=home'
  169. }
  170. if(this.shareInfo.cover){
  171. shareInfo.imageUrl = this.shareInfo.cover;
  172. }
  173. return shareInfo;
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. .title {
  179. font-size: 28rpx;
  180. color: $u-content-color;
  181. height: 88rpx;
  182. }
  183. // tab
  184. .ctab{
  185. width: 100%;
  186. margin: 20rpx 0 0rpx 0rpx;
  187. padding: 0 22rpx;
  188. }
  189. // 商品列表
  190. .com{
  191. width: 100%;
  192. height: 100%;
  193. overflow: hidden;
  194. .list{
  195. border-radius: 10rpx;
  196. overflow: hidden;
  197. margin: 20rpx 32rpx;
  198. background-color: #FFFFFF;
  199. box-shadow: 0 10rpx 20rpx 0 rgba(0, 0, 0, 0.1);
  200. align-items: flex-start;
  201. .left{
  202. overflow: hidden;
  203. image{
  204. width: 204rpx;
  205. height: 204rpx;
  206. margin: 20rpx;
  207. border-radius: 10rpx;
  208. }
  209. }
  210. .right{
  211. overflow: hidden;
  212. width: 64%;
  213. .title{
  214. margin: 18rpx 20rpx 0 0;
  215. color: #222222;
  216. font-size: 32rpx;
  217. }
  218. .tips{
  219. margin: 16rpx 0;
  220. overflow: hidden;
  221. .u-line-progress{
  222. width: 112rpx;
  223. overflow: hidden;
  224. margin-right:20rpx ;
  225. }
  226. .progress{
  227. color: #777777;
  228. font-size: 24rpx;
  229. }
  230. .bought{
  231. color: #777777;
  232. font-size: 24rpx;
  233. margin-right: 20rpx;
  234. }
  235. }
  236. .price{
  237. overflow: hidden;
  238. color:#FF0000;
  239. .original-price{
  240. text-decoration: line-through;
  241. color: #777777;
  242. }
  243. // text{
  244. // font-size: 48rpx;
  245. // color:#FF0000;
  246. // font-weight: 500;
  247. // }
  248. // text:nth-child(1){
  249. // color: #FF0000;
  250. // font-size: 28rpx;
  251. // }
  252. // text:nth-child(2){
  253. // color: #FF0000;
  254. // font-size: 48rpx;
  255. // }
  256. // text:nth-child(3){
  257. // color: #FF0000;
  258. // font-size: 28rpx;
  259. // }
  260. // text:nth-child(4){
  261. // color: #777777;
  262. // font-size: 28rpx;
  263. // text-decoration:line-through;
  264. // font-weight: 400;
  265. // }
  266. button{
  267. width: 160rpx;
  268. height: 60rpx;
  269. background: #FE9903;
  270. border-radius: 50px;
  271. font-size: 24rpx;
  272. color: #FFFFFF;
  273. margin: 0rpx 20rpx 0rpx 20rpx;
  274. border: none;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. </style>