2025-08-07 15:16:23 +08:00
|
|
|
<template>
|
|
|
|
|
<a-modal
|
2025-11-03 16:40:10 +08:00
|
|
|
:open="visible"
|
2025-08-07 15:16:23 +08:00
|
|
|
title="修改岗位"
|
|
|
|
|
cancelText="取消"
|
|
|
|
|
okText="提交"
|
|
|
|
|
@ok="submit"
|
|
|
|
|
@cancel="cancel"
|
|
|
|
|
>
|
|
|
|
|
<a-form
|
2025-11-07 14:32:00 +08:00
|
|
|
ref="formRef"
|
2025-08-07 15:16:23 +08:00
|
|
|
:model="formState"
|
|
|
|
|
:rules="formRules"
|
2025-11-07 14:32:00 +08:00
|
|
|
layout="vertical"
|
2025-08-07 15:16:23 +08:00
|
|
|
>
|
2025-11-07 14:32:00 +08:00
|
|
|
<a-col :span="12" v-if="formState.parent != 0">
|
|
|
|
|
<!-- 当前部门为根部门, 则不提供上级部门选择 -->
|
|
|
|
|
<a-form-item label="上级" name="parent">
|
2025-08-07 15:16:23 +08:00
|
|
|
<a-tree-select
|
|
|
|
|
v-model:value="formState.parent"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
:tree-data="state.depts"
|
|
|
|
|
placeholder="所属部门"
|
|
|
|
|
replace
|
|
|
|
|
tree-default-expand-all
|
|
|
|
|
:replaceFields="replaceFields"
|
|
|
|
|
>
|
|
|
|
|
</a-tree-select>
|
2025-11-07 14:32:00 +08:00
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-form-item ref="name" label="名称" name="name">
|
|
|
|
|
<a-input v-model:value="formState.name" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-form-item ref="sort" label="排序" name="sort">
|
|
|
|
|
<a-input-number style="width: 100%" v-model:value="formState.sort" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-form-item ref="address" label="地址" name="address">
|
|
|
|
|
<a-input v-model:value="formState.address" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-form-item label="状态" name="state">
|
|
|
|
|
<a-switch v-model:checked="formState.enable" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-form-item label="备注" name="remark">
|
|
|
|
|
<a-textarea v-model:value="formState.remark" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
2025-08-07 15:16:23 +08:00
|
|
|
</a-form>
|
|
|
|
|
</a-modal>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
2025-11-07 14:32:00 +08:00
|
|
|
import { message } from "@hwork/ant-design-vue";
|
2025-08-07 15:16:23 +08:00
|
|
|
import { edit, tree } from "@/api/module/dept";
|
|
|
|
|
import { defineComponent, reactive, ref, toRaw, watch } from "vue";
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
props: {
|
|
|
|
|
visible: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
|
|
|
|
record: {
|
|
|
|
|
type: Object,
|
2025-11-07 14:32:00 +08:00
|
|
|
},
|
2025-08-07 15:16:23 +08:00
|
|
|
},
|
|
|
|
|
emit: ["close"],
|
|
|
|
|
setup(props, context) {
|
2025-11-07 14:32:00 +08:00
|
|
|
const state = reactive({
|
|
|
|
|
depts: [],
|
|
|
|
|
});
|
2025-08-07 15:16:23 +08:00
|
|
|
|
|
|
|
|
const formRef = ref();
|
2025-11-07 14:32:00 +08:00
|
|
|
|
2025-08-07 15:16:23 +08:00
|
|
|
const formState = reactive({
|
|
|
|
|
sort: 0,
|
|
|
|
|
enable: true,
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-07 14:32:00 +08:00
|
|
|
watch(props, (props) => {
|
|
|
|
|
formState.id = props.record.id;
|
|
|
|
|
formState.name = props.record.name;
|
|
|
|
|
formState.sort = props.record.sort;
|
|
|
|
|
formState.parent = props.record.parent;
|
|
|
|
|
formState.remark = props.record.remark;
|
|
|
|
|
formState.enable = props.record.enable;
|
|
|
|
|
formState.address = props.record.address;
|
|
|
|
|
});
|
2025-08-07 15:16:23 +08:00
|
|
|
|
|
|
|
|
const formRules = {
|
2025-11-07 14:32:00 +08:00
|
|
|
name: [{ required: true, message: "请输入部门名称", trigger: "blur" }],
|
|
|
|
|
address: [{ required: true, message: "请输入详细地址", trigger: "blur" }],
|
|
|
|
|
parent: [
|
|
|
|
|
{ required: true, message: "请选择上级部门", trigger: "change" },
|
|
|
|
|
],
|
2025-08-07 15:16:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const submit = (e) => {
|
|
|
|
|
formRef.value
|
|
|
|
|
.validate()
|
|
|
|
|
.then(() => {
|
2025-11-07 14:32:00 +08:00
|
|
|
edit(toRaw(formState)).then((response) => {
|
|
|
|
|
if (response.success) {
|
|
|
|
|
message.success({ content: "保存成功", duration: 1 }).then(() => {
|
|
|
|
|
cancel();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
message.success({ content: "保存失败", duration: 1 }).then(() => {
|
|
|
|
|
cancel();
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-07 15:16:23 +08:00
|
|
|
});
|
|
|
|
|
})
|
2025-11-07 14:32:00 +08:00
|
|
|
.catch((error) => {
|
|
|
|
|
console.log("error", error);
|
2025-08-07 15:16:23 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const cancel = (e) => {
|
|
|
|
|
formRef.value.resetFields();
|
|
|
|
|
context.emit("close", false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadTree = () => {
|
2025-11-07 14:32:00 +08:00
|
|
|
tree({}).then((response) => {
|
2025-08-07 15:16:23 +08:00
|
|
|
state.depts = response.data;
|
2025-11-07 14:32:00 +08:00
|
|
|
});
|
|
|
|
|
};
|
2025-08-07 15:16:23 +08:00
|
|
|
|
|
|
|
|
/// 加载部门
|
|
|
|
|
loadTree();
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
state,
|
|
|
|
|
submit,
|
|
|
|
|
cancel,
|
|
|
|
|
formRef,
|
|
|
|
|
formState,
|
|
|
|
|
formRules,
|
2025-11-07 14:32:00 +08:00
|
|
|
|
2025-08-07 15:16:23 +08:00
|
|
|
labelCol: { span: 6 },
|
|
|
|
|
wrapperCol: { span: 18 },
|
|
|
|
|
|
2025-11-07 14:32:00 +08:00
|
|
|
replaceFields: {
|
|
|
|
|
children: "children",
|
|
|
|
|
title: "name",
|
|
|
|
|
key: "id",
|
|
|
|
|
value: "id",
|
|
|
|
|
},
|
2025-08-07 15:16:23 +08:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-11-07 14:32:00 +08:00
|
|
|
</script>
|