category.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. 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. //分类列表
  51. categoryList: [],
  52. search: '',
  53. cateTop: {},
  54. verticalNavTop: 0,
  55. }
  56. },
  57. onLoad() {
  58. this.initData();
  59. },
  60. methods: {
  61. // 跳转至商品列表
  62. navToList(id){
  63. uni.navigateTo({
  64. url: `/pages/product/list?cate_id=${id}`
  65. })
  66. },
  67. // 数据初始化
  68. initData() {
  69. this.getProductCate();
  70. },
  71. // 获取商品分类列表
  72. getProductCate () {
  73. queryGoodscategory().then(res =>{
  74. this.categoryList = res.data
  75. // 查询第一个拥有二级菜单的子菜单
  76. for (let i = 0; i < this.categoryList.length; i++) {
  77. if (this.categoryList[i].smalltypeList.length > 0) {
  78. this.showCategoryIndex = i;
  79. break;
  80. }
  81. }
  82. }).catch(res =>{
  83. this.$util.msg(res.msg,2000);
  84. })
  85. },
  86. showCategory(e,index){//分类切换显示
  87. this.showCategoryIndex = index;
  88. this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
  89. },
  90. toSearch () {// 跳转至搜索详情页
  91. uni.navigateTo({
  92. url: `/pages/search/search?search=${JSON.stringify(this.search)}`
  93. })
  94. },
  95. navToListPage(pro,index){//分类导航跳转
  96. let self = this;
  97. uni.setStorage({
  98. key: 'commodity_id',
  99. data: pro.tinyTypeID,
  100. success: function () {
  101. self.$api.navToListPage({type:'商品分类',value:pro.name,id:pro.tinyTypeID});
  102. }
  103. })
  104. }
  105. }
  106. }
  107. </script>
  108. <style scoped lang="scss">
  109. page {
  110. background-color: #fff;
  111. }
  112. .search-input-fixed{
  113. width: 100%;
  114. height:auto;
  115. position: fixed;
  116. top: 0;
  117. left: 0;
  118. z-index: 1000;
  119. background: #FFFFFF;
  120. border-bottom: 1px solid #F7F7F7;
  121. }
  122. #category {
  123. /*模块分类*/
  124. .category-list{
  125. width: 100%;
  126. background-color: #fff;
  127. display: flex;
  128. .left-aside,.right-aside{
  129. position: absolute;
  130. top: 100rpx;
  131. /* #ifdef APP-PLUS */
  132. top: calc(100rpx + var(--status-bar-height));
  133. /* #endif */
  134. bottom: 0rpx;
  135. }
  136. .left-aside{
  137. width: 200rpx;
  138. left: 0rpx;
  139. background-color: #f2f2f2;
  140. .row{
  141. width: 100%;
  142. height: 100rpx;
  143. display: flex;
  144. align-items: center;
  145. position: relative;
  146. .text{
  147. width: 100%;
  148. position: relative;
  149. font-size: $font-size-28;
  150. display: flex;
  151. justify-content: center;
  152. color: $text-color;
  153. /* transition: transform 0.3s ease;*/
  154. transition-property: transform;
  155. transition-duration: 0.2s;
  156. transition-timing-function: ease;
  157. }
  158. .block{
  159. position: absolute;
  160. width: 0rpx;
  161. left: 0;
  162. /* transition: transform 0.3s ease;*/
  163. transition-property: transform;
  164. transition-duration: 0.2s;
  165. transition-timing-function: ease;
  166. }
  167. &.on{
  168. height: 100rpx;
  169. background-color: #fff;
  170. .text{
  171. font-size: $font-size-28;
  172. color: $color-system;
  173. }
  174. .block{
  175. width: 10rpx;
  176. height: 60rpx;
  177. top: 20rpx;
  178. background-color: $color-system;
  179. border-radius: 0 15rpx 15rpx 0;
  180. }
  181. }
  182. }
  183. }
  184. .right-aside{
  185. width: 550rpx;
  186. left: 200rpx;
  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. }
  241. </style>