search-form.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <!-- 搜索框入口 -->
  3. <wd-search
  4. :placeholder="placeholder"
  5. :hide-cancel="true"
  6. disabled
  7. @click="visible = true"
  8. />
  9. <!-- 搜索弹窗 -->
  10. <wd-popup
  11. v-model="visible"
  12. position="top"
  13. custom-style="border-radius: 0 0 24rpx 24rpx;"
  14. safe-area-inset-top
  15. @close="visible = false"
  16. >
  17. <view class="p-32rpx">
  18. <view class="mb-24rpx text-32rpx text-[#333] font-semibold">
  19. 搜索菜单
  20. </view>
  21. <view class="mb-24rpx">
  22. <view class="mb-12rpx text-28rpx text-[#666]">
  23. 菜单名称
  24. </view>
  25. <wd-input
  26. v-model="formData.name"
  27. placeholder="请输入菜单名称"
  28. clearable
  29. />
  30. </view>
  31. <view class="mb-24rpx">
  32. <view class="mb-12rpx text-28rpx text-[#666]">
  33. 菜单状态
  34. </view>
  35. <wd-radio-group v-model="formData.status" shape="button">
  36. <wd-radio v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" :key="dict.value" :value="dict.value">
  37. {{ dict.label }}
  38. </wd-radio>
  39. </wd-radio-group>
  40. </view>
  41. <view class="w-full flex justify-center gap-24rpx">
  42. <wd-button class="flex-1" plain @click="handleReset">
  43. 重置
  44. </wd-button>
  45. <wd-button class="flex-1" type="primary" @click="handleSearch">
  46. 搜索
  47. </wd-button>
  48. </view>
  49. </view>
  50. </wd-popup>
  51. </template>
  52. <script lang="ts" setup>
  53. import { computed, reactive, ref } from 'vue'
  54. import { getIntDictOptions } from '@/hooks/useDict'
  55. import { DICT_TYPE } from '@/utils/constants'
  56. const emit = defineEmits<{
  57. search: [data: Record<string, any>]
  58. reset: []
  59. }>()
  60. const visible = ref(false)
  61. const formData = reactive({
  62. name: undefined as string | undefined,
  63. status: undefined as number | undefined,
  64. })
  65. /** 搜索条件 placeholder 拼接 */
  66. const placeholder = computed(() => {
  67. const conditions: string[] = []
  68. if (formData.name) {
  69. conditions.push(`名称:${formData.name}`)
  70. }
  71. if (formData.status !== undefined) {
  72. const dict = getIntDictOptions(DICT_TYPE.COMMON_STATUS).find(d => d.value === formData.status)
  73. if (dict) {
  74. conditions.push(`状态:${dict.label}`)
  75. }
  76. }
  77. return conditions.length > 0 ? conditions.join(' | ') : '搜索菜单'
  78. })
  79. /** 搜索 */
  80. function handleSearch() {
  81. visible.value = false
  82. emit('search', { ...formData })
  83. }
  84. /** 重置 */
  85. function handleReset() {
  86. formData.name = undefined
  87. formData.status = undefined
  88. visible.value = false
  89. emit('reset')
  90. }
  91. </script>