category.vue 6.6 KB

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