<template>
	<view class="center">
		<view class="c-list">
			<view class="xinxiup">
				<view>{{title}}</view>
				<view v-for="item in list">
					<view class="c-row b-b">
						<text class="tit">{{item.appendixName}}</text>
					</view>
					<view class="c-row b-b">
						<text class="tit">{{item.appendixSize}}</text>
					</view>
					<view class="c-row b-b">
						<text class="tit">{{item.appendixPath}}</text>
					</view>
					<u-button @click="download(item.appendixPath)">下载</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
			name: "trust",
			data() {
				return {
					list:[],
					title:""
				};
			},
			onLoad(param) {
				var that = this
				this.$api.doRequest('get', '/appendix/query/getFileList', {appendixIds:param.addressUrl}).then(res => {
					if (res.data.code == 200) {
						that.list = res.data.data
						that.title = "共"+that.list.length+"个附件"
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						})
					}
				})
				.catch(res => {
					if(res.errmsg){
						uni.showToast({
							title: res.errmsg,
							icon: 'none',
							duration: 2000
						})
					}
					else{
						uni.showToast({
							title: "系统异常，请联系管理员",
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
			methods: {
				download(path){
					uni.downloadFile({
					  url: path,
					  success: function (res) {
						var filePath = res.tempFilePath;
						uni.saveFile({
						      tempFilePath: filePath,
						      success: function (res) {
						        var savedFilePath = res.savedFilePath;
								uni.showModal({
									title: '提示',
									content: '下载成功，是否打开文件？',
									showCancel: true,
									success: (e) => {
										if (e.confirm) {
											uni.openDocument({
											  filePath: savedFilePath,
											  success: function (res) {
												uni.showToast({
													title: "打开成功",
													icon: 'none',
													duration: 2000
												})
											  }
											});
										}
									},
									fail: () => {},
									complete: () => {}
								})
								
						      }
						    });
					},
					})
				}
			}
		}
</script>

<style>
</style>
