<template> <div class="operate"> <el-form ref="ruleForm" :model="form" :rules="rules" :disabled="opts.type === 'view'"> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="项目名称:" prop="projectNo" class="formItem140"> <el-select v-model="form.projectNo" placeholder="请选择项目名称" style="width: 100%" @change="projectChange" > <el-option v-for="dict in projectList" :key="dict.projectNo" :label="dict.projectName" :value="dict.projectNo" /> </el-select> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="项目编码:" prop="projectNo" class="formItem140"> <el-input v-model="form.projectNo" :disabled="true" /> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="建设状态:" prop="buildStatus" class="formItem140"> <el-input v-model="form.buildStatusName" :disabled="true" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="项目估算(万元):" prop="valuation" class="formItem140"> <el-input v-model="form.valuation" placeholder="请输入项目估算" /> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="项目运作模式:" prop="projectOperationPattern" class="formItem140"> <el-input v-model="form.projectOperationPattern" :disabled="true" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="建设单位:" prop="chargeDepartment" class="formItem140"> <el-input v-model="form.chargeDepartment" :disabled="true" /> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="责任人:" prop="chargeUser" class="formItem140"> <el-input v-model="form.chargeUser" :disabled="true" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="联系方式:" prop="phone" class="formItem140"> <el-input v-model="form.phone" :disabled="true" /> </el-form-item> </el-col> </el-row> <div class="box" v-for="(item, i) in form.projectProcessAttachmentSaveRequestList"> <el-row :gutter="20"> <el-col :span="12"> <el-form-item :label="`${item.name}:`" :prop="'projectProcessAttachmentSaveRequestList.' + i + '.' + 'filieDescription'" class="formItem140" :rules="rules['filieDescription']" > <el-input v-model="item.filieDescription"/> </el-form-item> </el-col> <el-col :span="2"> <el-upload class="upload-demo" action="/prod-api/system/upload" :headers="uploadHeader" :before-upload="(rawFile) => beforeUpload(rawFile, ['.rar', '.zip', '.doc', '.docx', '.pdf'])" :on-success="(response) => onSuccess(response, item)" :on-error="(error, uploadFile, uploadFiles) => onError(error, uploadFile, uploadFiles)" :show-file-list="false" > <el-button icon="Upload" size="mini" type="primary" >上传文件</el-button > </el-upload> </el-col> <el-col :span="10"> <span class="tips">支持文件格式:.rar .zip .doc .docx .pdf ,单个文件不能超过500kb</span> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12" :offset="12"> <div class="fileSaveRequestList"> <div class="file-item" v-for="(it, index) in item.fileList"> <span>{{ it.name }}</span> <el-button type="danger" link @click="reoveFile(item.fileList, index)">删除</el-button> </div> </div> </el-col> </el-row> </div> <el-form-item label="项目位置:" prop="projectLocation" class="formItem140"> <div class="mapBox"> <MapBox :key="form.projectNo" ref="mapBoxRef" @endDraw="endDraw"></MapBox> </div> </el-form-item> </el-form> </div> </template> <script setup> import { reactive, onMounted, nextTick, watch } from 'vue' import { required } from '@/utils/validate-helper' import { getProjectInfoNewList, getDicts, projectApprovalAdd, projectApprovalEdit, projectApprovalDetail } from '@/api/projectApproval' import { useDicts } from '@/hooks' import MapBox from '@/components/Map' import { inheritAttr } from '@/utils/v3' import uploadHeader from '@/utils/getUploadHeader' const { proxy } = getCurrentInstance(); const { findText } = useDicts(proxy) const props = defineProps({ curRow: { type: Object, default: () => ({}) }, opts: { type: Object, default: () => ({}) } }) const { curRow, opts } = props const emit = defineEmits(['close']) const form = reactive({ projectName: '', projectNo: '', projectNo: '', buildStatus: '', buildStatusName: '', valuation: '', projectOperationPattern: '', chargeDepartment: '', chargeUser: '', phone: '', sysFileSaveRequestList: [], projectLocation: '', projectProcessAttachmentSaveRequestList: [] }) watch(() => form.projectLocation, () => { nextTick(() => { proxy.$refs.ruleForm.validateField('projectLocation') }) }) const rules = reactive({ projectNo: required('项目名称'), projectNo: required('项目编码'), buildStatus: required('建设状态'), valuation: required('项目估算'), projectOperationPattern: required('项目运作模式'), chargeDepartment: required('建设单位'), chargeUser: required('责任人'), phone: required('联系方式'), filieDescription: required('内容'), projectLocation: required('项目位置') }) const projectList = ref([]) const mapForm = reactive({ geometry: '' }) const beforeUpload = (rawFile) => { console.log(rawFile) } const onSuccess = (response, item) => { console.log(response) item.fileList.push({ ...response.data, refType: item.dictType, refField: item.dictData }) } const reoveFile = (fileList, index) => { proxy.$modal .confirm("是否确认删除?") .then(async () => { fileList.splice(index, 1) }) .catch(() => {}); } const onError = (error, uploadFile, uploadFiles) => { console.log(error, uploadFile, uploadFiles) } const getProjectList = async () => { const res = await getProjectInfoNewList() if(res?.code !== 200) return projectList.value = res?.data || [] if(opts.type === 'add' && projectList.value.length) { projectChange(projectList.value[0].projectNo) } } const projectChange = (val) => { mapForm.geometry = '' form.projectLocation = '' const it = projectList.value.find(item => item.projectNo === val) inheritAttr(it, form) form.buildStatusName = findText('build_status', form.buildStatus) form.projectOperationPattern = findText('project_operation_pattern', form.projectOperationPattern) getDictMaps('pro_project_approval') nextTick(() => { viewPosition(form.projectLocation) }) } const endDraw = (val) => { mapForm.geometry = val.geometry || '' form.projectLocation = mapForm.geometry } const viewPosition = (projectLocation) => { console.log(projectLocation) if(!projectLocation) return let data = []; if(projectLocation.includes('POINT')) { data = [ { type: NewFiberMap.Enum.VectorType.SPECIAL_CIRCLE, id: 'point', style: { radius: 10, clampToGround: false, material: 'rgba(255, 0, 0, 1)' }, geometrys: projectLocation, }, ]; } else if(projectLocation.includes('LINE')) { data = [ { type: NewFiberMap.Enum.VectorType.POLYLINE, id: 'line', geometrys: projectLocation, style: { width: 5, material: "rgba(255,0,0,1)", clampToGround: true, }, }, ] } else if(projectLocation.includes('POLYGON')) { data = [ { type: NewFiberMap.Enum.VectorType.POLYGON, style: { material: "rgba(255,0,0,1)", color: "rgba(255,0,0,1)" }, geometrys: projectLocation, id: 'area' }, ] } if (data.length) { setTimeout(() => { let geojson = NewFiberMap.Data.ToGeoJSON.beansWktToGeoJson(data); toCenterByGeoJson(geojson); newfiberMap.geojsonToMap(geojson); }, 500) } } const toCenterByGeoJson = (geojson) => { let coords = turf.getCoords(geojson.features[0].geometry).flat(); let flag = geojson.features.length == 1 && coords.length == 2; if (!!geojson.features.length && !flag) { newfiberMap.getMap().camera.flyTo({destination: new Cesium.Rectangle.fromDegrees(...turf.bbox(turf.transformScale(turf.bboxPolygon(turf.bbox(geojson)), 2)))}); } else { newfiberMap.setCenter({ "roll": 0.01658908985506884, "pitch": -87.24924906709752, "heading": 5.026928271138224, "lng": coords[0], "lat": coords[1], "height": 943.5996932813425 }) } } const getDictMaps = async (dictType) => { const res = await getDicts(dictType) if(res?.code !== 200) return if(res?.data){ form.projectProcessAttachmentSaveRequestList = [] for (const item of res.data) { form.projectProcessAttachmentSaveRequestList.push({ fileList: [], dictData: item.dictValue, dictType: item.dictType, filieDescription: '', projectNo: '', name: item.dictLabel }) } } setTimeout(() => { if(proxy.$refs.ruleForm){ proxy.$refs.ruleForm.clearValidate() } }) } const submit = () => { proxy.$refs.ruleForm.validate(async (valid, fields) => { if(valid){ const params = JSON.parse(JSON.stringify(form)) for (const item of params.projectProcessAttachmentSaveRequestList) { item.projectNo = params.projectNo for (const it of item.fileList) { params.sysFileSaveRequestList.push(it) } } console.log(params) let methed = '' if(curRow?.id) { params.id = curRow.id methed = projectApprovalEdit } else { methed = projectApprovalAdd } const res = await methed(params) if(res?.code !== 200) return proxy.$modal.msgSuccess('操作成功!') emit('close') } else { console.log('error submit!', fields) } }) } const getDetail = async () => { const res = await projectApprovalDetail(curRow.id) if(res?.code !== 200) return inheritAttr(res.data, form) const fileGroup = res.data.fileGroup const res1 = await getDicts('pro_project_approval') form.buildStatusName = findText('build_status', form.buildStatus) const dicts = res1.data for (const key in fileGroup) { if (Object.hasOwnProperty.call(fileGroup, key)) { const element = fileGroup[key]; for (const item of element) { const info = dicts.find(it => it.dictValue === item.dictData) form.projectProcessAttachmentSaveRequestList.push({ fileList: item.fileList, dictData: item.dictData, dictType: item.dictType, filieDescription: item.filieDescription, projectNo: item.projectNo, name: info.dictLabel }) } } } nextTick(() => { viewPosition(form.projectLocation) }) } onMounted(() => { getProjectList() if(curRow?.id) { getDetail() } }) defineExpose({ submit }) </script> <style lang="scss" scoped> .operate { .tips { margin-left: 10px; line-height: 30px } .pl140 { padding-left: 140px; } .mapBox { width: 100%; height: 500px; } .fileSaveRequestList { .file-item { white-space: nowrap; display: flex; align-items: center; .del { flex-shrink: 0; color: #f56c6c; cursor: pointer; margin-left: 10px; } } } .box { margin-bottom: 10px; } } </style>