| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <script setup lang="ts">
- const props = withDefaults(
- defineProps<{
- height?: string | number
- searchInputValue?: string | number
- queryType?: string | number
- searchType?: string | number
- queryTypeData?: any[]
- searchPlaceholder?: string
- searchBtnText?: string
- searchBtnIcon?: string
- searchDropdownValue?: string[] | number[]
- searchDropdownList?: any[]
- searchTabList?: any[]
- }>(),
- {
- searchPlaceholder: "请输入搜索内容",
- searchDropdownList: () => [],
- searchDropdownValue: () => [],
- }
- )
- const emits = defineEmits<{
- (e: "update:searchInputValue", v: string | number): void
- (e: "update:queryType", v: string | number): void
- (e: "update:searchType", v: string | number): void
- (e: "update:searchDropdownValue", v: string[] | number[]): void
- (e: "changeQueryType", v: string | number): void
- (e: "search-btn"): void
- (e: "search"): void
- }>()
- const { searchInputValue, queryType, searchDropdownValue, searchBtnText } = toRefs(props)
- const dropdownRef = ref<any[]>([])
- // const _searchBtnText = computed(() => {
- // console.log("----", props.searchBtnText)
- // return props.searchBtnText
- // })
- const style = computed(() => {
- const style: any = {}
- if (props.height) {
- style.height = addUnit(props.height)
- } else {
- style.height = props.queryTypeData?.length ? "130px" : "95px"
- }
- return style
- })
- const activeTabIndex = ref(0)
- const getDefaultSearchDropdownValue = () => {
- const arr = []
- for (let i = 0; i < props.searchDropdownList?.length; i++) {
- arr.push("")
- }
- return arr
- }
- function bindQueryChange(e: any) {
- activeTabIndex.value = 0
- emits("update:searchInputValue", "")
- emits("changeQueryType", e.detail.value)
- emits("update:queryType", e.detail.value)
- emits("update:searchType", "")
- emits("update:searchDropdownValue", getDefaultSearchDropdownValue())
- search()
- }
- function bindSearchBtnClick() {
- emits("search-btn")
- }
- function bindSearchTabClick(index: number, type?: string) {
- activeTabIndex.value = index
- if (index >= props.searchDropdownList.length) {
- dropdownRef.value.forEach((v: any) => {
- v.close()
- })
- emits("update:searchType", type || "")
- emits("update:searchDropdownValue", getDefaultSearchDropdownValue())
- } else {
- emits("update:searchType", "")
- }
- search()
- }
- function bindChangeDropdown(e: any, i: number) {
- searchDropdownValue.value[i] = e
- search()
- }
- function onSearch() {
- search()
- }
- function search() {
- nextTick(() => {
- emits("search")
- })
- }
- </script>
- <template>
- <view class="bg-white px-15 pt-15" :style="style">
- <view v-if="queryTypeData && queryTypeData.length" class="d-fc mb-10">
- <uni-data-checkbox
- v-model="queryType"
- :localdata="queryTypeData"
- selectedColor="var(--vb-color)"
- selectedTextColor="var(--vb-color)"
- @change="bindQueryChange"
- ></uni-data-checkbox>
- </view>
- <view class="d-flex align-center">
- <input
- class="w-100 px-20 h-40px br-30 me-15"
- type="text"
- :placeholder="searchPlaceholder"
- v-model="searchInputValue"
- style="background: #f2f2f2"
- confirm-type="search"
- adjust-position="false"
- auto-blur="true"
- @confirm="onSearch"
- />
- <view
- v-if="searchBtnIcon || searchBtnText"
- class="d-fc fs-15 br-20 text-white bg-vb"
- style="cursor: pointer; white-space: nowrap; height: 38px; min-width: 90px"
- @click="bindSearchBtnClick"
- >
- <i v-if="searchBtnIcon" class="me-3 fs-20 iconfont" :class="'icon-' + searchBtnIcon"></i>
- {{ searchBtnText }}
- </view>
- </view>
- <view class="d-flex h-30px mt-10 pb-5 align-center">
- <template v-if="searchDropdownList?.length">
- <vb-dropdown
- v-for="(v, i) in searchDropdownList"
- ref="dropdownRef"
- v-model="searchDropdownValue[i]"
- :active="activeTabIndex == i"
- :empty-title="v.emptyTitle"
- :options="v.data"
- :key="i"
- :map="v.map"
- @click="bindSearchTabClick(i)"
- @change="(e:any) => bindChangeDropdown(e, i)"
- custom-class="px-8"
- ></vb-dropdown>
- </template>
- <template v-if="searchTabList && searchTabList.length > 0">
- <template v-for="(v, i) in searchTabList" :key="i">
- <view class="text-gray-4">|</view>
- <view
- class="px-5"
- :class="{ 'text-vb font-bold': activeTabIndex == i + (searchDropdownList?.length || 0) }"
- @click="bindSearchTabClick(i + (searchDropdownList?.length || 0), v.value)"
- >
- {{ v.text }}
- </view>
- </template>
- </template>
- </view>
- </view>
- </template>
|