Files
pj_admin_cloud/src/components/Select/SelectSupplier.vue
T
2025-03-06 16:39:39 +08:00

83 lines
1.7 KiB
Vue

<template>
<el-select
style="width: 100%"
v-model="state.selectId"
:placeholder="props.placeholder"
clearable
remote-show-suffix
filterable
remote
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
>
<el-option v-for="v in state.options" :key="v.supplierId" :label="v.supplierName" :value="v.supplierId">
<!-- <div class="flex items-center">
<div class="color-primary">{{ v.name }}</div>
<div class="flex items-center just ml5">
<el-tag size="small">
{{ v.deptName }}
</el-tag>
</div>
</div> -->
</el-option>
</el-select>
</template>
<script setup lang="ts" name="SelectSupplier">
import { reactive } from "vue"
import { getSupplierSimpleAll } from "/@/api/supermarketerp/smErpSupplier"
const selectId = defineModel()
export type Props = {
placeholder?: string
}
const props = withDefaults(defineProps<Props>(), {
placeholder: "请选择",
})
const queryForm = reactive<any>({})
const state = reactive<any>({
loading: true,
selectId: selectId,
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,
}
const { data } = await getSupplierSimpleAll(_pa)
state.options = data ? data.filter((item: any) => item.supplierId) : []
} finally {
setTimeout(() => (state.loading = false), 500)
}
}
function remoteSearch(params: string) {
if (params != queryForm.name) {
queryForm.name = params
getOptions()
}
}
function clear() {
state.selectId = null
getOptions()
}
</script>