category.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="content">
  3. <!-- 左侧竖向导航 -->
  4. <scroll-view v-if='' scroll-y class="left_aside">
  5. <view v-for="(item_l,index_l) in leftData" :key="index_l" class="f_item" :class="{active: item_l.categoryId === currentId}"
  6. @click="initData(item_l.categoryId,index_l)">
  7. {{item_l.categoryName.length>5?item_l.categoryName.slice(0,5):item_l.categoryName}}
  8. </view>
  9. </scroll-view>
  10. <!-- 右侧商品显示 -->
  11. <scroll-view scroll-with-animation scroll-y class="right_aside">
  12. <!-- 每个分类上部轮播图 -->
  13. <view class="cat_swiper" v-if="topSwiperData.length>0 && topSwiperData[0].imgUrl != ''">
  14. <uni-swiper-dot :info="topSwiperData" :current="current" field="content" :mode="topSwiperData && topSwiperData.length > 1 ? 'dot' : ''"
  15. :dotsStyles="dotsStyles">
  16. <swiper class="swiper-box" @change="change">
  17. <swiper-item v-for="(item_top ,index_top) in topSwiperData" :key="index_top">
  18. <view class="swiper-item flex_row_center_center" @click="$diyNavTo(item_top)">
  19. <image class="item_img" :src='item_top.imgUrl' />
  20. </view>
  21. </swiper-item>
  22. </swiper>
  23. </uni-swiper-dot>
  24. </view>
  25. <block v-if="!rightData || (rightData && rightData.length == 0 && noData)">
  26. <view class="noData">
  27. <image :src="imgUrl + 'empty_goods1.png'" mode=""></image>
  28. <text>{{$L('暂无任何商品~')}}</text>
  29. </view>
  30. </block>
  31. <block v-else>
  32. <!-- 每个二级分类盒子 -->
  33. <view v-for="item_r in rightData" :key="item_r.categoryId" class="s_list" :id="'main-'+item_r.categoryId">
  34. <!-- 二级分类标题 -->
  35. <text class="s_item" @click="navToList(item_r)">{{item_r.categoryName}}</text>
  36. <!-- 二级分类列表 -->
  37. <view class="t_list" v-if="item_r.children.length!=undefined">
  38. <view @click="navToList(item_r_3)" class="t_item" v-for="item_r_3 in item_r.children" :key="item_r_3.categoryId">
  39. <view class="cat_img" :style="{backgroundImage: 'url('+item_r_3.categoryImage+')'}"></view>
  40. <text>{{item_r_3.categoryName}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </block>
  45. </scroll-view>
  46. </view>
  47. </template>
  48. <script>
  49. let app = getApp()
  50. import uniSwiperDot from "@/components/uni-swiper-dot/uni-swiper-dot.vue"
  51. export default {
  52. components: {
  53. uniSwiperDot,
  54. },
  55. data() {
  56. return {
  57. current: 0,
  58. currentId: '',
  59. leftData: [], //左侧分类数据
  60. rightData: [], //右侧分类数据
  61. topSwiperData: [], //一级分类轮播图
  62. imgUrl: getApp().globalData.imgUrl, //全局图片地址
  63. dotsStyles: {
  64. selectedBackgroundColor: '#fff',
  65. width: 6,
  66. height: 6,
  67. selectedBorder: 'none',
  68. backgroundColor: 'rgba(0, 0, 0, .2)',
  69. border: 'none',
  70. bottom: 8
  71. },
  72. noData: false, //无分类数据
  73. ifOnShow: false
  74. }
  75. },
  76. onLoad() {
  77. this.initData();
  78. },
  79. methods: {
  80. initData(pid = '', index = 0) {
  81. let param = {};
  82. param.url = 'v3/goods/front/goods/category/list';
  83. if (pid) {
  84. param.data = {};
  85. param.data.categoryId1 = pid;
  86. this.currentId = pid;
  87. }
  88. this.$request(param).then(res => {
  89. this.leftData = res.data.list;
  90. if(this.leftData.length>0){
  91. if (pid == '') {
  92. pid = res.data.list[0].categoryId;
  93. if (app.globalData.cateId != '') {
  94. this.currentId = app.globalData.cateId
  95. } else {
  96. this.currentId = pid;
  97. }
  98. }
  99. let tmp_data = res.data.list.filter(item => item.categoryId == pid)[0].children;
  100. this.rightData = (tmp_data.length != undefined) ? tmp_data : [];
  101. if (this.rightData.length == 0) {
  102. this.noData = true;
  103. } else {
  104. this.noData = false;
  105. }
  106. this.current = 0;
  107. if(this.leftData[index].mobileImage != null){
  108. if(this.leftData[index].mobileImage.substr(0,1) == '['){
  109. this.topSwiperData = JSON.parse(this.leftData[index].mobileImage);
  110. }else{
  111. this.topSwiperData.push(this.leftData[index].mobileImage);
  112. }
  113. this.topSwiperData = this.topSwiperData.filter(item=>item.imgUrl != '');
  114. }else{
  115. this.topSwiperData = []
  116. }
  117. }
  118. })
  119. },
  120. navToList(item) {
  121. let url = `/pages/product/list?categoryId=${item.categoryId}`;
  122. uni.navigateTo({
  123. url: url
  124. })
  125. },
  126. change(e) {
  127. this.current = e.detail.current;
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang='scss'>
  133. page,
  134. .content {
  135. height: 100%;
  136. background-color: $bg-color-split;
  137. width: 750rpx;
  138. margin: 0 auto;
  139. }
  140. .content {
  141. display: flex;
  142. }
  143. .left_aside {
  144. flex-shrink: 0;
  145. width: 190rpx;
  146. height: 100%;
  147. background-color: #fff;
  148. }
  149. .f_item {
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. width: 190rpx;
  154. height: 100rpx;
  155. color: #666;
  156. position: relative;
  157. font-size: 28rpx;
  158. &.active {
  159. color: $main-color;
  160. background: #F8F8F8;
  161. font-size: 32rpx;
  162. font-weight: bold;
  163. &:before {
  164. content: '';
  165. position: absolute;
  166. left: 0;
  167. top: 50%;
  168. transform: translateY(-50%);
  169. height: 100rpx;
  170. width: 5rpx;
  171. background-color: $main-color;
  172. border-radius: 0 4px 4px 0;
  173. opacity: .8;
  174. }
  175. }
  176. }
  177. .right_aside {
  178. flex: 1;
  179. overflow: hidden;
  180. padding-left: 20rpx;
  181. }
  182. .s_item {
  183. display: flex;
  184. align-items: center;
  185. font-size: 28rpx;
  186. color: #333;
  187. margin-top: 30rpx;
  188. margin-bottom: 20rpx;
  189. padding-left: 6rpx;
  190. font-weight: bold;
  191. }
  192. .t_list {
  193. display: flex;
  194. flex-wrap: wrap;
  195. background: #fff;
  196. border-radius: 6rpx;
  197. margin-right: 20rpx;
  198. &:after {
  199. content: '';
  200. flex: 99;
  201. height: 0;
  202. }
  203. }
  204. .t_item {
  205. flex-shrink: 0;
  206. display: flex;
  207. justify-content: center;
  208. align-items: center;
  209. flex-direction: column;
  210. font-size: 26rpx;
  211. color: #666;
  212. padding: 20rpx;
  213. .cat_img {
  214. width: 133rpx;
  215. height: 133rpx;
  216. background-size: contain;
  217. background-position: center center;
  218. background-repeat: no-repeat;
  219. overflow: hidden;
  220. }
  221. text {
  222. color: #666;
  223. font-size: 24rpx;
  224. margin-top: 20rpx;
  225. font-weight: 600;
  226. }
  227. }
  228. .cat_swiper {
  229. width: 520rpx;
  230. height: 210rpx;
  231. margin-top: 20rpx;
  232. .swiper-box {
  233. width: 520rpx;
  234. height: 210rpx;
  235. border-radius: 10rpx;
  236. overflow: hidden;
  237. .swiper-item {
  238. .item_img {
  239. width: 520rpx;
  240. height: 210rpx;
  241. border-radius: 10rpx;
  242. overflow: hidden;
  243. }
  244. }
  245. }
  246. }
  247. .noData {
  248. display: flex;
  249. flex-direction: column;
  250. align-items: center;
  251. padding-top: 265rpx;
  252. image {
  253. width: 186rpx;
  254. height: 185rpx;
  255. }
  256. text {
  257. font-size: 26rpx;
  258. font-family: Source Han Sans CN;
  259. font-weight: 400;
  260. color: #999999;
  261. margin-top: 31rpx;
  262. }
  263. }
  264. </style>