category.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="content">
  3. <scroll-view scroll-y class="left-aside">
  4. <view v-for="(item,ind) in flist" :key="item.id" class="f-item b-b" :class="{ active:ind === index }"
  5. @click="tabtap(item,ind)">{{ item.cate_name }}</view>
  6. </scroll-view>
  7. <scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll"
  8. :scroll-top="tabScrollTop">
  9. <view class="list-box-h">
  10. <view v-if="flist[index]" v-for="(item, index) in flist[index].list" :key="index" class="guess-item" @click="navToDetailPage(item)">
  11. <image class="itemImg" :src="item.image"></image>
  12. <view class="guess-box">
  13. <view class="title clamp2">{{ item.store_name }}</view>
  14. <!-- <view class="price-box flex">
  15. <view class="yuanprice">{{ item.ot_price }}</view>
  16. <image src="../../static/img/jiantou.png" mode=""></image>
  17. <view class="jiang">直降{{ (item.ot_price - item.price).toFixed(2) }}元</view>
  18. </view> -->
  19. <view class="price">¥{{ item.price }}</view>
  20. <view class="btn">立即购买</view>
  21. </view>
  22. </view>
  23. <view class="noData" v-if="flist[index]?flist[index].list.length==0:true">
  24. <view v-if="flist[index].loading">
  25. 暂无数据
  26. </view>
  27. <view v-else>
  28. 数据加载中...
  29. </view>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. getCategoryList,
  38. getProducts
  39. } from '@/api/product.js';
  40. export default {
  41. data() {
  42. return {
  43. sizeCalcState: false,
  44. tabScrollTop: 0,
  45. currentId: 9,
  46. index: 0, //当前选中的对象
  47. flist: [],
  48. };
  49. },
  50. onLoad() {
  51. this.loadData();
  52. },
  53. // 监听导航栏输入框点击事件
  54. onNavigationBarSearchInputClicked(e) {
  55. uni.navigateTo({
  56. url: '/pages/product/search'
  57. });
  58. },
  59. methods: {
  60. // 载入数据
  61. async loadData() {
  62. let obj = this;
  63. getCategoryList({
  64. sid: 10
  65. })
  66. .then(({
  67. data
  68. }) => {
  69. obj.flist = data[0].children.map((e) => {
  70. let data = {
  71. id: e.id,
  72. pic: e.pic,
  73. cate_name: e.cate_name,
  74. loading: false,
  75. list: [],
  76. }
  77. return data
  78. });
  79. obj.currentId = obj.flist[0].id;
  80. obj.loadProducts(obj.flist[0])
  81. })
  82. .catch(err => {
  83. console.log(err);
  84. });
  85. },
  86. //一级分类点击
  87. tabtap(item, ind) {
  88. this.index = ind;
  89. if (!item.loading) {
  90. this.loadProducts(item)
  91. }
  92. },
  93. //加载商品 ,带下拉刷新和上滑加载
  94. loadProducts(item) {
  95. let obj = this;
  96. let data = {
  97. page: 1,
  98. limit: 1000,
  99. sid: item.id //分类id
  100. };
  101. getProducts(data).then(function(e) {
  102. console.log(e.data);
  103. item.list = e.data;
  104. item.loading = true;
  105. }).catch((e) => {
  106. item.loading = false;
  107. });
  108. },
  109. navToDetailPage(item) {
  110. uni.navigateTo({
  111. url: '/pages/product/product?id=' + item.id
  112. });
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss">
  118. page,
  119. .content {
  120. height: 100%;
  121. background-color: #f8f8f8;
  122. }
  123. .content {
  124. display: flex;
  125. }
  126. .left-aside {
  127. flex-shrink: 0;
  128. width: 200rpx;
  129. height: 100%;
  130. background-color: #fff;
  131. .f-item {
  132. display: flex;
  133. align-items: center;
  134. justify-content: center;
  135. width: 100%;
  136. height: 100rpx;
  137. font-size: 28rpx;
  138. color: $font-color-base;
  139. position: relative;
  140. &.active {
  141. color: $base-color;
  142. background: #f8f8f8;
  143. &:before {
  144. content: '';
  145. position: absolute;
  146. left: 0;
  147. top: 50%;
  148. transform: translateY(-50%);
  149. height: 36rpx;
  150. width: 8rpx;
  151. background-color: $base-color;
  152. border-radius: 0 4px 4px 0;
  153. opacity: 0.8;
  154. }
  155. }
  156. }
  157. }
  158. .right-aside {
  159. flex: 1;
  160. overflow: hidden;
  161. padding-left: 20rpx;
  162. padding-right: 20rpx;
  163. padding-top: 20rpx;
  164. .noData{
  165. color: #a3a3a3;
  166. text-align: center;
  167. }
  168. }
  169. .guess-item {
  170. padding: 10rpx;
  171. display: flex;
  172. min-width: 100%;
  173. width: 0;
  174. background: #ffffff;
  175. border-radius: 10rpx;
  176. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  177. image {
  178. width: 200rpx;
  179. height: 200rpx;
  180. border-radius: 10rpx;
  181. flex-shrink: 0;
  182. }
  183. .guess-box {
  184. width: 100%;
  185. padding: 5px;
  186. .title {
  187. font-size: 30rpx;
  188. color: #333333;
  189. height: 2.5em;
  190. line-height: 1.25em;
  191. }
  192. .price-box {
  193. margin-top: 80rpx;
  194. justify-content: flex-start;
  195. }
  196. .price {
  197. font-size: 36rpx;
  198. font-family: PingFang SC;
  199. font-weight: bold;
  200. color: #FF6F0F;
  201. }
  202. .btn {
  203. background: #16cc9f;
  204. border-radius: 28rpx;
  205. font-size: 28rpx;
  206. font-weight: 500;
  207. color: #ffffff;
  208. float: right;
  209. padding: 5rpx 20rpx;
  210. margin-top: 20rpx;
  211. }
  212. }
  213. }
  214. </style>