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

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