裂变星小程序-25.03.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.2 KiB

  1. <template>
  2. <view class="drop-down">
  3. <button class="btn-simple" plain @click="openPicker" >
  4. <slot>
  5. <image src="../../static/image/record/filter.png" style="width: 30rpx; height: 30rpx; margin: 10rpx;"></image>
  6. </slot>
  7. </button>
  8. <template v-if="popupVisible">
  9. <view class="drop-down-overlay" @click="closePicker"></view>
  10. <view class="card drop-down-popup">
  11. <view
  12. v-for="item in options"
  13. class="drop-down-option"
  14. :class="[item.value === value ? 'is-active' : '']"
  15. :key="item.value"
  16. @click="onSelect(item.value)"
  17. >
  18. <text>{{ item.label }}</text>
  19. </view>
  20. </view>
  21. </template>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. value: {
  28. type: String | Number,
  29. default: null,
  30. },
  31. options: {
  32. type: Array,
  33. default() {
  34. return []
  35. }
  36. }
  37. },
  38. data() {
  39. return {
  40. popupVisible: false,
  41. }
  42. },
  43. methods: {
  44. openPicker() {
  45. this.popupVisible = true
  46. },
  47. closePicker() {
  48. this.popupVisible = false
  49. },
  50. onSelect(val) {
  51. const selected = this.value
  52. const newVal = selected === val ? null : val
  53. this.$emit('input', newVal)
  54. this.$emit('change', newVal)
  55. },
  56. },
  57. }
  58. </script>
  59. <style scoped lang="scss">
  60. .drop-down {
  61. position: relative;
  62. clear: both;
  63. &-overlay {
  64. position: fixed;
  65. width: 100vw;
  66. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  67. background: transparent;
  68. bottom: 0;
  69. left: 0;
  70. font-size: 0;
  71. }
  72. &-popup {
  73. box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  74. padding: 16rpx 40rpx;
  75. position: absolute;
  76. z-index: 99;
  77. right: -14rpx;
  78. margin-top: 28rpx;
  79. &:before {
  80. content: ' ';
  81. position: absolute;
  82. top: -28rpx;
  83. right: 14rpx;
  84. width: 0;
  85. height: 0;
  86. border: 14rpx solid transparent;
  87. border-bottom-color: #FFFFFF;
  88. }
  89. }
  90. &-option {
  91. color: #999999;
  92. font-size: 28rpx;
  93. white-space: nowrap;
  94. &.is-active {
  95. color: #1B1B1B;
  96. font-weight: 700;
  97. }
  98. & + & {
  99. margin-top: 16rpx;
  100. }
  101. }
  102. }
  103. </style>