Files
klp-oa/klp-ui/src/components/KLPService/RawMaterialSelect/index.vue

109 lines
2.2 KiB
Vue
Raw Normal View History

2025-07-18 17:22:56 +08:00
<template>
<el-select
v-model="selected"
:placeholder="placeholder"
filterable
clearable
2025-07-21 11:55:04 +08:00
remote
:remote-method="debouncedRemoteMethod"
:loading="loading"
2025-07-18 17:22:56 +08:00
@change="onChange"
style="width: 100%"
2025-07-21 10:56:50 +08:00
:value-key="'rawMaterialId'"
2025-07-18 17:22:56 +08:00
>
<el-option
v-for="item in options"
:key="item.rawMaterialId"
2025-07-21 10:56:50 +08:00
:label="`${item.rawMaterialName}${item.rawMaterialCode}`"
2025-07-18 17:22:56 +08:00
:value="item.rawMaterialId"
2025-07-21 10:56:50 +08:00
>
<div class="option-label">
<span class="material-name">{{ item.rawMaterialName }}</span>
<span class="material-code">{{ item.rawMaterialCode }}</span>
</div>
</el-option>
2025-07-18 17:22:56 +08:00
</el-select>
</template>
<script>
import { listRawMaterial } from "@/api/wms/rawMaterial";
2025-07-21 11:55:04 +08:00
function debounce(fn, delay) {
let timer = null;
return function (...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
}, delay);
};
}
2025-07-18 17:22:56 +08:00
export default {
name: "RawMaterialSelect",
props: {
2025-07-21 10:56:50 +08:00
value: [String, null],
2025-07-18 17:22:56 +08:00
placeholder: {
type: String,
default: "请选择原材料"
}
},
data() {
return {
options: [],
2025-07-21 11:55:04 +08:00
selected: this.value,
loading: false
2025-07-18 17:22:56 +08:00
};
},
watch: {
value(val) {
this.selected = val;
2025-07-21 10:56:50 +08:00
},
selected(val) {
this.$emit("input", val);
this.$emit("change", val);
2025-07-18 17:22:56 +08:00
}
},
mounted() {
2025-07-21 11:55:04 +08:00
this.fetchOptions("");
2025-07-18 17:22:56 +08:00
},
methods: {
2025-07-21 11:55:04 +08:00
fetchOptions(keyword) {
this.loading = true;
listRawMaterial({ pageNum: 1, pageSize: 10, rawMaterialName: keyword }).then(res => {
2025-07-18 17:22:56 +08:00
this.options = res.rows || [];
2025-07-21 11:55:04 +08:00
this.loading = false;
}).catch(() => {
this.loading = false;
2025-07-18 17:22:56 +08:00
});
},
2025-07-21 11:55:04 +08:00
remoteMethod(keyword) {
this.fetchOptions(keyword);
},
debouncedRemoteMethod: debounce(function(keyword) {
this.remoteMethod(keyword);
}, 400),
2025-07-18 17:22:56 +08:00
onChange(val) {
this.$emit("input", val);
this.$emit("change", val);
}
}
};
</script>
2025-07-21 10:56:50 +08:00
<style scoped>
.option-label {
display: flex;
justify-content: space-between;
align-items: center;
}
.material-name {
font-size: 14px;
color: #333;
}
.material-code {
font-size: 12px;
color: #999;
margin-left: 10px;
}
</style>