多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
5.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <view>
  3. <global-loading />
  4. <view class="header">
  5. <image class="logo" src="https://ceres.zkthink.com//assets/img/logo.png" mode="widthFix"></image>
  6. </view>
  7. <view class="content">
  8. <!-- 分类中心 -->
  9. <scroll-view scroll-y class="left-aside">
  10. <view v-for="(item,index) in flist" :key="item.classifyId" class="f-item b-b" :class="{active: index === currentIndex}" @click="tabtap(item,index)">
  11. {{item.classifyName}}
  12. </view>
  13. </scroll-view>
  14. <scroll-view scroll-with-animation scroll-y class="right-aside" v-if="!ifEmpty">
  15. <view v-if="onlyTwoLayer">
  16. <view class="t-list" v-if="slist.length>0">
  17. <view @click="navToList(titem.classifyPid, titem.classifyId)" class="t-item" v-for="titem in slist" :key="titem.classifyId">
  18. <image :src="titem.classifyImage" class="pic-img"></image>
  19. <text>{{titem.classifyName}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <view v-if="!onlyTwoLayer">
  24. <view v-for="item in slist" :key="item.classifyId" class="s-list">
  25. <view class="classBox flex-items-plus" v-if="slist.childs.length>0">
  26. <image class="emptyOrder-img" src="https://ceres.zkthink.com/static/images/classRight.png"></image>
  27. <text class="s-item" >{{item.classifyName}}</text>
  28. <image class="emptyOrder-img" src="https://ceres.zkthink.com/static/images/classLeft.png"></image>
  29. </view>
  30. <view class="t-list">
  31. <view @click="navToList(item.classifyId, titem.classifyId)" class="t-item" v-for="titem in slist.childs" :key="titem.classifyId">
  32. <image :src="titem.classifyImage" class="pic-img"></image>
  33. <text>{{titem.classifyName}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. <view v-if="ifEmpty" class="emptyOrder-box flex-items-plus flex-column">
  40. <image class="emptyOrder-img" src="https://ceres.zkthink.com/static/img/bgnull.png"></image>
  41. <label class="font-color-999 fs26 mar-top-30">该分类没有商品</label>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. const NET = require('../../../utils/request')
  48. const API = require('../../../config/api')
  49. export default {
  50. data() {
  51. return {
  52. sizeCalcState: false,
  53. tabScrollTop: 0,
  54. currentIndex: 0,
  55. currentId:'',
  56. flist: [],
  57. slist: [],
  58. ifEmpty: false,
  59. onlyTwoLayer : true
  60. }
  61. },
  62. onLoad() {
  63. this.loadData();
  64. },
  65. methods: {
  66. loadData(){
  67. // uni.showLoading({
  68. // mask: true,
  69. // title:'加载中...'
  70. // })
  71. NET.request(API.FindCategoryListByDepth, {
  72. classifyId: "",
  73. }, 'GET').then(res => {
  74. this.flist = res.data
  75. this.currentId = this.flist[0].classifyId
  76. uni.hideLoading()
  77. this.getChildCategory()
  78. }).catch(res => {
  79. uni.hideLoading()
  80. })
  81. },
  82. getChildCategory(){
  83. // uni.showLoading({
  84. // mask: true,
  85. // title:'加载中...'
  86. // })
  87. NET.request(API.FindCategoryListByDepth,{
  88. classifyId:this.currentId
  89. },'GET').then(res => {
  90. uni.hideLoading()
  91. if (res.data.length === 0) {
  92. this.ifEmpty = true
  93. }
  94. this.onlyTwoLayer = !this.slist.some(function(item){
  95. return item.childs.length>0
  96. });
  97. this.slist = res.data
  98. }).catch(res => {
  99. uni.hideLoading()
  100. })
  101. },
  102. //一级分类点击
  103. tabtap(item,index){
  104. this.ifEmpty = false
  105. if(this.currentIndex == index){
  106. return;
  107. }
  108. this.currentId = item.classifyId;
  109. this.currentIndex = index
  110. this.getChildCategory()
  111. },
  112. //右侧栏滚动
  113. asideScroll(e){
  114. if(!this.sizeCalcState){
  115. this.calcSize();
  116. }
  117. let scrollTop = e.detail.scrollTop;
  118. let tabs = this.slist.filter(item=>item.top <= scrollTop).reverse();
  119. if(tabs.length > 0){
  120. this.currentId = tabs[0].pid;
  121. }
  122. },
  123. //计算右侧栏每个tab的高度等信息
  124. calcSize(){
  125. let h = 0;
  126. this.slist.forEach(item=>{
  127. let view = uni.createSelectorQuery().select("#main-" + item.id);
  128. view.fields({
  129. size: true
  130. }, data => {
  131. item.top = h;
  132. h += data.height;
  133. item.bottom = h;
  134. }).exec();
  135. })
  136. this.sizeCalcState = true;
  137. },
  138. navToList(sid, tid){
  139. uni.navigateTo({
  140. url: `../../../pages_category_page1/goodsModule/goodsList?category3Id=${tid}`
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang='scss'>
  147. page,
  148. .content {
  149. height: 100%;
  150. /* background-color: #f8f8f8; */
  151. }
  152. .header{
  153. border-bottom: 1px solid #F3F4F5FF;
  154. }
  155. .logo {
  156. width: 280rpx;
  157. height: 42rpx;
  158. }
  159. .content {
  160. display: flex;
  161. }
  162. .left-aside {
  163. flex-shrink: 0;
  164. width: 200upx;
  165. height: 100vh;
  166. background-color: #F8F8F8;
  167. }
  168. .f-item {
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. width: 100%;
  173. height: 100upx;
  174. font-size: 28upx;
  175. color: $font-color-base;
  176. position: relative;
  177. &.active{
  178. color: $base-color;
  179. background: #FFFFFF;
  180. }
  181. }
  182. .right-aside{
  183. flex: 1;
  184. padding: 20upx 0 20upx 0;
  185. background: #fff;
  186. height: 100vh;
  187. }
  188. .s-item{
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. height: 70upx;
  193. padding-top: 8upx;
  194. font-size: 28upx;
  195. color: $font-color-dark;
  196. }
  197. .t-list{
  198. display: flex;
  199. flex-wrap: wrap;
  200. width: 100%;
  201. background: #fff;
  202. padding-top: 12upx;
  203. &:after{
  204. content: '';
  205. flex: 99;
  206. height: 0;
  207. }
  208. image{
  209. width: 140rpx;
  210. height: 140rpx;
  211. }
  212. }
  213. .t-item{
  214. flex-shrink: 0;
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. flex-direction: column;
  219. width: 176upx;
  220. font-size: 26upx;
  221. color: #666;
  222. padding-bottom: 20upx;
  223. image{
  224. width: 140upx;
  225. height: 140upx;
  226. }
  227. }
  228. .emptyOrder-box{
  229. margin-left: 180upx;
  230. .emptyOrder-img{
  231. margin-top: -130upx;
  232. width: 113upx;
  233. height: 98upx;
  234. }
  235. }
  236. .classBox {
  237. image {
  238. width: 66rpx;
  239. height: 4rpx;
  240. margin-top: 10rpx;
  241. }
  242. .s-item {
  243. margin: 0 10rpx;
  244. }
  245. }
  246. </style>