完成合同下载功能
This commit is contained in:
parent
cb864a7f08
commit
b226641a52
@ -1,6 +1,7 @@
|
||||
export const apiArr = {
|
||||
ecApply: "/api/v2/wechat/lkl-split-business/ec-apply", //电子合同申请
|
||||
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", //附件上传
|
||||
applyLedgerReceiver: "/api/v2/wechat/lkl-split-business/apply-ledger-receiver", //分账接收方创建申请
|
||||
applyBind: "/api/v2/wechat/lkl-split-business/apply-bind", //分账关系绑定申请
|
||||
|
||||
@ -22,7 +22,7 @@ page {
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.select-btn{
|
||||
.download-btn{
|
||||
height: 65rpx;
|
||||
border: none;
|
||||
border-radius: 10rpx;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
<view class="contract-apply-container">
|
||||
<view class="page-header">
|
||||
<h1>合同申请</h1>
|
||||
<button type="button" class="download-btn" @click="download">合同下载</button>
|
||||
</view>
|
||||
|
||||
<form class="contract-form">
|
||||
@ -111,7 +112,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils";
|
||||
import { picUrl, menuButtonInfo, request, NavgateTo, RequsetUrl } from "../../../utils";
|
||||
import { apiArr } from "../../../api/contract";
|
||||
export default {
|
||||
data() {
|
||||
@ -158,6 +159,88 @@ export default {
|
||||
}
|
||||
},
|
||||
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() {
|
||||
const storeValue = uni.getStorageSync('storeValue');
|
||||
@ -172,7 +255,6 @@ export default {
|
||||
ec_apply_id: storeValue.ec_apply_id
|
||||
}
|
||||
request(apiArr.ecQuery, "POST", params).then(res => {
|
||||
console.log("🚀 ~ res:", res)
|
||||
})
|
||||
},
|
||||
// 获取合同类别显示文本
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user