董国庆
2025-06-26 fcc84cfea24bb528fc9142240d4dbcf94eaa0a88
culture/src/views/projectList/addProject.vue
@@ -31,7 +31,7 @@
                </div>
            </div>
            <div class="add-project-footer">
                <el-button @click="submitForm" type="primary">保存</el-button>
                <el-button @click="submitForm" type="primary" :loading="loading" :disabled="loading">保存</el-button>
            </div>
        </template>
        <SelectMember ref="selectMember" @submit="selectUser" />
@@ -58,10 +58,13 @@
                1: { key: 'approver', limit: 1, label: '菌种审批人' },
                2: { key: 'engineer', limit: 1, label: '菌种工程师' },
            },
            loading: false,
        }
    },
    methods: {
        submitForm() {
            if (this.loading) return; // 防止重复提交
            this.loading = true;
            this.$refs.form.validate((valid) => {
                if (valid) {
                    const requiredRoles = ['菌种审批人', '菌种工程师', '菌种实验员'];
@@ -69,11 +72,13 @@
                    for (const role of requiredRoles) {
                        if (!selectedRoleNames.includes(role)) {
                            this.$message.error(`请选择${role}`);
                            this.loading = false;
                            return;
                        }
                    }
                    if (this.selectMemberData.length == 0) {
                        this.$message.error('请选择项目组成员');
                        this.loading = false;
                        return;
                    }
                    const ROLE_NAME_TO_TYPE = {
@@ -90,14 +95,17 @@
                        }))
                    }
                    addProject(data).then(res => {
                        this.loading = false;
                        if (res.code == 200) {
                            this.$message.success('添加成功');
                            this.resetForm(); // 添加成功后重置表单
                            this.$router.back(); // 跳转到上一个页面
                            // Optionally, navigate away or give other feedback
                            // this.$router.push({ name: 'ProjectList' });
                        }
                    }).catch(() => {
                        this.loading = false; // 失败时也关闭 loading
                    })
                } else {
                    this.loading = false;
                }
            })
        },