category.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 && first.smallTypeList.length > 0">
  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 && 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">全部商品a</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. initData() {// 数据初始化
  84. this.GetProductCate(this.categoryTabIndex);
  85. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  86. this.windowHeight = windowHeight - 1;
  87. this.scrollHeight = windowHeight - 1;
  88. },
  89. hanldTabClick(data){
  90. this.categoryList = []
  91. this.GetProductCate(data);
  92. },
  93. GetProductCate (index) {// 获取商品分类列表
  94. this.CommonService.GetFirstClassly({typeSort:index,source :'crm'}).then(response =>{
  95. this.categoryList = response.data
  96. // 查询第一个拥有二级菜单的子菜单
  97. for (let i = 0; i < this.categoryList.length; i++) {
  98. if (this.categoryList[i].smallTypeList.length > 0) {
  99. this.showCategoryIndex = i;
  100. break;
  101. }
  102. }
  103. this.skeletonShow = false
  104. }).catch(error =>{
  105. this.$util.msg(error.msg,2000)
  106. })
  107. },
  108. showCategory(e,index){//分类切换显示
  109. this.showCategoryIndex = index;
  110. this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
  111. },
  112. toSearch () {// 跳转至搜索详情页
  113. uni.navigateTo({
  114. url: `/pages/search/search?search=${JSON.stringify(this.search)}`
  115. })
  116. },
  117. navToListPage(item,index){//分类导航跳转
  118. switch(index){
  119. case 1:
  120. this.$api.navigateTo(`/pages/goods/goods-classify?classType=1&id=${item.bigTypeId}&title=${item.name}`)
  121. break;
  122. case 2:
  123. this.$api.navigateTo(`/pages/goods/goods-classify?classType=2&id=${item.smallTypeId}&title=${item.name}`)
  124. break;
  125. case 3:
  126. this.$api.navigateTo(`/pages/goods/goods-classify?classType=3&id=${item.tinyTypeId}&title=${item.name}`)
  127. break;
  128. }
  129. },
  130. setHeaderBtnPosi(){
  131. // 获得胶囊按钮位置信息
  132. let headerBtnPosi = uni.getMenuButtonBoundingClientRect();
  133. return headerBtnPosi
  134. },
  135. setSysteminfo(){
  136. let systeminfo;
  137. uni.getSystemInfo({ // 获取设备信息
  138. success: (res) => {
  139. systeminfo = res
  140. },
  141. })
  142. return systeminfo
  143. },
  144. }
  145. }
  146. </script>
  147. <style lang="scss">
  148. page {
  149. background-color: #fff;
  150. }
  151. .search-input-fixed{
  152. width: 100%;
  153. height:auto;
  154. position: fixed;
  155. top: 0;
  156. left: 0;
  157. z-index: 1000;
  158. background: #FFFFFF;
  159. border-bottom: 1px solid #F7F7F7;
  160. }
  161. .category-list{
  162. width: 100%;
  163. background-color: #fff;
  164. display: flex;
  165. .left-aside,.right-aside{
  166. position: absolute;
  167. top: 100rpx;
  168. /* #ifdef APP-PLUS */
  169. top: calc(100rpx + var(--status-bar-height));
  170. /* #endif */
  171. bottom: 0rpx;
  172. }
  173. .left-aside{
  174. width: 200rpx;
  175. left: 0rpx;
  176. background-color: #f2f2f2;
  177. .row{
  178. width: 100%;
  179. height: 100rpx;
  180. display: flex;
  181. align-items: center;
  182. position: relative;
  183. .text{
  184. width: 100%;
  185. position: relative;
  186. font-size: $font-size-28;
  187. display: flex;
  188. justify-content: center;
  189. color: $text-color;
  190. /* transition: transform 0.3s ease;*/
  191. transition-property: transform;
  192. transition-duration: 0.2s;
  193. transition-timing-function: ease;
  194. }
  195. .block{
  196. position: absolute;
  197. width: 0rpx;
  198. left: 0;
  199. /* transition: transform 0.3s ease;*/
  200. transition-property: transform;
  201. transition-duration: 0.2s;
  202. transition-timing-function: ease;
  203. }
  204. &.on{
  205. height: 100rpx;
  206. background-color: #fff;
  207. .text{
  208. font-size: $font-size-28;
  209. color: $color-system;
  210. }
  211. .block{
  212. width: 10rpx;
  213. height: 60rpx;
  214. top: 20rpx;
  215. background-color: $color-system;
  216. border-radius: 0 15rpx 15rpx 0;
  217. }
  218. }
  219. }
  220. }
  221. .right-aside{
  222. width: 550rpx;
  223. left: 200rpx;
  224. .category{
  225. width: calc(100%);
  226. padding: 0 15rpx 20rpx 0;
  227. background: #F7F7F7;
  228. .category-box{
  229. background: #FFFFFF;
  230. margin-bottom: 20rpx;
  231. .title{
  232. padding: 0 24rpx;
  233. line-height: 80rpx;
  234. height: 80rpx;
  235. text-align: left;
  236. color: $text-color;
  237. font-size: $font-size-26;
  238. border-bottom: 1px solid #F7F7F7;
  239. font-weight: 600;
  240. }
  241. .list{
  242. margin-top: 24rpx;
  243. width: 100%;
  244. display: flex;
  245. flex-wrap: wrap;
  246. .box{
  247. width: calc(71.44vw / 3);
  248. margin-bottom: 40rpx;
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. flex-wrap: wrap;
  253. image{
  254. width: 140rpx;
  255. height: 140rpx;
  256. }
  257. .text{
  258. margin-top: 8rpx;
  259. width: 100%;
  260. display: flex;
  261. justify-content: center;
  262. font-size: $font-size-24;
  263. }
  264. }
  265. }
  266. .no-data {
  267. text-align: center;
  268. margin: 30rpx 0;
  269. color: #666666;
  270. font-size: 24rpx;
  271. line-height: 80rpx;
  272. .box{
  273. width: calc(71.44vw / 3);
  274. margin-bottom: 40rpx;
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. flex-wrap: wrap;
  279. image{
  280. width: 140rpx;
  281. height: 140rpx;
  282. }
  283. .text{
  284. margin-top: 8rpx;
  285. width: 100%;
  286. display: flex;
  287. justify-content: center;
  288. font-size: $font-size-24;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. }
  295. }
  296. </style>