lanan-system-vue/src/views/repair/Components/StaffChoose.vue

73 lines
1.4 KiB
Vue
Raw Normal View History

2024-09-11 18:49:43 +08:00
<template>
<el-select :loading="selectLoading" v-model="staffSelected" clearable filterable :filter-method="changeQuery"
@blur="$emit('input-blur', $event)">
<el-option v-for="staff in staffList" :key="staff.id" :label="staff.name + ' ' + staff.tel" :value="staff.id"/>
2024-09-11 18:49:43 +08:00
</el-select>
</template>
<script>
import {getStaffList} from "@/api/company/staff";
export default {
name: "StaffChoose",
2024-09-20 21:21:39 +08:00
props: {
2024-09-14 18:27:01 +08:00
value: {
type: Object,
2024-09-25 15:42:23 +08:00
},
isGet: {
2024-09-25 15:42:23 +08:00
type: String,
default: '',
required: false
2024-09-14 18:27:01 +08:00
}
},
2024-09-11 18:49:43 +08:00
data() {
return {
staffList: [],
staffSelected: undefined,
hasRequest: false,
query: null,
selectLoading: false,
2024-09-11 18:49:43 +08:00
}
},
2024-09-20 21:21:39 +08:00
watch: {
2024-09-11 18:49:43 +08:00
staffSelected(val) {
const staff = this.staffList.find(item => item.id === val);
if (staff) {
this.$emit("input", staff);
}
2024-09-14 18:27:01 +08:00
},
2024-09-20 21:21:39 +08:00
value(newVal) {
if (newVal) {
2024-09-14 18:27:01 +08:00
this.staffSelected = newVal.id
2024-09-20 21:21:39 +08:00
} else {
2024-09-14 18:27:01 +08:00
this.staffSelected = null
}
2024-09-20 21:21:39 +08:00
},
2024-09-11 18:49:43 +08:00
},
mounted() {
this.listStaff()
},
methods: {
async listStaff() {
this.selectLoading = true
2024-09-11 18:49:43 +08:00
try {
2024-09-25 15:42:23 +08:00
if (!this.isGet) return;
const res = await getStaffList(this.query)
2024-09-11 18:49:43 +08:00
this.staffList = res.data
} finally {
this.selectLoading = false
2024-09-11 18:49:43 +08:00
}
},
changeQuery(val) {
this.query = val
this.listStaff()
2024-09-11 18:49:43 +08:00
}
}
}
</script>
<style scoped lang="scss">
</style>