index.vue 7.5 KB

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