修改下载合同功能逻辑

This commit is contained in:
赵毅 2025-12-12 15:26:41 +08:00
parent 93dcdc6357
commit a0c801ee61

View File

@ -108,7 +108,7 @@
<button type="button" class="submit-btn" @click="submitApplication">提交申请</button> <button type="button" class="submit-btn" @click="submitApplication">提交申请</button>
</view> </view>
</form> </form>
<!-- 自定义弹窗 --> <!-- 自定义弹窗 -->
<view v-if="showCustomModal" class="custom-modal-overlay" @click="closeModal"> <view v-if="showCustomModal" class="custom-modal-overlay" @click="closeModal">
<view class="custom-modal" @click.stop> <view class="custom-modal" @click.stop>
@ -177,7 +177,7 @@ export default {
if (options.ec_content) { if (options.ec_content) {
this.formData.ec_content_parameters = options.ec_content; this.formData.ec_content_parameters = options.ec_content;
} }
// //
uni.$on('agreementSigned', (data) => { uni.$on('agreementSigned', (data) => {
if (data && data.ec_content) { if (data && data.ec_content) {
@ -189,7 +189,7 @@ export default {
} }
}); });
}, },
// //
onUnload() { onUnload() {
uni.$off('agreementSigned'); uni.$off('agreementSigned');
@ -214,68 +214,103 @@ export default {
mask: true mask: true
}); });
// URL request(apiArr.ecDownload, "POST", params).then(res => {
const downloadUrl = `${RequsetUrl}${apiArr.ecDownload}?ec_apply_id=${storeValue.ec_apply_id}`; const respData = res.resp_data;
//
if (respData.ec_status === 'COMPLETED' && respData.ec_file) {
try {
// Base64URLBase64
const base64Data = respData.ec_file;
// URLBase64
const safeBase64 = base64Data.replace(/-/g, '+').replace(/_/g, '/');
// uni.downloadFile //
uni.downloadFile({ const fileName = `contract_${respData.ec_apply_id || Date.now()}.pdf`;
url: downloadUrl,
header: { // uni-app使API
'Authorization': uni.getStorageSync('ctoken') //
}, const fs = uni.getFileSystemManager();
success: (res) => {
uni.hideLoading(); //
// const tempFilePath = `${uni.env.USER_DATA_PATH}/${fileName}`;
uni.saveFile({
tempFilePath: res.tempFilePath, try {
success: (saveRes) => { // Base64
uni.showToast({ fs.writeFile({
title: '下载成功', filePath: tempFilePath,
icon: 'success' data: safeBase64,
}); encoding: 'base64',
// success: () => {
uni.showModal({ uni.hideLoading();
title: '提示', uni.showToast({
content: '合同已下载完成,是否立即打开?', title: '合同下载成功',
success: (modalRes) => { icon: 'success'
if (modalRes.confirm) { });
// console.log('文件保存成功:', tempFilePath);
uni.openDocument({
filePath: saveRes.savedFilePath, //
showMenu: true, uni.openDocument({
success: (openRes) => { filePath: tempFilePath,
console.log('文件打开成功'); showMenu: true,
}, success: (openRes) => {
fail: (err) => { console.log('文件打开成功:', openRes);
console.error('文件打开失败:', err); },
uni.showToast({ fail: (openErr) => {
title: '文件打开失败', console.error('文件打开失败:', openErr);
icon: 'none' uni.showToast({
}); title: '文件打开失败',
} icon: 'none'
}); });
} }
});
},
fail: (writeErr) => {
uni.hideLoading();
console.error('文件写入失败:', writeErr);
uni.showToast({
title: '合同下载失败',
icon: 'none'
});
} }
}); });
}, } catch (fsError) {
fail: (err) => { uni.hideLoading();
console.error('文件保存失败:', err); console.error('文件系统操作失败:', fsError);
uni.showToast({ uni.showToast({
title: '文件保存失败', title: '文件系统错误',
icon: 'none' icon: 'none'
}); });
} }
}); } catch (error) {
}, uni.hideLoading();
fail: (err) => { console.error('处理文件数据失败:', error);
uni.showToast({
title: '文件处理失败',
icon: 'none'
});
}
} else {
uni.hideLoading(); uni.hideLoading();
console.error('下载请求失败:', err); if (respData.ec_status !== 'COMPLETED') {
uni.showToast({ uni.showToast({
title: '下载失败,请稍后重试', title: '电子合同尚未完成',
icon: 'none' icon: 'none'
}); });
} else {
uni.showToast({
title: '合同文件不存在',
icon: 'none'
});
}
} }
}); }).catch(err => {
uni.hideLoading();
console.error('下载合同失败:', err);
uni.showToast({
title: '下载失败,请重试',
icon: 'none'
});
})
}, },
// //
ecQuery() { ecQuery() {
@ -283,12 +318,12 @@ export default {
this.applyUrl = uni.getStorageSync('applyUrl'); this.applyUrl = uni.getStorageSync('applyUrl');
this.showCustomModal = true; this.showCustomModal = true;
}, },
// //
closeModal() { closeModal() {
this.showCustomModal = false; this.showCustomModal = false;
}, },
// //
openApplyUrl() { openApplyUrl() {
if (this.applyUrl) { if (this.applyUrl) {
@ -297,11 +332,11 @@ export default {
}); });
} }
}, },
// //
confirmQuery() { confirmQuery() {
this.showCustomModal = false; this.showCustomModal = false;
// //
const storeValue = uni.getStorageSync('storeValue'); const storeValue = uni.getStorageSync('storeValue');
if (!storeValue || !storeValue.ec_apply_id) { if (!storeValue || !storeValue.ec_apply_id) {
@ -328,7 +363,7 @@ export default {
} }
}) })
}, },
// //
getEcTypeLabel(code) { getEcTypeLabel(code) {
// valuevalue // valuevalue