<template>
	<view class="app-container">
		<view class="card-container">
			<view class="top">
				<view class="title">请加我的企业微信</view>
				<view class="main">
					<image src="/static/mine/wx.png" class="wx"></image>
					<image :src="detail.workQrcode2 ? detail.workQrcode2 : detail.workQrcode" class="code"></image>
					<!-- <image :src="detail.avatar" class="avatar"></image> -->
					<view class="btn" @tap="save()">保存二维码</view>
				</view>
				<view class="info">
					<view class="name">{{detail.workName}}</view>
					<view class="text">{{configInfo.companyName}}</view>
				</view>
			</view>
			<view class="bottom">
				<image :src="configInfo.minLogo2" mode="heightFix"></image>
			</view>
		</view>
		<view class="tips">扫一扫二维码，添加我的企业微信</view>
	</view>
</template>

<script>
	import {mapState} from 'vuex';
	
	export default {
		data() {
			return {
				configInfo: uni.getStorageSync('configInfo'),
				detail: {},
			}
		},
		computed:{
			...mapState(['userInfo', 'isLogin', 'userId']),
		},
		
		onLoad() {
			this.getDetail();
		},
		
		methods: {
			// 获取个人信息
			getDetail() {
				this.$axios({
					url: '/user/user/detail',
					method: 'get',
					params: {
						userId: this.userId
					}
				}).then(res => {
					this.detail = res.data;
				})
			},
			
			// 保存图片
			save() {
				uni.downloadFile({
				    url: this.detail.workQrcode2 ? this.detail.workQrcode2 : this.detail.workQrcode,
				    success: (res) => {
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: () => {
								this.$successToast('保存成功');
							}
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.app-container {
		background: #F4F2F2;
		padding: 40rpx 40rpx 0;
		box-sizing: border-box;
	}
	.tips {
		font-size: 28rpx;
		line-height: 28rpx;
		color: #999999;
		text-align: center;
		margin: 60rpx 0 20rpx;
	}
	.card-container {
		width: 670rpx;
		border-radius: 20rpx;
		background: #FFFFFF;
		box-shadow: -20px 0px 40px 20px rgba(155,155,155,0.30); 
		overflow: hidden;
		.top {
			background: #006FE2;
			display: flex;
			flex-direction: column;
			align-items: center;
			.title {
				font-family: 'PingFang SC';
				font-size: 50rpx;
				color: #FFFFFF;
				line-height: 160rpx;
			}
			.main {
				position: relative;
				display: flex;
				padding-top: 44rpx;
				margin-top: 20rpx;
				.wx {
					width: 508rpx;
					height: 440rpx;
					display: block;
				}
				.code {
					width: 360rpx;
					height: 360rpx;
					display: block;
					position: absolute;
					top: 0;
					left: 74rpx;
					border-radius: 5rpx;
				}
				.btn {
					width: 160rpx;
					height: 48rpx;
					display: block;
					position: absolute;
					top: 380rpx;
					left: 170rpx;
					border-radius: 5rpx;
					border: 1px solid #ffffff;
					line-height: 48rpx;
					text-align: center;
					font-size: 24rpx;
					color: #FFFFFF;
					opacity: .8;
				}
				.avatar {
					width: 88rpx;
					height: 88rpx;
					display: block;
					position: absolute;
					top: 131rpx;
					left: 205rpx;
					border-radius: 5rpx;
					padding: 5rpx;
					background: #FFFFFF;
				}
			}
			.info {
				width: 360rpx;
				text-align: right;
				margin-bottom: 58rpx;
				.name {
					font-size: 36rpx;
					color: #FFFFFF;
					height: 36rpx;
					line-height: 36rpx;
				}
				.text {
					font-size: 28rpx;
					color: #FFFFFF;
					height: 28rpx;
					line-height: 28rpx;
					margin-top: 20rpx;
				}
			}
		}
		.bottom {
			height: 140rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			image {
				height: 60rpx;
				display: block;
			}
		}
	}
</style>
