search-form.vue 2.5 KB

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