|
|
|
@ -431,6 +431,7 @@ |
|
|
|
|
|
|
|
<button class="verify-btn" id="verifyBtn" onclick="checkSubmissionStatus()">经销商查验</button> |
|
|
|
<button class="verify-btn" id="exportBtn" onclick="exportCertificate()" style="margin-top: 10px;">导出信息</button> |
|
|
|
<button class="verify-btn" id="resetBtn" onclick="resetSubmissionStatus()" style="margin-top: 10px; background-color: #6c757d;">重置提交</button> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="hint"> |
|
|
|
@ -708,10 +709,36 @@ |
|
|
|
// 保存签名 |
|
|
|
function saveSignature() { |
|
|
|
if (!canvas) return; |
|
|
|
|
|
|
|
// 检查画布是否有内容 |
|
|
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); |
|
|
|
const data = imageData.data; |
|
|
|
let hasContent = false; |
|
|
|
|
|
|
|
// 遍历像素数据,检查是否有非背景色的像素 |
|
|
|
for (let i = 0; i < data.length; i += 4) { |
|
|
|
const r = data[i]; |
|
|
|
const g = data[i + 1]; |
|
|
|
const b = data[i + 2]; |
|
|
|
const a = data[i + 3]; |
|
|
|
|
|
|
|
// 检查是否不是透明像素且不是背景色(#f8f9fa) |
|
|
|
if (a > 0 && !(r === 248 && g === 249 && b === 250)) { |
|
|
|
hasContent = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 只有当画布有内容时才存储签名数据 |
|
|
|
if (hasContent) { |
|
|
|
// 将画布转换为base64编码 |
|
|
|
const signatureData = canvas.toDataURL('image/png'); |
|
|
|
// 存储到隐藏输入字段 |
|
|
|
document.getElementById('signature').value = signatureData; |
|
|
|
} else { |
|
|
|
// 画布为空,清空签名字段 |
|
|
|
document.getElementById('signature').value = ''; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 清除表单 |
|
|
|
@ -731,11 +758,11 @@ |
|
|
|
// 检查提交状态 |
|
|
|
function checkSubmissionStatus() { |
|
|
|
const sessionId = getSessionId(); |
|
|
|
const hasSubmitted = localStorage.getItem('certificateSubmitted_' + sessionId); |
|
|
|
const hasSubmitted = sessionStorage.getItem('certificateSubmitted_' + sessionId); |
|
|
|
|
|
|
|
if (hasSubmitted) { |
|
|
|
// 已提交过,显示提示 |
|
|
|
if (confirm('您已填写过信息,需要导出当前信息吗?')) { |
|
|
|
if (confirm('您已填写过信息,需要导出当前信息吗?\n\n如果需要填写新信息,请点击取消后选择"重置提交"。')) { |
|
|
|
// 触发导出信息按钮的点击事件 |
|
|
|
document.getElementById('exportBtn').click(); |
|
|
|
} |
|
|
|
@ -769,6 +796,19 @@ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 重置提交状态 |
|
|
|
function resetSubmissionStatus() { |
|
|
|
const sessionId = getSessionId(); |
|
|
|
|
|
|
|
if (confirm('确定要重置提交状态吗?\n\n重置后您将可以重新填写新的合格证信息,同时之前导出的二维码仍然可以查看对应的数据。')) { |
|
|
|
// 清除会话存储的提交标记 |
|
|
|
sessionStorage.removeItem('certificateSubmitted_' + sessionId); |
|
|
|
|
|
|
|
// 刷新页面,显示空状态 |
|
|
|
location.reload(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 生成二维码并显示 |
|
|
|
function generateQRCode(url) { |
|
|
|
// 创建二维码容器 |
|
|
|
@ -865,6 +905,50 @@ |
|
|
|
// 保存签名 |
|
|
|
saveSignature(); |
|
|
|
|
|
|
|
// 验证必填字段 |
|
|
|
const subjectName = document.getElementById('subjectName').value.trim(); |
|
|
|
const productName = document.getElementById('productName').value.trim(); |
|
|
|
const weight = document.getElementById('weight').value.trim(); |
|
|
|
const basis = document.getElementById('basis').value.trim(); |
|
|
|
const origin = document.getElementById('origin').value.trim(); |
|
|
|
const contact = document.getElementById('contact').value.trim(); |
|
|
|
const date = document.getElementById('date').value; |
|
|
|
const signature = document.getElementById('signature').value; |
|
|
|
|
|
|
|
// 检查所有必填字段 |
|
|
|
if (!subjectName) { |
|
|
|
alert('请填写主体名称'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!productName) { |
|
|
|
alert('请填写产品名称'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!weight) { |
|
|
|
alert('请填写产品重量'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!basis) { |
|
|
|
alert('请填写承诺依据'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!origin) { |
|
|
|
alert('请填写产地'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!contact) { |
|
|
|
alert('请填写联系方式'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!date) { |
|
|
|
alert('请选择开具日期'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!signature) { |
|
|
|
alert('请进行手写签名'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 收集表单数据 |
|
|
|
const formData = new FormData(this); |
|
|
|
const certificate = {}; |
|
|
|
@ -896,7 +980,7 @@ |
|
|
|
if (data.success) { |
|
|
|
// 标记为已提交 |
|
|
|
const sessionId = getSessionId(); |
|
|
|
localStorage.setItem('certificateSubmitted_' + sessionId, 'true'); |
|
|
|
sessionStorage.setItem('certificateSubmitted_' + sessionId, 'true'); |
|
|
|
|
|
|
|
// 显示结果 |
|
|
|
displayCertificate(data.certificate); |
|
|
|
|