|
|
@@ -62,7 +62,7 @@
|
|
|
<span class="label">损失描述:</span>
|
|
|
<span class="value">{{ LossReportItemFormData?.description }}</span>
|
|
|
</div>
|
|
|
- <div class="disaster-information__content--item" v-if="LossReportItemFormData?.images">
|
|
|
+ <div class="disaster-information__content--item" v-if="JSON.parse(LossReportItemFormData?.images).length">
|
|
|
<span class="label">受灾图片:</span>
|
|
|
<div class="image-container">
|
|
|
<el-image
|
|
|
@@ -93,17 +93,17 @@
|
|
|
</div>
|
|
|
<BasicForm ref="basicFormRef" :formData="ruleFormData" :formRules="formRules" :formConfig="ruleFormConfig">
|
|
|
<template #fixImages>
|
|
|
- <UploadImages @uploadSuccess="handleUploadImageSuccess" />
|
|
|
+ <UploadImages ref="uploadImagesRef" @uploadSuccess="handleUploadImageSuccess" />
|
|
|
</template>
|
|
|
<template #fixMaterials>
|
|
|
- <Upload label="上传文件" @uploadSuccess="handleUploadFileSuccess" />
|
|
|
+ <UploadFiles ref="uploadFilesRef" label="上传材料" @uploadSuccess="handleUploadFileSuccess" />
|
|
|
</template>
|
|
|
</BasicForm>
|
|
|
</section>
|
|
|
</main>
|
|
|
<footer class="disaster-precaution-container__footer">
|
|
|
<el-button @click="router.back()">取消</el-button>
|
|
|
- <el-button type="primary" v-if="isShowNextSubmit">提交,并处置下一条</el-button>
|
|
|
+ <el-button type="primary" v-if="isShowNextSubmit" @click="handleNextSubmit">提交,并处置下一条</el-button>
|
|
|
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
|
|
</footer>
|
|
|
<UploadLoading :form-loading="formLoading" v-if="formLoading" />
|
|
|
@@ -116,8 +116,8 @@
|
|
|
import UploadLoading from '@/components/UploadLoading.vue';
|
|
|
import BasicForm from '@/components/BasicForm.vue';
|
|
|
import UploadImages from './src/components/UploadImages.vue';
|
|
|
- import Upload from '@/views/disaster/components/Upload.vue';
|
|
|
- import { ref, onMounted } from 'vue';
|
|
|
+ import UploadFiles from '@/views/disaster/components/UploadFiles.vue';
|
|
|
+ import { ref, onMounted, watch, computed, onUnmounted } from 'vue';
|
|
|
import { useDisasterControlHook } from './src/hook';
|
|
|
import { useFormConfigHook } from '@/hooks/useFormConfigHook';
|
|
|
import { useUserInfoHook } from '@/views/disaster/hooks/userInfo';
|
|
|
@@ -133,6 +133,8 @@
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
|
const basicFormRef = ref<InstanceType<typeof BasicForm>>();
|
|
|
+ const uploadImagesRef = ref<InstanceType<typeof UploadImages>>();
|
|
|
+ const uploadFilesRef = ref<InstanceType<typeof UploadFiles>>();
|
|
|
|
|
|
const LossReportItemFormData = ref<disasterReportRecordDetailListResponse>();
|
|
|
const { getLossReportItem, getSafetyLevel, getSafetyLevelDict } = useDisasterControlHook();
|
|
|
@@ -140,12 +142,12 @@
|
|
|
|
|
|
const router = useRouter();
|
|
|
const route = useRoute();
|
|
|
- const id = Number(route.params.id);
|
|
|
+ const id = ref<number>(Number(route.params.id));
|
|
|
const handleTaskId = Number(route.query.handleTaskId);
|
|
|
const fixTaskId = Number(route.query.fixTaskId);
|
|
|
const formLoading = ref(false);
|
|
|
const getLossReportItemData = async () => {
|
|
|
- const res = await getLossReportItem(handleTaskId, id);
|
|
|
+ const res = await getLossReportItem(handleTaskId, id.value);
|
|
|
LossReportItemFormData.value = res;
|
|
|
};
|
|
|
const { ruleFormConfig, ruleFormData, formRules, cloneRuleFormData, beforeRouteLeave } =
|
|
|
@@ -155,7 +157,9 @@
|
|
|
DISPOSAL_RECTIFICATION_FORM_RULES,
|
|
|
);
|
|
|
const rectificationIds = ref<number[]>([]);
|
|
|
- const isShowNextSubmit = ref(false);
|
|
|
+ const isShowNextSubmit = computed(() => {
|
|
|
+ return rectificationIds.value.length > 1 && rectificationIds.value.includes(id.value);
|
|
|
+ });
|
|
|
const handleUploadImageSuccess = (files: File[]) => {
|
|
|
ruleFormData.uploadImages = files;
|
|
|
};
|
|
|
@@ -184,44 +188,109 @@
|
|
|
fileId,
|
|
|
};
|
|
|
};
|
|
|
+ const submitDisposalRectification = async () => {
|
|
|
+ const imagesListRes: string[] = await Promise.all(
|
|
|
+ (ruleFormData.uploadImages || []).map((item) => formatImageList(item)),
|
|
|
+ );
|
|
|
+ const fileListRes: FileItem[] = await Promise.all(
|
|
|
+ (ruleFormData.uploadFiles || []).map((item) => formatFileList(item)),
|
|
|
+ );
|
|
|
+ const imagesListString = JSON.stringify(imagesListRes);
|
|
|
+ const fileListString = JSON.stringify(fileListRes);
|
|
|
+ ruleFormData.fixImages = imagesListString;
|
|
|
+ ruleFormData.fixMaterials = fileListString;
|
|
|
+ await createDisposalRectification({
|
|
|
+ fixTaskId,
|
|
|
+ ...ruleFormData,
|
|
|
+ });
|
|
|
+ ElMessage.success('提交成功');
|
|
|
+ cloneRuleFormData();
|
|
|
+ };
|
|
|
const handleSubmit = async () => {
|
|
|
if (!basicFormRef.value) return;
|
|
|
const validateResult = await basicFormRef.value.validateForm();
|
|
|
if (!validateResult) return;
|
|
|
formLoading.value = true;
|
|
|
try {
|
|
|
- const imagesListRes: string[] = await Promise.all(
|
|
|
- (ruleFormData.uploadImages || []).map((item) => formatImageList(item)),
|
|
|
- );
|
|
|
- const fileListRes: FileItem[] = await Promise.all(
|
|
|
- (ruleFormData.uploadFiles || []).map((item) => formatFileList(item)),
|
|
|
- );
|
|
|
- const imagesListString = JSON.stringify(imagesListRes);
|
|
|
- const fileListString = JSON.stringify(fileListRes);
|
|
|
- ruleFormData.fixImages = imagesListString;
|
|
|
- ruleFormData.fixMaterials = fileListString;
|
|
|
- await createDisposalRectification({
|
|
|
- fixTaskId,
|
|
|
- ...ruleFormData,
|
|
|
- });
|
|
|
- ElMessage.success('提交成功');
|
|
|
- cloneRuleFormData();
|
|
|
+ await submitDisposalRectification();
|
|
|
router.back();
|
|
|
} finally {
|
|
|
formLoading.value = false;
|
|
|
}
|
|
|
};
|
|
|
- onMounted(() => {
|
|
|
+ const defaultRouterName = 'disaster-control-disposal-rectification-item';
|
|
|
+ const handleNextSubmit = async () => {
|
|
|
+ if (!basicFormRef.value) return;
|
|
|
+ const validateResult = await basicFormRef.value.validateForm();
|
|
|
+ if (!validateResult) return;
|
|
|
+ try {
|
|
|
+ await submitDisposalRectification();
|
|
|
+ } finally {
|
|
|
+ formLoading.value = false;
|
|
|
+ }
|
|
|
+ // 查找当前id在数组中的索引
|
|
|
+ const currentIndex = rectificationIds.value.indexOf(id.value);
|
|
|
+
|
|
|
+ if (currentIndex !== -1) {
|
|
|
+ // 从数组中移除当前id
|
|
|
+ rectificationIds.value.splice(currentIndex, 1);
|
|
|
+
|
|
|
+ // 确定下一个要处理的id
|
|
|
+ let nextId;
|
|
|
+ if (currentIndex < rectificationIds.value.length) {
|
|
|
+ // 如果不是最后一个元素,取当前索引位置的元素(移除当前id后,下一个id会自动前移)
|
|
|
+ nextId = rectificationIds.value[currentIndex];
|
|
|
+ } else {
|
|
|
+ // 如果是最后一个元素,取第一个元素
|
|
|
+ nextId = rectificationIds.value[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存更新后的数组到sessionStorage
|
|
|
+ sessionStorage.setItem('rectificationIds', JSON.stringify(rectificationIds.value));
|
|
|
+ router.replace({
|
|
|
+ name: defaultRouterName,
|
|
|
+ params: {
|
|
|
+ id: nextId,
|
|
|
+ },
|
|
|
+ query: {
|
|
|
+ handleTaskId,
|
|
|
+ fixTaskId,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const mainElement = document.querySelector('.disaster-precaution-container__main');
|
|
|
+ if (!mainElement) return;
|
|
|
+ mainElement.scrollTop = 0;
|
|
|
+ };
|
|
|
+ const initRuleFormCreatedBy = () => {
|
|
|
ruleFormData.createdBy = userId;
|
|
|
ruleFormData.createdByName = realname;
|
|
|
+ };
|
|
|
+ onMounted(() => {
|
|
|
+ initRuleFormCreatedBy();
|
|
|
cloneRuleFormData();
|
|
|
beforeRouteLeave();
|
|
|
getLossReportItemData();
|
|
|
getSafetyLevelDict();
|
|
|
const sessionRectificationIds = sessionStorage.getItem('rectificationIds') || '[]';
|
|
|
rectificationIds.value = JSON.parse(sessionRectificationIds);
|
|
|
- isShowNextSubmit.value = rectificationIds.value.length > 1 && rectificationIds.value.includes(id);
|
|
|
});
|
|
|
+ onUnmounted(() => {
|
|
|
+ sessionStorage.removeItem('rectificationIds');
|
|
|
+ });
|
|
|
+ watch(
|
|
|
+ () => route.params.id,
|
|
|
+ (newId) => {
|
|
|
+ id.value = Number(newId);
|
|
|
+ getLossReportItemData();
|
|
|
+ basicFormRef.value?.clearValidate();
|
|
|
+ initRuleFormCreatedBy();
|
|
|
+ uploadImagesRef.value?.removeAllImages();
|
|
|
+ uploadFilesRef.value?.removeAllFiles();
|
|
|
+ cloneRuleFormData();
|
|
|
+ },
|
|
|
+ );
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|