<template>
	<view class="center">
		<view class="c-list">
			<view class="xinxiup">
				<view class='xinxiup-title'>{{title}}</view>
				<view style='width:100%;' class='flex justify-between fujian align-item-center' v-for="item in list">
					<view style='flex:2;' class="flex align-item-center">
						<view><image style='width:25px;height:25px;position:relative;top:2px;' src="../../static/img/contract/pdf@3x.png" mode=""></image></view>
						<view>
							<text class="tit">{{item.appendixName}}</text>
							<view style='color:#B0B3BF;font-size:12px;'>{{item.appendixSize}}</view>
						</view>
						
					</view>
					<view style='flex:1;'>
						<image @click="download(item.appendixPath)" style='width:15px;height:15px;' src="../../static/img/contract/xiazai@3x.png" mode=""></image>
					</view>
					
					<!-- <view class="c-row b-b">
						<text class="tit">{{item.appendixPath}}</text>
					</view> -->
				</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 scoped>
	page{
		background:#F5F6FA;
	}
	.center{
		background:#fff;
		margin:10px;
		padding:29rpx;
	}
	.xinxiup-title{
		padding-bottom:10px;border-bottom:1px solid #EEEEEE;
	}
	.fujian{
		padding:10px 0;
	}
	.tit{
		font-size:16px;
	}
</style>
