category.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <view class="category-wrap">
  3. <!-- #ifdef APP-PLUS -->
  4. <header-bar></header-bar>
  5. <!-- #endif -->
  6. <!-- 搜索框 -->
  7. <view class="index-search-box-cate" id="searchBox">
  8. <view class="index-search-cate t-c" @click="gotoSearch">
  9. <span class="icon iconfont icon-sousuo"></span>
  10. <text class="ml10">{{ searchName }}</text>
  11. </view>
  12. </view>
  13. <!--类别列表-->
  14. <view class="category-content">
  15. <!--一级分类 大图-->
  16. <view class="cotegory-type cotegory-type-1" v-if="show_type==10">
  17. <scroll-view scroll-y="true" class="scroll-Y" :style="'height:'+scrollviewHigh+'px;'">
  18. <view class="list">
  19. <view class="item" v-for="(item,index) in listData" :key="index"
  20. @click="gotoList(item.category_id)">
  21. <view class="pic">
  22. <image :src="hasImages(item)" mode="widthFix"></image>
  23. </view>
  24. <view class="p-20-0 fb tc f34">
  25. {{item.name}}
  26. </view>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. <!--一级分类 小图-->
  32. <view class="cotegory-type cotegory-type-2" v-if="show_type==20">
  33. <scroll-view scroll-y="true" class="scroll-Y" :style="'height:'+scrollviewHigh+'px;'">
  34. <view class="list">
  35. <view class="item" v-for="(item,index) in listData" :key="index"
  36. @click="gotoList(item.category_id)">
  37. <image :src="hasImages(item)" mode="aspectFit"></image>
  38. <text>{{item.name}}</text>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. </view>
  43. <!--二级分类-->
  44. <view class="cotegory-type cotegory-type-3" v-if="show_type==30">
  45. <view class="category-tab">
  46. <scroll-view scroll-y="true" class="scroll-Y" :style="'height:'+scrollviewHigh+'px;'">
  47. <view :class="index==select_index?'item active':'item'" v-for="(item,index) in listData"
  48. :key="index" @click="selectCategory(index)">
  49. <text>{{item.name}}</text>
  50. </view>
  51. </scroll-view>
  52. </view>
  53. <view class="category-content pr">
  54. <scroll-view scroll-y="true" class="scroll-Y scroll-3" :style="'height:'+(scrollviewHigh+15)+'px;'">
  55. <view class="list">
  56. <view class="item" v-for="(item,index) in childlist" :key="index"
  57. @click="gotoList(item.category_id)">
  58. <image :src="hasImages(item)" mode="aspectFit"></image>
  59. <text class="type-name">{{item.name}}</text>
  60. </view>
  61. </view>
  62. </scroll-view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import utils from '@/common/utils.js';
  70. export default {
  71. components: {},
  72. data() {
  73. return {
  74. isloadding: true,
  75. searchName: '搜索商品',
  76. /*展示方式*/
  77. show_type: 3,
  78. /*手机高度*/
  79. phoneHeight: 0,
  80. /*可滚动视图区域高度*/
  81. scrollviewHigh: 0,
  82. /*数据*/
  83. listData: [],
  84. /*子类数据*/
  85. childlist: [],
  86. /*当前选中的分类*/
  87. select_index: 0,
  88. };
  89. },
  90. onLoad() {
  91. },
  92. mounted() {
  93. this.init();
  94. this.getData();
  95. },
  96. methods: {
  97. /*初始化*/
  98. init() {
  99. let _this = this;
  100. uni.getSystemInfo({
  101. success(res) {
  102. _this.phoneHeight = res.windowHeight;
  103. // 计算组件的高度
  104. let view = uni.createSelectorQuery().select('#searchBox');
  105. view.boundingClientRect(data => {
  106. let h = _this.phoneHeight - data.height;
  107. _this.scrollviewHigh = h;
  108. }).exec();
  109. }
  110. });
  111. },
  112. /*判断是否有图片*/
  113. hasImages(e) {
  114. if (e.images != null && e.images.file_path != null) {
  115. return e.images.file_path;
  116. } else {
  117. return '';
  118. }
  119. },
  120. /*获取数据*/
  121. getData() {
  122. let _this = this;
  123. _this.isloadding = true;
  124. _this._get('product.category/index', {}, function(res) {
  125. _this.listData = res.data.list;
  126. _this.show_type = res.data.template.category_style;
  127. console.log(_this.show_type);
  128. if (_this.listData[0].child) {
  129. _this.childlist = _this.listData[0].child;
  130. }
  131. _this.background = res.data.background;
  132. _this.isloadding = false;
  133. });
  134. },
  135. /*选择分类*/
  136. selectCategory(e) {
  137. if (this.listData[e].child) {
  138. this.childlist = this.listData[e].child;
  139. this.select_index = e;
  140. }
  141. },
  142. /*跳转产品列表*/
  143. gotoList(e) {
  144. let category_id = e;
  145. let sortType = 'all';
  146. let search = '';
  147. let sortPrice = 0;
  148. this.gotoPage('/pages/product/list/list?category_id=' + category_id + '&sortType=' + sortType +
  149. '&search=' + search +
  150. '&sortPrice=' + sortPrice);
  151. },
  152. wxGetUserInfo: function(res) {
  153. if (!res.detail.iv) {
  154. uni.showToast({
  155. title: "您取消了授权,登录失败",
  156. icon: "none"
  157. });
  158. return false;
  159. }
  160. },
  161. /*跳转搜索页面*/
  162. gotoSearch() {
  163. this.gotoPage('/pages/product/search/search');
  164. },
  165. /**
  166. * 设置分享内容
  167. */
  168. onShareAppMessage() {
  169. let self = this;
  170. return {
  171. title: self.templet.share_title,
  172. path: '/pages/product/category?' + self.getShareUrlParams()
  173. };
  174. },
  175. }
  176. };
  177. </script>
  178. <style lang="scss">
  179. @import '@/common/mixin.scss';
  180. .foot_ {
  181. height: 98rpx;
  182. width: 100%;
  183. }
  184. .cotegory-type {
  185. line-height: 40rpx;
  186. background: #ffffff;
  187. }
  188. .cotegory-type image {
  189. width: 100%;
  190. }
  191. .cotegory-type-1 .list {
  192. padding: 20rpx;
  193. }
  194. .cotegory-type-1 .list .item {
  195. margin-top: 30rpx;
  196. }
  197. .cotegory-type-1 .list .item .pic {
  198. border: 1px solid #e3e3e3;
  199. width: 710rpx;
  200. height: auto;
  201. overflow: hidden;
  202. border-radius: 8px;
  203. }
  204. .cotegory-type-1 .list .item image {
  205. width: 100%;
  206. height: 100%;
  207. }
  208. .cotegory-type-2 .list,
  209. .cotegory-type-3 .list {
  210. padding: 0 20rpx;
  211. display: flex;
  212. flex-wrap: wrap;
  213. justify-content: flex-start;
  214. }
  215. .cotegory-type-2 .list .item,
  216. .cotegory-type-3 .list .item {
  217. display: flex;
  218. flex-direction: column;
  219. justify-content: center;
  220. align-items: center;
  221. }
  222. .cotegory-type-2 .list .item {
  223. padding: 0 16rpx;
  224. width: 200rpx;
  225. height: 300rpx;
  226. font-size: 28rpx;
  227. }
  228. .cotegory-type-2 .list .item image {
  229. width: 180rpx;
  230. height: 180rpx;
  231. margin-bottom: 20rpx;
  232. }
  233. .cotegory-type-3 {
  234. display: flex;
  235. }
  236. .cotegory-type-3 .category-tab {
  237. width: 150rpx;
  238. background: #FFFFFF;
  239. border-right: 1px solid #e3e3e3;
  240. }
  241. .cotegory-type-3 .category-tab .item {
  242. padding: 40rpx 0;
  243. font-size: 32rpx;
  244. text-align: center;
  245. }
  246. .cotegory-type-3 .category-tab .item.active {
  247. position: relative;
  248. background: #ffffff;
  249. // font-weight: bold;
  250. color: $dominant-color;
  251. }
  252. .cotegory-type-3 .category-tab .item.active::after {
  253. position: absolute;
  254. content: '';
  255. top: 40rpx;
  256. bottom: 40rpx;
  257. right: 0;
  258. width: 2rpx;
  259. height: 24rpx;
  260. margin: auto;
  261. background: $dominant-color;
  262. }
  263. .cotegory-type-3 .category-content {
  264. flex: 1;
  265. margin: 0 20rpx;
  266. }
  267. .cotegory-type-3 .list .item {
  268. width: 140rpx;
  269. height: 200rpx;
  270. margin-top: 40rpx;
  271. margin-right: 40rpx;
  272. font-size: 24rpx;
  273. }
  274. .cotegory-type-3 .list .item:nth-child(3n) {
  275. margin-right: 0;
  276. }
  277. .cotegory-type-3 .list .item image {
  278. width: 140rpx;
  279. height: 140rpx;
  280. }
  281. .cotegory-type-3 .list .item .type-name {
  282. display: block;
  283. margin-top: 20rpx;
  284. height: 80rpx;
  285. line-height: 60rpx;
  286. text-overflow: ellipsis;
  287. width: 100%;
  288. color: #818181;
  289. font-size: 26rpx;
  290. white-space: nowrap;
  291. overflow: hidden;
  292. text-align: center;
  293. }
  294. .scroll-3 {
  295. position: absolute;
  296. top: -15px;
  297. background: #ffffff;
  298. border-radius: 12px;
  299. }
  300. </style>