96 lines
2.0 KiB
Vue
96 lines
2.0 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.name}`" :value="v.id">
|
|
<div class="flex items-center">
|
|
<div class="color-primary">{{ v.name }}</div>
|
|
<div class="flex items-center justify-center ml5">
|
|
<el-tag size="small">
|
|
{{ v.deptName }}
|
|
</el-tag>
|
|
</div>
|
|
</div>
|
|
</el-option>
|
|
</el-select>
|
|
</template>
|
|
|
|
<script setup lang="ts" name="select-merchant">
|
|
import { reactive } from "vue"
|
|
import * as mchApi from "/@/api/wallet/mch-manage"
|
|
|
|
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 mchApi.select(_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>
|