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

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