category.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view id="category">
  3. <!--顶部搜索导航栏-->
  4. <view class="'search-input-fixed">
  5. <bt-search :clickPath="clickPath" :toestText='hotSearchText'></bt-search>
  6. </view>
  7. <view class="category-list">
  8. <!-- 左侧分类导航 -->
  9. <scroll-view scroll-y="true" class="left-aside" >
  10. <view class="row" v-if="m.smalltypeList.length > 0" v-for="(m, index) in categoryList" :key="index" :class="[index==showCategoryIndex?'on':'']" @tap="showCategory(index)">
  11. <view class="text">
  12. {{m.name}}
  13. </view>
  14. <view class="block"></view>
  15. </view>
  16. </scroll-view>
  17. <!--右侧子导航-->
  18. <scroll-view scroll-y="true" class="right-aside">
  19. <view class="category" v-if="n.smalltypeList.length > 0" v-for="(n,index) in categoryList" :key="index" v-show="index==showCategoryIndex" >
  20. <view class="category-box" v-for="(o,oIndex) in n.smalltypeList" :key="oIndex">
  21. <view class="title">{{o.name}}</view>
  22. <view class="list" v-if="o.tinytypeList.length > 0">
  23. <view class="box" v-for="(pro,proIndex) in o.tinytypeList" :key="proIndex" @click.stop="navToListPage(pro,proIndex)">
  24. <image :src="pro.icon"></image>
  25. <view class="text">{{pro.name}}</view>
  26. </view>
  27. </view>
  28. <view v-else class="no-data">
  29. 该栏目暂无分类~
  30. </view>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. /**
  39. * @des 分类
  40. * @author zhjy
  41. * @date 2020-03-19 11:19
  42. */
  43. import btSearch from '@/components/uni-search/bt-search.vue'
  44. export default {
  45. components: {
  46. btSearch
  47. },
  48. data() {
  49. return {
  50. headerShow:true,
  51. hotSearchText: '你想要的这里都有',
  52. showCategoryIndex: 0,
  53. //分类列表
  54. categoryList: [],
  55. search: '',
  56. cateTop: {}
  57. }
  58. },
  59. onShow() {
  60. this.initData();
  61. },
  62. methods: {
  63. // 跳转至商品列表
  64. navToList(id){
  65. uni.navigateTo({
  66. url: `/pages/product/list?cate_id=${id}`
  67. })
  68. },
  69. // 数据初始化
  70. async initData() {
  71. this.getProductCate();
  72. },
  73. // 获取商品分类列表
  74. async getProductCate () {
  75. let list = await this.$util.json('categoryList');
  76. this.categoryList = list
  77. console.log(this.categoryList)
  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. },
  86. //分类切换显示
  87. showCategory(index){
  88. this.showCategoryIndex = index;
  89. },
  90. // 跳转至搜索详情页
  91. toSearch () {
  92. uni.navigateTo({
  93. url: `/pages/search/search?search=${JSON.stringify(this.search)}`
  94. })
  95. },
  96. //分类导航跳转
  97. navToListPage(pro,index){
  98. console.log(index)
  99. let self = this;
  100. console.log(pro)
  101. uni.setStorage({
  102. key: 'commodity_id',
  103. data: pro.tinyTypeID,
  104. success: function () {
  105. self.$api.navToListPage({type:'商品分类',value:pro.name,id:pro.tinyTypeID});
  106. }
  107. })
  108. },
  109. // 跳至广告图指定页面
  110. indexTopToDetailPage(type, url){
  111. switch (type) {
  112. case 'product_view':
  113. url = `/pages/product/product?id=${url}`;
  114. break;
  115. case 'article_view':
  116. this.$api.msg('article_view');
  117. break;
  118. case 'coupon_view':
  119. url = `/pages/coupon/detail?id=${url}`;
  120. break;
  121. case 'helper_view':
  122. this.$api.msg('helper_view');
  123. break;
  124. case 'product_list_for_cate':
  125. url = `/pages/product/list?cate_id=${url}`;
  126. break;
  127. default:
  128. break;
  129. }
  130. if (url) {
  131. uni.navigateTo({
  132. url,
  133. })
  134. }
  135. },
  136. }
  137. }
  138. </script>
  139. <style scoped lang="scss">
  140. page {
  141. background-color: #fff;
  142. }
  143. .search-input-fixed{
  144. width: 100%;
  145. height:auto;
  146. position: fixed;
  147. top: 0;
  148. left: 0;
  149. z-index: 1000;
  150. background: #FFFFFF;
  151. border-bottom: 1px solid #F7F7F7;
  152. }
  153. #category {
  154. /*模块分类*/
  155. .category-list{
  156. width: 100%;
  157. background-color: #fff;
  158. display: flex;
  159. .left-aside,.right-aside{
  160. position: absolute;
  161. top: 100rpx;
  162. /* #ifdef APP-PLUS */
  163. top: calc(100rpx + var(--status-bar-height));
  164. /* #endif */
  165. bottom: 0rpx;
  166. }
  167. .left-aside{
  168. width: 200rpx;
  169. left: 0rpx;
  170. background-color: #f2f2f2;
  171. .row{
  172. width: 100%;
  173. height: 100rpx;
  174. display: flex;
  175. align-items: center;
  176. position: relative;
  177. .text{
  178. width: 100%;
  179. position: relative;
  180. font-size: $font-size-28;
  181. display: flex;
  182. justify-content: center;
  183. color: $text-color;
  184. /* transition: transform 0.3s ease;*/
  185. transition-property: transform;
  186. transition-duration: 0.2s;
  187. transition-timing-function: ease;
  188. }
  189. .block{
  190. position: absolute;
  191. width: 0rpx;
  192. left: 0;
  193. /* transition: transform 0.3s ease;*/
  194. transition-property: transform;
  195. transition-duration: 0.2s;
  196. transition-timing-function: ease;
  197. }
  198. &.on{
  199. height: 100rpx;
  200. background-color: #fff;
  201. .text{
  202. font-size: $font-size-30;
  203. color: $color-system;
  204. }
  205. .block{
  206. width: 10rpx;
  207. height: 100rpx;
  208. top: 0;
  209. background-color: $color-system;
  210. border-radius: 0 5rpx 5rpx 0;
  211. }
  212. }
  213. }
  214. }
  215. .right-aside{
  216. width: 550rpx;
  217. left: 200rpx;
  218. .category{
  219. width: calc(100%);
  220. padding: 0 15rpx 20rpx 0;
  221. background: #F7F7F7;
  222. .category-box{
  223. background: #FFFFFF;
  224. margin-bottom: 20rpx;
  225. .title{
  226. padding: 0 24rpx;
  227. line-height: 80rpx;
  228. height: 80rpx;
  229. text-align: left;
  230. color: $text-color;
  231. font-size: $font-size-26;
  232. border-bottom: 1px solid #F7F7F7;
  233. font-weight: 600;
  234. }
  235. .list{
  236. margin-top: 24rpx;
  237. width: 100%;
  238. display: flex;
  239. flex-wrap: wrap;
  240. .box{
  241. width: calc(71.44vw / 3);
  242. margin-bottom: 40rpx;
  243. display: flex;
  244. justify-content: center;
  245. align-items: center;
  246. flex-wrap: wrap;
  247. image{
  248. width: 140rpx;
  249. height: 140rpx;
  250. }
  251. .text{
  252. margin-top: 8rpx;
  253. width: 100%;
  254. display: flex;
  255. justify-content: center;
  256. font-size: $font-size-24;
  257. }
  258. }
  259. }
  260. .no-data {
  261. text-align: center;
  262. margin: 30rpx 0;
  263. color: $color-system;
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. </style>