<template>
	<view class="list-body">
		<uni-nav-bar @clickLeft="goBack()" class="nav-bar" height="110rpx" leftWidth="400rpx" leftText="我的证书"
			leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="oplCate-info" v-if="certificates.length>0">
			<view class="uni-list-cell uni-list-cell-pd" v-for="row in certificates" :key="row.id" @click="download(row.file_f)">
				<view>
					<view class="name">{{row.name}}</view>
				</view>
				<image class="oplAddImg" :src="require('@/static/common/downIcon.png')" mode="widthFix">
				</image>
			</view>
		</view>
		<view style="text-align: center;padding-top: 200upx;">暂无证书</view>
	</view>
</template>
<script>
	export default {
		name: "myCertificates",
		data() {
			return {	
				certificates: [],
			}
		},
	
		onShow() {
			debugger;
			console.log(this.vuex_perm)
			this.certificates = [];
			this.getCertificates();
		},
		methods: {
			getCertificates(e) {
				let that = this;
				that.certificates =[];
				that.$u.api.hrmCertificate({page: 0,employee__user:this.vuex_user.id})
						.then((res) => {
							that.certificates = res
							console.log(res);
						});
				},
			
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			//下载文件
			      download(urls) {
			        let that = this
			        uni.downloadFile({
			          url: urls, //下载地址，后端接口获取的链接
			          success: (data) => {
			            console.log(data.tempFilePath)
			            console.log(JSON.stringify(data))
			            if (data.statusCode === 200) {
			              uni.saveFile({ //文件保存到本地
			                tempFilePath: data.tempFilePath, //临时路径
			                success: function(res) {
			                  console.log(JSON.stringify(res))
			                  uni.showToast({
			                    icon: 'none',
			                    mask: true,
			                    title: '文件已保存!', 
			                    duration: 3000,
			                  });
			                  uni.openDocument({
			                    fileType: 'docx',
			                    filePath: res.savedFilePath,
			                    success: function(res) {
			                      console.log('打开文档成功');
			                    }
			                  });
			                }
			              });
			            }
			          },
			          fail: (err) => {
			            console.log(err);
			            uni.showToast({
			              icon: 'none',
			              mask: true,
			              title: '失败请重新下载',
			            });
			          },
			        });
			      },
		}
	}
</script>

<style>
	>>>.uni-navbar__header,
	>>>.uni-status-bar {
		background-image: linear-gradient(90deg, #164cc3 0%, #2c6fd9 100%), linear-gradient(#e60012, #e60012) !important;
	}

	.list-body {
		background-color: #f3fbff;
		padding-bottom: 113px;
		height: 100%;
		min-height:100vh;
	}

	.oplCate-info {
		width: 360px;
		margin: 0 auto;
		background-color: #FFFFFF;
		border-radius: 5px;
		padding: 12px 16px;
		box-sizing: border-box;
		margin-top: 12px;
	}

	.oplCate-info-title {
		font-size: 32upx;
		color: #333333;
		font-weight: bold;
		border-bottom: 1upx solid #eeeeee;
		height: 70upx;
	}

	.row {
		padding: 10upx;
		margin-bottom: 20upx;
		border-bottom: 1upx solid #eeeeee;
	}

	.uni-list-cell {
		display: flex;
		padding: 10upx;
		padding: 30upx 0;
		justify-content: space-between;
		border-bottom: 1upx solid #eeeeee;
	}

	.uni-list-cell:last-child {
		border-bottom: 0;
	}

	.oplEditImg {
		width: 40rpx;
		height: 40upx;
		background-size: cover;
		background-image: url('@/static/workSpace/new_apply/update.png');
	}
	.oplAddImg {
		width: 40rpx;
		height: 40upx;
	}

	.add {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 120upx;
		justify-content: center;
		align-items: center;
	}

	.btn {
		margin: auto;
		box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.4);
		width: 70%;
	}

	.save-btn {
		height: 80rpx;
		color: #fff;
		font-size: 30upx;
		justify-content: center;
		align-items: center;
	}
</style>
