修改食材入库的表单中下拉选择加载缓慢导致的卡顿

This commit is contained in:
weiwei committed 2025-05-28 16:06:57 +08:00
1 parent edf9d8bc15
commit 9031f92404
3 files changed
+91 -55

No files matched your search

+30 -11
View File
@@ -10,24 +10,30 @@
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
@change="change"
>
<el-option v-for="v in state.options" :key="v.supplierId" :label="v.supplierName" :value="v.supplierId" />
</el-select>
</template>
<script setup lang="ts" name="SelectSupplier">
<script setup lang="ts">
import { reactive } from "vue"
import { canteenSupplierSelect } from "/@/api/canteen/canteenSupplier"
import { fetchList } from "/@/api/canteen/canteenSupplier"
const emit = defineEmits(["change"])
const selectId = defineModel()
const props = withDefaults(defineProps<{ placeholder?: string }>(), {
placeholder: "请选择",
export type Props = {
placeholder?: string
}
const props = withDefaults(defineProps<Props>(), {
placeholder: "请输入货商",
})
const queryForm = reactive<any>({
name: "",
supplierId: "",
supplierName: "",
current: 1,
size: 10,
})
const state = reactive<any>({
@@ -41,7 +47,6 @@ watch(
(newVal, oldValue) => {
if (newVal == oldValue) return
state.selectId = newVal
queryForm.supplierId = newVal
getOptions()
},
{ immediate: true },
@@ -50,17 +55,31 @@ watch(
async function getOptions() {
try {
state.loading = true
const { data } = await canteenSupplierSelect(queryForm)
state.options = data ? data : []
const _pa = {
supplierId: selectId.value,
...queryForm,
}
const { data } = await fetchList(_pa)
state.options = data.records ?? []
} finally {
setTimeout(() => (state.loading = false), 500)
}
}
function remoteSearch(params: string) {
if (params != queryForm.name) {
queryForm.name = params
if (params != queryForm.supplierName) {
queryForm.supplierName = params
getOptions()
}
}
function clear() {
state.selectId = null
getOptions()
}
function change(v: any) {
const targetUser = state.options.find((i: any) => i.userId == v)
emit("change", targetUser)
}
</script>
+32 -21
View File
@@ -1,7 +1,5 @@
<template>
<span v-if="isDisplayName">{{ state.options.find((item: any) => item.id == selectId)?.nameWithMobile }}</span>
<el-select
v-else
style="width: 100%"
v-model="state.selectId"
:placeholder="props.placeholder"
@@ -12,36 +10,36 @@
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
@change="change"
>
<el-option v-for="v in state.options" :key="v.id" :label="`${v.nameWithMobile}`" :value="v.id">
<!-- <div class="flex items-center">
<el-option v-for="v in state.options" :key="v.userId" :label="`${v.name}-${v.phone}`" :value="v.userId">
<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> -->
<div class="pl5 color-success">{{ v.phone }}</div>
</div>
</el-option>
</el-select>
</template>
<script setup lang="ts" name="SelectHandlerUser">
<script setup lang="ts" name="select-user">
import { reactive } from "vue"
import { getSimpleUserAll } from "/@/api/admin/user"
import * as userApi from "/@/api/admin/user"
const emit = defineEmits(["change"])
const selectId = defineModel()
export type Props = {
placeholder?: string
isDisplayName?: boolean
}
const props = withDefaults(defineProps<Props>(), {
placeholder: "请选择",
isDisplayName: false,
placeholder: "输入姓名、手机号",
})
const queryForm = reactive<any>({})
const queryForm = reactive<any>({
nameOrPhone: "",
current: 1,
size: 10,
})
const state = reactive<any>({
loading: true,
@@ -54,7 +52,6 @@ watch(
(newVal, oldValue) => {
if (newVal == oldValue) return
state.selectId = newVal
queryForm.userId = newVal
getOptions()
},
{ immediate: true },
@@ -63,17 +60,31 @@ watch(
async function getOptions() {
try {
state.loading = true
const { data } = await getSimpleUserAll(queryForm)
state.options = data ?? []
const _pa = {
userId: selectId.value,
...queryForm,
}
const { data } = await userApi.pageList(_pa)
state.options = data.records ?? []
} finally {
setTimeout(() => (state.loading = false), 500)
}
}
function remoteSearch(params: string) {
if (params != queryForm.name) {
queryForm.name = params
if (params != queryForm.nameOrPhone) {
queryForm.nameOrPhone = params
getOptions()
}
}
function clear() {
state.selectId = null
getOptions()
}
function change(v: any) {
const targetUser = state.options.find((i: any) => i.userId == v)
emit("change", targetUser)
}
</script>
+29 -23
View File
@@ -1,7 +1,5 @@
<template>
<span v-if="isDisplayName">{{ state.options.find((item: any) => item.supplierId == selectId)?.supplierName }}</span>
<el-select
v-else
style="width: 100%"
v-model="state.selectId"
:placeholder="props.placeholder"
@@ -12,36 +10,31 @@
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
@change="change"
>
<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-option v-for="v in state.options" :key="v.supplierId" :label="v.supplierName" :value="v.supplierId" />
</el-select>
</template>
<script setup lang="ts" name="SelectSupplier">
<script setup lang="ts">
import { reactive } from "vue"
import { getSupplierSimpleAll } from "/@/api/supermarketerp/smErpSupplier"
import { fetchList } from "/@/api/supermarketerp/smErpSupplier"
const emit = defineEmits(["change"])
const selectId = defineModel()
export type Props = {
placeholder?: string
isDisplayName?: boolean
}
const props = withDefaults(defineProps<Props>(), {
placeholder: "请选择",
isDisplayName: false,
placeholder: "请输入货商",
})
const queryForm = reactive<any>({})
const queryForm = reactive<any>({
supplierName: "",
current: 1,
size: 10,
})
const state = reactive<any>({
loading: true,
@@ -54,7 +47,6 @@ watch(
(newVal, oldValue) => {
if (newVal == oldValue) return
state.selectId = newVal
queryForm.supplierId = newVal
getOptions()
},
{ immediate: true },
@@ -63,17 +55,31 @@ watch(
async function getOptions() {
try {
state.loading = true
const { data } = await getSupplierSimpleAll(queryForm)
state.options = data ? data.filter((item: any) => item.supplierId) : []
const _pa = {
supplierId: selectId.value,
...queryForm,
}
const { data } = await fetchList(_pa)
state.options = data.records ?? []
} finally {
setTimeout(() => (state.loading = false), 500)
}
}
function remoteSearch(params: string) {
if (params != queryForm.name) {
queryForm.name = params
if (params != queryForm.supplierName) {
queryForm.supplierName = params
getOptions()
}
}
function clear() {
state.selectId = null
getOptions()
}
function change(v: any) {
const targetUser = state.options.find((i: any) => i.userId == v)
emit("change", targetUser)
}
</script>