商户下拉选择
This commit is contained in:
1 parent
5da50dbc19
commit
79497d7b05
8 files changed
+209
-248
No files matched your search
@@ -1,73 +1,86 @@
|
||||
<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.id" :label="`${v.name}`" :value="v.id">
|
||||
<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>
|
||||
<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.id" :label="`${v.name}`" :value="v.id">
|
||||
<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="select-merchant">
|
||||
import { reactive, computed, defineModel, withDefaults, defineProps } from 'vue'
|
||||
import * as mchApi from '/@/api/wallet/mch-manage'
|
||||
import { reactive, computed, defineModel, withDefaults, defineProps } from 'vue';
|
||||
import * as mchApi from '/@/api/wallet/mch-manage';
|
||||
|
||||
const selectId = defineModel()
|
||||
const selectId = defineModel();
|
||||
|
||||
export type Props = {
|
||||
placeholder?: string,
|
||||
}
|
||||
placeholder?: string;
|
||||
};
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
placeholder: "请选择",
|
||||
})
|
||||
placeholder: '请选择',
|
||||
});
|
||||
|
||||
const queryForm = reactive<any>({
|
||||
name: "",
|
||||
current: 1,
|
||||
size: 10,
|
||||
})
|
||||
name: '',
|
||||
current: 1,
|
||||
size: 10,
|
||||
});
|
||||
|
||||
const state = reactive<any>({
|
||||
loading: true,
|
||||
selectId: selectId,
|
||||
options: []
|
||||
})
|
||||
loading: true,
|
||||
selectId: selectId,
|
||||
options: [],
|
||||
});
|
||||
|
||||
watch(selectId, (newVal, oldValue) => {
|
||||
if (newVal == oldValue) return
|
||||
state.selectId = newVal
|
||||
getOptions()
|
||||
}, { immediate: true })
|
||||
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 mchApi.pageJoin(_pa)
|
||||
state.options = data.records ?? []
|
||||
} finally {
|
||||
setTimeout(() => state.loading = false, 500);
|
||||
}
|
||||
try {
|
||||
state.loading = true;
|
||||
const _pa = {
|
||||
...queryForm,
|
||||
};
|
||||
const { data } = await mchApi.pageJoin(_pa);
|
||||
state.options = data.records ?? [];
|
||||
} finally {
|
||||
setTimeout(() => (state.loading = false), 500);
|
||||
}
|
||||
}
|
||||
|
||||
function remoteSearch(params: string) {
|
||||
if (params != queryForm.name) {
|
||||
queryForm.name = params
|
||||
getOptions()
|
||||
}
|
||||
if (params != queryForm.name) {
|
||||
queryForm.name = params;
|
||||
getOptions();
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
state.selectId = null
|
||||
getOptions()
|
||||
state.selectId = null;
|
||||
getOptions();
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
Reference in new issue
Block a user