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

253 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. console.log("res", res);
  99. let isPage = res.data.has_more_page;
  100. tab_item.isPage = isPage;
  101. if(!isPage){
  102. tab_item.loadingClass = false;
  103. tab_item.loadingText = '没有更多数据啦~';
  104. }
  105. if(tab_item.page == 1){
  106. tab_item.list = res.data.items;
  107. }else{
  108. tab_item.list.push(...res.data.items);
  109. }
  110. })
  111. },
  112. // 去到详情页
  113. toDetail(item){
  114. this.$url('/pages/goodsDetail/index?id='+ item.id);
  115. }
  116. },
  117. onReachBottom(){
  118. let tab_item = this.tab_list[this.current];
  119. if(tab_item.isPage){
  120. tab_item.page = tab_item.page + 1;
  121. this.getGoodsList();
  122. }
  123. },
  124. onPullDownRefresh(){
  125. let tab_item = this.tab_list[this.current];
  126. tab_item.page = 1;
  127. tab_item.isPage = true;
  128. tab_item.loadingClass = true;
  129. tab_item.loadingText = '正在加载中';
  130. this.getGoodsList();
  131. uni.stopPullDownRefresh()
  132. },
  133. onShareAppMessage(){
  134. let shareInfo = {
  135. title: this.shareInfo.title || '欢迎使用时空网小程序',
  136. path: '/pages/route/index?route=home'
  137. }
  138. if(this.shareInfo.cover){
  139. shareInfo.imageUrl = this.shareInfo.cover;
  140. }
  141. return shareInfo;
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .title {
  147. font-size: 28rpx;
  148. color: $u-content-color;
  149. height: 88rpx;
  150. }
  151. // tab
  152. .ctab{
  153. width: 100%;
  154. margin: 20rpx 0 0rpx 0rpx;
  155. padding: 0 22rpx;
  156. }
  157. // 商品列表
  158. .com{
  159. width: 100%;
  160. overflow: hidden;
  161. .list{
  162. border-radius: 10rpx;
  163. overflow: hidden;
  164. margin: 20rpx 32rpx;
  165. background-color: #FFFFFF;
  166. box-shadow: 0 10rpx 20rpx 0 rgba(0, 0, 0, 0.1);
  167. align-items: flex-start;
  168. .left{
  169. overflow: hidden;
  170. image{
  171. width: 204rpx;
  172. height: 204rpx;
  173. margin: 20rpx;
  174. border-radius: 10rpx;
  175. }
  176. }
  177. .right{
  178. overflow: hidden;
  179. width: 64%;
  180. .title{
  181. margin: 18rpx 20rpx 0 0;
  182. color: #222222;
  183. font-size: 32rpx;
  184. }
  185. .tips{
  186. margin: 16rpx 0;
  187. overflow: hidden;
  188. .u-line-progress{
  189. width: 112rpx;
  190. overflow: hidden;
  191. margin-right:20rpx ;
  192. }
  193. .progress{
  194. color: #777777;
  195. font-size: 24rpx;
  196. }
  197. .bought{
  198. color: #777777;
  199. font-size: 24rpx;
  200. margin-right: 20rpx;
  201. }
  202. }
  203. .price{
  204. overflow: hidden;
  205. color:#FF0000;
  206. .original-price{
  207. text-decoration: line-through;
  208. color: #777777;
  209. }
  210. // text{
  211. // font-size: 48rpx;
  212. // color:#FF0000;
  213. // font-weight: 500;
  214. // }
  215. // text:nth-child(1){
  216. // color: #FF0000;
  217. // font-size: 28rpx;
  218. // }
  219. // text:nth-child(2){
  220. // color: #FF0000;
  221. // font-size: 48rpx;
  222. // }
  223. // text:nth-child(3){
  224. // color: #FF0000;
  225. // font-size: 28rpx;
  226. // }
  227. // text:nth-child(4){
  228. // color: #777777;
  229. // font-size: 28rpx;
  230. // text-decoration:line-through;
  231. // font-weight: 400;
  232. // }
  233. button{
  234. width: 160rpx;
  235. height: 60rpx;
  236. background: #FE9903;
  237. border-radius: 50px;
  238. font-size: 24rpx;
  239. color: #FFFFFF;
  240. margin: 0rpx 20rpx 0rpx 20rpx;
  241. border: none;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. </style>