category.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="category-container clearfix">
  3. <!-- 头部轮播 -->
  4. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  5. <view class="category-list tui-skeleton">
  6. <!--顶部搜索导航栏-->
  7. <!-- <view class="'search-input-fixed">
  8. <bt-search :clickPath="clickPath" :toestText='hotSearchText'></bt-search>
  9. </view> -->
  10. <!-- 左侧分类导航 -->
  11. <scroll-view class="left-aside" scroll-y="true" scroll-with-animation :scroll-top="verticalNavTop" style="height:calc(100vh - 202rpx)" :style="{top:CustomBar+'px'}">
  12. <view class="row" v-if="m.smalltypeList.length > 0" v-for="(m, index) in categoryList" :key="index" :class="[index==showCategoryIndex?'on':'']" @tap="showCategory($event,index)" :data-id="index">
  13. <view class="text tui-skeleton-fillet">
  14. {{m.name}}
  15. </view>
  16. <view class="block"></view>
  17. </view>
  18. </scroll-view>
  19. <!--右侧子导航-->
  20. <scroll-view scroll-y="true" class="right-aside" style="height:calc(100vh - 202rpx)" :style="{top:CustomBar+'px'}">
  21. <view class="category" v-if="n.smalltypeList.length > 0" v-for="(n,index) in categoryList" :key="index" v-show="index==showCategoryIndex" >
  22. <view class="category-box" v-for="(o,oIndex) in n.smalltypeList" :key="oIndex">
  23. <view class="title tui-skeleton-fillet">{{o.name}}</view>
  24. <view class="list" v-if="o.tinytypeList.length > 0">
  25. <view class="box" v-for="(pro,proIndex) in o.tinytypeList" :key="proIndex" @click.stop="navToListPage(pro,proIndex)">
  26. <image :src="pro.icon" class="tui-skeleton-fillet"></image>
  27. <view class="text tui-skeleton-fillet">{{pro.name}}</view>
  28. </view>
  29. </view>
  30. <view v-else class="no-data">
  31. 该栏目暂无分类~
  32. </view>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import btSearch from '@/components/uni-search/bt-search.vue'
  41. import { queryGoodscategory } from "@/api/product.js"
  42. export default {
  43. components: {
  44. btSearch,
  45. },
  46. data() {
  47. return {
  48. skeletonShow: true,
  49. headerShow:true,
  50. hotSearchText: '你想要的这里都有',
  51. clickPath:'/pages/search/search',
  52. showCategoryIndex: 0,
  53. categoryList: [],//分类列表
  54. search: '',
  55. cateTop: {},
  56. verticalNavTop: 0,
  57. CustomBar:this.CustomBar,// 顶部导航栏高度
  58. }
  59. },
  60. created() {
  61. this.getProductCate();
  62. },
  63. methods: {
  64. // 跳转至商品列表
  65. navToList(id){
  66. this.$api.navigateTo(`/pages/product/list?cate_id=${id}`)
  67. },
  68. // 获取商品分类列表
  69. getProductCate () {
  70. queryGoodscategory().then(res =>{
  71. this.categoryList = res.data
  72. // 查询第一个拥有二级菜单的子菜单
  73. for (let i = 0; i < this.categoryList.length; i++) {
  74. if (this.categoryList[i].smalltypeList.length > 0) {
  75. this.showCategoryIndex = i;
  76. break;
  77. }
  78. }
  79. this.skeletonShow = false;
  80. }).catch(res =>{
  81. this.$util.msg(res.msg,2000);
  82. })
  83. },
  84. showCategory(e,index){//分类切换显示
  85. this.showCategoryIndex = index;
  86. this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
  87. },
  88. toSearch () {// 跳转至搜索详情页
  89. uni.navigateTo({
  90. url: `/pages/search/search?search=${JSON.stringify(this.search)}`
  91. })
  92. },
  93. navToListPage(pro,index){//分类导航跳转
  94. let self = this;
  95. uni.setStorage({
  96. key: 'commodity_id',
  97. data: pro.tinyTypeID,
  98. success: function () {
  99. self.$api.navToListPage({type:'4',value:pro.name,id:pro.tinyTypeID});
  100. }
  101. })
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped lang="scss">
  107. page {
  108. background-color: #fff;
  109. }
  110. .search-input-fixed{
  111. width: 100%;
  112. height:auto;
  113. position: fixed;
  114. top: 0;
  115. left: 0;
  116. z-index: 1000;
  117. background: #FFFFFF;
  118. border-bottom: 1px solid #F7F7F7;
  119. }
  120. .category-container{
  121. height: 100%;
  122. }
  123. /*模块分类*/
  124. .category-list{
  125. width: 100%;
  126. background-color: #fff;
  127. display: flex;
  128. .left-aside,.right-aside{
  129. position: absolute;
  130. /* #ifdef APP-PLUS */
  131. top: calc(100rpx + var(--status-bar-height));
  132. /* #endif */
  133. bottom: 0rpx;
  134. }
  135. .left-aside{
  136. width: 200rpx;
  137. left: 0rpx;
  138. background-color: #f2f2f2;
  139. .row{
  140. width: 100%;
  141. height: 100rpx;
  142. display: flex;
  143. align-items: center;
  144. position: relative;
  145. .text{
  146. width: 100%;
  147. position: relative;
  148. font-size: $font-size-28;
  149. display: flex;
  150. justify-content: center;
  151. color: $text-color;
  152. /* transition: transform 0.3s ease;*/
  153. transition-property: transform;
  154. transition-duration: 0.2s;
  155. transition-timing-function: ease;
  156. }
  157. .block{
  158. position: absolute;
  159. width: 0rpx;
  160. left: 0;
  161. /* transition: transform 0.3s ease;*/
  162. transition-property: transform;
  163. transition-duration: 0.2s;
  164. transition-timing-function: ease;
  165. }
  166. &.on{
  167. height: 100rpx;
  168. background-color: #fff;
  169. .text{
  170. font-size: $font-size-28;
  171. color: $color-system;
  172. }
  173. .block{
  174. width: 10rpx;
  175. height: 60rpx;
  176. top: 20rpx;
  177. background-color: $color-system;
  178. border-radius: 0 15rpx 15rpx 0;
  179. }
  180. }
  181. }
  182. }
  183. .right-aside{
  184. width: 550rpx;
  185. left: 200rpx;
  186. background: #FFFFFF;
  187. .category{
  188. width: calc(100%);
  189. padding: 0 15rpx 20rpx 0;
  190. background: #F7F7F7;
  191. .category-box{
  192. background: #FFFFFF;
  193. margin-bottom: 20rpx;
  194. .title{
  195. padding: 0 24rpx;
  196. line-height: 80rpx;
  197. height: 80rpx;
  198. text-align: left;
  199. color: $text-color;
  200. font-size: $font-size-26;
  201. border-bottom: 1px solid #F7F7F7;
  202. font-weight: 600;
  203. }
  204. .list{
  205. margin-top: 24rpx;
  206. width: 100%;
  207. display: flex;
  208. flex-wrap: wrap;
  209. .box{
  210. width: calc(71.44vw / 3);
  211. margin-bottom: 40rpx;
  212. display: flex;
  213. justify-content: center;
  214. align-items: center;
  215. flex-wrap: wrap;
  216. image{
  217. width: 140rpx;
  218. height: 140rpx;
  219. }
  220. .text{
  221. margin-top: 8rpx;
  222. width: 100%;
  223. display: flex;
  224. justify-content: center;
  225. font-size: $font-size-24;
  226. }
  227. }
  228. }
  229. .no-data {
  230. text-align: center;
  231. margin: 30rpx 0;
  232. color: #999999;
  233. font-size: 24rpx;
  234. line-height: 80rpx;
  235. }
  236. }
  237. }
  238. }
  239. }
  240. </style>