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

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