category.vue 5.6 KB

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