cat.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-y scroll-with-animation class="tab-view" :scroll-into-view="scrollViewId"
  4. :style="{ height: height + 'px', top: top + 'px' }">
  5. <view :id="`id_${index}`" v-for="(item, index) in Category" :key="item.id" class="tab-bar-item"
  6. :class="[currentTab == index ? 'active' : '']" :data-current="index"
  7. @tap.stop="swichNav(item.id,index)">
  8. <text>{{ item.title }}</text>
  9. </view>
  10. </scroll-view>
  11. <scroll-view @scrolltolower="tolower" scroll-y class="right-box" :scroll-into-view="floorNum"
  12. :style="{ height: height + 'px', top: top + 'px' }">
  13. <view class="page-view">
  14. <view class="class-box">
  15. <view class="class-item" :id="'b'+item.id" v-if="Category.length>0"
  16. v-for="(item, index) in Category" :key="index">
  17. <view class="class-name" @tap.stop="gogoodsList" :data-cid="item.id" :data-key="item.title">
  18. {{ item.title }}</view>
  19. <view class="g-container">
  20. <view class="g-box" v-for="(son, i1) in item.son" :key="i1" @tap.stop="gogoodsList"
  21. :data-cid="son.id" :data-key="son.title">
  22. <image :src="son.icon" class="g-image" />
  23. <view class="g-title">{{ son.title }}</view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view :style='"height:"+(height-300)+"rpx;"' v-if="number<15"></view>
  30. </scroll-view>
  31. <tui-tabbar :current="current">
  32. </tui-tabbar>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. current: '',
  40. banners: [],
  41. Category: [],
  42. categoryId: "",
  43. goodsList: [],
  44. page: 1,
  45. getSon: [],
  46. height: 0, //scroll-view高度
  47. top: 0,
  48. currentTab: 0, //预设当前项的值
  49. floorNum: '',
  50. number: "",
  51. scrollViewId: "id_0"
  52. };
  53. },
  54. onLoad: function(options) {
  55. let _this = this
  56. // #ifdef MP-WEIXIN
  57. this.current = "/" + this.__route__;
  58. // #endif
  59. //#ifdef H5
  60. this.current = this.$route.path;
  61. //#endif
  62. setTimeout(() => {
  63. uni.getSystemInfo({
  64. success: res => {
  65. let header = 0;
  66. let top = 0;
  67. console.log(res.windowHeight);
  68. this.height = res.windowHeight - uni.upx2px(header);
  69. this.top = top + uni.upx2px(header);
  70. }
  71. });
  72. }, 50);
  73. this.getCategoryall();
  74. },
  75. onShow() {
  76. },
  77. methods: {
  78. // 点击标题切换当前页时改变样式
  79. swichNav: function(Categoryid, e) {
  80. let cur = e;
  81. if (this.currentTab == cur) {
  82. return false;
  83. } else {
  84. this.currentTab = cur;
  85. this.checkCor();
  86. }
  87. this.floorNum = 'b' + Categoryid;
  88. },
  89. //判断当前滚动超过一屏时,设置tab标题滚动条。
  90. checkCor: function() {
  91. if (this.currentTab > 6) {
  92. this.scrollViewId = `id_${this.currentTab - 2}`;
  93. } else {
  94. this.scrollViewId = `id_0`;
  95. }
  96. },
  97. gogoodsList(e) {
  98. let key = e.currentTarget.dataset.key;
  99. let cid = e.currentTarget.dataset.cid;
  100. uni.setStorageSync('cat_id', cid);
  101. uni.setStorageSync('cat_name', key);
  102. uni.navigateBack({});
  103. },
  104. getCategoryall: function() {
  105. let _this = this;
  106. this.$request.get('Category.demand', {
  107. ptype: 2
  108. }).then(res => {
  109. if (res.errno == 0) {
  110. _this.Category = res.data;
  111. _this.categoryId = _this.Category[0].id;
  112. setTimeout(function() {
  113. _this.infoScroll();
  114. }, 500)
  115. console.info("services---request---getsonList--右侧二级三级分类成功")
  116. }
  117. })
  118. },
  119. infoScroll: function() {
  120. let _this = this;
  121. let len = _this.Category.length;
  122. if (_this.Category[len - 1].son) {
  123. this.number = _this.Category[len - 1].son.length;
  124. }
  125. }
  126. },
  127. /**
  128. * 页面相关事件处理函数--监听用户下拉动作
  129. */
  130. onPullDownRefresh: function() {
  131. setTimeout(() => {
  132. uni.stopPullDownRefresh()
  133. }, 200);
  134. },
  135. };
  136. </script>
  137. <style>
  138. page {
  139. background: #fcfcfc;
  140. }
  141. /* 左侧导航布局 start*/
  142. /* 隐藏scroll-view滚动条*/
  143. ::-webkit-scrollbar {
  144. width: 0;
  145. height: 0;
  146. color: transparent;
  147. }
  148. .tab-view {
  149. /* height: 100%; */
  150. background: #f6f6f6;
  151. width: 200rpx;
  152. position: fixed;
  153. left: 0;
  154. z-index: 10;
  155. }
  156. .tab-bar-item {
  157. width: 200rpx;
  158. height: 110rpx;
  159. background: #f6f6f6;
  160. box-sizing: border-box;
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. font-size: 26rpx;
  165. color: #444;
  166. font-weight: 400;
  167. }
  168. .active {
  169. position: relative;
  170. color: #000;
  171. font-size: 30rpx;
  172. font-weight: 600;
  173. background: #fcfcfc;
  174. }
  175. .active::before {
  176. content: '';
  177. position: absolute;
  178. border-left: 8rpx solid #e41f19;
  179. height: 30rpx;
  180. left: 0;
  181. }
  182. /* 左侧导航布局 end*/
  183. .right-box {
  184. width: 100%;
  185. position: fixed;
  186. padding-left: 220rpx;
  187. box-sizing: border-box;
  188. left: 0;
  189. }
  190. .page-view {
  191. width: 100%;
  192. overflow: hidden;
  193. padding-top: 20rpx;
  194. padding-right: 20rpx;
  195. box-sizing: border-box;
  196. padding-bottom: env(safe-area-inset-bottom);
  197. }
  198. .class-box {
  199. padding-top: 10rpx;
  200. }
  201. .class-item {
  202. background: #fff;
  203. width: 100%;
  204. box-sizing: border-box;
  205. padding: 20rpx;
  206. margin-bottom: 20rpx;
  207. border-radius: 12rpx;
  208. }
  209. .class-name {
  210. font-size: 32rpx;
  211. font-weight: bold;
  212. }
  213. .g-container {
  214. /* padding-top: 20rpx; */
  215. display: flex;
  216. display: -webkit-flex;
  217. justify-content: flex-start;
  218. flex-direction: row;
  219. flex-wrap: wrap;
  220. }
  221. .g-box {
  222. width: 33.3333%;
  223. text-align: center;
  224. padding-top: 40rpx;
  225. }
  226. .g-image {
  227. width: 120rpx;
  228. height: 120rpx;
  229. border-radius: 12rpx;
  230. }
  231. .g-title {
  232. font-size: 22rpx;
  233. }
  234. .goods-item {
  235. width: 96%;
  236. height: 150rpx;
  237. display: flex;
  238. padding-left: 5px;
  239. padding-right: 5px;
  240. padding-top: 12px;
  241. padding-bottom: 12px;
  242. flex-direction: row;
  243. margin-left: 20rpx;
  244. align-items: center;
  245. justify-content: flex-start;
  246. border-bottom: 1rpx dotted #f2f2f2;
  247. }
  248. .goods-pic {
  249. width: 80px;
  250. height: 80px;
  251. flex-shrink: 0;
  252. }
  253. .goods-info {
  254. display: flex;
  255. flex-direction: column;
  256. padding: 6px 5px 0px 5px;
  257. height: 70px;
  258. font-size: 24rpx;
  259. justify-content: space-between;
  260. }
  261. </style>