category.vue 5.9 KB

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