GoodsclassBody.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. // #ifdef APP-PLUS
  81. if(uni.getSystemInfoSync().platform === 'android'){
  82. this.navHeight = 50
  83. }
  84. // #endif
  85. },
  86. }
  87. </script>
  88. <style scoped lang="scss">
  89. .ui-category-body{
  90. width: 100%;
  91. position: absolute;
  92. bottom: 0;
  93. top: var(--status-bar-height);
  94. .category-flex {
  95. height: 100%;
  96. box-sizing: border-box;
  97. padding-top:$headerHeight;
  98. background: #fff;
  99. display: flex;
  100. display: -webkit-box;
  101. display: -moz-box;
  102. display: -ms-flexbox;
  103. display: -webkit-flex;
  104. .category-sidebar {
  105. flex-basis:6rem;
  106. background-color: #F0F1F5;
  107. overflow-y: scroll;
  108. border-radius:0 .8rem 0 0;
  109. margin-top: 1rem;
  110. .ul {
  111. .li {
  112. display: block;
  113. padding: 0.8rem 0.25rem;
  114. .a {
  115. color: $formInputColor;
  116. display: -webkit-box;
  117. -webkit-box-orient: vertical;
  118. -webkit-line-clamp: 1;
  119. overflow: hidden;
  120. font-size:$fontSize;
  121. text-align: center;
  122. }
  123. }
  124. .li.noActive {
  125. background-color: #F0F2F5;
  126. border-left: 0.1rem solid transparent;
  127. .a {
  128. color: $formInputColor;
  129. }
  130. }
  131. .li.sidbaractive{
  132. background-color: #FFFFFF;
  133. border-left: 0.1rem solid $primaryColor;
  134. .a {
  135. font-weight:600;
  136. color: $primaryColor;
  137. }
  138. }
  139. }
  140. }
  141. .category-content {
  142. width: 100%;
  143. background-color: #fff;
  144. overflow: auto;
  145. .ul {
  146. height: 100%;
  147. .li {
  148. display: block;
  149. padding: 0.95rem 0;
  150. cursor: pointer;
  151. .a {
  152. color: $formInputColor;
  153. font-size:$h2;
  154. margin-bottom:1rem;
  155. font-weight:700;
  156. text-align: center;
  157. display:block;;
  158. }
  159. }
  160. .dl{
  161. display:inline-block;
  162. width:33.33%;
  163. text-align:center;
  164. .dt{
  165. position:relative;
  166. .img{width:3.5rem;height:3.5rem;overflow:hidden;border-radius:.4rem;}
  167. }
  168. .dd{font-size:$fontSize;line-height:1rem;height:1rem;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;margin-bottom:0.5rem;margin-top:.2rem;}
  169. }
  170. }
  171. }
  172. }
  173. }
  174. </style>