超市模块系统反馈修改
This commit is contained in:
1 parent
c2cd2dbbc9
commit
6094b9c928
7 files changed
+77
-49
No files matched your search
@@ -3,13 +3,16 @@
|
||||
style="width: 100%"
|
||||
v-model="state.selectId"
|
||||
:placeholder="props.placeholder"
|
||||
:disabled="props.disabled"
|
||||
clearable
|
||||
remote-show-suffix
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
default-first-option
|
||||
remote-show-suffix
|
||||
:remote-method="remoteSearch"
|
||||
:loading="state.loading"
|
||||
@visible-change="(e: boolean) => e && getOptions()"
|
||||
@visible-change="handleVisibleChange"
|
||||
@change="change"
|
||||
>
|
||||
<el-option v-for="item in state.options" :key="item.supplierId" :label="item.supplierName" :value="item.supplierId" />
|
||||
@@ -18,65 +21,76 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, watch } from "vue"
|
||||
import { fetchList } from "/@/api/supermarketerp/smErpSupplier"
|
||||
import { getSupplierSimpleAll } from "/@/api/supermarketerp/smErpSupplier"
|
||||
|
||||
const emit = defineEmits(["change"])
|
||||
|
||||
const selectId = defineModel()
|
||||
const selectId = defineModel<string | number>()
|
||||
|
||||
export type Props = {
|
||||
placeholder?: string
|
||||
disabled?: boolean
|
||||
isDisplayName?: boolean
|
||||
}
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
placeholder: "输入货商搜索",
|
||||
})
|
||||
|
||||
const queryForm = reactive<any>({
|
||||
supplierName: "",
|
||||
current: 1,
|
||||
size: 10,
|
||||
placeholder: "输入供货商名称搜索",
|
||||
disabled: false,
|
||||
isDisplayName: false,
|
||||
})
|
||||
|
||||
const state = reactive<any>({
|
||||
loading: true,
|
||||
loading: false,
|
||||
selectId: selectId,
|
||||
options: [],
|
||||
keyword: "",
|
||||
})
|
||||
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
watch(
|
||||
selectId,
|
||||
(newVal, oldValue) => {
|
||||
if (newVal == oldValue) return
|
||||
state.selectId = newVal
|
||||
getOptions()
|
||||
loadOptions(state.keyword)
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
async function getOptions() {
|
||||
async function loadOptions(keyword = "") {
|
||||
try {
|
||||
state.loading = true
|
||||
const _pa = {
|
||||
supplierId: selectId.value,
|
||||
...queryForm,
|
||||
const params: Record<string, any> = {}
|
||||
if (keyword) {
|
||||
params.name = keyword
|
||||
}
|
||||
const { data } = await fetchList(_pa)
|
||||
state.options = data.records ?? []
|
||||
const { data } = await getSupplierSimpleAll(params)
|
||||
let options = Array.isArray(data) ? data : []
|
||||
if (selectId.value && !options.some((item: any) => item.supplierId == selectId.value)) {
|
||||
const { data: selectedData } = await getSupplierSimpleAll({ supplierId: selectId.value })
|
||||
const selected = Array.isArray(selectedData) ? selectedData : []
|
||||
if (selected.length) {
|
||||
options = [...selected, ...options.filter((item: any) => item.supplierId != selectId.value)]
|
||||
}
|
||||
}
|
||||
state.options = options
|
||||
} finally {
|
||||
setTimeout(() => (state.loading = false), 500)
|
||||
state.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
function remoteSearch(params: string) {
|
||||
if (params != queryForm.supplierName) {
|
||||
queryForm.supplierName = params
|
||||
getOptions()
|
||||
function handleVisibleChange(visible: boolean) {
|
||||
if (visible) {
|
||||
loadOptions(state.keyword)
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
state.selectId = null
|
||||
getOptions()
|
||||
function remoteSearch(keyword: string) {
|
||||
state.keyword = keyword
|
||||
if (searchTimer) {
|
||||
clearTimeout(searchTimer)
|
||||
}
|
||||
searchTimer = setTimeout(() => loadOptions(keyword), 300)
|
||||
}
|
||||
|
||||
function change(v: any) {
|
||||
|
||||
Reference in new issue
Block a user