| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <template>
- <db-popup :show="show" height="70vh" @close="close" @update:show="(v) => emit('update:show', v)">
- <view class="picker">
- <view class="picker__search">
- <db-search
- v-model="keyword"
- placeholder="搜索客户名称"
- @change="onKeyword"
- @search="load"
- @clear="onClear"
- />
- </view>
- <scroll-view scroll-y class="picker__list">
- <view
- v-for="item in options"
- :key="item.id"
- class="picker__cell"
- @click="onSelect(item)"
- >
- <text class="picker__title">{{ item.customerName }}</text>
- <text v-if="item.customerNo" class="picker__label">{{ item.customerNo }}</text>
- </view>
- <view v-if="!loading && !options.length" class="db-empty">暂无匹配</view>
- </scroll-view>
- </view>
- </db-popup>
- </template>
- <script setup>
- import { ref, watch } from 'vue'
- import { fetchCustomerOptions } from '@/api/dbOptions'
- import DbPopup from '@/components/db-ui/db-popup.vue'
- import DbSearch from '@/components/db-ui/db-search.vue'
- const props = defineProps({ show: Boolean })
- const emit = defineEmits(['update:show', 'select'])
- const keyword = ref('')
- const loading = ref(false)
- const options = ref([])
- let timer = null
- watch(
- () => props.show,
- (v) => {
- if (v) {
- keyword.value = ''
- load()
- }
- }
- )
- function close() {
- emit('update:show', false)
- }
- function onClear() {
- keyword.value = ''
- load()
- }
- function onKeyword() {
- if (timer) clearTimeout(timer)
- timer = setTimeout(load, 300)
- }
- async function load() {
- loading.value = true
- try {
- options.value = await fetchCustomerOptions(keyword.value)
- } catch (e) {
- options.value = []
- } finally {
- loading.value = false
- }
- }
- function onSelect(item) {
- emit('select', item)
- close()
- }
- </script>
- <style scoped>
- .picker {
- display: flex;
- flex-direction: column;
- height: 70vh;
- }
- .picker__search {
- padding: 12px;
- }
- .picker__list {
- flex: 1;
- height: 0;
- }
- .picker__cell {
- padding: 14px 16px;
- border-bottom: 1px solid #f5f6f8;
- }
- .picker__title {
- display: block;
- font-size: 15px;
- color: #323233;
- }
- .picker__label {
- display: block;
- margin-top: 4px;
- font-size: 12px;
- color: #969799;
- }
- .db-empty {
- padding: 40px;
- text-align: center;
- color: #969799;
- font-size: 14px;
- }
- </style>
|