category-popup.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <u-popup v-model="showPopup" mode="bottom" border-radius="20">
  3. <view class="category-popup">
  4. <view class="popup-header">
  5. <text>分类</text>
  6. <u-icon name="close" size="32" @click="close"></u-icon>
  7. </view>
  8. <view class="category-list">
  9. <view v-for="(item, index) in categories" :key="index" class="category-item"
  10. :class="{ 'active': selectedCategories.includes(item.value), 'disabled': item.disabled }"
  11. @click="toggleSelect(item)">
  12. {{ item.label }}
  13. </view>
  14. </view>
  15. <view class="confirm-btn" @click="confirm">
  16. 确定筛选
  17. </view>
  18. </view>
  19. </u-popup>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'category-popup',
  24. props: {
  25. show: {
  26. type: Boolean,
  27. default: false
  28. }
  29. },
  30. data() {
  31. return {
  32. showPopup: false,
  33. categories: [],
  34. selectedCategories: []
  35. }
  36. },
  37. watch: {
  38. show(newVal) {
  39. this.showPopup = newVal
  40. newVal && this.getDict()
  41. },
  42. showPopup(newVal) {
  43. if (!newVal) {
  44. this.$emit('update:show', false)
  45. }
  46. },
  47. },
  48. methods: {
  49. toggleSelect(item) {
  50. if (item.disabled) return
  51. const index = this.selectedCategories.indexOf(item.value)
  52. if (index > -1) {
  53. this.selectedCategories.splice(index, 1)
  54. } else {
  55. this.selectedCategories.push(item.value)
  56. }
  57. },
  58. confirm() {
  59. this.$emit('confirm', this.selectedCategories)
  60. this.close()
  61. },
  62. close() {
  63. this.showPopup = false
  64. this.$emit('update:show', false)
  65. },
  66. //根据code获取字典 user_account_change_type
  67. getDict(code = 'user_account_change_type') {
  68. uni.$u.http.get('/token/common/getDictOptions?type=' + code).then(res => {
  69. if (res.code === 200) {
  70. this.categories = res.data.map(item => ({ label: item.dictLabel, value: item.dictValue }))
  71. }
  72. })
  73. },
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .category-popup {
  79. padding: 30rpx;
  80. padding-bottom: env(safe-area-inset-bottom);
  81. .popup-header {
  82. display: flex;
  83. justify-content: space-between;
  84. align-items: center;
  85. padding-bottom: 30rpx;
  86. font-size: 32rpx;
  87. color: #333;
  88. }
  89. .category-list {
  90. display: flex;
  91. flex-wrap: wrap;
  92. padding: 20rpx 0;
  93. gap: 20rpx;
  94. .category-item {
  95. padding: 0 42rpx;
  96. height: 60rpx;
  97. line-height: 60rpx;
  98. text-align: center;
  99. border-radius: 10rpx;
  100. font-size: 28rpx;
  101. color: #38C148;
  102. border: 1px solid #38C148;
  103. &.active {
  104. color: #ffffff;
  105. border: 1px solid #38C148;
  106. background-color: #38C148;
  107. }
  108. }
  109. }
  110. .confirm-btn {
  111. margin-top: 40rpx;
  112. height: 90rpx;
  113. line-height: 90rpx;
  114. text-align: center;
  115. background: #38C148;
  116. border-radius: 45rpx;
  117. color: #FFFFFF;
  118. font-size: 32rpx;
  119. }
  120. }
  121. </style>