<template>
<view>
<template v-if="annexJson.length>0">
<view class="contain" v-for="(item,index) in annexJson" :key="index">
<view class="containTitle" v-if="bz==1">
<image src="../../static/common/附件名称.png" mode=""></image>
<text v-if="item.templateFilePath && item.templateFilePath!=''" @click="haveTemplate(item)">附件名称:<text style="color: #0000FE;">{
{item.fileName}}</text></text>
<text v-else>附件名称:{
{item.fileName}}</text>
</view>
<view class="containTitle" v-else>
<image src="../../static/common/附件名称.png" mode=""></image>
<text>附件名称:{
{item.fileName}}</text>
</view>
<view class="containTitle">
<image src="../../static/common/附件类型.png" mode=""></image>
<text>附件类型:{
{item.fileType}}</text>
</view>
<view class="containTitle">
<image src="../../static/common/附件大小.png" mode=""></image>
<text>附件大小:{
{item.fileSize}}</text>
</view>
<view v-if="downloadshow==2">
<button type="default" v-if="item.filePath == ''">无操作</button>
<button type="primary" v-else @tap="download(item)">下载</button>
</view>
<view v-else>
<view style="margin-top: 10upx;" v-if="item.filePath == ''">
<button type="primary" @tap="uploadPictures(item)">上传</button>
</view>
<view class="btn" v-else>
<button type="warn" @tap="deletes(item)">删除附件</button>
<button type="primary" @tap="download(item)">下载</button>
</view>
</view>
</view>
<load-more :loadtext="loadtext" style="margin-bottom: 100upx;" />
</template>
<template v-else>
<view class="nodata">
暂无数据,请先上传
</view>
</template>
<!-- <view class="btnP" v-if="hiddens ==0">
<button type="primary" @tap="uploadPictures">上传</button>
</view> -->
</view>
</template>
<script>
import {
getNewFormJsonString,
getNewAnnexJsonString,
getNewAnnexJsonNull
} from '@/common/formJson.js'
import loadMore from "../../components/common/load-more.vue";
export default {
components: {
loadMore
},
data() {
return {
annexJson: [],
loadtext: '',
itemData: null,
downloadshow: null,
bz: '',
flowCode:'',
templateFileNames:''
};
},
onLoad(e) {
this.downloadshow = e.a
this.bz = e.bz
this.flowCode = e.flowCode
this.templateFileNames = e.templateFileName
this.itemData = JSON.parse(e.item)
this.annexJson = JSON.parse(this.itemData.annexJson)
console.log(this.itemData)
},
methods: {
deletes(item) {
var that = this
uni.showModal({
content: '确定要删除吗',
success: function(res) {
if (res.confirm) {
that.config.postRequestFormData('/dic/annex/deleteByUrl', {
fileUrl: item.filePath
}).then(res => {
if (res.data.code == 0) {
var annexJsonObj = getNewAnnexJsonNull(that.annexJson, item.key, item.filePath)
if (that.bz == 1) {
that.config.postRequest('/flow/FlowStdSqs/update', {
annexJson: annexJsonObj,
id: that.itemData.id,
flowInstId:that.itemData.flowInstId,
flowCode:that.flowCode,
templateFileName:that.templateFileNames
}).then(res => {
if (res.data.code == 0) {
//this.annexJson = JSON.parse(res.data.data.annexJson)
uni.showToast({
title: '删除成功',
duration: 2000
});
} else {
}
}).catch(err => {
});
} else {
that.config.postRequest('/flow/inst/update', {
annexJson: annexJsonObj,
id: that.itemData.id,
}).then(res => {
if (res.data.code == 0) {
//this.annexJson = JSON.parse(res.data.data.annexJson)
uni.showToast({
title: '删除成功',
duration: 2000
});
} else {
}
}).catch(err => {
});
}
} else {
uni.showToast({
title: '删除失败',
duration: 2000
});
}
}).catch(err => {
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
uploadPictures(item) {
var that = this
var id
if (that.bz == 1) {
id = that.itemData.flowInstId
}else{
id = that.itemData.id
}
uni.chooseFile({
extension: ['.' + item.fileType],
success: function(res) {
that.config.postRequestFile('/dic/annex/updatingFile', res.tempFilePaths[0], {
'fkId': id,
'tableName': 'flow_inst',
'saveAnnexTable': 'no'
}).then(res => {
var res = JSON.parse(res)
if (res.code == 0) {
var annexJsonObj = getNewAnnexJsonString(that.annexJson, item.key, res.data.fileUrl)
if (that.bz == 1) {
that.config.postRequest('/flow/FlowStdSqs/update', {
annexJson: annexJsonObj,
id: that.itemData.id,
flowInstId:that.itemData.flowInstId,
flowCode:that.flowCode,
templateFileName:that.templateFileNames
}).then(res => {
if (res.data.code == 0) {
//this.annexJson = JSON.parse(res.data.data.annexJson)
uni.showToast({
title: '上传成功',
duration: 2000
});
} else {
}
}).catch(err => {
});
} else {
that.config.postRequest('/flow/inst/update', {
annexJson: annexJsonObj,
id: that.itemData.id,
}).then(res => {
if (res.data.code == 0) {
//this.annexJson = JSON.parse(res.data.data.annexJson)
uni.showToast({
title: '上传成功',
duration: 2000
});
} else {
}
}).catch(err => {
});
}
} else {
uni.showToast({
title: '上传失败',
duration: 2000
});
}
}).catch(err => {
});
}
});
},
download(item) {
var that = this
uni.openDocument({
//http://59.207.61.1:11337/
//https://mylys.oss-cn-hangzhou.aliyuncs.com/
filePath: 'https://mylys.oss-cn-hangzhou.aliyuncs.com/' + item.filePath,
success: function(res) {
console.log('打开文档成功');
}
});
},
haveTemplate(item) {
var that = this
uni.openDocument({
//http://59.207.61.1:11337/
//https://mylys.oss-cn-hangzhou.aliyuncs.com/
filePath: 'https://mylys.oss-cn-hangzhou.aliyuncs.com/' + item.templateFilePath,
success: function(res) {
console.log('打开文档成功');
}
});
}
},
onUnload(){
let pages = getCurrentPages(); // 当前页面
let beforePage = pages[pages.length - 1]; // 前一个页面
beforePage.$refs.one[0].pageNo=1
beforePage.$refs.one[0].getData(); // 执行前一个页面的onLoad方法
console.log(beforePage)
}
}
</script>
<style>
page {
background-color: #fafafa;
}
.contain {
width: 88%;
background-color: #FFFFFF;
padding: 30upx;
margin: 10upx auto 30upx;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, .12);
}
.containTitle {
font-size: 34upx;
color: #333333;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 90%;
}
.containTitle image {
width: 42upx;
height: 42upx;
vertical-align: middle;
margin-right: 6upx;
}
.containTitle text {
vertical-align: middle;
}
.nodata {
text-align: center;
margin-top: 50upx;
}
.btn {
margin-top: 10upx;
display: flex;
justify-content: space-between;
}
.btn button {
width: 48%;
}
.btnP {
width: 90%;
position: fixed;
bottom: 20upx;
left: 0;
right: 0;
margin: 0 auto;
}
</style>
uniapp 之 文件上传 下载等操作
猜你喜欢
转载自blog.csdn.net/weixin_42268006/article/details/123082705
今日推荐
周排行