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

275 lines
6.7 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. }
  49. },
  50. onLoad() {
  51. this.getCategoryList();
  52. // this.get();
  53. },
  54. methods: {
  55. get(){
  56. this.$http(this.API.TEST, {
  57. goods_id: 1,
  58. goods_specs_id: 1,
  59. number: 1,
  60. token: 'b1f20b424ec9e7a2a4c9788fd0f75643'
  61. }).then(res => {
  62. console.log(res)
  63. // let nonceStr = res.data.nonceStr
  64. // appId: "wxb35ef055a4dd8ad4"
  65. // nonceStr: "60d3125d138af"
  66. // order_num: "2842855348400816128"
  67. // package: "prepay_id=wx23185213000285e14ea77ac97acc670000"
  68. // paySign: "6DC330CBDF6C29BEDD4D254D9DA97364"
  69. // signType: "MD5"
  70. // timeStamp: "1624445533"
  71. uni.requestPayment({
  72. orderInfo: res.data.order_num,
  73. timeStamp: res.data.timeStamp,
  74. nonceStr: res.data.nonceStr,
  75. package: res.data.package,
  76. signType: res.data.signType,
  77. paySign: res.data.paySign,
  78. complete: result => {
  79. console.log(result)
  80. }
  81. })
  82. })
  83. },
  84. // 切换tab
  85. change(index) {
  86. this.current = index;
  87. if(this.tab_list[index].list.length <= 0){
  88. this.getGoodsList(); // tab下没有数据,请求第一页
  89. }
  90. },
  91. // 获取分类tab
  92. getCategoryList(){
  93. this.$http(this.API.API_CATEGORY_LIST).then(res => {
  94. let res_list = res.data || [];
  95. let tab_list = res_list.map(item => {
  96. return {
  97. id: item.id,
  98. name: item.name,
  99. type: item.type,
  100. list: [],
  101. loadingClass: true,
  102. loadingText: '正在加载中',
  103. page: 1,
  104. isPage: true
  105. }
  106. })
  107. this.tab_list = tab_list;
  108. this.getGoodsList();
  109. })
  110. },
  111. // 获取分类下的商品列表
  112. getGoodsList(){
  113. let per_page = this.pageSize;
  114. let tab_item = this.tab_list[this.current];
  115. this.$http(this.API.API_GOODS_LIST, {
  116. category_id: tab_item.id,
  117. type: tab_item.type,
  118. page: tab_item.page,
  119. per_page
  120. }).then(res => {
  121. console.log("res", res);
  122. let isPage = res.data.has_more_page;
  123. tab_item.isPage = isPage;
  124. if(!isPage){
  125. tab_item.loadingClass = false;
  126. tab_item.loadingText = '没有更多数据啦~';
  127. }
  128. if(tab_item.page == 1){
  129. tab_item.list = res.data.items;
  130. }else{
  131. tab_item.list.push(...res.data.items);
  132. }
  133. })
  134. },
  135. // 去到详情页
  136. toDetail(item){
  137. this.$url('/pages/goodsDetail/index?id='+ item.id);
  138. }
  139. },
  140. onReachBottom(){
  141. let tab_item = this.tab_list[this.current];
  142. if(tab_item.isPage){
  143. tab_item.page = tab_item.page + 1;
  144. this.getGoodsList();
  145. }
  146. },
  147. onPullDownRefresh(){
  148. let tab_item = this.tab_list[this.current];
  149. tab_item.page = 1;
  150. tab_item.isPage = true;
  151. tab_item.loadingClass = true;
  152. tab_item.loadingText = '正在加载中';
  153. this.getGoodsList();
  154. uni.stopPullDownRefresh()
  155. },
  156. onShareAppMessage(){
  157. return {
  158. title: '分享小程序',
  159. path: '/pages/route/index?route=home'
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .title {
  166. font-size: 28rpx;
  167. color: $u-content-color;
  168. height: 88rpx;
  169. }
  170. // tab
  171. .ctab{
  172. width: 100%;
  173. margin: 20rpx 0 0rpx 0rpx;
  174. padding: 0 22rpx;
  175. }
  176. // 商品列表
  177. .com{
  178. width: 100%;
  179. overflow: hidden;
  180. .list{
  181. border-radius: 10rpx;
  182. overflow: hidden;
  183. margin: 20rpx 32rpx;
  184. background-color: #FFFFFF;
  185. box-shadow: 0 10rpx 20rpx 0 rgba(0, 0, 0, 0.1);
  186. align-items: flex-start;
  187. .left{
  188. overflow: hidden;
  189. image{
  190. width: 204rpx;
  191. height: 204rpx;
  192. margin: 20rpx;
  193. border-radius: 10rpx;
  194. }
  195. }
  196. .right{
  197. overflow: hidden;
  198. width: 64%;
  199. .title{
  200. margin: 18rpx 20rpx 0 0;
  201. color: #222222;
  202. font-size: 32rpx;
  203. }
  204. .tips{
  205. margin: 16rpx 0;
  206. overflow: hidden;
  207. .u-line-progress{
  208. width: 112rpx;
  209. overflow: hidden;
  210. margin-right:20rpx ;
  211. }
  212. .progress{
  213. color: #777777;
  214. font-size: 24rpx;
  215. }
  216. .bought{
  217. color: #777777;
  218. font-size: 24rpx;
  219. margin-right: 20rpx;
  220. }
  221. }
  222. .price{
  223. overflow: hidden;
  224. color:#FF0000;
  225. .original-price{
  226. text-decoration: line-through;
  227. color: #777777;
  228. }
  229. // text{
  230. // font-size: 48rpx;
  231. // color:#FF0000;
  232. // font-weight: 500;
  233. // }
  234. // text:nth-child(1){
  235. // color: #FF0000;
  236. // font-size: 28rpx;
  237. // }
  238. // text:nth-child(2){
  239. // color: #FF0000;
  240. // font-size: 48rpx;
  241. // }
  242. // text:nth-child(3){
  243. // color: #FF0000;
  244. // font-size: 28rpx;
  245. // }
  246. // text:nth-child(4){
  247. // color: #777777;
  248. // font-size: 28rpx;
  249. // text-decoration:line-through;
  250. // font-weight: 400;
  251. // }
  252. button{
  253. width: 160rpx;
  254. height: 60rpx;
  255. background: #FE9903;
  256. border-radius: 50px;
  257. font-size: 24rpx;
  258. color: #FFFFFF;
  259. margin: 0rpx 20rpx 0rpx 20rpx;
  260. border: none;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. </style>