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

114 lines
2.7 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"
2025-10-14 17:36:06 +08:00
@blur="$emit('input-blur', selectedStaff)" @change="handleChange">
<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";
2024-10-26 21:30:12 +08:00
import {getUserProfile} from "@/api/system/user";
2024-09-11 18:49:43 +08:00
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-10-26 21:30:12 +08:00
},
roleCode:{
type: String,
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
}
},
2025-10-14 17:36:06 +08:00
computed: {
selectedStaff() {
const staff = this.staffList.find(item => item.id === this.staffSelected) || null;
return staff;
}
},
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()
2025-10-14 17:36:06 +08:00
// 只有在需要自动获取当前用户信息时才调用 getNow()
if (this.isGet && this.isGet !== 'false') {
this.getNow()
}
2024-09-11 18:49:43 +08:00
},
methods: {
2025-10-14 17:36:06 +08:00
handleChange(val) {
if (val) {
const staff = this.staffList.find(item => item.id === val);
if (staff) {
this.$emit("input", staff);
this.$emit("input-blur", staff);
}
} else {
this.$emit("input", null);
this.$emit("input-blur", null);
}
},
2024-09-11 18:49:43 +08:00
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;
2024-10-26 21:30:12 +08:00
if (this.roleCode){
// todo 暂时先把流程跑通了来
}else {
const res = await getStaffList(this.query)
this.staffList = res.data
if (this.query){
2025-10-14 17:36:06 +08:00
const filtered = this.staffList.filter(item => item.tel === this.query);
if (filtered.length > 0) {
this.staffSelected = filtered[0].id
}
2024-10-26 21:30:12 +08:00
this.query = null
}
}
} finally {
this.selectLoading = false
2024-09-11 18:49:43 +08:00
}
},
changeQuery(val) {
this.query = val
this.listStaff()
2024-10-26 21:30:12 +08:00
},
async getNow(){
// 获取当前登录用户
const res = await getUserProfile()
this.changeQuery(res.data.mobile)
2024-09-11 18:49:43 +08:00
}
}
}
</script>
<style scoped lang="scss">
2025-10-14 17:36:06 +08:00
</style>