帐号治理-帐号管理--更新

This commit is contained in:
Cheng Zhou
2025-12-18 19:14:38 +08:00
parent f6b89cb8c4
commit eed83cec5a
23 changed files with 233 additions and 30 deletions
+47 -4
View File
@@ -10,8 +10,23 @@
<el-form-item label="PI" prop="pi_name">
<el-input v-model="form.pi_name" placeholder="PI(可选)" />
</el-form-item>
<el-form-item label="CRA 联系人" prop="contact">
<el-input v-model="form.contact" placeholder="多个联系人用逗号分隔" />
<el-form-item label="电话" prop="phone">
<el-input v-model="form.phone" placeholder="电话(可选)" />
</el-form-item>
<el-form-item label="负责人" prop="contact">
<el-select
v-model="form.craSelections"
multiple
filterable
placeholder="选择项目成员作为负责人,可多选"
>
<el-option
v-for="user in craOptions"
:key="user.value"
:label="user.label"
:value="user.value"
/>
</el-select>
</el-form-item>
<el-form-item v-if="site" label="状态" prop="is_active">
<el-switch v-model="form.is_active" active-text="启用" inactive-text="停用" />
@@ -37,6 +52,8 @@ const props = defineProps<{
visible: boolean;
studyId: string;
site?: Site | null;
members?: any[];
users?: any[];
}>();
const emit = defineEmits<{
@@ -56,7 +73,9 @@ const form = reactive({
name: "",
city: "",
pi_name: "",
phone: "",
contact: "",
craSelections: [] as string[],
is_active: true,
});
@@ -64,11 +83,24 @@ const rules = reactive<FormRules>({
name: [{ required: true, message: "请输入中心名称", trigger: "blur" }],
});
const craOptions = computed(() => {
const userMap = (props.users || []).reduce<Record<string, string>>((acc, cur: any) => {
if (cur?.id) acc[cur.id] = cur.username || cur.id;
return acc;
}, {});
return (props.members || []).map((m: any) => ({
label: userMap[m.user_id] || m.username || m.user_id,
value: m.user_id,
}));
});
const resetForm = () => {
form.name = "";
form.city = "";
form.pi_name = "";
form.phone = "";
form.contact = "";
form.craSelections = [];
form.is_active = true;
};
@@ -81,7 +113,17 @@ watch(
form.name = props.site.name;
form.city = props.site.city || "";
form.pi_name = props.site.pi_name || "";
form.phone = (props.site as any)?.contact_phone || (props.site as any)?.phone || "";
form.contact = props.site.contact || "";
const rawSelections = (props.site.contact || "")
.split(",")
.map((s) => s.trim())
.filter(Boolean);
const optionByLabel: Record<string, string> = {};
craOptions.value.forEach((opt) => {
optionByLabel[opt.label] = opt.value;
});
form.craSelections = rawSelections.map((s) => optionByLabel[s] || s);
form.is_active = props.site.is_active;
}
}
@@ -108,12 +150,13 @@ const onSubmit = async () => {
await formRef.value.validate();
submitting.value = true;
try {
const contact = form.craSelections.length ? form.craSelections.join(",") : form.contact;
if (props.site) {
await updateSite(props.studyId, props.site.id, {
name: form.name,
city: form.city,
pi_name: form.pi_name,
contact: form.contact,
contact,
is_active: form.is_active,
});
ElMessage.success("中心已更新");
@@ -128,7 +171,7 @@ const onSubmit = async () => {
name: form.name,
city: form.city,
pi_name: form.pi_name,
contact: form.contact,
contact,
});
ElMessage.success("中心已创建");
logAudit("SITE_STATUS_CHANGED", {