classify.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="classify">
  3. <view class="classify_search center">
  4. <view class="classify_search_ipt flexs" @click="goSearch">
  5. <image src="https://www.chaomangdao.com/image/home/sousuo@2x.png" mode=""></image>
  6. <input type="text" disabled placeholder="输入您要搜索的内容" placeholder-style="color:#808080" />
  7. </view>
  8. </view>
  9. <view class="classify_main flexs">
  10. <scroll-view scroll-y="true" class="classify_main_left scroll-view">
  11. <view class="classify_main_left_li center" :class="{active:index == i}" v-for="(item,index) in classList" :key="index" @click="changeIndex(index)">{{ item.name }}</view>
  12. </scroll-view>
  13. <scroll-view scroll-y="true" class="scroll-view classify_main_right">
  14. <view class="scroll-view_ul">
  15. <view class="classify_main_right_li flexs" v-for="(item,index) in boxList" :key="index" @click="goMessage(item)">
  16. <view class="classify_main_right_li_img">
  17. <image :src="item.image" mode="aspectFill"></image>
  18. </view>
  19. <view class="classify_main_right_li_main">
  20. <view class="classify_main_right_li_name">{{ item.box_name }}</view>
  21. <view class="classify_main_right_li_price">{{ item.coin_price }}金币</view>
  22. </view>
  23. </view>
  24. </view>
  25. </scroll-view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. i:0,//选择哪个分类
  34. page:1,//分页
  35. pages:null,//总页数
  36. boxList:[],//盒子列表
  37. classList:[],//分类列表
  38. category_id:'',//分类ID
  39. };
  40. },
  41. methods:{
  42. //去搜索
  43. goSearch () {
  44. uni.navigateTo({url:'/pages/index/search'})
  45. },
  46. //选择分类
  47. changeIndex (index) {
  48. this.i = index
  49. this.page = 1
  50. this.category_id = this.classList[index].category_id
  51. this.getBoxListByCategory()
  52. },
  53. //去详情
  54. goMessage (item) {
  55. uni.navigateTo({url:'/pages/index/details?id=' + item.box_id})
  56. },
  57. //获取一级分类
  58. getCategoryList () {
  59. this.$api.categoryList().then(res=>{
  60. if (res.code === 1) {
  61. this.classList = res.data
  62. this.category_id = res.data[this.i].category_id
  63. this.getBoxListByCategory()
  64. }
  65. })
  66. },
  67. //get
  68. getBoxListByCategory () {
  69. this.$api.boxListByCategory({page:this.page,pagesize:'10',category_id:this.category_id,msg:'数据加载中'}).then(res=>{
  70. if (res.code === 1) {
  71. this.boxList = this.page == 1 ? res.data.data : [...rhis.boxList,...res.data.data],
  72. this.pages = res.data.last_page
  73. }
  74. })
  75. }
  76. },
  77. onLoad() {
  78. this.getCategoryList()
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. .classify_search {
  84. // position: fixed;
  85. width: 100%;
  86. height: 88rpx;
  87. // top: 0;
  88. // left: 0;
  89. padding: 0 30rpx;
  90. background: #FFFFFF;
  91. border-bottom: 2rpx solid #FAFAFA;
  92. .classify_search_ipt {
  93. width: 100%;
  94. padding: 0 20rpx;
  95. height: 58rpx;
  96. background: #F7F7F7;
  97. border-radius: 29rpx;
  98. image {
  99. width: 44rpx;
  100. height: 44rpx;
  101. margin-right: 15rpx;
  102. }
  103. input {
  104. flex: 1;
  105. font-size: 26rpx;
  106. }
  107. }
  108. }
  109. .scroll-view {
  110. height: calc(100vh - 88rpx - 50px);
  111. box-sizing: border-box;
  112. }
  113. .classify_main_left {
  114. width: 260rpx;
  115. background: #FFFFFF;
  116. .classify_main_left_li {
  117. height: 80rpx;
  118. font-size: 30rpx;
  119. }
  120. .active {
  121. color: #F6AF32;
  122. font-weight: bold;
  123. background: #F5F5F5;
  124. }
  125. }
  126. .classify_main_right {
  127. padding: 40rpx 0rpx 0rpx 30rpx;
  128. .scroll-view_ul {
  129. overflow: hidden;
  130. }
  131. .classify_main_right_li {
  132. padding-right: 30rpx;
  133. margin-bottom: 30rpx;
  134. &:last-child {
  135. // margin-bottom: 0;
  136. }
  137. .classify_main_right_li_img {
  138. image {
  139. width: 120rpx;
  140. height: 120rpx;
  141. background: #ECEEFB;
  142. border-radius: 10rpx;
  143. }
  144. margin-right: 20rpx;
  145. }
  146. .classify_main_right_li_main {
  147. .classify_main_right_li_name {
  148. // width: 284rpx;
  149. display: -webkit-box;
  150. -webkit-box-orient: vertical;
  151. -webkit-line-clamp: 2;
  152. overflow: hidden;
  153. margin-bottom: 20rpx;
  154. }
  155. .classify_main_right_li_price {
  156. color: #CF271B;
  157. font-size: 26rpx;
  158. }
  159. }
  160. }
  161. }
  162. </style>