将客户编辑对话改为组件
This commit is contained in:
48
src/components/customer/CustomerEditDialog.vue
Normal file
48
src/components/customer/CustomerEditDialog.vue
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" title="新增客户单位"
|
||||||
|
width="400px">
|
||||||
|
<el-form :model="form" label-width="100px">
|
||||||
|
<el-form-item label="单位名称" required>
|
||||||
|
<el-input v-model="form.company_name" placeholder="例如:方舟星河" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="$emit('update:modelValue', false)">取消</el-button>
|
||||||
|
<el-button type="primary" @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 });
|
||||||
|
const emit = defineEmits(["update:modelValue", "success"]);
|
||||||
|
|
||||||
|
const form = ref({ company_name: "" });
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(val) => {
|
||||||
|
if (val) form.value.company_name = "";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!form.value.company_name) return ElMessage.error("名称不能为空");
|
||||||
|
try {
|
||||||
|
const res = await customerApi.addCustomerName({
|
||||||
|
company_name: form.value.company_name,
|
||||||
|
});
|
||||||
|
if (res.code === 200) {
|
||||||
|
ElMessage.success("客户单位创建成功");
|
||||||
|
emit("success");
|
||||||
|
emit("update:modelValue", false);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error("创建失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user