search-form.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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-input
  24. v-model="formData.code"
  25. placeholder="请输入分类标志"
  26. clearable
  27. />
  28. </view>
  29. <view class="yd-search-form-item">
  30. <view class="yd-search-form-label">
  31. 分类状态
  32. </view>
  33. <wd-radio-group v-model="formData.status" shape="button">
  34. <wd-radio :value="-1">
  35. 全部
  36. </wd-radio>
  37. <wd-radio
  38. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  39. :key="dict.value"
  40. :value="dict.value"
  41. >
  42. {{ dict.label }}
  43. </wd-radio>
  44. </wd-radio-group>
  45. </view>
  46. <view class="yd-search-form-item">
  47. <view class="yd-search-form-label">
  48. 创建时间
  49. </view>
  50. <view class="yd-search-form-date-range-container">
  51. <view class="flex-1" @click="visibleCreateTime[0] = true">
  52. <view class="yd-search-form-date-range-picker">
  53. {{ formatDate(formData.createTime?.[0]) || '开始日期' }}
  54. </view>
  55. </view>
  56. -
  57. <view class="flex-1" @click="visibleCreateTime[1] = true">
  58. <view class="yd-search-form-date-range-picker">
  59. {{ formatDate(formData.createTime?.[1]) || '结束日期' }}
  60. </view>
  61. </view>
  62. </view>
  63. <wd-datetime-picker-view v-if="visibleCreateTime[0]" v-model="tempCreateTime[0]" type="date" />
  64. <view v-if="visibleCreateTime[0]" class="yd-search-form-date-range-actions">
  65. <wd-button size="small" plain @click="visibleCreateTime[0] = false">
  66. 取消
  67. </wd-button>
  68. <wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
  69. 确定
  70. </wd-button>
  71. </view>
  72. <wd-datetime-picker-view v-if="visibleCreateTime[1]" v-model="tempCreateTime[1]" type="date" />
  73. <view v-if="visibleCreateTime[1]" class="yd-search-form-date-range-actions">
  74. <wd-button size="small" plain @click="visibleCreateTime[1] = false">
  75. 取消
  76. </wd-button>
  77. <wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
  78. 确定
  79. </wd-button>
  80. </view>
  81. </view>
  82. <view class="yd-search-form-actions">
  83. <wd-button class="flex-1" plain @click="handleReset">
  84. 重置
  85. </wd-button>
  86. <wd-button class="flex-1" type="primary" @click="handleSearch">
  87. 搜索
  88. </wd-button>
  89. </view>
  90. </view>
  91. </wd-popup>
  92. </template>
  93. <script lang="ts" setup>
  94. import { computed, reactive, ref } from 'vue'
  95. import { getDictLabel, getIntDictOptions } from '@/hooks/useDict'
  96. import { getNavbarHeight } from '@/utils'
  97. import { DICT_TYPE } from '@/utils/constants'
  98. import { formatDate, formatDateRange } from '@/utils/date'
  99. const emit = defineEmits<{
  100. search: [data: Record<string, any>]
  101. reset: []
  102. }>()
  103. const visible = ref(false)
  104. const formData = reactive({
  105. name: undefined as string | undefined,
  106. code: undefined as string | undefined,
  107. status: -1, // -1 表示全部
  108. createTime: [undefined, undefined] as [number | undefined, number | undefined],
  109. })
  110. // 时间范围选择器状态
  111. const visibleCreateTime = ref<[boolean, boolean]>([false, false])
  112. const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
  113. /** 搜索条件 placeholder 拼接 */
  114. const placeholder = computed(() => {
  115. const conditions: string[] = []
  116. if (formData.name) {
  117. conditions.push(`分类名:${formData.name}`)
  118. }
  119. if (formData.code) {
  120. conditions.push(`分类标志:${formData.code}`)
  121. }
  122. if (formData.status !== -1) {
  123. conditions.push(`状态:${getDictLabel(DICT_TYPE.COMMON_STATUS, formData.status)}`)
  124. }
  125. if (formData.createTime?.[0] && formData.createTime?.[1]) {
  126. conditions.push(`创建时间:${formatDate(formData.createTime[0])}~${formatDate(formData.createTime[1])}`)
  127. }
  128. return conditions.length > 0 ? conditions.join(' | ') : '搜索流程分类'
  129. })
  130. /** 创建时间[0]确认 */
  131. function handleCreateTime0Confirm() {
  132. formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
  133. visibleCreateTime.value[0] = false
  134. }
  135. /** 创建时间[1]确认 */
  136. function handleCreateTime1Confirm() {
  137. formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
  138. visibleCreateTime.value[1] = false
  139. }
  140. /** 搜索 */
  141. function handleSearch() {
  142. visible.value = false
  143. emit('search', {
  144. ...formData,
  145. status: formData.status === -1 ? undefined : formData.status,
  146. createTime: formatDateRange(formData.createTime),
  147. })
  148. }
  149. /** 重置 */
  150. function handleReset() {
  151. formData.name = undefined
  152. formData.code = undefined
  153. formData.status = -1
  154. formData.createTime = [undefined, undefined]
  155. visible.value = false
  156. emit('reset')
  157. }
  158. </script>