将编辑员工对话改为组件
This commit is contained in:
60
src/components/customer/EmployeeEditDialog.vue
Normal file
60
src/components/customer/EmployeeEditDialog.vue
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" title="新增客户员工"
|
||||||
|
width="450px">
|
||||||
|
<el-form :model="form" label-width="100px">
|
||||||
|
<el-form-item label="员工姓名" required>
|
||||||
|
<el-input v-model="form.employee_name" placeholder="请输入姓名" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="所属客户" required>
|
||||||
|
<el-select v-model="form.customer_id" placeholder="请选择归属单位" style="width: 100%">
|
||||||
|
<el-option v-for="item in customerList" :key="item.customer_id" :label="item.company_name"
|
||||||
|
:value="item.customer_id" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="$emit('update:modelValue', false)">取消</el-button>
|
||||||
|
<el-button type="success" @click="handleSubmit">保存员工</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, watch } from "vue";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
import { customerApi } from "@/api/ticket";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: Boolean,
|
||||||
|
customerList: Array,
|
||||||
|
});
|
||||||
|
const emit = defineEmits(["update:modelValue", "success"]);
|
||||||
|
|
||||||
|
const form = ref({ employee_name: "", customer_id: null });
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(val) => {
|
||||||
|
if (val) form.value = { employee_name: "", customer_id: null };
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!form.value.employee_name || !form.value.customer_id) {
|
||||||
|
return ElMessage.error("请填写员工姓名并选择所属单位");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await customerApi.addEmployee({
|
||||||
|
emp_name: form.value.employee_name,
|
||||||
|
customer_id: form.value.customer_id,
|
||||||
|
});
|
||||||
|
if (res.code === 200) {
|
||||||
|
ElMessage.success("员工保存成功");
|
||||||
|
emit("success");
|
||||||
|
emit("update:modelValue", false);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error("保存失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user