| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <template>
- <view class="wrap">
- <view class="card">
- <!-- 左侧 region -->
- <view class="region" @tap="openPicker">
- <text class="region-text" :class="{ active: !!region }">
- {{ regionLabel }}
- </text>
- <wd-icon v-if="region" name="close" color="#8a94a6" class="clear" @tap.stop="clearRegion" />
- <wd-icon v-else name="down" color="#8a94a6" size="36rpx" class="clear"></wd-icon>
- </view>
- <!-- 分割 -->
- <view class="split" />
- <!-- 输入 -->
- <view class="input-box">
- <wd-search v-model="keyword" placeholder="请输入关键词" hide-cancel :show-action="false" />
- </view>
- </view>
- <!-- picker -->
- <wd-picker v-model:visible="visible" :columns="provinces" @confirm="onConfirm" />
- </view>
- </template>
- <script setup lang="ts">
- import { computed, ref, watch } from 'vue'
- import { debounce } from '@/plugins/debounce'
- import { provinces } from '@/constants/regionOptions'
- const emit = defineEmits<{
- search: [{ region: string; keyword: string }]
- }>()
- const region = ref('')
- const keyword = ref('')
- const visible = ref(false)
- const regionLabel = computed(() => {
- return region.value || '区域'
- })
- const openPicker = () => (visible.value = true)
- const clearRegion = () => {
- region.value = ''
- }
- interface PickerConfirmEvent {
- selectedItems: [
- {
- label: string
- value: string
- },
- ]
- value: string[]
- }
- const onConfirm = (value: PickerConfirmEvent) => {
- region.value = value.selectedItems[0].label
- }
- const doSearch = () => {
- emit('search', {
- region: region.value,
- keyword: keyword.value.trim(),
- })
- }
- const trigger = debounce(doSearch, 350)
- watch([region, keyword], trigger)
- </script>
- <style scoped lang="scss">
- .wrap {
- padding: 24rpx;
- }
- .card {
- display: flex;
- align-items: center;
- height: 92rpx;
- background: #ffffff;
- border-radius: 999rpx;
- box-shadow:
- 0 12rpx 30rpx rgba(0, 0, 0, 0.06),
- inset 0 0 0 1rpx rgba(0, 0, 0, 0.04);
- overflow: hidden;
- }
- /* region */
- .region {
- display: flex;
- align-items: center;
- padding: 0 22rpx;
- height: 100%;
- flex-shrink: 0;
- }
- .region-text {
- font-size: 28rpx;
- margin-right: 6rpx;
- color: #8a94a6;
- }
- .region-text.active {
- color: #1f2937;
- font-weight: 600;
- }
- .clear {
- margin-left: 10rpx;
- font-size: 22rpx;
- color: #9aa4b2;
- }
- /* split */
- .split {
- width: 1rpx;
- height: 42rpx;
- background: linear-gradient(#e5e7eb, #f3f4f6, #e5e7eb);
- }
- /* input */
- .input-box {
- flex: 1;
- padding-right: 16rpx;
- }
- /* 去掉 wd-search 默认背景 */
- :deep(.wd-search__block) {
- background: transparent !important;
- box-shadow: none !important;
- border: none !important;
- }
- :deep(.wd-search__input) {
- font-size: 30rpx;
- }
- </style>
|