category.vue 6.6 KB

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