index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="">
  3. <view class="choose-tab" :style="{position}">
  4. <view class="tab-list">
  5. <view class="tab" v-for="(item,index) in tabList" :class="[chooseList[index] ?'active':'']" :key="index" @click="handleTab(item,index)">
  6. {{chooseList[index].label|| item.label}}
  7. <u-icon name="arrow-down" color="#222" size="24"></u-icon>
  8. </view>
  9. </view>
  10. <view class="box" v-show="show">
  11. <view class="item " :class="[chooseList[active].id == item.id ?'active':'']" v-for="(item,index) in tabList[active].list" :key="index" @click="choose(item)">
  12. {{item.label}}
  13. </view>
  14. </view>
  15. </view>
  16. <view class="choose-modal" :style="{background:showModal?'rgba(0, 0, 0, .4)':'none'}" v-show="show" @click="show = false">
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. position: {
  24. type: String,
  25. default: 'fixed'
  26. },
  27. showModal: {
  28. type: Boolean,
  29. default: true
  30. },
  31. tabList: {
  32. type: Array,
  33. default: ()=>{
  34. return []
  35. }
  36. },
  37. },
  38. data() {
  39. return {
  40. show:false,
  41. chooseList:['','','',''],
  42. list:[],
  43. active:0,
  44. // tabList: [{
  45. // id: 1,
  46. // label: '区域',
  47. // list: [
  48. // {
  49. // label: '观山湖'
  50. // },
  51. // {
  52. // label: '白云区'
  53. // },
  54. // {
  55. // label: '花果山区'
  56. // }
  57. // ]
  58. // },
  59. // {
  60. // id: 1,
  61. // label: '全部分类',
  62. // list: [{
  63. // label: '甜点饮品'
  64. // },
  65. // {
  66. // label: '特色美食'
  67. // },
  68. // {
  69. // label: '风味小吃'
  70. // }
  71. // ]
  72. // },
  73. // {
  74. // id: 1,
  75. // label: '智能排序',
  76. // list: [
  77. // {
  78. // label: '距离优先'
  79. // },
  80. // {
  81. // label: '销量优先'
  82. // },
  83. // {
  84. // label: '低价优先'
  85. // }
  86. // ]
  87. // },
  88. // {
  89. // id: 1,
  90. // label: '附近',
  91. // list: [
  92. // {
  93. // label: '500m'
  94. // },
  95. // {
  96. // label: '1KM'
  97. // },
  98. // {
  99. // label: '2KM'
  100. // }
  101. // ]
  102. // },
  103. // ]
  104. }
  105. },
  106. methods: {
  107. handleTab(item,index) {
  108. this.active = index
  109. this.$nextTick(()=>{
  110. this.show = true
  111. })
  112. },
  113. choose(item){
  114. this.show = false
  115. this.chooseList[this.active] = item.id == this.chooseList[this.active].id?'':item
  116. this.$emit('choose',this.chooseList)
  117. },
  118. },
  119. }
  120. </script>
  121. <style lang="scss" >
  122. .choose-modal {
  123. position: fixed;
  124. top: 0;
  125. left: 0;
  126. width: 100%;
  127. height: 100%;
  128. background: rgba(0, 0, 0, .4);
  129. z-index: 99;
  130. }
  131. .choose-tab {
  132. // position: fixed;
  133. top: 0;
  134. left: 0;
  135. width: 100%;
  136. z-index: 100;
  137. .tab-list{
  138. display: flex;
  139. align-items: center;
  140. padding: 22rpx;
  141. background: #fff;
  142. .tab {
  143. background: #F0F0F0;
  144. border-radius: 8rpx 8rpx 8rpx 8rpx;
  145. height: 40rpx;
  146. line-height: 40rpx;
  147. color: #222222;
  148. font-size: 24rpx;
  149. padding: 0 20rpx;
  150. margin-right: 16rpx;
  151. display: flex;
  152. align-items: center;
  153. .u-icon{
  154. margin-left: 5rpx;
  155. }
  156. }
  157. }
  158. .box{
  159. background: #fff;
  160. border-radius: 0rpx 0rpx 16rpx 16rpx;
  161. padding: 14rpx 0;
  162. max-height: 600rpx;
  163. overflow: auto;
  164. .item{
  165. font-size: 24rpx;
  166. color: #222222;
  167. padding: 14rpx 24rpx;
  168. }
  169. }
  170. .active{
  171. color: #3879F9!important;
  172. }
  173. }
  174. </style>