166 lines
4.2 KiB
JavaScript
166 lines
4.2 KiB
JavaScript
|
|
import url from "@/common/http/url.js"
|
|||
|
|
import { sendRequest, sendRequestJson } from "@/common/http/api.js"
|
|||
|
|
/**
|
|||
|
|
* 显示消息提示框
|
|||
|
|
* @param content 提示的标题
|
|||
|
|
*/
|
|||
|
|
export function toast(content, callBack) {
|
|||
|
|
uni.showToast({
|
|||
|
|
icon: 'none',
|
|||
|
|
title: content,
|
|||
|
|
duration: 2000,
|
|||
|
|
success:() => {
|
|||
|
|
console.log('22')
|
|||
|
|
if (callBack) {
|
|||
|
|
setTimeout(() => {
|
|||
|
|
callBack()
|
|||
|
|
}, 2000)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 显示模态弹窗
|
|||
|
|
* @param content 提示的标题
|
|||
|
|
*/
|
|||
|
|
export function showConfirm(content) {
|
|||
|
|
return new Promise((resolve, reject) => {
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '提示',
|
|||
|
|
content: content,
|
|||
|
|
cancelText: '取消',
|
|||
|
|
confirmText: '确定',
|
|||
|
|
success: function(res) {
|
|||
|
|
resolve(res)
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 参数处理
|
|||
|
|
* @param params 参数
|
|||
|
|
*/
|
|||
|
|
export function tansParams(params) {
|
|||
|
|
let result = ''
|
|||
|
|
for (const propName of Object.keys(params)) {
|
|||
|
|
const value = params[propName]
|
|||
|
|
var part = encodeURIComponent(propName) + "="
|
|||
|
|
if (value !== null && value !== "" && typeof (value) !== "undefined") {
|
|||
|
|
if (typeof value === 'object') {
|
|||
|
|
for (const key of Object.keys(value)) {
|
|||
|
|
if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
|
|||
|
|
let params = propName + '[' + key + ']'
|
|||
|
|
var subPart = encodeURIComponent(params) + "="
|
|||
|
|
result += subPart + encodeURIComponent(value[key]) + "&"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
result += part + encodeURIComponent(value) + "&"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return result
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
export function handlerSign (orderId) {
|
|||
|
|
uni.showLoading({
|
|||
|
|
mask: true,
|
|||
|
|
title: '正在查询合同状态'
|
|||
|
|
})
|
|||
|
|
sendRequest("GET", url.order.signContract, { orderId: orderId }).then((res) => {
|
|||
|
|
let { code, data } = res;
|
|||
|
|
console.log('res', res)
|
|||
|
|
uni.hideLoading()
|
|||
|
|
if (code == 200) {
|
|||
|
|
console.log('666')
|
|||
|
|
if (data.status == 1) {
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '提示',
|
|||
|
|
content: '合同已签署',
|
|||
|
|
cancelText: '查看',
|
|||
|
|
confirmText: '下载',
|
|||
|
|
success:(ret) => {
|
|||
|
|
if(ret.confirm) {
|
|||
|
|
uni.showLoading({
|
|||
|
|
title: '下载中',
|
|||
|
|
mask: true
|
|||
|
|
})
|
|||
|
|
downFile(data.url);
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
uni.downloadFile({
|
|||
|
|
url: data.url,
|
|||
|
|
success: ({ tempFilePath }) => {
|
|||
|
|
console.log('tempFilePath', tempFilePath)
|
|||
|
|
if (ret.confirm) {
|
|||
|
|
uni.saveFile({
|
|||
|
|
tempFilePath: tempFilePath,
|
|||
|
|
success: ({ savedFilePath }) => {
|
|||
|
|
toast('成功保存到' + savedFilePath)
|
|||
|
|
},
|
|||
|
|
fail: () => {
|
|||
|
|
toast('文件保存失败')
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
} else {
|
|||
|
|
uni.openDocument({
|
|||
|
|
filePath: tempFilePath
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
fail: () => {
|
|||
|
|
toast('文件下载失败')
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
} else {
|
|||
|
|
uni.navigateTo({
|
|||
|
|
url: '/pages/common/webView/webView?url=' + data.url
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}).catch(() => {
|
|||
|
|
uni.hideLoading()
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function downFile (url) {
|
|||
|
|
let dtask = plus.downloader.createDownload(url, {
|
|||
|
|
filename: "_downloads/中亿华商/" + url.split('aliyuncs.com/')[1] //利用保存路径,实现下载文件的重命名
|
|||
|
|
},(d, status)=> {
|
|||
|
|
//d为下载的文件对象
|
|||
|
|
if (status == 200) {
|
|||
|
|
uni.hideLoading();
|
|||
|
|
uni.showToast({
|
|||
|
|
icon: 'none',
|
|||
|
|
mask: true,
|
|||
|
|
title: '已保存到文件夹:/中亿华商/' + url.split('aliyuncs.com/')[1], //保存路径
|
|||
|
|
duration: 3000,
|
|||
|
|
});
|
|||
|
|
//下载成功,d.filename是文件在保存在本地的相对路径,使用下面的API可转为平台绝对路径
|
|||
|
|
let fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename);
|
|||
|
|
setTimeout(()=>{
|
|||
|
|
console.log('打开文件')
|
|||
|
|
plus.runtime.openFile(d.filename); //选择软件打开文件
|
|||
|
|
},1500)
|
|||
|
|
} else {
|
|||
|
|
//下载失败
|
|||
|
|
uni.hideLoading();
|
|||
|
|
plus.downloader.clear(); //清除下载任务
|
|||
|
|
uni.showToast({
|
|||
|
|
icon:'none',
|
|||
|
|
mask:true,
|
|||
|
|
title: '下载失败,请稍后重试',
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
dtask.start();
|
|||
|
|
}
|