category.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view id="category" :style="{paddingTop:CustomBar+'px'}">
  3. <!--顶部搜索导航栏-->
  4. <view class="'search-input-fixed" :style="{top:CustomBar/2+'px'}">
  5. <cat-search :systeminfo='systeminfo' :navbar-data='nvabarData' :headerBtnPosi ="headerBtnPosi" @click="hanldTabClick"></cat-search>
  6. </view>
  7. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  8. <view class="category-list" v-else>
  9. <!-- 左侧分类导航 -->
  10. <scroll-view class="left-aside" scroll-y="true" scroll-with-animation :scroll-top="verticalNavTop" :style="{top:(CustomBar+38)+'px',height:(windowHeight-CustomBar+38)+'px'}">
  11. <view class="row" v-for="(m, index) in categoryList" :key="index" :class="[index==showCategoryIndex?'on':'']" @tap="showCategory($event,index)" :data-id="index">
  12. <view class="text">{{m.name}}</view>
  13. <view class="block"></view>
  14. </view>
  15. </scroll-view>
  16. <!--右侧子导航-->
  17. <scroll-view scroll-y="true" class="right-aside" :style="{top:(CustomBar+38)+'px',height:(windowHeight-CustomBar+38)+'px'}">
  18. <view class="category" v-for="(first,index) in categoryList" :key="index" v-show="index==showCategoryIndex" >
  19. <template v-if="first.smalltypeList">
  20. <view class="category-box AAA" v-for="(small,oIndex) in first.smalltypeList" :key="oIndex">
  21. <view class="title">{{small.name}}</view>
  22. <view class="list" v-if="small.tinytypeList.length > 0">
  23. <view class="box" v-for="(pro,proIndex) in small.tinytypeList" :key="proIndex" @click.stop="navToListPage(pro,3)">
  24. <image :src="pro.crmIcon ? pro.crmIcon : 'https://static.caimei365.com/app/img/icon/icon-noneproduct.jpg'"></image>
  25. <view class="text">{{pro.name}}</view>
  26. </view>
  27. </view>
  28. <view v-else class="no-data">
  29. <view class="box" @click.stop="navToListPage(small,2)">
  30. <image :src="small.crmIcon ? small.crmIcon : 'https://static.caimei365.com/app/img/icon/icon-noneproduct.jpg'"></image>
  31. <view class="text">全部商品</view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <template v-else>
  37. <view class="category-box BBB">
  38. <view class="title">{{first.name}}</view>
  39. <view class="no-data">
  40. <view class="box" @click.stop="navToListPage(first,1)">
  41. <image :src="first.crmIcon ? first.crmIcon : 'https://static.caimei365.com/app/img/icon/icon-noneproduct.jpg'"></image>
  42. <view class="text">全部商品</view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. </view>
  48. </scroll-view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import catSearch from '@/components/uni-search/cat-search.vue'
  54. export default {
  55. components: {
  56. catSearch
  57. },
  58. data() {
  59. return {
  60. nvabarData: { //顶部自定义导航
  61. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示
  62. title: '' // 导航栏 中间的标题
  63. },
  64. CustomBar:this.CustomBar,// 顶部导航栏高度
  65. headerBtnPosi: this.setHeaderBtnPosi(), //获取设备顶部胶囊高度
  66. systeminfo: this.setSysteminfo(), //获取设备信息
  67. headerShow:true,
  68. showCategoryIndex: 0,
  69. categoryList: [],//分类列表
  70. search: '',
  71. cateTop: {},
  72. verticalNavTop: 0,
  73. categoryTabIndex:1,
  74. windowHeight:0,
  75. scrollHeight:0,
  76. skeletonShow:true
  77. }
  78. },
  79. created() {
  80. this.initData();
  81. },
  82. methods: {
  83. // 数据初始化
  84. initData() {
  85. this.GetProductCate(this.categoryTabIndex);
  86. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  87. this.windowHeight = windowHeight - 1;
  88. this.scrollHeight = windowHeight - 1;
  89. },
  90. hanldTabClick(data){
  91. this.categoryList = []
  92. this.GetProductCate(data);
  93. },
  94. // 获取商品分类列表
  95. GetProductCate (index) {
  96. this.CommonService.GetFirstClassly({typeSort:index,source :'crm'}).then(response =>{
  97. this.categoryList = response.data
  98. // 查询第一个拥有二级菜单的子菜单
  99. for (let i = 0; i < this.categoryList.length; i++) {
  100. if (this.categoryList[i].smalltypeList.length > 0) {
  101. this.showCategoryIndex = i;
  102. break;
  103. }
  104. }
  105. this.skeletonShow = false
  106. }).catch(error =>{
  107. this.$util.msg(error.msg,2000)
  108. })
  109. },
  110. showCategory(e,index){//分类切换显示
  111. this.showCategoryIndex = index;
  112. this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
  113. },
  114. toSearch () {// 跳转至搜索详情页
  115. uni.navigateTo({
  116. url: `/search/pages/search/search?search=${JSON.stringify(this.search)}`
  117. })
  118. },
  119. navToListPage(item,index){//分类导航跳转
  120. switch(index){
  121. case 1:
  122. this.$api.navigateTo(`/pages/goods/goods-classify?classType=1&id=${item.bigTypeID}&title=${item.name}`)
  123. break;
  124. case 2:
  125. this.$api.navigateTo(`/pages/goods/goods-classify?classType=2&id=${item.smallTypeID}&title=${item.name}`)
  126. break;
  127. case 3:
  128. this.$api.navigateTo(`/pages/goods/goods-classify?classType=3&id=${item.tinyTypeID}&title=${item.name}`)
  129. break;
  130. }
  131. },
  132. setHeaderBtnPosi(){
  133. // 获得胶囊按钮位置信息
  134. let headerBtnPosi = uni.getMenuButtonBoundingClientRect();
  135. return headerBtnPosi
  136. },
  137. setSysteminfo(){
  138. let systeminfo;
  139. uni.getSystemInfo({ // 获取设备信息
  140. success: (res) => {
  141. systeminfo = res
  142. },
  143. })
  144. return systeminfo
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss">
  150. page {
  151. background-color: #fff;
  152. }
  153. .search-input-fixed{
  154. width: 100%;
  155. height:auto;
  156. position: fixed;
  157. top: 0;
  158. left: 0;
  159. z-index: 1000;
  160. background: #FFFFFF;
  161. border-bottom: 1px solid #F7F7F7;
  162. }
  163. .category-list{
  164. width: 100%;
  165. background-color: #fff;
  166. display: flex;
  167. .left-aside,.right-aside{
  168. position: absolute;
  169. top: 100rpx;
  170. /* #ifdef APP-PLUS */
  171. top: calc(100rpx + var(--status-bar-height));
  172. /* #endif */
  173. bottom: 0rpx;
  174. }
  175. .left-aside{
  176. width: 200rpx;
  177. left: 0rpx;
  178. background-color: #f2f2f2;
  179. .row{
  180. width: 100%;
  181. height: 100rpx;
  182. display: flex;
  183. align-items: center;
  184. position: relative;
  185. .text{
  186. width: 100%;
  187. position: relative;
  188. font-size: $font-size-28;
  189. display: flex;
  190. justify-content: center;
  191. color: $text-color;
  192. /* transition: transform 0.3s ease;*/
  193. transition-property: transform;
  194. transition-duration: 0.2s;
  195. transition-timing-function: ease;
  196. }
  197. .block{
  198. position: absolute;
  199. width: 0rpx;
  200. left: 0;
  201. /* transition: transform 0.3s ease;*/
  202. transition-property: transform;
  203. transition-duration: 0.2s;
  204. transition-timing-function: ease;
  205. }
  206. &.on{
  207. height: 100rpx;
  208. background-color: #fff;
  209. .text{
  210. font-size: $font-size-28;
  211. color: $color-system;
  212. }
  213. .block{
  214. width: 10rpx;
  215. height: 60rpx;
  216. top: 20rpx;
  217. background-color: $color-system;
  218. border-radius: 0 15rpx 15rpx 0;
  219. }
  220. }
  221. }
  222. }
  223. .right-aside{
  224. width: 550rpx;
  225. left: 200rpx;
  226. .category{
  227. width: calc(100%);
  228. padding: 0 15rpx 20rpx 0;
  229. background: #F7F7F7;
  230. .category-box{
  231. background: #FFFFFF;
  232. margin-bottom: 20rpx;
  233. .title{
  234. padding: 0 24rpx;
  235. line-height: 80rpx;
  236. height: 80rpx;
  237. text-align: left;
  238. color: $text-color;
  239. font-size: $font-size-26;
  240. border-bottom: 1px solid #F7F7F7;
  241. font-weight: 600;
  242. }
  243. .list{
  244. margin-top: 24rpx;
  245. width: 100%;
  246. display: flex;
  247. flex-wrap: wrap;
  248. .box{
  249. width: calc(71.44vw / 3);
  250. margin-bottom: 40rpx;
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. flex-wrap: wrap;
  255. image{
  256. width: 140rpx;
  257. height: 140rpx;
  258. }
  259. .text{
  260. margin-top: 8rpx;
  261. width: 100%;
  262. display: flex;
  263. justify-content: center;
  264. font-size: $font-size-24;
  265. }
  266. }
  267. }
  268. .no-data {
  269. text-align: center;
  270. margin: 30rpx 0;
  271. color: #666666;
  272. font-size: 24rpx;
  273. line-height: 80rpx;
  274. .box{
  275. width: calc(71.44vw / 3);
  276. margin-bottom: 40rpx;
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. flex-wrap: wrap;
  281. image{
  282. width: 140rpx;
  283. height: 140rpx;
  284. }
  285. .text{
  286. margin-top: 8rpx;
  287. width: 100%;
  288. display: flex;
  289. justify-content: center;
  290. font-size: $font-size-24;
  291. }
  292. }
  293. }
  294. }
  295. }
  296. }
  297. }
  298. </style>