时空网前端
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.

282 lines
7.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 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. },
  83. // 获取分类tab
  84. getCategoryList(options = {}){
  85. this.$http(this.API.API_CATEGORY_LIST).then(res => {
  86. let res_list = res.data || [];
  87. let tab_list = res_list.map(item => {
  88. return {
  89. id: item.id,
  90. name: item.name,
  91. type: item.type,
  92. list: [],
  93. loadingClass: true,
  94. loadingText: '正在加载中',
  95. page: 1,
  96. isPage: true
  97. }
  98. });
  99. if(options.type == 'pageRefresh'){
  100. uni.stopPullDownRefresh();
  101. }else if(options.type == 'scrollRefresh'){
  102. this.isRefresher = false;
  103. }
  104. this.tab_list = tab_list;
  105. this.getGoodsList();
  106. })
  107. },
  108. // 获取分类下的商品列表
  109. getGoodsList(){
  110. let per_page = this.pageSize;
  111. let tab_item = this.tab_list[this.current];
  112. this.$http(this.API.API_GOODS_LIST, {
  113. category_id: tab_item.id,
  114. type: tab_item.type,
  115. page: tab_item.page,
  116. per_page
  117. }).then(res => {
  118. let isPage = res.data.has_more_page;
  119. tab_item.isPage = isPage;
  120. if(!isPage){
  121. tab_item.loadingClass = false;
  122. tab_item.loadingText = '没有更多数据啦~';
  123. }
  124. if(tab_item.page == 1){
  125. tab_item.list = res.data.items;
  126. }else{
  127. tab_item.list.push(...res.data.items);
  128. }
  129. })
  130. },
  131. // 去到详情页
  132. toDetail(item){
  133. this.$url('/pages/goodsDetail/index?id='+ item.id);
  134. },
  135. // 页面触底,加载下一页
  136. onScrolltolower(){
  137. let tab_item = this.tab_list[this.current];
  138. if(tab_item.isPage){
  139. tab_item.page = tab_item.page + 1;
  140. this.getGoodsList();
  141. }
  142. },
  143. // scroll-view 下拉刷新
  144. onRefresherrefresh(){
  145. this.isRefresher = true;
  146. this.getCategoryList({type: 'scrollRefresh'});
  147. }
  148. },
  149. // page 下拉刷新
  150. onPullDownRefresh(){
  151. // 新版逻辑,刷新则整个数据全部重新获取
  152. this.getCategoryList({type: 'pageRefresh'});
  153. // 旧版逻辑,刷新只刷tab下的商品列表
  154. // let tab_item = this.tab_list[this.current];
  155. // tab_item.page = 1;
  156. // tab_item.isPage = true;
  157. // tab_item.loadingClass = true;
  158. // tab_item.loadingText = '正在加载中';
  159. // this.getGoodsList();
  160. },
  161. onShareAppMessage(){
  162. let shareInfo = {
  163. title: this.shareInfo.title || '欢迎使用时空网小程序',
  164. path: '/pages/route/index?route=home'
  165. }
  166. if(this.shareInfo.cover){
  167. shareInfo.imageUrl = this.shareInfo.cover;
  168. }
  169. return shareInfo;
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .title {
  175. font-size: 28rpx;
  176. color: $u-content-color;
  177. height: 88rpx;
  178. }
  179. // tab
  180. .ctab{
  181. width: 100%;
  182. margin: 20rpx 0 0rpx 0rpx;
  183. padding: 0 22rpx;
  184. }
  185. // 商品列表
  186. .com{
  187. width: 100%;
  188. height: 100%;
  189. overflow: hidden;
  190. .list{
  191. border-radius: 10rpx;
  192. overflow: hidden;
  193. margin: 20rpx 32rpx;
  194. background-color: #FFFFFF;
  195. box-shadow: 0 10rpx 20rpx 0 rgba(0, 0, 0, 0.1);
  196. align-items: flex-start;
  197. .left{
  198. overflow: hidden;
  199. image{
  200. width: 204rpx;
  201. height: 204rpx;
  202. margin: 20rpx;
  203. border-radius: 10rpx;
  204. }
  205. }
  206. .right{
  207. overflow: hidden;
  208. width: 64%;
  209. .title{
  210. margin: 18rpx 20rpx 0 0;
  211. color: #222222;
  212. font-size: 32rpx;
  213. }
  214. .tips{
  215. margin: 16rpx 0;
  216. overflow: hidden;
  217. .u-line-progress{
  218. width: 112rpx;
  219. overflow: hidden;
  220. margin-right:20rpx ;
  221. }
  222. .progress{
  223. color: #777777;
  224. font-size: 24rpx;
  225. }
  226. .bought{
  227. color: #777777;
  228. font-size: 24rpx;
  229. margin-right: 20rpx;
  230. }
  231. }
  232. .price{
  233. overflow: hidden;
  234. color:#FF0000;
  235. .original-price{
  236. text-decoration: line-through;
  237. color: #777777;
  238. }
  239. // text{
  240. // font-size: 48rpx;
  241. // color:#FF0000;
  242. // font-weight: 500;
  243. // }
  244. // text:nth-child(1){
  245. // color: #FF0000;
  246. // font-size: 28rpx;
  247. // }
  248. // text:nth-child(2){
  249. // color: #FF0000;
  250. // font-size: 48rpx;
  251. // }
  252. // text:nth-child(3){
  253. // color: #FF0000;
  254. // font-size: 28rpx;
  255. // }
  256. // text:nth-child(4){
  257. // color: #777777;
  258. // font-size: 28rpx;
  259. // text-decoration:line-through;
  260. // font-weight: 400;
  261. // }
  262. button{
  263. width: 160rpx;
  264. height: 60rpx;
  265. background: #FE9903;
  266. border-radius: 50px;
  267. font-size: 24rpx;
  268. color: #FFFFFF;
  269. margin: 0rpx 20rpx 0rpx 20rpx;
  270. border: none;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. </style>