category.vue 5.8 KB

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