SelectList.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <script setup lang="ts">
  2. import { useSelectListPopup } from '~/composables/useSelectListPopup'
  3. import OrderCheckSvg from '~/assets/icons/order/check.svg'
  4. const { state, close, select } = useSelectListPopup()
  5. const handleUpdateShow = (value: boolean) => {
  6. if (!value) {
  7. close()
  8. }
  9. }
  10. </script>
  11. <template>
  12. <van-popup
  13. :show="state.visible"
  14. round
  15. position="bottom"
  16. class="select-list-popup"
  17. @update:show="handleUpdateShow"
  18. >
  19. <div class="select-list-popup__container">
  20. <!-- 可选标题 -->
  21. <h3
  22. v-if="state.title"
  23. class="select-list-popup__title"
  24. >
  25. {{ state.title }}
  26. </h3>
  27. <section class="select-list-popup__card">
  28. <button
  29. v-for="item in state.options"
  30. :key="item.value"
  31. type="button"
  32. class="select-list-popup__item"
  33. @click="select(item)"
  34. >
  35. <span class="select-list-popup__item-label">
  36. <img
  37. v-if="item.icon"
  38. :src="item.icon"
  39. :alt="item.label"
  40. loading="lazy"
  41. >
  42. {{ item.label }}
  43. </span>
  44. <OrderCheckSvg
  45. v-if="state.selectedValue === item.value"
  46. />
  47. <span
  48. v-else
  49. class="select-list-popup__indicator"
  50. />
  51. </button>
  52. </section>
  53. </div>
  54. </van-popup>
  55. </template>
  56. <style scoped lang="scss">
  57. .select-list-popup {
  58. background-color: transparent;
  59. &__container {
  60. position: relative;
  61. border-radius: 15px 15px 0 0;
  62. padding: 18px 16px;
  63. background: #FFF;
  64. overflow: hidden;
  65. }
  66. &__title {
  67. margin: 0 0 8px;
  68. text-align: center;
  69. font-family: var(--font-title);
  70. font-size: 14px;
  71. font-weight: 600;
  72. color: var(--color-text-primary);
  73. }
  74. &__card {
  75. border-radius: 12px;
  76. background-color: #fff;
  77. padding: 4px 0;
  78. max-height: 260px;
  79. overflow-y: auto;
  80. }
  81. &__item {
  82. width: 100%;
  83. display: flex;
  84. align-items: center;
  85. justify-content: space-between;
  86. background-color: transparent;
  87. border: none;
  88. cursor: pointer;
  89. -webkit-tap-highlight-color: transparent;
  90. & {
  91. padding: 12px 0;
  92. }
  93. &:first-child {
  94. padding-top: 0;
  95. }
  96. &:last-child {
  97. padding-bottom: 0;
  98. }
  99. &:not(:last-child) {
  100. border-bottom: 1px solid #f2f3f5;
  101. }
  102. }
  103. &__item-label {
  104. font-size: 14px;
  105. font-weight: 600;
  106. color: var(--color-text-primary);
  107. display: flex;
  108. align-items: center;
  109. gap: 8px;
  110. img {
  111. @include size(24px);
  112. }
  113. }
  114. &__indicator {
  115. @include size(22px);
  116. border-radius: 999px;
  117. border: 2px solid #dadce6;
  118. box-sizing: border-box;
  119. }
  120. }
  121. </style>
  122. <style lang="scss">
  123. .van-popup.select-list-popup {
  124. overflow-y: unset;
  125. }
  126. </style>