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

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