category.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="category-box">
  3. <Navbar title="商品分类" background-color="#fff" color="#333"></Navbar>
  4. <view class="container">
  5. <view class="bottom-category">
  6. <view class="left">
  7. <view class="item" @click="handleFirst(item)" :class="{active: firstActive === item.id}"
  8. v-for="item in categoryList" :key="item.id">
  9. <view class="bar" v-if="firstActive === item.id"></view>
  10. {{item.oneName}}
  11. </view>
  12. </view>
  13. <view class="right">
  14. <view class="first-name">
  15. {{nameMap[firstActive] || ''}}
  16. </view>
  17. <view class="second-box">
  18. <view class="item" v-for="item in secondList" :key="item.id" @click="toSearch(item)">
  19. <!-- <image class="img" :src="item.twoPic" mode="aspectFill"></image> -->
  20. <text>{{item.twoName}}</text>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script lang="ts">
  29. import {
  30. Component,
  31. Prop,
  32. Vue,
  33. Mixins
  34. } from 'vue-property-decorator';
  35. import {
  36. namespace
  37. } from 'vuex-class';
  38. import {
  39. types
  40. } from '@/common/store/index';
  41. const baseModule = namespace('base');
  42. import loginMixin from '@/common/mixins/loginMixin.ts';
  43. @Component({})
  44. export default class Category extends Mixins(loginMixin) {
  45. @baseModule.Mutation(types.SET_TABBARINDEX) setTabBarIndex: any;
  46. categoryList: any = [];
  47. firstActive: any = null;
  48. categoryObj: any = {};
  49. secondList: any = [];
  50. nameMap: any = {};
  51. staticUrl: string = this.$oss_url; //oss地址
  52. shareInfo: any = {};
  53. async onShow() {
  54. this.$nextTick(function() {
  55. uni.hideTabBar();
  56. });
  57. // this.getShareInfo();
  58. await this.getCategoryList();
  59. if (uni.getStorageSync('categoryId')) {
  60. this.handleFirst({
  61. id: +uni.getStorageSync('categoryId'),
  62. twoSort: this.categoryObj[+uni.getStorageSync('categoryId')]
  63. });
  64. uni.setStorageSync('categoryId', '');
  65. }
  66. }
  67. onShareAppMessage() {
  68. // return {
  69. // title: '东方智选',
  70. // path: '/pages/front/front?s=1&uid=' + this._userInfo.uid,
  71. // imageUrl: this.shareInfo.pic
  72. // };
  73. }
  74. //获取商品分类
  75. getCategoryList() {
  76. // uni.showLoading({
  77. // title: '加载中',
  78. // });
  79. return this.$http
  80. .get({
  81. url: this.$api.getCategoryList
  82. })
  83. .then((res: any) => {
  84. this.categoryList = res.list;
  85. let obj: any = {},
  86. nameMap: any = {};
  87. res.list.forEach((item: any) => {
  88. obj[item.id] = item.twoSort;
  89. nameMap[item.id] = item.oneName;
  90. })
  91. this.nameMap = nameMap;
  92. this.categoryObj = obj;
  93. this.handleFirst(res.list[0]);
  94. // uni.hideLoading();
  95. }, (err: any) => {
  96. console.log(err);
  97. // uni.hideLoading();
  98. });
  99. }
  100. // getShareInfo() {
  101. // this.$http
  102. // .get({
  103. // url: this.$api.getShareInfo
  104. // })
  105. // .then((res: any) => {
  106. // this.shareInfo = res.info;
  107. // }, (err: any) => {
  108. // console.log(err);
  109. // });
  110. // }
  111. handleFirst(item: any) {
  112. this.firstActive = item.id;
  113. this.secondList = item.twoSort;
  114. }
  115. toSearch(item: any) {
  116. // uni.setStorageSync('categoryId', item.fid);
  117. this.$Router.push({
  118. path: '/packages/goods/search2',
  119. query: {
  120. sortOneId: this.firstActive,
  121. sortTwoId: item.id,
  122. name: this.nameMap[this.firstActive]
  123. }
  124. })
  125. }
  126. toPage(path: any) {
  127. this.$Router.push({
  128. path: path
  129. })
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .category-box {
  135. height: 100vh;
  136. background: #F8F8F8;
  137. @include flex-y();
  138. .container {
  139. width: 100%;
  140. @include flex-y();
  141. flex: 1;
  142. padding-bottom: vw(64);
  143. box-sizing: border-box;
  144. overflow: hidden;
  145. .top-search {
  146. width: vw(335);
  147. height: vw(32);
  148. background: #F6F6F6;
  149. border-radius: vw(16);
  150. @include flex-x(flex-start);
  151. @include word-vw(14, #999);
  152. padding: 0 vw(12);
  153. box-sizing: border-box;
  154. margin-top: vw(3);
  155. }
  156. .bottom-category {
  157. flex: 1;
  158. width: 100%;
  159. @include flex-x(flex-start);
  160. // padding-top: vw(20);
  161. box-sizing: border-box;
  162. overflow: hidden;
  163. .left {
  164. width: vw(88);
  165. height: 100%;
  166. overflow-y: auto;
  167. flex-shrink: 0;
  168. background: #fff;
  169. /deep/ ::-webkit-scrollbar {
  170. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  171. display: none
  172. }
  173. .item {
  174. background: #fff;
  175. height: vw(50);
  176. width: 100%;
  177. @include flex-x(center);
  178. @include word-vw(13, #333);
  179. position: relative;
  180. &.active {
  181. background: #F8F8F8;
  182. color: #2A5CE9;
  183. }
  184. .bar {
  185. width: vw(2);
  186. height: vw(16);
  187. background: #2A5CE9;
  188. position: absolute;
  189. left: 0;
  190. }
  191. }
  192. }
  193. .right {
  194. flex: 1;
  195. height: 100%;
  196. padding: vw(10) vw(15) 0;
  197. overflow-y: auto;
  198. box-sizing: border-box;
  199. .first-name {
  200. height: vw(36);
  201. line-height: vw(36);
  202. @include word-vw(14, #333);
  203. font-weight: bold;
  204. }
  205. .second-box {
  206. @include flex-x(flex-start);
  207. // margin-top: vw(12);
  208. flex-wrap: wrap;
  209. .item {
  210. @include flex-y();
  211. @include word-vw(12, #333);
  212. margin-bottom: vw(10);
  213. background: #fff;
  214. height: vw(32);
  215. padding: 0 vw(10);
  216. border-radius: vw(5);
  217. line-height: vw(32);
  218. margin-right: vw(5);
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. </style>