list-tab-header.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="list-tab-header linear-gradient">
  3. <view class="container">
  4. <view class="nav">
  5. <text
  6. v-for="(item, i) in list"
  7. :key="i"
  8. :class="{active: value === i}"
  9. class="nav-item"
  10. @click="handleClick(i, item)">
  11. {{ item.label }}
  12. </text>
  13. <!-- #ifdef MP-WEIXIN -->
  14. <slot />
  15. <!-- #endif -->
  16. </view>
  17. <!-- #ifndef MP-WEIXIN -->
  18. <slot />
  19. <view v-if="showSearch" class="header-control">
  20. <button class="search-btn" @click="handleSearch">
  21. <text class="icon wk wk-search" />
  22. </button>
  23. </view>
  24. <!-- #endif -->
  25. </view>
  26. <!-- #ifdef MP-WEIXIN -->
  27. <view v-if="showSearch" class="search-box">
  28. <view class="box" @click="handleSearch">
  29. <text class="wk wk-search" />
  30. <text class="wk-placeholder">
  31. {{ placeholder }}
  32. </text>
  33. </view>
  34. </view>
  35. <!-- #endif -->
  36. <uni-popup ref="popup" :mask-click="false" type="dialog">
  37. <wk-popup-expiration />
  38. </uni-popup>
  39. </view>
  40. </template>
  41. <script>
  42. import { mapGetters } from 'vuex'
  43. export default {
  44. name: 'ListTabHeader',
  45. props: {
  46. navList: {
  47. type: Array,
  48. default: () => []
  49. },
  50. value: {
  51. type: Number,
  52. default: 0
  53. },
  54. showSearch: {
  55. type: Boolean,
  56. default: true
  57. },
  58. placeholder: {
  59. type: String,
  60. default: ''
  61. },
  62. hasBorder: {
  63. type: Boolean,
  64. default: true
  65. }
  66. },
  67. data() {
  68. return {}
  69. },
  70. computed: {
  71. ...mapGetters({
  72. showExpiration: 'user/showExpiration'
  73. }),
  74. list() {
  75. return this.navList.filter(o => {
  76. if (this.$isEmpty(o.action) || o.noCheck) return true
  77. return this.$auth(o.action)
  78. })
  79. }
  80. },
  81. watch: {
  82. list: {
  83. handler() {
  84. if (this.list.length === 0) return
  85. if (this.value > this.list.length - 1) {
  86. this.handleClick(0, this.list[0])
  87. }
  88. },
  89. deep: true
  90. },
  91. showExpiration: {
  92. handler() {
  93. if (this.showExpiration) {
  94. this.$nextTick(function() {
  95. this.$refs.popup.open()
  96. })
  97. }
  98. },
  99. immediate: true,
  100. deep: true
  101. }
  102. },
  103. methods: {
  104. handleClick(index, item) {
  105. this.$emit('input', index)
  106. this.$emit('change', {
  107. index: index,
  108. item: item
  109. })
  110. },
  111. handleSearch() {
  112. this.$emit('search')
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped lang="scss">
  118. .list-tab-header {
  119. width: 100%;
  120. padding: 0 34rpx;
  121. .container {
  122. width: 100%;
  123. color: white;
  124. @include left;
  125. .nav {
  126. flex: 1;
  127. height: 96rpx;
  128. font-size: 32rpx;
  129. @include left;
  130. .nav-item {
  131. position: relative;
  132. line-height: 96rpx;
  133. margin-right: 36rpx;
  134. &.active {
  135. font-weight: 500;
  136. font-size: 42rpx;
  137. }
  138. }
  139. }
  140. .header-control {
  141. @include right;
  142. .search-btn {
  143. .icon {
  144. font-weight: 400;
  145. font-size: 42rpx;
  146. }
  147. }
  148. }
  149. }
  150. .search-box {
  151. width: 100%;
  152. padding-top: 10rpx;
  153. padding-bottom: 20rpx;
  154. .box {
  155. width: 100%;
  156. height: 62rpx;
  157. color: #BBBBBB;
  158. background-color: white;
  159. border-radius: 12rpx;
  160. padding: 0 20rpx;
  161. @include left;
  162. .wk-search {
  163. margin-right: 15rpx;
  164. }
  165. }
  166. }
  167. }
  168. </style>