GoodsclassBody.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="div ui-category-body" :style="'padding-top:'+navHeight+'px'">
  3. <view class="common-header-holder"></view>
  4. <view class="div category-flex">
  5. <view class="div category-sidebar">
  6. <view class="ul">
  7. <view class="li item"
  8. v-for='item in items'
  9. v-bind:key="item.id"
  10. v-on:click='(item.children && item.children.length)?onItemClick(item):goProduct(item.id)'
  11. v-bind:class="{'sidbaractive': (currentItem && item.id == currentItem.id), 'noActive' : (currentItem && item.id != currentItem.id)}">
  12. <text class="a">{{ item.value }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="div category-content" ref="content" v-if='currentItem && currentItem.children'>
  17. <view class="ul">
  18. <view class="li item clearfix" v-for='item in currentItem.children' v-bind:key = "item.id">
  19. <text class="a" v-on:click='goProduct(item.id)'>{{item.value}}</text>
  20. <view class="dl" v-for='item_1 in item.children' :key = "item_1.id" v-on:click='goProduct(item_1.id)'>
  21. <view class="dt"><image mode="aspectFit" class="img" :src="item_1.image" /></view>
  22. <view class="dd">{{item_1.value}}</view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { urlencode } from '@/util/common'
  32. import { mapState, mapMutations, mapActions } from 'vuex'
  33. export default {
  34. data () {
  35. return {
  36. navHeight:0,
  37. currentItem:{}
  38. }
  39. },
  40. computed: {
  41. ...mapState({
  42. items: state => state.goodsclass.items,
  43. }),
  44. },
  45. created () {
  46. this.getGoodsclassList()
  47. },
  48. methods: {
  49. ...mapMutations({
  50. saveCurrentGoodsclassItem: 'saveCurrentGoodsclassItem'
  51. }),
  52. ...mapActions({
  53. fetchGoodsclassList: 'fetchGoodsclassList'
  54. }),
  55. getGoodsclassList () {
  56. if (!(this.items && this.items.length)) {
  57. uni.showLoading({ title: '加载中' })
  58. }
  59. this.fetchGoodsclassList().then((res) => {
  60. var item=res.result.class_list[0]
  61. this.onItemClick (item)
  62. uni.hideLoading()
  63. }, (error) => {
  64. uni.showToast({icon:'none',title: error.message})
  65. uni.hideLoading()
  66. })
  67. },
  68. onItemClick (item) {
  69. this.currentItem=item
  70. },
  71. goProduct (id) {
  72. let params = { 'cate_id': id }
  73. uni.navigateTo({ url: '/pages/home/goodslist/Goodslist'+'?'+urlencode( params )})
  74. }
  75. },
  76. mounted: function() {
  77. // #ifdef MP-WEIXIN
  78. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  79. // #endif
  80. },
  81. }
  82. </script>
  83. <style scoped lang="scss">
  84. .ui-category-body{
  85. width: 100%;
  86. position: absolute;
  87. bottom: 0;
  88. top: var(--status-bar-height);
  89. .category-flex {
  90. height: 100%;
  91. box-sizing: border-box;
  92. padding-top:$headerHeight;
  93. background: #fff;
  94. display: flex;
  95. display: -webkit-box;
  96. display: -moz-box;
  97. display: -ms-flexbox;
  98. display: -webkit-flex;
  99. .category-sidebar {
  100. flex-basis:6rem;
  101. background-color: #F0F1F5;
  102. overflow-y: scroll;
  103. border-radius:0 .8rem 0 0;
  104. margin-top: 1rem;
  105. .ul {
  106. .li {
  107. display: block;
  108. padding: 0.8rem 0.25rem;
  109. .a {
  110. color: $formInputColor;
  111. display: -webkit-box;
  112. -webkit-box-orient: vertical;
  113. -webkit-line-clamp: 1;
  114. overflow: hidden;
  115. font-size:$fontSize;
  116. text-align: center;
  117. }
  118. }
  119. .li.noActive {
  120. background-color: #F0F2F5;
  121. border-left: 0.1rem solid transparent;
  122. .a {
  123. color: $formInputColor;
  124. }
  125. }
  126. .li.sidbaractive{
  127. background-color: #FFFFFF;
  128. border-left: 0.1rem solid $primaryColor;
  129. .a {
  130. font-weight:600;
  131. color: $primaryColor;
  132. }
  133. }
  134. }
  135. }
  136. .category-content {
  137. width: 100%;
  138. background-color: #fff;
  139. overflow: auto;
  140. .ul {
  141. height: 100%;
  142. .li {
  143. display: block;
  144. padding: 0.95rem 0;
  145. cursor: pointer;
  146. .a {
  147. color: $formInputColor;
  148. font-size:$h2;
  149. margin-bottom:1rem;
  150. font-weight:700;
  151. text-align: center;
  152. display:block;;
  153. }
  154. }
  155. .dl{
  156. display:inline-block;
  157. width:33.33%;
  158. text-align:center;
  159. .dt{
  160. position:relative;
  161. .img{width:3.5rem;height:3.5rem;overflow:hidden;border-radius:.4rem;}
  162. }
  163. .dd{font-size:$fontSize;line-height:1rem;height:1rem;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;margin-bottom:0.5rem;margin-top:.2rem;}
  164. }
  165. }
  166. }
  167. }
  168. }
  169. </style>