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