| | |
| | | label-position="top" |
| | | style="margin-top: 38px" |
| | | > |
| | | <el-form-item prop="name" label="项目课题方案名称"> |
| | | <el-input v-model="form.name" placeholder="请输入" /> |
| | | <el-form-item prop="projectName" label="项目课题方案名称"> |
| | | <el-input v-model="form.projectName" placeholder="请输入" /> |
| | | </el-form-item> |
| | | <el-form-item prop="description" label="项目阶段"> |
| | | <el-input v-model="form.description" placeholder="请输入" /> |
| | | <el-form-item prop="projectStage" label="项目阶段"> |
| | | <el-select v-model="form.projectStage" placeholder="请选择"> |
| | | <el-option label="实验室开发阶段" :value="1" /> |
| | | <el-option label="中式试验阶段" :value="2" /> |
| | | <el-option label="生产验证试验阶段" :value="3" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item prop="description" label="项目课题方案编号"> |
| | | <el-input v-model="form.description" placeholder="请输入" /> |
| | | <el-form-item prop="projectCode" label="项目课题方案编号"> |
| | | <el-input v-model="form.projectCode" placeholder="请输入" disabled /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div class="header-title"> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="purposeEditor" |
| | | v-model="editorContents.purpose" |
| | | :value="editorContents.experimentObjective" |
| | | height="200px" |
| | | placeholder="请输入实验目的..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="materialEditor" |
| | | v-model="editorContents.material" |
| | | :value="editorContents.experimentMaterial" |
| | | height="200px" |
| | | placeholder="请输入实验材料..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="equipmentEditor" |
| | | v-model="editorContents.equipment" |
| | | :value="editorContents.experimentDevice" |
| | | height="200px" |
| | | placeholder="请输入实验设备..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="methodEditor" |
| | | v-model="editorContents.method" |
| | | :value="editorContents.experimentTestMethod" |
| | | height="200px" |
| | | placeholder="请输入检测方法及开发..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="stepsEditor" |
| | | v-model="editorContents.steps" |
| | | :value="editorContents.experimentProcedure" |
| | | height="200px" |
| | | placeholder="请输入实验步骤..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="dataAnalysisEditor" |
| | | v-model="editorContents.dataAnalysis" |
| | | :value="editorContents.dataAcquisition" |
| | | height="200px" |
| | | placeholder="请输入数据采集及分析..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="evaluationEditor" |
| | | v-model="editorContents.evaluation" |
| | | :value="editorContents.resultEvaluation" |
| | | height="200px" |
| | | placeholder="请输入结果评估..." |
| | | /> |
| | |
| | | </div> |
| | | <AiEditor |
| | | ref="notesEditor" |
| | | v-model="editorContents.notes" |
| | | :value="editorContents.precautions" |
| | | height="200px" |
| | | placeholder="请输入注意事项..." |
| | | /> |
| | |
| | | |
| | | <script> |
| | | import AiEditor from '@/components/AiEditor' |
| | | // import { savePlan, saveDraft } from '@/api/approvalPlan' |
| | | import { addProposal, updateProposal, getDetailById } from './service' |
| | | |
| | | export default { |
| | | name: "AddProject", |
| | |
| | | }, |
| | | data() { |
| | | return { |
| | | id: '', // 用于编辑时存储id |
| | | form: { |
| | | name: '', |
| | | description: '', |
| | | purpose: '', |
| | | material: '', |
| | | equipment: '', |
| | | method: '', |
| | | steps: '', |
| | | dataAnalysis: '', |
| | | evaluation: '', |
| | | notes: '' |
| | | projectName: '', |
| | | projectStage: '', |
| | | projectCode: '', |
| | | experimentObjective: '', |
| | | experimentMaterial: '', |
| | | experimentDevice: '', |
| | | experimentTestMethod: '', |
| | | experimentProcedure: '', |
| | | dataAcquisition: '', |
| | | resultEvaluation: '', |
| | | precautions: '', |
| | | auditStatus: 1, // 默认为审批中 |
| | | }, |
| | | editorContents: { |
| | | purpose: '', |
| | | material: '', |
| | | equipment: '', |
| | | method: '', |
| | | steps: '', |
| | | dataAnalysis: '', |
| | | evaluation: '', |
| | | notes: '' |
| | | experimentObjective: '', |
| | | experimentMaterial: '', |
| | | experimentDevice: '', |
| | | experimentTestMethod: '', |
| | | experimentProcedure: '', |
| | | dataAcquisition: '', |
| | | resultEvaluation: '', |
| | | precautions: '' |
| | | }, |
| | | rules: { |
| | | name: [ |
| | | { required: true, message: "请输入项目组名称", trigger: "blur" }, |
| | | projectName: [ |
| | | { required: true, message: "请输入项目课题方案名称", trigger: "blur" }, |
| | | ], |
| | | description: [ |
| | | { required: true, message: "请输入项目组描述", trigger: "blur" }, |
| | | projectStage: [ |
| | | { required: true, message: "请选择项目阶段", trigger: "change" }, |
| | | ], |
| | | purpose: [ |
| | | experimentObjective: [ |
| | | { required: true, message: "请输入实验目的", trigger: "blur" }, |
| | | ], |
| | | material: [ |
| | | experimentMaterial: [ |
| | | { required: true, message: "请输入实验材料", trigger: "blur" }, |
| | | ], |
| | | equipment: [ |
| | | experimentDevice: [ |
| | | { required: true, message: "请输入实验设备", trigger: "blur" }, |
| | | ], |
| | | method: [ |
| | | experimentTestMethod: [ |
| | | { required: true, message: "请输入检测方法及开发", trigger: "blur" }, |
| | | ], |
| | | steps: [ |
| | | experimentProcedure: [ |
| | | { required: true, message: "请输入实验步骤", trigger: "blur" }, |
| | | ], |
| | | dataAnalysis: [ |
| | | dataAcquisition: [ |
| | | { required: true, message: "请输入数据采集及分析", trigger: "blur" }, |
| | | ], |
| | | evaluation: [ |
| | | resultEvaluation: [ |
| | | { required: true, message: "请输入结果评估", trigger: "blur" }, |
| | | ], |
| | | notes: [ |
| | | { required: true, message: "请输入注意事项", trigger: "blur" }, |
| | | ], |
| | | // precautions: [ |
| | | // { required: true, message: "请输入注意事项", trigger: "blur" }, |
| | | // ], |
| | | }, |
| | | }; |
| | | }, |
| | |
| | | // 获取所有编辑器的内容 |
| | | getAllEditorContent() { |
| | | return { |
| | | purpose: this.$refs.purposeEditor.getContent(), |
| | | material: this.$refs.materialEditor.getContent(), |
| | | equipment: this.$refs.equipmentEditor.getContent(), |
| | | method: this.$refs.methodEditor.getContent(), |
| | | steps: this.$refs.stepsEditor.getContent(), |
| | | dataAnalysis: this.$refs.dataAnalysisEditor.getContent(), |
| | | evaluation: this.$refs.evaluationEditor.getContent(), |
| | | notes: this.$refs.notesEditor.getContent() |
| | | experimentObjective: this.$refs.purposeEditor.getContent(), |
| | | experimentMaterial: this.$refs.materialEditor.getContent(), |
| | | experimentDevice: this.$refs.equipmentEditor.getContent(), |
| | | experimentTestMethod: this.$refs.methodEditor.getContent(), |
| | | experimentProcedure: this.$refs.stepsEditor.getContent(), |
| | | dataAcquisition: this.$refs.dataAnalysisEditor.getContent(), |
| | | resultEvaluation: this.$refs.evaluationEditor.getContent(), |
| | | precautions: this.$refs.notesEditor.getContent() |
| | | } |
| | | }, |
| | | // 保存 |
| | | handleSave() { |
| | | // 统一处理方法 |
| | | handleSubmit(type) { |
| | | this.$refs.form.validate((valid) => { |
| | | if (valid) { |
| | | // 获取所有编辑器内容 |
| | | const editorContents = this.getAllEditorContent() |
| | | |
| | | // 检查编辑器内容是否为空 |
| | | const emptyFields = [] |
| | | console.log('editorContents', editorContents) |
| | | |
| | | // 判断内容是否为空(排除<p></p>) |
| | | const isEmptyContent = (content) => { |
| | | return !content || content === '<p></p>' || content.trim() === '<p></p>' |
| | | } |
| | | |
| | | if (isEmptyContent(editorContents.experimentObjective)) emptyFields.push('实验目的') |
| | | if (isEmptyContent(editorContents.experimentMaterial)) emptyFields.push('实验材料') |
| | | if (isEmptyContent(editorContents.experimentDevice)) emptyFields.push('实验设备') |
| | | if (isEmptyContent(editorContents.experimentTestMethod)) emptyFields.push('检测方法及开发') |
| | | if (isEmptyContent(editorContents.experimentProcedure)) emptyFields.push('实验步骤') |
| | | if (isEmptyContent(editorContents.dataAcquisition)) emptyFields.push('数据采集及分析') |
| | | if (isEmptyContent(editorContents.resultEvaluation)) emptyFields.push('结果评估') |
| | | // if (isEmptyContent(editorContents.precautions)) emptyFields.push('注意事项') |
| | | |
| | | if (emptyFields.length > 0) { |
| | | this.$message.warning(`请填写${emptyFields.join('、')}`) |
| | | return false |
| | | } |
| | | |
| | | const formData = { |
| | | ...this.form, |
| | | ...this.getAllEditorContent() |
| | | ...editorContents, |
| | | auditStatus: type === 'draft' ? -1 : 1 // 草稿箱:-1, 审批中:1 |
| | | } |
| | | console.log('保存数据:', formData) |
| | | this.$message.success('保存成功') |
| | | |
| | | const request = this.id ? updateProposal : addProposal |
| | | if (this.id) { |
| | | formData.id = this.id |
| | | } |
| | | |
| | | console.log('请求参数:', { |
| | | formData |
| | | }) |
| | | |
| | | request(formData).then(res => { |
| | | console.log('接口返回:', res) |
| | | if (res.code === 200) { |
| | | const successMsg = type === 'draft' ? '草稿保存成功' : (this.id ? '更新成功' : '保存成功') |
| | | this.$message.success(successMsg) |
| | | this.$router.back() |
| | | } else { |
| | | const errorMsg = type === 'draft' ? '草稿保存失败' : (this.id ? '更新失败' : '保存失败') |
| | | this.$message.error(res.msg || errorMsg) |
| | | } |
| | | }).catch(err => { |
| | | console.error('接口错误:', err) |
| | | const errorMsg = type === 'draft' ? '草稿保存失败' : (this.id ? '更新失败' : '保存失败') |
| | | this.$message.error(errorMsg) |
| | | }) |
| | | } else { |
| | | this.$message.warning('请填写必填项') |
| | | return false |
| | | } |
| | | }) |
| | | }, |
| | | // 保存 |
| | | handleSave() { |
| | | this.handleSubmit('save') |
| | | }, |
| | | // 保存草稿 |
| | | handleSaveDraft() { |
| | | const formData = { |
| | | ...this.form, |
| | | ...this.getAllEditorContent(), |
| | | status: 'draft' |
| | | } |
| | | console.log('草稿数据:', formData) |
| | | this.$message.success('草稿保存成功') |
| | | this.handleSubmit('draft') |
| | | }, |
| | | // 获取详情 |
| | | getDetail() { |
| | | if (this.id) { |
| | | console.log('获取详情参数:', { id: this.id }) |
| | | getDetailById({ id: this.id }).then(res => { |
| | | console.log('详情接口返回:', res) |
| | | if (res.code === 200 && res.data) { |
| | | const data = res.data |
| | | // 设置表单数据 |
| | | this.form = { |
| | | projectName: data.projectName, |
| | | projectStage: data.projectStage, |
| | | projectCode: data.projectCode, |
| | | auditStatus: data.auditStatus |
| | | } |
| | | // 设置编辑器内容 |
| | | this.editorContents = { |
| | | experimentObjective: data.experimentObjective, |
| | | experimentMaterial: data.experimentMaterial, |
| | | experimentDevice: data.experimentDevice, |
| | | experimentTestMethod: data.experimentTestMethod, |
| | | experimentProcedure: data.experimentProcedure, |
| | | dataAcquisition: data.dataAcquisition, |
| | | resultEvaluation: data.resultEvaluation, |
| | | precautions: data.precautions |
| | | } |
| | | } |
| | | }).catch(err => { |
| | | console.error('获取详情失败:', err) |
| | | }) |
| | | } |
| | | } |
| | | }, |
| | | created() { |
| | | // 从路由参数中获取id |
| | | this.id = this.$route.query.id |
| | | if (this.id) { |
| | | this.getDetail() |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |