index.vue 3.2 KB

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