修改下载合同功能逻辑
This commit is contained in:
parent
93dcdc6357
commit
a0c801ee61
@ -108,7 +108,7 @@
|
||||
<button type="button" class="submit-btn" @click="submitApplication">提交申请</button>
|
||||
</view>
|
||||
</form>
|
||||
|
||||
|
||||
<!-- 自定义弹窗 -->
|
||||
<view v-if="showCustomModal" class="custom-modal-overlay" @click="closeModal">
|
||||
<view class="custom-modal" @click.stop>
|
||||
@ -177,7 +177,7 @@ export default {
|
||||
if (options.ec_content) {
|
||||
this.formData.ec_content_parameters = options.ec_content;
|
||||
}
|
||||
|
||||
|
||||
// 监听协议签署成功事件
|
||||
uni.$on('agreementSigned', (data) => {
|
||||
if (data && data.ec_content) {
|
||||
@ -189,7 +189,7 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
// 页面卸载时移除事件监听
|
||||
onUnload() {
|
||||
uni.$off('agreementSigned');
|
||||
@ -214,68 +214,103 @@ export default {
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 构建完整的下载URL
|
||||
const downloadUrl = `${RequsetUrl}${apiArr.ecDownload}?ec_apply_id=${storeValue.ec_apply_id}`;
|
||||
request(apiArr.ecDownload, "POST", params).then(res => {
|
||||
const respData = res.resp_data;
|
||||
// 检查合同状态是否为已完成
|
||||
if (respData.ec_status === 'COMPLETED' && respData.ec_file) {
|
||||
try {
|
||||
// 处理Base64编码的文件数据(URL安全的Base64)
|
||||
const base64Data = respData.ec_file;
|
||||
// 替换URL安全的Base64字符
|
||||
const safeBase64 = base64Data.replace(/-/g, '+').replace(/_/g, '/');
|
||||
|
||||
// 调用uni.downloadFile进行文件下载
|
||||
uni.downloadFile({
|
||||
url: downloadUrl,
|
||||
header: {
|
||||
'Authorization': uni.getStorageSync('ctoken')
|
||||
},
|
||||
success: (res) => {
|
||||
uni.hideLoading();
|
||||
// 下载成功,保存文件到本地
|
||||
uni.saveFile({
|
||||
tempFilePath: res.tempFilePath,
|
||||
success: (saveRes) => {
|
||||
uni.showToast({
|
||||
title: '下载成功',
|
||||
icon: 'success'
|
||||
});
|
||||
// 提示用户打开文件
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '合同已下载完成,是否立即打开?',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
// 打开文件
|
||||
uni.openDocument({
|
||||
filePath: saveRes.savedFilePath,
|
||||
showMenu: true,
|
||||
success: (openRes) => {
|
||||
console.log('文件打开成功');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('文件打开失败:', err);
|
||||
uni.showToast({
|
||||
title: '文件打开失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// 文件名(可以根据需要设置)
|
||||
const fileName = `contract_${respData.ec_apply_id || Date.now()}.pdf`;
|
||||
|
||||
// 在uni-app中,我们需要使用文件系统API来保存文件
|
||||
// 首先获取文件系统管理器
|
||||
const fs = uni.getFileSystemManager();
|
||||
|
||||
// 生成临时文件路径
|
||||
const tempFilePath = `${uni.env.USER_DATA_PATH}/${fileName}`;
|
||||
|
||||
try {
|
||||
// 将Base64数据写入临时文件
|
||||
fs.writeFile({
|
||||
filePath: tempFilePath,
|
||||
data: safeBase64,
|
||||
encoding: 'base64',
|
||||
success: () => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '合同下载成功',
|
||||
icon: 'success'
|
||||
});
|
||||
console.log('文件保存成功:', tempFilePath);
|
||||
|
||||
// 打开文件
|
||||
uni.openDocument({
|
||||
filePath: tempFilePath,
|
||||
showMenu: true,
|
||||
success: (openRes) => {
|
||||
console.log('文件打开成功:', openRes);
|
||||
},
|
||||
fail: (openErr) => {
|
||||
console.error('文件打开失败:', openErr);
|
||||
uni.showToast({
|
||||
title: '文件打开失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
fail: (writeErr) => {
|
||||
uni.hideLoading();
|
||||
console.error('文件写入失败:', writeErr);
|
||||
uni.showToast({
|
||||
title: '合同下载失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('文件保存失败:', err);
|
||||
} catch (fsError) {
|
||||
uni.hideLoading();
|
||||
console.error('文件系统操作失败:', fsError);
|
||||
uni.showToast({
|
||||
title: '文件保存失败',
|
||||
title: '文件系统错误',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error('处理文件数据失败:', error);
|
||||
uni.showToast({
|
||||
title: '文件处理失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
console.error('下载请求失败:', err);
|
||||
uni.showToast({
|
||||
title: '下载失败,请稍后重试',
|
||||
icon: 'none'
|
||||
});
|
||||
if (respData.ec_status !== 'COMPLETED') {
|
||||
uni.showToast({
|
||||
title: '电子合同尚未完成',
|
||||
icon: 'none'
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '合同文件不存在',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}).catch(err => {
|
||||
uni.hideLoading();
|
||||
console.error('下载合同失败:', err);
|
||||
uni.showToast({
|
||||
title: '下载失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
})
|
||||
},
|
||||
// 合同查询
|
||||
ecQuery() {
|
||||
@ -283,12 +318,12 @@ export default {
|
||||
this.applyUrl = uni.getStorageSync('applyUrl');
|
||||
this.showCustomModal = true;
|
||||
},
|
||||
|
||||
|
||||
// 关闭自定义弹窗
|
||||
closeModal() {
|
||||
this.showCustomModal = false;
|
||||
},
|
||||
|
||||
|
||||
// 打开申请链接
|
||||
openApplyUrl() {
|
||||
if (this.applyUrl) {
|
||||
@ -297,11 +332,11 @@ export default {
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// 确认查询
|
||||
confirmQuery() {
|
||||
this.showCustomModal = false;
|
||||
|
||||
|
||||
// 继续查询流程
|
||||
const storeValue = uni.getStorageSync('storeValue');
|
||||
if (!storeValue || !storeValue.ec_apply_id) {
|
||||
@ -328,7 +363,7 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
// 获取合同类别显示文本
|
||||
getEcTypeLabel(code) {
|
||||
// 兼容直接传入value或者包含value属性的对象
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user