102 lines
1.9 KiB
Vue
102 lines
1.9 KiB
Vue
<template>
|
|
<el-select
|
|
style="width: 100%"
|
|
v-model="selectId"
|
|
:placeholder="props.placeholder"
|
|
clearable
|
|
remote-show-suffix
|
|
filterable
|
|
remote
|
|
:disabled="props.disabled"
|
|
:remote-method="remoteSearch"
|
|
:loading="state.loading"
|
|
@visible-change="(e: boolean) => e && getOptions()"
|
|
:multiple="props.multiple"
|
|
>
|
|
<el-option v-for="v in state.options" :key="v.id" :label="`${v.actTitle}`" :value="v.id">
|
|
<div class="flex items-center">
|
|
<div class="color-primary">{{ v.actTitle }}</div>
|
|
</div>
|
|
</el-option>
|
|
</el-select>
|
|
</template>
|
|
|
|
<script setup lang="ts" name="select-merchant">
|
|
import { reactive } from "vue"
|
|
import * as actCancelApi from "/@/api/act/actCancel"
|
|
|
|
const selectId = defineModel()
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
placeholder?: string
|
|
apiParams?: any
|
|
autoFirst?: boolean
|
|
disabled?: boolean
|
|
multiple?: boolean
|
|
}>(),
|
|
{
|
|
placeholder: "请选择",
|
|
apiParams: {},
|
|
autoFirst: false,
|
|
disabled: false,
|
|
multiple: false,
|
|
},
|
|
)
|
|
|
|
const queryForm = reactive<any>({
|
|
name: null,
|
|
current: 1,
|
|
size: 9999,
|
|
})
|
|
|
|
const state = reactive<any>({
|
|
loading: true,
|
|
selectId: selectId.value,
|
|
options: [],
|
|
})
|
|
|
|
watch(
|
|
selectId,
|
|
(newVal, oldValue) => {
|
|
if (newVal == oldValue) return
|
|
state.selectId = newVal
|
|
getOptions()
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
|
|
async function getOptions() {
|
|
try {
|
|
state.loading = true
|
|
const _pa = {
|
|
...queryForm,
|
|
...props.apiParams,
|
|
}
|
|
const { data } = await actCancelApi.fetchList(_pa)
|
|
state.options = data.records ?? []
|
|
if (props.autoFirst && state.options.length != 0) {
|
|
state.selectId = state.options[0].id
|
|
}
|
|
} finally {
|
|
setTimeout(() => (state.loading = false), 500)
|
|
}
|
|
}
|
|
|
|
function remoteSearch(params: string) {
|
|
if (params != queryForm.name) {
|
|
queryForm.name = params
|
|
getOptions()
|
|
}
|
|
}
|
|
|
|
function clear() {
|
|
state.selectId = null
|
|
getOptions()
|
|
}
|
|
|
|
onMounted(() => {
|
|
props.autoFirst && getOptions()
|
|
})
|
|
</script>
|