smart-bid-web/src/views/analysis/components/AnalysisForm.vue

332 lines
10 KiB
Vue
Raw Normal View History

2025-11-05 09:47:20 +08:00
<template>
<!-- 小型弹窗用于完成删除保存等操作 -->
<el-dialog class="l-dialog" :class="lDialog" :title="title" :visible.sync="dialogVisible" :showClose="true"
:closeOnClickModal="false" @close="handleClose" :append-to-body="true">
<div>
<el-form :model="form" :rules="rules" ref="ruleForm" label-width="110px">
2025-11-05 10:09:26 +08:00
<el-form-item label="选择模板" prop="templateId">
2025-11-05 11:22:39 +08:00
<el-select v-model="form.templateId" placeholder="请选择模板" class="form-item"
@change="handleTemplateChange">
<el-option v-for="item in modelList" :key="item.id" :label="item.name"
:value="item.id"></el-option>
2025-11-05 10:09:26 +08:00
</el-select>
</el-form-item>
2025-11-05 11:22:39 +08:00
<el-form-item v-for="(item, index) in uploadType" :key="index" :label="item"
:prop="`fileList${index + 1}`">
<UploadMoreFile :fileList="form[`fileList${index + 1}`]" @file-change="handleFileChange"
@del-file="handleDelFile" :type="`fileList${index + 1}`" :uploadType="defaultParams.uploadType"
:maxFileTips="defaultParams.maxFileTips" :fileUploadRule="defaultParams.fileUploadRule"
:limitUploadNum="defaultParams.limitUploadNum" />
2025-11-05 09:47:20 +08:00
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
2025-11-05 11:22:39 +08:00
<el-button type="primary" class="confirm-btn" @click="submitForm('ruleForm')">确认</el-button>
2025-11-05 09:47:20 +08:00
<el-button class="cancel-btn" @click="handleClose">取消</el-button>
</span>
</el-dialog>
</template>
<script>
import _ from 'lodash'
2025-11-05 11:22:39 +08:00
import UploadMoreFile from '@/views/common/UploadMoreFile.vue'
2025-11-05 09:47:20 +08:00
// 默认参数
const defaultParams = {
fileUploadRule: {
2025-11-05 11:22:39 +08:00
fileUploadType: 'bidding',
2025-11-05 09:47:20 +08:00
fields_json: '',
2025-11-05 11:22:39 +08:00
suffix: 'analysis_database',
2025-11-05 09:47:20 +08:00
},
2025-11-05 10:09:26 +08:00
uploadType: 'pdf、doc、docx',
maxFileTips: '500MB',
2025-11-05 11:22:39 +08:00
limitUploadNum: 1,
}
2025-11-05 10:09:26 +08:00
2025-11-05 09:47:20 +08:00
export default {
2025-11-05 11:22:39 +08:00
name: 'AnalysisForm',
2025-11-05 09:47:20 +08:00
components: {
2025-11-05 10:09:26 +08:00
UploadMoreFile,
2025-11-05 09:47:20 +08:00
},
2025-11-05 11:22:39 +08:00
props: ['width', 'rowData', 'title'],
2025-11-05 09:47:20 +08:00
data() {
return {
2025-11-05 11:22:39 +08:00
lDialog: this.width > 500 ? 'w700' : 'w500',
2025-11-05 09:47:20 +08:00
dialogVisible: true,
defaultParams,
2025-11-05 11:22:39 +08:00
uploadType: [],
modelList: [
{
id: 1,
name: '南网工程类模板',
uploadType: '招标文件,招标公告',
},
{
id: 2,
name: '南网服务类模板',
uploadType: '评标文件',
},
2025-11-05 10:09:26 +08:00
],
2025-11-05 09:47:20 +08:00
form: {
2025-11-05 10:09:26 +08:00
templateId: null,
2025-11-05 11:22:39 +08:00
delFileList: [],
2025-11-05 09:47:20 +08:00
},
rules: {
2025-11-05 10:09:26 +08:00
templateId: [
2025-11-05 11:22:39 +08:00
{
required: true,
message: '请选择模板',
trigger: 'change',
},
2025-11-05 09:47:20 +08:00
],
},
2025-11-05 11:22:39 +08:00
}
2025-11-05 09:47:20 +08:00
},
watch: {
2025-11-05 11:22:39 +08:00
uploadType: {
handler(newVal, oldVal) {
if (newVal && newVal.length > 0) {
// 立即清除验证
this.$refs.ruleForm && this.$refs.ruleForm.clearValidate()
if (oldVal && oldVal.length > 0) {
oldVal.forEach((item, index) => {
this.$delete(this.form, `fileList${index + 1}`)
this.$delete(this.rules, `fileList${index + 1}`)
})
}
newVal.forEach((item, index) => {
this.$set(this.form, `fileList${index + 1}`, [])
this.$set(this.rules, `fileList${index + 1}`, [
{
required: true,
message: `请上传${item}`,
trigger: ['change'],
},
])
})
this.$nextTick(() => {
this.$refs.ruleForm &&
this.$refs.ruleForm.clearValidate()
})
2025-11-05 09:47:20 +08:00
}
},
immediate: true,
},
},
2025-11-05 11:22:39 +08:00
2025-11-05 09:47:20 +08:00
methods: {
2025-11-05 11:22:39 +08:00
/* 模板变化选择对应的需要上传的文件 */
handleTemplateChange(val) {
const uploadType = this.modelList.find(
(item) => item.id === val,
).uploadType
this.uploadType = uploadType.split(',')
2025-11-05 09:47:20 +08:00
},
// 文件变化
2025-11-05 11:22:39 +08:00
handleFileChange(file, fileName) {
console.log(file)
this.form[fileName] = file
this.$refs.ruleForm && this.$refs.ruleForm.clearValidate([fileName])
2025-11-05 09:47:20 +08:00
},
// 文件删除时触发
handleDelFile(file) {
2025-11-05 11:22:39 +08:00
console.log(file)
const delPath =
file?.response?.fileRes?.filePath || file?.filePath || null
2025-11-05 09:47:20 +08:00
if (delPath) {
2025-11-05 11:22:39 +08:00
this.form.delFileList.push(delPath)
2025-11-05 09:47:20 +08:00
}
},
/*关闭弹窗 */
handleClose() {
2025-11-05 11:22:39 +08:00
this.dialogVisible = false
this.$emit('closeDialog')
2025-11-05 09:47:20 +08:00
},
/**确认弹窗 */
sureBtnClick() {
2025-11-05 11:22:39 +08:00
this.dialogVisible = false
this.$emit('closeDialog')
2025-11-05 09:47:20 +08:00
},
/**重置表单*/
reset() {
this.form = {
id: null,
pid: null,
2025-11-05 11:22:39 +08:00
templateId: null,
fileList: [],
delFileList: [],
2025-11-05 09:47:20 +08:00
remark: '',
2025-11-05 11:22:39 +08:00
}
this.resetForm('ruleForm')
2025-11-05 09:47:20 +08:00
},
handleReuslt(res) {
2025-11-05 11:22:39 +08:00
this.$modal.msgSuccess(res.msg)
this.reset()
this.$emit('handleQuery')
this.handleClose()
2025-11-05 09:47:20 +08:00
},
validate(formName) {
return new Promise((resolve, reject) => {
this.$refs[formName].validate((valid) => {
if (valid) {
resolve(this.form) // 校验成功返回表单数据
} else {
reject(new Error('数据未填写完整'))
}
})
})
},
/**验证 */
async submitForm(formName) {
try {
2025-11-05 11:22:39 +08:00
const data = await this.validate(formName)
2025-11-05 09:47:20 +08:00
// 所有校验通过,组装完整数据
let formData = {
...data,
allFiles: [
2025-11-05 11:22:39 +08:00
...data.fileList.map((file) =>
JSON.parse(JSON.stringify(file)),
),
2025-11-05 09:47:20 +08:00
],
2025-11-05 11:22:39 +08:00
delFiles: [...data.delFileList],
2025-11-05 09:47:20 +08:00
}
2025-11-05 11:22:39 +08:00
let allFiles = formData.allFiles
.map((file) => {
return file?.response?.fileRes
? {
...file.response.fileRes,
}
: null
})
.filter((item) => item !== null)
formData.files = allFiles
delete formData.fileList
delete formData.delFileList
delete formData.allFiles
2025-11-05 09:47:20 +08:00
// 显示遮罩层
this.loading = this.$loading({
lock: true,
2025-11-05 11:22:39 +08:00
text: '数据提交中,请稍候...',
2025-11-05 09:47:20 +08:00
background: 'rgba(0,0,0,0.5)',
2025-11-05 11:22:39 +08:00
target:
this.$el.querySelector('.el-dialog') || document.body,
2025-11-05 09:47:20 +08:00
})
console.log('所有表单校验通过,完整数据:', formData)
2025-11-05 11:22:39 +08:00
/* const res = await this.saveData(formData)
2025-11-05 09:47:20 +08:00
if (res.code === 200) {
2025-11-05 11:22:39 +08:00
this.handleReuslt(res)
2025-11-05 09:47:20 +08:00
} else {
2025-11-05 11:22:39 +08:00
this.$modal.msgError(res.msg)
} */
2025-11-05 09:47:20 +08:00
} catch (error) {
} finally {
2025-11-05 11:22:39 +08:00
if (this.loading) {
this.loading.close()
}
2025-11-05 09:47:20 +08:00
}
},
// 保存接口
async saveData(formData) {
return new Promise((resolve, reject) => {
2025-11-05 11:22:39 +08:00
if (this.isAdd === 'add') {
// 新增
addDataAPI(formData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
} else {
// 修改
editDataAPI(formData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
2025-11-05 09:47:20 +08:00
}
})
},
2025-11-05 11:22:39 +08:00
},
}
2025-11-05 09:47:20 +08:00
</script>
<style lang="scss" scoped>
.w700 ::v-deep .el-dialog {
width: 700px;
font-family: Source Han Sans CN, Source Han Sans CN;
}
.w500 ::v-deep .el-dialog {
width: 500px;
font-family: Source Han Sans CN, Source Han Sans CN;
}
.w500 ::v-deep .el-dialog__header,
.w700 ::v-deep .el-dialog__header {
.el-dialog__title {
font-size: 16px;
}
}
.yxq .el-range-separator {
margin-right: 7px !important;
}
.el-date-editor--daterange.el-input__inner {
width: 260px;
}
.form-item {
width: 100%;
}
.select-style {
display: flex;
justify-content: space-between;
}
.confirm-btn {
width: 98px;
height: 36px;
2025-11-05 11:22:39 +08:00
background: #1f72ea;
2025-11-05 09:47:20 +08:00
box-shadow: 0px 4px 8px 0px rgba(51, 135, 255, 0.5);
border-radius: 4px 4px 4px 4px;
color: #fff;
border: none;
font-size: 14px;
transition: all 0.3s;
&:hover {
2025-11-05 11:22:39 +08:00
background: #4a8bff;
2025-11-05 09:47:20 +08:00
box-shadow: 0px 6px 12px 0px rgba(51, 135, 255, 0.6);
}
}
.cancel-btn {
width: 98px;
height: 36px;
2025-11-05 11:22:39 +08:00
background: #e5e5e5;
2025-11-05 09:47:20 +08:00
box-shadow: 0px 4px 8px 0px rgba(76, 76, 76, 0.2);
border-radius: 4px 4px 4px 4px;
color: #333;
border: none;
font-size: 14px;
transition: all 0.3s;
&:hover {
background: #d0d0d0;
box-shadow: 0px 6px 12px 0px rgba(76, 76, 76, 0.3);
}
}
::v-deep .el-dialog__footer {
text-align: center;
}
2025-11-05 11:22:39 +08:00
</style>