app-head-navigation.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="bd-nav">
  3. <view class="bd-mask" @touchmove.stop.prevent v-if="isSwitch"></view>
  4. <view class="bd-head dir-left-nowrap">
  5. <scroll-view scroll-x scroll-with-animation :scroll-left="scrollLeft" :scroll-into-view="`scroll-${activeIndex}`" class="app-head-navigation dir-left-nowrap cross-center">
  6. <text class="head-text" :id="`scroll-${index}`" :class="item.active ? 'app-active':''" :style="{'background-color': item.active ? theme.background : '#ffffff'}"
  7. v-for="(item, index) in list"
  8. :key="index"
  9. @click="active(item)">
  10. {{item.name}}
  11. </text>
  12. </scroll-view>
  13. <view class="bd-btn" @click="isSwitch = true">
  14. <image class="bd-bt-img" src="/static/image/icon/icon-down.png"></image>
  15. </view>
  16. </view>
  17. <view class="bd-content" v-if="isSwitch" @touchmove.stop.prevent>
  18. <view class="bd-head dir-left-nowrap">
  19. <view class="app-head-navigation">
  20. 切换分类
  21. </view>
  22. <view class="bd-btn" @click="isSwitch = false">
  23. <image class="bd-bt-img" src="/static/image/icon/icon-up.png"></image>
  24. </view>
  25. </view>
  26. <view class="bd-back dir-left-wrap" >
  27. <view class="bd-item" @click="active(item)" :style="{'color': item.active ? theme.color : '#353535', 'border-color': item.active ? theme.border : '#e5e5e5'}" :key="index" v-for="(item, index) in list">{{item.name}}</view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'app-head-navigation',
  35. props: {
  36. list: {
  37. type: Array,
  38. default: function() {
  39. return [];
  40. }
  41. },
  42. theme: Object,
  43. },
  44. methods: {
  45. active(item) {
  46. this.isSwitch = false;
  47. console.log(item);
  48. this.$emit('click', item);
  49. }
  50. },
  51. data() {
  52. return {
  53. activeIndex: 0,
  54. isSwitch: false,
  55. scrollLeft: 0
  56. }
  57. },
  58. watch: {
  59. list: {
  60. handler(newVal) {
  61. for (let i = 0; i < newVal.length; i++) {
  62. if (newVal[i].active && i > 1) {
  63. this.activeIndex = i - 2;
  64. } else if (newVal[i].active && i <= 1) {
  65. this.activeIndex = 0;
  66. }
  67. }
  68. },
  69. immediate: true,
  70. deep: true
  71. }
  72. }
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. .bd-head {
  77. width: #{750rpx};
  78. height: #{100rpx};
  79. background-color: #ffffff;
  80. border-top: #{1rpx} solid #e2e2e2;
  81. border-bottom: #{1rpx} solid #e2e2e2;
  82. .app-active {
  83. color: #ffffff;
  84. }
  85. }
  86. .bd-btn {
  87. width:70upx;
  88. height: #{100rpx};
  89. }
  90. .app-head-navigation {
  91. width: 680upx;
  92. height: #{100rpx};
  93. line-height: #{100rpx};
  94. padding: 0 0 0 24upx;
  95. font-size: #{28rpx};
  96. white-space:nowrap;
  97. color: #666666;
  98. .head-text {
  99. display: inline-block;
  100. height: #{56rpx};
  101. padding: 0 #{20rpx};
  102. line-height: #{56rpx};
  103. border-radius: #{28rpx};
  104. margin-right: #{32rpx};
  105. white-space:nowrap;
  106. }
  107. }
  108. .bd-bt-img {
  109. width: 22upx;
  110. height:12upx;
  111. margin: 44upx 24upx;
  112. }
  113. .bd-back {
  114. background: #f5f5f5;
  115. padding: 48upx 0upx 24upx 20upx;
  116. }
  117. .bd-item {
  118. padding: 15upx 30upx;
  119. margin-bottom: 24upx;
  120. margin-right:19upx;
  121. background-color: #ffffff;
  122. border-radius: 35upx;
  123. border-width: 2upx;
  124. border-style: solid;
  125. font-size: 26upx;
  126. }
  127. .bd-nav {
  128. position: relative;
  129. }
  130. .bd-content {
  131. position: absolute;
  132. top:0;
  133. z-index: 100;
  134. }
  135. .bd-mask {
  136. position: fixed;
  137. top: 0;
  138. left: 0;
  139. right: 0;
  140. bottom: 0;
  141. background: rgba(0, 0, 0, 0.6);
  142. }
  143. </style>