完成合同下载功能

This commit is contained in:
赵毅 2025-12-04 17:07:25 +08:00
parent cb864a7f08
commit b226641a52
3 changed files with 86 additions and 3 deletions

View File

@ -1,6 +1,7 @@
export const apiArr = { export const apiArr = {
ecApply: "/api/v2/wechat/lkl-split-business/ec-apply", //电子合同申请 ecApply: "/api/v2/wechat/lkl-split-business/ec-apply", //电子合同申请
ecQuery: "/api/v2/wechat/lkl-split-business/ec-query", //电子合同查询 ecQuery: "/api/v2/wechat/lkl-split-business/ec-query", //电子合同查询
ecDownload: "/api/v2/wechat/lkl-split-business/ec-download", //电子合同下载
upload: "/api/v2/wechat/lkl-split-business/upload", //附件上传 upload: "/api/v2/wechat/lkl-split-business/upload", //附件上传
applyLedgerReceiver: "/api/v2/wechat/lkl-split-business/apply-ledger-receiver", //分账接收方创建申请 applyLedgerReceiver: "/api/v2/wechat/lkl-split-business/apply-ledger-receiver", //分账接收方创建申请
applyBind: "/api/v2/wechat/lkl-split-business/apply-bind", //分账关系绑定申请 applyBind: "/api/v2/wechat/lkl-split-business/apply-bind", //分账关系绑定申请

View File

@ -22,7 +22,7 @@ page {
margin-bottom: 10rpx; margin-bottom: 10rpx;
} }
.select-btn{ .download-btn{
height: 65rpx; height: 65rpx;
border: none; border: none;
border-radius: 10rpx; border-radius: 10rpx;

View File

@ -2,6 +2,7 @@
<view class="contract-apply-container"> <view class="contract-apply-container">
<view class="page-header"> <view class="page-header">
<h1>合同申请</h1> <h1>合同申请</h1>
<button type="button" class="download-btn" @click="download">合同下载</button>
</view> </view>
<form class="contract-form"> <form class="contract-form">
@ -111,7 +112,7 @@
</template> </template>
<script> <script>
import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils"; import { picUrl, menuButtonInfo, request, NavgateTo, RequsetUrl } from "../../../utils";
import { apiArr } from "../../../api/contract"; import { apiArr } from "../../../api/contract";
export default { export default {
data() { data() {
@ -158,6 +159,88 @@ export default {
} }
}, },
methods: { methods: {
//
download() {
const storeValue = uni.getStorageSync('storeValue');
if (!storeValue || !storeValue.ec_apply_id) {
uni.showToast({
title: '请先提交申请',
icon: 'none'
});
return;
}
const params = {
ec_apply_id: storeValue.ec_apply_id
};
uni.showLoading({
title: '下载中',
mask: true
});
// URL
const downloadUrl = `${RequsetUrl}${apiArr.ecDownload}?ec_apply_id=${storeValue.ec_apply_id}`;
// 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'
});
}
});
}
}
});
},
fail: (err) => {
console.error('文件保存失败:', err);
uni.showToast({
title: '文件保存失败',
icon: 'none'
});
}
});
},
fail: (err) => {
uni.hideLoading();
console.error('下载请求失败:', err);
uni.showToast({
title: '下载失败,请稍后重试',
icon: 'none'
});
}
});
},
// //
ecQuery() { ecQuery() {
const storeValue = uni.getStorageSync('storeValue'); const storeValue = uni.getStorageSync('storeValue');
@ -172,7 +255,6 @@ export default {
ec_apply_id: storeValue.ec_apply_id ec_apply_id: storeValue.ec_apply_id
} }
request(apiArr.ecQuery, "POST", params).then(res => { request(apiArr.ecQuery, "POST", params).then(res => {
console.log("🚀 ~ res:", res)
}) })
}, },
// //