1080 lines
33 KiB
Vue
1080 lines
33 KiB
Vue
<template>
|
||
<view class="page padding">
|
||
<view class="padding bg-white radius">
|
||
<view class="text-gray margin-bottom">整改记录</view>
|
||
<view class="padding solid radius">
|
||
<view>
|
||
<view style="color: #999; margin-bottom: 10rpx;">整改方案:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifyPlan || '暂无' }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">整改措施:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectificationMeasures || '暂无' }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">管控措施:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.controlMeasures || '暂无' }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">整改完成情况:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifyResult || '暂无' }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">计划投资资金:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ formatMoney(rectifyData.planCost) }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">实际投资资金:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ formatMoney(rectifyData.actualCost) }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">安全管理人员:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ formatPersonNames(rectifyData.managerNames) }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">整改责任人:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ formatPersonNames(rectifyData.memberNames) }}</view>
|
||
</view>
|
||
<view class="margin-top">
|
||
<view style="color: #999; margin-bottom: 10rpx;">完成情况:</view>
|
||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifyStatusName || '暂无' }}</view>
|
||
</view>
|
||
<view class="margin-top-sm">
|
||
<view>整改附件:</view>
|
||
<view class="flex margin-top-xs" style="flex-wrap: wrap; gap: 10rpx;" v-if="rectifyAttachments.length > 0">
|
||
<image v-for="(img, idx) in rectifyAttachments" :key="idx" :src="getFullPath(img.filePath)" style="width: 136rpx;height: 136rpx;border-radius: 16rpx;" mode="aspectFill" @click="previewImage(idx)"></image>
|
||
</view>
|
||
<view v-else class="text-gray text-sm margin-top-xs">暂无附件</view>
|
||
</view>
|
||
</view>
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">验收结果</view>
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<view class="flex" style="gap: 20rpx;">
|
||
<button :class="['result-btn', formData.result === 1 ? 'active' : '']" @click="onResultChange(1)">通过</button>
|
||
<button :class="['result-btn', formData.result === 2 ? 'active' : '']" @click="onResultChange(2)">不通过</button>
|
||
</view>
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">验收备注</view>
|
||
</view>
|
||
<up-textarea v-model="formData.verifyRemark" placeholder="请输入验收备注"></up-textarea>
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">验收图片/视频</view>
|
||
</view>
|
||
<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple imageMode="aspectFill" :maxCount="10"></up-upload>
|
||
|
||
<template v-if="formData.result === 1">
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">是否结束隐患验收</view>
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<up-radio-group :key="'hazard-end-' + hazardEndRadio" v-model="hazardEndRadio" placement="row" activeColor="#2667e9" @change="onHazardEndChange">
|
||
<up-radio
|
||
label="否"
|
||
name="no"
|
||
:customStyle="{ marginRight: '48rpx' }"
|
||
></up-radio>
|
||
<up-radio label="是" name="yes"></up-radio>
|
||
</up-radio-group>
|
||
</template>
|
||
|
||
<template v-if="formData.result === 1 && hazardEndRadio !== 'yes'">
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">是否快速审批</view>
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<up-radio-group :key="'quick-approve-' + quickApproveRadio" v-model="quickApproveRadio" placement="row" activeColor="#2667e9" @change="onQuickApproveChange">
|
||
<up-radio
|
||
label="是"
|
||
name="yes"
|
||
:customStyle="{ marginRight: '48rpx' }"
|
||
></up-radio>
|
||
<up-radio label="否" name="no"></up-radio>
|
||
</up-radio-group>
|
||
</template>
|
||
|
||
<!-- 隐藏的 Canvas,用于渲染防作弊时间戳水印 -->
|
||
<canvas canvas-id="watermarkCanvas" :width="canvasWidth" :height="canvasHeight" :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px', position: 'fixed', left: '-9999px', top: '-9999px' }"></canvas>
|
||
|
||
<view v-if="!(formData.result === 1 && hazardEndRadio === 'yes')" class="flex margin-bottom margin-top">
|
||
<view class="text-gray">下一步流程</view>
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<view v-if="!(formData.result === 1 && hazardEndRadio === 'yes')" class="static-field">{{ nextStepDisplay }}</view>
|
||
|
||
<template v-if="showAssigneeSection">
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">下一步处理人</view>
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<view v-if="formData.result === 2" class="static-field">{{ rectifierDisplayName }}</view>
|
||
<view v-else class="select-trigger" @click="openAssigneePopup">
|
||
<view class="select-content" :class="{ 'text-gray': !selectedAssigneeName }">
|
||
{{ selectedAssigneeName || '请选择下一步处理人' }}
|
||
</view>
|
||
<text class="cuIcon-unfold"></text>
|
||
</view>
|
||
</template>
|
||
|
||
<FlowAssigneePickerPopup
|
||
:show="showAssigneePopup"
|
||
:task-id="taskId"
|
||
v-model:picker-identity-id="pickerAssigneeIdentityId"
|
||
v-model:picker-name="pickerAssigneeName"
|
||
@cancel="cancelAssigneeSelect"
|
||
@confirm="confirmAssigneeSelect"
|
||
/>
|
||
|
||
<!-- 短信提醒(暂不使用)
|
||
<view class="flex margin-bottom margin-top">
|
||
<view class="text-gray">短信提醒</view>
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<up-radio-group v-model="sendMsgFlagRadio" placement="row" activeColor="#2667e9">
|
||
<up-radio
|
||
label="是"
|
||
name="yes"
|
||
:customStyle="{ marginRight: '48rpx' }"
|
||
></up-radio>
|
||
<up-radio label="否" name="no"></up-radio>
|
||
</up-radio-group>
|
||
-->
|
||
|
||
<!-- 电子签名(表单最底部) -->
|
||
<view class="flex justify-between margin-bottom margin-top align-center">
|
||
<view class="text-gray flex align-center">
|
||
电子签名
|
||
<view class="text-red">*</view>
|
||
</view>
|
||
<button v-if="showCanvas" class="cu-btn sm round line-blue" style="margin: 0; padding: 0 20rpx; height: 50rpx; font-size: 22rpx;" @click="clearSignature">清除重写</button>
|
||
<button v-else class="cu-btn sm round line-blue" style="margin: 0; padding: 0 20rpx; height: 50rpx; font-size: 22rpx;" @click="reSign">重新签名</button>
|
||
</view>
|
||
<view class="signature-box margin-bottom">
|
||
<view v-if="!showCanvas" class="signature-display flex align-center justify-center" style="width: 100%; height: 160px; background-color: #f8f8f8; display: flex; align-items: center; justify-content: center;">
|
||
<image
|
||
v-if="signatureUrl"
|
||
:src="signatureUrl"
|
||
class="signature-img"
|
||
mode="aspectFit"
|
||
style="width: 100%; height: 100%;"
|
||
></image>
|
||
<text v-else class="signature-placeholder">暂无签名,请点击重新签名</text>
|
||
</view>
|
||
<!-- 改为 v-if 解决小程序原生 canvas 真机渲染与生命周期挂载残留问题 -->
|
||
<!-- 弹窗打开时卸载 Canvas,解决微信原生 canvas 真机穿透盖住弹层的问题 -->
|
||
<view v-if="showCanvas && !showAssigneePopup" class="signature-pad-wrap" style="border: 1px dashed #dcdfe6; border-radius: 8rpx; overflow: hidden; background-color: #f8f8f8;">
|
||
<wd-signature
|
||
ref="signatureRef"
|
||
:width="signatureWidth"
|
||
:height="160"
|
||
backgroundColor="#f8f8f8"
|
||
penColor="#000000"
|
||
:lineWidth="3"
|
||
:enableHistory="false"
|
||
@confirm="(res) => onSignatureConfirm(res.tempFilePath)"
|
||
@start="onSignatureStart"
|
||
@signing="onSignatureSigning"
|
||
@end="onSignatureEnd"
|
||
@clear="onSignatureClear"
|
||
>
|
||
<template #footer></template>
|
||
</wd-signature>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="flex margin-top-xl" style="gap: 20rpx;">
|
||
<button class="round flex-sub" @click="handleCancel">取消</button>
|
||
<button class="bg-blue round flex-sub" @click="handleSubmit">提交验收</button>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, reactive, computed, nextTick, getCurrentInstance } from 'vue';
|
||
import { onLoad, onHide } from '@dcloudio/uni-app';
|
||
import { acceptanceRectification, getHiddenDangerDetail, getRectifyDetail, getFlowNextNodes } from '@/request/api.js';
|
||
import FlowAssigneePickerPopup from '@/components/flow/FlowAssigneePickerPopup.vue';
|
||
import { toImageUrl } from '@/request/request.js';
|
||
import { buildDraftKey, buildDraftKeyCompact, DRAFT_NS } from '@/utils/draftCache.js';
|
||
import { useDraftCache } from '@/utils/useDraftCache.js';
|
||
import {
|
||
createUploadListHandlers,
|
||
buildAttachmentItem,
|
||
uploadToCloud,
|
||
toSubmitFileUrl
|
||
} from '@/utils/upload.js';
|
||
|
||
// 页面参数
|
||
const rectifyId = ref('');
|
||
const hazardId = ref('');
|
||
const assignId = ref('');
|
||
const taskId = ref('');
|
||
|
||
// 下一步流程
|
||
const nextStepName = ref('');
|
||
const nextStepLoading = ref(false);
|
||
|
||
const nextStepDisplay = computed(() => {
|
||
if (nextStepLoading.value) return '加载中...';
|
||
return nextStepName.value || '暂无下一步流程';
|
||
});
|
||
|
||
const resolveTaskIdFromAssign = (assign) => {
|
||
if (!assign) return '';
|
||
if (assign.taskId) return String(assign.taskId);
|
||
if (assign.flowTaskId) return String(assign.flowTaskId);
|
||
if (assign.currentTaskId) return String(assign.currentTaskId);
|
||
return '';
|
||
};
|
||
|
||
// 从 assigns 中找到包含整改记录的那一项
|
||
const resolveAssignWithRectify = (assigns) => {
|
||
if (!assigns?.length) return null;
|
||
if (rectifyId.value) {
|
||
const byRectifyId = assigns.find(
|
||
(item) => item.rectify && String(item.rectify.rectifyId) === String(rectifyId.value)
|
||
);
|
||
if (byRectifyId) return byRectifyId;
|
||
}
|
||
if (assignId.value) {
|
||
const byAssignId = assigns.find(
|
||
(item) => String(item.assignId) === String(assignId.value) && item.rectify
|
||
);
|
||
if (byAssignId) return byAssignId;
|
||
}
|
||
return assigns.find((item) => item.rectify) || null;
|
||
};
|
||
|
||
const resolveTaskIdFromDetail = (data) => {
|
||
if (!data) return '';
|
||
if (data.taskId) return String(data.taskId);
|
||
if (data.flowTaskId) return String(data.flowTaskId);
|
||
if (data.currentTaskId) return String(data.currentTaskId);
|
||
|
||
const assigns = data.assigns || [];
|
||
const matchedAssign = resolveAssignWithRectify(assigns);
|
||
const fromMatched = resolveTaskIdFromAssign(matchedAssign);
|
||
if (fromMatched) return fromMatched;
|
||
|
||
for (const assign of assigns) {
|
||
const id = resolveTaskIdFromAssign(assign);
|
||
if (id) return id;
|
||
}
|
||
return '';
|
||
};
|
||
|
||
const resolveNextTaskName = (data) => {
|
||
if (!data) return '';
|
||
const branches = data.branches || [];
|
||
const matchedBranch = branches.find((item) => item.matched) || branches[0];
|
||
return matchedBranch?.nextNode?.taskName || '';
|
||
};
|
||
|
||
const buildPreviewVariables = () => {
|
||
if (formData.result === 2) {
|
||
return { pass: false };
|
||
}
|
||
if (hazardEndRadio.value === 'yes') {
|
||
return { pass: true, hazardEnd: true };
|
||
}
|
||
return {
|
||
pass: true,
|
||
quickApprove: quickApproveRadio.value === 'yes'
|
||
};
|
||
};
|
||
|
||
const rectifierDisplayName = computed(() => rectifyData.rectifierName?.trim() || '暂无');
|
||
|
||
// 通过且快速审批时无需选择下一步处理人;结束验收时也不显示
|
||
const showAssigneeSection = computed(() => {
|
||
if (formData.result === 1 && hazardEndRadio.value === 'yes') return false;
|
||
if (formData.result === 2) return true;
|
||
if (formData.result === 1 && quickApproveRadio.value === 'no') return true;
|
||
return false;
|
||
});
|
||
|
||
const selectedAssigneeIdentityId = ref('');
|
||
const selectedAssigneeName = ref('');
|
||
const pickerAssigneeIdentityId = ref('');
|
||
const pickerAssigneeName = ref('');
|
||
const showAssigneePopup = ref(false);
|
||
|
||
const openAssigneePopup = () => {
|
||
if (!taskId.value) {
|
||
uni.showToast({ title: '缺少任务ID', icon: 'none' });
|
||
return;
|
||
}
|
||
pickerAssigneeIdentityId.value = selectedAssigneeIdentityId.value;
|
||
pickerAssigneeName.value = selectedAssigneeName.value;
|
||
showAssigneePopup.value = true;
|
||
};
|
||
|
||
const confirmAssigneeSelect = ({ identityId, name }) => {
|
||
selectedAssigneeIdentityId.value = identityId;
|
||
selectedAssigneeName.value = name;
|
||
showAssigneePopup.value = false;
|
||
};
|
||
|
||
const cancelAssigneeSelect = () => {
|
||
showAssigneePopup.value = false;
|
||
};
|
||
|
||
const onResultChange = (result) => {
|
||
formData.result = result;
|
||
if (result === 2) {
|
||
hazardEndRadio.value = 'no';
|
||
selectedAssigneeIdentityId.value = '';
|
||
selectedAssigneeName.value = '';
|
||
} else if (!quickApproveRadio.value) {
|
||
quickApproveRadio.value = 'yes';
|
||
}
|
||
fetchNextStep();
|
||
};
|
||
|
||
const onHazardEndChange = (value) => {
|
||
if (value === 'yes') {
|
||
quickApproveRadio.value = 'yes';
|
||
selectedAssigneeIdentityId.value = '';
|
||
selectedAssigneeName.value = '';
|
||
} else {
|
||
fetchNextStep();
|
||
}
|
||
};
|
||
|
||
const onQuickApproveChange = () => {
|
||
selectedAssigneeIdentityId.value = '';
|
||
selectedAssigneeName.value = '';
|
||
fetchNextStep();
|
||
};
|
||
|
||
const fetchNextStep = async () => {
|
||
if (formData.result === 1 && hazardEndRadio.value === 'yes') {
|
||
nextStepName.value = '';
|
||
return;
|
||
}
|
||
nextStepLoading.value = true;
|
||
try {
|
||
const currentTaskId = taskId.value;
|
||
if (!currentTaskId) {
|
||
nextStepName.value = '';
|
||
return;
|
||
}
|
||
const res = await getFlowNextNodes({
|
||
taskId: currentTaskId,
|
||
previewVariables: buildPreviewVariables(),
|
||
includeSubProcess: true
|
||
});
|
||
if (res.code === 0) {
|
||
const payload = res.data && typeof res.data === 'object' ? res.data : res;
|
||
nextStepName.value = resolveNextTaskName(payload);
|
||
} else {
|
||
nextStepName.value = '';
|
||
}
|
||
} catch (error) {
|
||
console.error('获取下一步流程失败:', error);
|
||
nextStepName.value = '';
|
||
} finally {
|
||
nextStepLoading.value = false;
|
||
}
|
||
};
|
||
|
||
// 整改记录数据
|
||
const rectifyData = reactive({
|
||
rectifyPlan: '',
|
||
rectificationMeasures: '',
|
||
controlMeasures: '',
|
||
rectifyResult: '',
|
||
planCost: null,
|
||
actualCost: null,
|
||
managerNames: [],
|
||
memberNames: [],
|
||
rectifierName: '',
|
||
rectifyStatusName: ''
|
||
});
|
||
|
||
const formatPersonNames = (names) => {
|
||
if (!names) return '暂无';
|
||
if (Array.isArray(names)) {
|
||
const text = names.filter(Boolean).join('、');
|
||
return text || '暂无';
|
||
}
|
||
if (typeof names === 'string') {
|
||
return names.trim() || '暂无';
|
||
}
|
||
return '暂无';
|
||
};
|
||
|
||
const formatMoney = (value) => {
|
||
if (value === null || value === undefined || value === '') {
|
||
return '暂无';
|
||
}
|
||
const num = Number(value);
|
||
if (Number.isNaN(num)) {
|
||
return '暂无';
|
||
}
|
||
return `${num.toFixed(2)} 元`;
|
||
};
|
||
|
||
// 整改附件
|
||
const rectifyAttachments = ref([]);
|
||
|
||
// 是否结束隐患验收
|
||
const hazardEndRadio = ref('no');
|
||
const hazardEnd = computed(() => hazardEndRadio.value === 'yes');
|
||
const normalizeHazardEndRadio = (value) => (value === 'yes' ? 'yes' : 'no');
|
||
|
||
// 是否快速审批
|
||
const quickApproveRadio = ref('yes');
|
||
const normalizeQuickApproveRadio = (value) => (value === 'no' ? 'no' : 'yes');
|
||
|
||
// 表单数据
|
||
const formData = reactive({
|
||
result: 1, // 验收结果 1.通过 2.不通过
|
||
verifyRemark: '' // 验收备注
|
||
});
|
||
|
||
const fileList1 = ref([]);
|
||
|
||
// 短信提醒(暂不使用)
|
||
// const sendMsgFlagRadio = ref('yes');
|
||
// const sendMsgFlag = computed(() => sendMsgFlagRadio.value === 'yes');
|
||
|
||
// 防作弊时间戳水印 Canvas 大小配置
|
||
const canvasWidth = ref(300);
|
||
const canvasHeight = ref(300);
|
||
|
||
// 电子签名及草稿相关
|
||
const showCanvas = ref(true); // 是否显示签字画板
|
||
const signatureUrl = ref(''); // 签名完整预览地址
|
||
const signatureServerPath = ref(''); // 签名服务器相对路径
|
||
const signatureWidth = ref(340); // 签名画板宽度(动态计算)
|
||
const signatureRef = ref(null); // 签名组件 ref
|
||
const isSignatureEmpty = ref(true); // 签名是否为空
|
||
const isSubmitting = ref(false); // 是否正在提交表单
|
||
const signaturePaths = ref([]); // 缓存手写签名的绘制路径
|
||
const signatureLocalPath = ref(''); // 未上传云端的本地签名临时图
|
||
const isDraftExporting = ref(false); // 是否为草稿导出(非提交上传)
|
||
let signatureExportTimer = null;
|
||
|
||
/** 将已上传的签名地址应用到预览区 */
|
||
const applySignatureFromServer = (signPath) => {
|
||
const url = signPath ? toSubmitFileUrl(signPath) : '';
|
||
if (!url) {
|
||
showCanvas.value = true;
|
||
signatureServerPath.value = '';
|
||
signatureUrl.value = '';
|
||
signatureLocalPath.value = '';
|
||
isSignatureEmpty.value = true;
|
||
return;
|
||
}
|
||
signatureServerPath.value = url;
|
||
signatureUrl.value = url;
|
||
signatureLocalPath.value = '';
|
||
showCanvas.value = false;
|
||
isSignatureEmpty.value = false;
|
||
};
|
||
|
||
/** 将本地临时签名图应用到预览区(草稿回显) */
|
||
const applySignatureFromLocal = (localPath) => {
|
||
if (!localPath) return;
|
||
signatureLocalPath.value = localPath;
|
||
signatureUrl.value = localPath;
|
||
signatureServerPath.value = '';
|
||
showCanvas.value = false;
|
||
isSignatureEmpty.value = false;
|
||
};
|
||
|
||
const acceptDraftHasContent = (data) => {
|
||
const form = data.formData || {};
|
||
return !!(
|
||
form.verifyRemark ||
|
||
(data.fileList1 && data.fileList1.length > 0) ||
|
||
data.signatureServerPath ||
|
||
data.signatureLocalPath ||
|
||
(data.signaturePaths && data.signaturePaths.length > 0)
|
||
);
|
||
};
|
||
|
||
const {
|
||
showRestoreBanner,
|
||
clear: clearDraft,
|
||
restore: restoreDraft,
|
||
save: saveDraft,
|
||
bindAutoSave
|
||
} = useDraftCache({
|
||
getKey: () => buildDraftKey(DRAFT_NS.ACCEPT, rectifyId.value),
|
||
getFallbackKeys: () => {
|
||
const primary = buildDraftKey(DRAFT_NS.ACCEPT, rectifyId.value);
|
||
const compact = buildDraftKeyCompact(DRAFT_NS.ACCEPT, rectifyId.value);
|
||
return compact !== primary ? [compact] : [];
|
||
},
|
||
getPayload: () => ({
|
||
formData: {
|
||
result: formData.result,
|
||
verifyRemark: formData.verifyRemark,
|
||
hazardEndRadio: hazardEndRadio.value,
|
||
quickApproveRadio: quickApproveRadio.value
|
||
},
|
||
selectedAssigneeIdentityId: selectedAssigneeIdentityId.value,
|
||
selectedAssigneeName: selectedAssigneeName.value,
|
||
fileList1: fileList1.value,
|
||
signatureServerPath: signatureServerPath.value,
|
||
signatureUrl: signatureUrl.value,
|
||
signatureLocalPath: signatureLocalPath.value,
|
||
showCanvas: showCanvas.value,
|
||
signaturePaths: signaturePaths.value
|
||
// sendMsgFlagRadio: sendMsgFlagRadio.value
|
||
}),
|
||
hasContent: acceptDraftHasContent,
|
||
applyPayload: (data) => {
|
||
const form = data.formData || {};
|
||
formData.result = form.result !== undefined ? form.result : 1;
|
||
formData.verifyRemark = form.verifyRemark || '';
|
||
hazardEndRadio.value = normalizeHazardEndRadio(form.hazardEndRadio ?? (form.hazardEnd === true ? 'yes' : 'no'));
|
||
quickApproveRadio.value = normalizeQuickApproveRadio(form.quickApproveRadio);
|
||
selectedAssigneeIdentityId.value = data.selectedAssigneeIdentityId || '';
|
||
selectedAssigneeName.value = data.selectedAssigneeName || '';
|
||
fileList1.value = data.fileList1 || [];
|
||
signaturePaths.value = data.signaturePaths || [];
|
||
if (data.signatureServerPath || data.signatureUrl) {
|
||
applySignatureFromServer(data.signatureServerPath || data.signatureUrl);
|
||
} else if (data.signatureLocalPath) {
|
||
applySignatureFromLocal(data.signatureLocalPath);
|
||
} else {
|
||
showCanvas.value = data.showCanvas !== undefined ? data.showCanvas : true;
|
||
signatureServerPath.value = '';
|
||
signatureUrl.value = '';
|
||
signatureLocalPath.value = '';
|
||
isSignatureEmpty.value = true;
|
||
}
|
||
// sendMsgFlagRadio.value = data.sendMsgFlagRadio === 'no' ? 'no' : 'yes';
|
||
},
|
||
clearForm: () => {
|
||
formData.result = 1;
|
||
formData.verifyRemark = '';
|
||
hazardEndRadio.value = 'no';
|
||
quickApproveRadio.value = 'yes';
|
||
selectedAssigneeIdentityId.value = '';
|
||
selectedAssigneeName.value = '';
|
||
fileList1.value = [];
|
||
signatureServerPath.value = '';
|
||
signatureUrl.value = '';
|
||
signatureLocalPath.value = '';
|
||
showCanvas.value = true;
|
||
signaturePaths.value = [];
|
||
if (signatureRef.value) {
|
||
signatureRef.value.clear();
|
||
}
|
||
// sendMsgFlagRadio.value = 'yes';
|
||
},
|
||
canSave: () => !!rectifyId.value,
|
||
requireInitialized: true,
|
||
onAfterRestore: (data) => {
|
||
fetchNextStep();
|
||
if (data.signatureServerPath || data.signatureUrl || data.signatureLocalPath) {
|
||
return;
|
||
}
|
||
if (data.signaturePaths?.length > 0) {
|
||
setTimeout(() => {
|
||
if (signatureRef.value) {
|
||
isSignatureEmpty.value = false;
|
||
}
|
||
}, 450);
|
||
}
|
||
}
|
||
});
|
||
|
||
bindAutoSave(() => [
|
||
formData.result,
|
||
formData.verifyRemark,
|
||
hazardEndRadio.value,
|
||
quickApproveRadio.value,
|
||
selectedAssigneeIdentityId.value,
|
||
selectedAssigneeName.value,
|
||
fileList1.value,
|
||
signatureServerPath.value,
|
||
signatureUrl.value,
|
||
signatureLocalPath.value,
|
||
showCanvas.value,
|
||
signaturePaths.value
|
||
// sendMsgFlagRadio.value
|
||
]);
|
||
|
||
// 获取完整图片路径
|
||
const getFullPath = (filePath) => {
|
||
if (!filePath) return '';
|
||
if (filePath.startsWith('http://') || filePath.startsWith('https://')) {
|
||
return toImageUrl(filePath);
|
||
}
|
||
return toImageUrl(filePath);
|
||
};
|
||
|
||
// 图片预览
|
||
const previewImage = (index) => {
|
||
const urls = rectifyAttachments.value.map(item => getFullPath(item.filePath));
|
||
uni.previewImage({
|
||
current: index,
|
||
urls: urls
|
||
});
|
||
};
|
||
|
||
const mapPersonListToNickNames = (people) => {
|
||
if (!Array.isArray(people) || people.length === 0) return [];
|
||
const names = people
|
||
.map((person) => person.nickName || person.userName || person.name || '')
|
||
.filter(Boolean);
|
||
return [...new Set(names)];
|
||
};
|
||
|
||
const resolveManagerNames = (rectify) => {
|
||
if (Array.isArray(rectify.managers) && rectify.managers.length > 0) {
|
||
return mapPersonListToNickNames(rectify.managers);
|
||
}
|
||
return rectify.managerNames || [];
|
||
};
|
||
|
||
const resolveMemberNames = (rectify) => {
|
||
if (Array.isArray(rectify.members) && rectify.members.length > 0) {
|
||
return mapPersonListToNickNames(rectify.members);
|
||
}
|
||
return rectify.memberNames || [];
|
||
};
|
||
|
||
const applyRectifyData = (rectify) => {
|
||
if (!rectify) return;
|
||
rectifyData.rectifyPlan = rectify.rectifyPlan || '';
|
||
rectifyData.rectificationMeasures = rectify.rectificationMeasures || '';
|
||
rectifyData.controlMeasures = rectify.controlMeasures || '';
|
||
rectifyData.rectifyResult = rectify.rectifyResult || '';
|
||
rectifyData.planCost = rectify.planCost ?? null;
|
||
rectifyData.actualCost = rectify.actualCost ?? null;
|
||
rectifyData.managerNames = resolveManagerNames(rectify);
|
||
rectifyData.memberNames = resolveMemberNames(rectify);
|
||
rectifyData.rectifierName = rectify.rectifierName || '';
|
||
rectifyData.rectifyStatusName = rectify.rectifyStatusName || rectify.statusName || '';
|
||
rectifyAttachments.value = rectify.attachments || [];
|
||
};
|
||
|
||
// 获取整改详情(有 rectifyId 时作为唯一数据源)
|
||
const fetchRectifyDetail = async () => {
|
||
if (!rectifyId.value) return;
|
||
|
||
try {
|
||
const res = await getRectifyDetail({ rectifyId: rectifyId.value });
|
||
if (res.code === 0 && res.data) {
|
||
applyRectifyData(res.data);
|
||
if (!hazardId.value && res.data.hazardId) {
|
||
hazardId.value = String(res.data.hazardId);
|
||
}
|
||
if (!assignId.value && res.data.assignId) {
|
||
assignId.value = String(res.data.assignId);
|
||
}
|
||
const resolvedTaskId = resolveTaskIdFromDetail(res.data);
|
||
if (resolvedTaskId) {
|
||
taskId.value = resolvedTaskId;
|
||
}
|
||
} else {
|
||
uni.showToast({ title: res.msg || '获取整改详情失败', icon: 'none' });
|
||
}
|
||
} catch (error) {
|
||
console.error('获取整改详情失败:', error);
|
||
uni.showToast({ title: '获取整改详情失败', icon: 'none' });
|
||
}
|
||
};
|
||
|
||
// 获取隐患详情(无 rectifyId 时,从 assigns[].rectify 取整改记录)
|
||
const fetchDetail = async () => {
|
||
if (!hazardId.value) return;
|
||
|
||
try {
|
||
const res = await getHiddenDangerDetail({
|
||
hazardId: hazardId.value,
|
||
assignId: assignId.value
|
||
});
|
||
if (res.code === 0 && res.data) {
|
||
const assign = resolveAssignWithRectify(res.data.assigns);
|
||
if (assign?.rectify) {
|
||
applyRectifyData(assign.rectify);
|
||
if (!rectifyId.value && assign.rectify.rectifyId) {
|
||
rectifyId.value = String(assign.rectify.rectifyId);
|
||
}
|
||
} else {
|
||
uni.showToast({ title: '该隐患暂无整改记录', icon: 'none' });
|
||
}
|
||
const resolvedTaskId = resolveTaskIdFromAssign(assign) || resolveTaskIdFromDetail(res.data);
|
||
if (resolvedTaskId) {
|
||
taskId.value = resolvedTaskId;
|
||
}
|
||
} else {
|
||
uni.showToast({ title: res.msg || '获取详情失败', icon: 'none' });
|
||
}
|
||
} catch (error) {
|
||
console.error('获取隐患详情失败:', error);
|
||
uni.showToast({ title: '请求失败', icon: 'none' });
|
||
}
|
||
};
|
||
|
||
const loadPageData = async () => {
|
||
if (rectifyId.value) {
|
||
await fetchRectifyDetail();
|
||
} else if (hazardId.value) {
|
||
await fetchDetail();
|
||
}
|
||
await fetchNextStep();
|
||
};
|
||
|
||
const validateFormBeforeSubmit = () => {
|
||
if (formData.result === 1 && hazardEndRadio.value === 'yes') {
|
||
return true;
|
||
}
|
||
if (formData.result === 1 && !quickApproveRadio.value) {
|
||
uni.showToast({ title: '请选择是否快速审批', icon: 'none' });
|
||
return false;
|
||
}
|
||
if (formData.result === 1 && quickApproveRadio.value === 'no' && !selectedAssigneeIdentityId.value) {
|
||
uni.showToast({ title: '请选择下一步处理人', icon: 'none' });
|
||
return false;
|
||
}
|
||
return true;
|
||
};
|
||
|
||
// 取消
|
||
const handleCancel = () => {
|
||
uni.navigateBack();
|
||
};
|
||
|
||
// 提交验收
|
||
const handleSubmit = async () => {
|
||
if (!rectifyId.value) {
|
||
uni.showToast({
|
||
title: '缺少整改ID',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
if (!validateFormBeforeSubmit()) {
|
||
return;
|
||
}
|
||
|
||
// 电子签名验证与处理
|
||
if (showCanvas.value) {
|
||
if (!signatureRef.value || isSignatureEmpty.value) {
|
||
uni.showToast({
|
||
title: '请进行电子签名',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
isSubmitting.value = true;
|
||
uni.showLoading({ title: '正在提交...', mask: true });
|
||
// 触发组件导出,导出成功会回调 onSignatureConfirm
|
||
signatureRef.value.confirm();
|
||
} else {
|
||
// 已经有回显的签名(云端或本地草稿)
|
||
if (!signatureServerPath.value && !signatureLocalPath.value) {
|
||
uni.showToast({
|
||
title: '请进行电子签名',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
isSubmitting.value = true;
|
||
uni.showLoading({ title: '正在提交...', mask: true });
|
||
try {
|
||
if (!signatureServerPath.value && signatureLocalPath.value) {
|
||
const { url } = await uploadToCloud(signatureLocalPath.value);
|
||
applySignatureFromServer(url);
|
||
}
|
||
await executeSubmit();
|
||
} catch (err) {
|
||
isSubmitting.value = false;
|
||
uni.hideLoading();
|
||
console.error('签名上传失败:', err);
|
||
uni.showToast({ title: '签名上传失败,请重试', icon: 'none' });
|
||
}
|
||
}
|
||
};
|
||
|
||
// 真正调取后台接口提交验收
|
||
const executeSubmit = async () => {
|
||
// 构建附件列表
|
||
const attachments = fileList1.value
|
||
.filter((f) => f.status === 'success')
|
||
.map((file) => buildAttachmentItem(file));
|
||
|
||
const params = {
|
||
rectifyId: Number(rectifyId.value),
|
||
result: formData.result,
|
||
verifyRemark: formData.verifyRemark || '',
|
||
attachments: attachments,
|
||
signPath: signatureServerPath.value || '', // 电子签名路径
|
||
hazardEnd: formData.result === 1 && hazardEndRadio.value === 'yes'
|
||
// sendMsgFlag: sendMsgFlag.value
|
||
};
|
||
|
||
if (formData.result === 1) {
|
||
if (hazardEndRadio.value === 'yes') {
|
||
params.quickApprove = null;
|
||
} else {
|
||
params.quickApprove = quickApproveRadio.value === 'yes';
|
||
if (quickApproveRadio.value === 'no') {
|
||
params.assigneeIdentityId = selectedAssigneeIdentityId.value;
|
||
}
|
||
}
|
||
}
|
||
|
||
console.log('提交验收参数:', params);
|
||
|
||
try {
|
||
const res = await acceptanceRectification(params);
|
||
uni.hideLoading();
|
||
if (res.code === 0) {
|
||
clearDraft(false);
|
||
uni.showToast({
|
||
title: '验收成功',
|
||
icon: 'success'
|
||
});
|
||
setTimeout(() => {
|
||
uni.navigateBack();
|
||
}, 1500);
|
||
} else {
|
||
uni.showToast({
|
||
title: res.msg || '验收失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
} catch (error) {
|
||
uni.hideLoading();
|
||
console.error('验收失败:', error);
|
||
uni.showToast({
|
||
title: '请求失败',
|
||
icon: 'none'
|
||
});
|
||
} finally {
|
||
isSubmitting.value = false;
|
||
}
|
||
};
|
||
|
||
const acceptUploadInstance = getCurrentInstance();
|
||
const { afterRead, deletePic } = createUploadListHandlers(fileList1, {
|
||
watermark: {
|
||
canvasId: 'watermarkCanvas',
|
||
canvasWidthRef: canvasWidth,
|
||
canvasHeightRef: canvasHeight,
|
||
instance: acceptUploadInstance
|
||
}
|
||
});
|
||
|
||
// 电子签名:手写过程中自动导出本地预览图写入草稿
|
||
const onSignatureStart = () => {
|
||
isSignatureEmpty.value = false;
|
||
};
|
||
|
||
const onSignatureSigning = () => {
|
||
isSignatureEmpty.value = false;
|
||
};
|
||
|
||
const onSignatureClear = () => {
|
||
isSignatureEmpty.value = true;
|
||
signatureLocalPath.value = '';
|
||
};
|
||
|
||
const scheduleSignatureDraftExport = () => {
|
||
clearTimeout(signatureExportTimer);
|
||
signatureExportTimer = setTimeout(() => {
|
||
if (
|
||
!showCanvas.value ||
|
||
isSignatureEmpty.value ||
|
||
!signatureRef.value ||
|
||
isSubmitting.value ||
|
||
isDraftExporting.value
|
||
) {
|
||
return;
|
||
}
|
||
isDraftExporting.value = true;
|
||
signatureRef.value.confirm();
|
||
}, 600);
|
||
};
|
||
|
||
const onSignatureEnd = () => {
|
||
isSignatureEmpty.value = false;
|
||
scheduleSignatureDraftExport();
|
||
};
|
||
|
||
// 清除画布
|
||
const clearSignature = () => {
|
||
clearTimeout(signatureExportTimer);
|
||
isSignatureEmpty.value = true;
|
||
signatureLocalPath.value = '';
|
||
if (signatureRef.value) {
|
||
signatureRef.value.clear();
|
||
}
|
||
};
|
||
|
||
// 重新签字
|
||
const reSign = () => {
|
||
clearTimeout(signatureExportTimer);
|
||
isSignatureEmpty.value = true;
|
||
showCanvas.value = true;
|
||
signatureUrl.value = '';
|
||
signatureServerPath.value = '';
|
||
signatureLocalPath.value = '';
|
||
nextTick(() => {
|
||
if (signatureRef.value) {
|
||
signatureRef.value.clear();
|
||
}
|
||
});
|
||
};
|
||
|
||
// 签名导出失败
|
||
const onSignatureError = (err) => {
|
||
console.error('签名绘制失败:', err);
|
||
uni.showToast({ title: '签名生成失败', icon: 'none' });
|
||
isSubmitting.value = false;
|
||
uni.hideLoading();
|
||
};
|
||
|
||
// 签名导出成功回调
|
||
const onSignatureConfirm = async (tempFilePath) => {
|
||
if (isDraftExporting.value) {
|
||
isDraftExporting.value = false;
|
||
applySignatureFromLocal(tempFilePath);
|
||
saveDraft();
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const { url } = await uploadToCloud(tempFilePath);
|
||
applySignatureFromServer(url);
|
||
saveDraft();
|
||
|
||
if (isSubmitting.value) {
|
||
await executeSubmit();
|
||
}
|
||
} catch (err) {
|
||
isSubmitting.value = false;
|
||
uni.hideLoading();
|
||
console.error('签名上传失败:', err);
|
||
uni.showToast({ title: '签名上传失败,请重试', icon: 'none' });
|
||
}
|
||
};
|
||
|
||
onHide(() => {
|
||
if (showCanvas.value && !isSignatureEmpty.value && signatureRef.value && !isDraftExporting.value) {
|
||
isDraftExporting.value = true;
|
||
signatureRef.value.confirm();
|
||
}
|
||
saveDraft();
|
||
});
|
||
|
||
onLoad((options) => {
|
||
// 计算签名画布宽度
|
||
try {
|
||
const sysInfo = uni.getSystemInfoSync();
|
||
signatureWidth.value = sysInfo.windowWidth - 40;
|
||
} catch (e) {
|
||
console.error('获取系统信息失败:', e);
|
||
}
|
||
if (options.rectifyId) {
|
||
rectifyId.value = options.rectifyId;
|
||
}
|
||
if (options.hazardId) {
|
||
hazardId.value = options.hazardId;
|
||
}
|
||
if (options.assignId) {
|
||
assignId.value = options.assignId;
|
||
}
|
||
if (options.taskId) {
|
||
taskId.value = options.taskId;
|
||
}
|
||
console.log('验收页面参数:', { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value, taskId: taskId.value });
|
||
|
||
loadPageData();
|
||
|
||
// 页面打开时自动恢复草稿
|
||
restoreDraft();
|
||
nextTick(() => {
|
||
hazardEndRadio.value = normalizeHazardEndRadio(hazardEndRadio.value);
|
||
quickApproveRadio.value = normalizeQuickApproveRadio(quickApproveRadio.value);
|
||
});
|
||
});
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.page {
|
||
min-height: 100vh;
|
||
background: #EBF2FC;
|
||
}
|
||
|
||
.result-btn {
|
||
flex: 1;
|
||
height: 80rpx;
|
||
line-height: 80rpx;
|
||
border-radius: 8rpx;
|
||
background: #f5f5f5;
|
||
color: #666;
|
||
font-size: 28rpx;
|
||
|
||
&::after {
|
||
border: none;
|
||
}
|
||
|
||
&.active {
|
||
background: #2667E9;
|
||
color: #fff;
|
||
}
|
||
}
|
||
|
||
.static-field {
|
||
background: #fff;
|
||
border: 1rpx solid #dcdfe6;
|
||
border-radius: 8rpx;
|
||
padding: 20rpx 24rpx;
|
||
margin-bottom: 20rpx;
|
||
font-size: 28rpx;
|
||
color: #333;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.select-trigger {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
background: #fff;
|
||
border: 1rpx solid #dcdfe6;
|
||
border-radius: 8rpx;
|
||
padding: 20rpx 24rpx;
|
||
margin-bottom: 20rpx;
|
||
|
||
.select-content {
|
||
flex: 1;
|
||
font-size: 28rpx;
|
||
color: #333;
|
||
}
|
||
}
|
||
|
||
// 签名相关样式
|
||
.signature-box {
|
||
width: 100%;
|
||
min-height: 240rpx;
|
||
background: #f8f8f8;
|
||
border: 1rpx dashed #dcdfe6;
|
||
border-radius: 8rpx;
|
||
margin-top: 16rpx;
|
||
|
||
.signature-img {
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
|
||
.signature-placeholder {
|
||
color: #909399;
|
||
font-size: 28rpx;
|
||
}
|
||
}
|
||
</style>
|