<template>
	<view class="container" >
		<!-- style="flex: 1;" -->
		<view style="flex: 1;">
			<view class="cardHeader" >
				<view class="userHeader">
					
					<!-- #ifdef APP -->
					<text class="iconfont icon-youjiantou zuojiantou" @click="goBack()" style="left: 20rpx;"></text>
					<!-- #endif -->
					<view class="headerBox">
						<view class="add">
							<text class="iconfont icon-jiahao" ></text>
						</view>
						<view class="avartBox" @click="uploadAvatar('avatar')">
							<view class="avartTip">
								点击上传
							</view>
							<image v-if="optionForm.avatarUrl" :src="optionForm.avatarUrl " mode="widthFix"></image>
						</view>
					</view>
					
				</view>
				<view class="userInformation">
					<view style="flex: 1;">
						<view class="headerTitle">
							基本信息
						</view>
						<view class="shimingBox">
							<view class="itemBox">
								<view class="formBox">
									<view class="formItem">
										<view class="left">
											<text class="require">*</text>
											<text>姓名</text>
										</view>
										<input
											class="user-input"  
											maxlength="10" 
											type="text"
											placeholder="请输入"
											v-model="optionForm.userName"
										/>
									</view>
									<!-- <view class="formItem" >
										<view class="left">
											<text class="require">*</text>
											<text>证件类型</text>
										</view>
										<commonSelect
											:dataList="idTypesList"
											:visible="showIdType"
											:showValue="idTypeIdx"
											@confirm="changeIdTypeSelect"
											@close="showIdType=false"
											
										/>
									</view> -->
									<view class="formItem">
										<view class="left">
											<text class="require">*</text>
											<text>手机号</text>
										</view>
										<input
											class="user-input"  
											maxlength="11" 
											type="number"
											placeholder="请输入"
											v-model="optionForm.phone"
										/>
									</view>
									<view class="formItem">
										<view class="left">
											<text class="require">*</text>
											<text>邮箱</text>
										</view>
										<input
											class="user-input"  
											maxlength="30" 
											type="text"
											placeholder="请输入"
											v-model="optionForm.email"
										/>
									</view>
									<view class="formItem">
										<view class="left">
											<text class="require">*</text>
											<text>上传企微二维码</text>
											<view class="uploadTip">
												请保证图片的清晰度(400*400)
											</view>
										</view>
										<view class="iconBox" @click="uploadAvatar('qrCode')">
											<text  class="iconfont icon-zhaoxiangji"></text>
										</view>
									</view>
								</view>
							</view>
						</view>
						
					</view>
					
				</view>
					
			</view>
			<view class="imageBox" v-if="optionForm.qwQrcode" >
				<text>上传的二维码如下：</text>
				<view class="imageCon">
					<image :src="optionForm.qwQrcode" mode="widthFix" ></image>
				</view>
				
			</view>
		</view>
		
		<view class="cardBtn">
			<view class="" @click="applyCard()">
				申请名片
			</view>
		</view>
	</view>
</template>

<script>
	import api from "@/api/api";
	import ListItem from '@/components/listItem/listItem.vue'
	import commonSelect from '@/components/commonSelect/commonSelect.vue';
	import common from '../../common/common';
	import {
		CommonUpload
	} from '@/util/uploaderFile';
	export default{
		name:'businessCard',
		components:{
			ListItem,
			commonSelect
		},
		data(){
			return{
				 companyLogo : '../../static/suplogo.png',
				 itemList:[
					 {leftText:'头像',rightImage:'../../static/suplogo.png',id:'1',},
					 {leftText:'姓名',rightText:'豆丝店',id:'2'},
				 ],
				 infoList:[
					 {name:'135 6477 5722',icon:'icon-dianhua',id:'1'},
					 {name:'yangww@homelegal.cn',icon:'icon-xinfeng',id:'2'},
					 {name:'上海市浦东新区陆家嘴软件园6号楼',icon:'icon-dingwei',id:'3'},
				 ],
				 items: ["关于我们", "企业荣誉", "关注官微"],
				 current: 0,
				 systemInfo:{},
				 codeImage:'../../static/suplogo.png',
				 dataForm: {
				 	loginId: uni.getStorageSync('cffp_userId'),
				 	targetType: "7",
				 	targetId: '',
				 	targetNo: "",
				 	targetUseFor: "14",
				 	targetSeq: "0"
				 }, 
				optionForm: {
					avatarUrl:'',
					userName:'',
					phone:'',
					email:'',
					qwQrcode:'',
					userId:uni.getStorageSync('cffp_userId')
				},
				idTypesList:[]
			}
		},
		
		 onLoad() {
		   this.systemInfo = uni.getSystemInfoSync();
		   const { platform, deviceType, screenWidth, screenHeight } = this.systemInfo;
		   // console.log('this.systemInfo',this.systemInfo)
		   // console.log('platform',platform)
		   //  console.log('deviceType',deviceType)
		 },
		methods:{
			uploadAvatar(upType) {
				let that = this;
				if(upType=='avatar'){
					that.dataForm.targetUseFor = '2'
				}else if(upType=='qrCode') {
					 that.dataForm.targetUseFor = '14'
				}
				CommonUpload(that.dataForm).then(res => {
					if(upType=='avatar'){
						this.optionForm.avatarUrl = res.data.filePath
					}else if(upType=='qrCode') {
						this.optionForm.qwQrcode = res.data.filePath
					}
					
				})
			},
			 handleItemClick(type) {
			      console.log('点击了:', type)
			      // 根据类型跳转不同页面或执行不同操作
			 },
			 goBack() {
			 	let back = getCurrentPages();
			 	if (back && back.length > 1) {
			 		uni.navigateBack({
			 			delta: 1
			 		});
			 	} 
			 },
			 // 提交申请名片
			applyCard(){
				let obj = {
					avatarUrl:'头像',
					userName:'姓名',
					phone:'手机号',
					email:'邮箱',
					qwQrcode:'企微二维码',
				}
				for (var key1 in this.optionForm) {
					for (var key2 in obj) {
						if(key1==key2&&!this.optionForm[key1]){
								uni.showModal({
								  title: '提示',
								  content: `${obj[key2]}不能为空`,
								  showCancel: false,
								  confirmText: '我知道了'
								});
								return
						}
					}
				}
				if(!common.phoneValid(this.optionForm.phone)){
					uni.showModal({
					  title: '提示',
					  content: `请输入正确的手机号`,
					  showCancel: false,
					  confirmText: '我知道了'
					});
					return
				}
				if(!common.emailValid(this.optionForm.email)){
					uni.showModal({
					  title: '提示',
					  content: `请输入正确的邮箱`,
					  showCancel: false,
					  confirmText: '我知道了'
					});
					return
				}
				api.saveApplyCard(
					this.optionForm
				).then(res =>{
					if(res['success']){
						uni.showModal({
							title: '提交成功',
							content: '您的名片正在审核中...',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.navigateBack({
										delta: 1
									});
								} 
							}
						});
					}else {
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'					
						})
					}
				})
			}
			
		},
		
		
	}
</script>

<style lang="scss" scoped>
	.container{
		position: relative;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		width: 100%;
		height: auto;
		box-sizing: border-box;
		padding: 20rpx;
		
		.cardHeader{
			box-sizing: border-box;
			width: 100%;
			.headerTitle{
				font-size: 35rpx;
				color: #333333;
			}
			.custom-right{
				.avatar{
					flex-grow: 0;
					width: 70rpx;
					height: 70rpx;
					border-radius: 50%;
					overflow: hidden;
					margin-right: 15rpx;
					/* 背景图设置 */
					  background-size: cover;
					  background-position: center;
					  background-repeat: no-repeat;
					/* 添加以下属性强制硬件加速 */
					transform: translateZ(0);
					-webkit-transform: translateZ(0);
					backface-visibility: hidden;
					-webkit-backface-visibility: hidden;
					image{
						width: 100%;
						height: 100%;
						object-fit: cover;
						/* 同样为图片添加硬件加速 */
						transform: translateZ(0);
						-webkit-transform: translateZ(0);
						border-radius: none !important;
					}
										}
			}
			
		}
		.userHeader{
			position: relative;
			height: 250rpx;
			width: 100%;
			box-sizing: border-box;
			.headerBox{
				// margin-top: -20rpx;
				// margin-left: 100rpx;
				position: absolute;
				bottom: 15%;
				left: 50%;
				transform: translateX(-50%);
				z-index: 99;
				.add{
					width: 50rpx;
					height: 50rpx;
					position: absolute;
					bottom: 2%;
					right: 3%;
					background-color: #20269B;
					z-index: 2;
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 8rpx;
					border-radius: 50%;
					box-sizing: border-box;
					.icon-jiahao{
						font-size: 28rpx;
						color: #fff;
					}
				}
				.avartBox{
				    width: 200rpx;
				    height: 200rpx;
				    border-radius: 50%;
					border: 10rpx solid #fff;
				    box-sizing: border-box;
				    box-shadow: 0 0 30rpx 15rpx rgba(150, 150, 150, 0.1);
				    position: relative;
					/* 添加以下属性强制硬件加速 */
					transform: translateZ(0);
					-webkit-transform: translateZ(0);
					backface-visibility: hidden;
					-webkit-backface-visibility: hidden;
					overflow: hidden;
					.avartTip{
						font-size: 22rpx;
						position: absolute;
						top: 38%;
						left: 50%;
						transform: translateX(-50%);
					}
				    image{
				        display: block; /* 确保图片是块级元素 */
				        width: 100%;    /* 宽度填满容器 */
				        height: 100%;   /* 高度填满容器 */
				        // border-radius: 50%; /* 保持圆形 */
				        object-fit: cover; /* 防止图片变形（可选） */
						/* 同样为图片添加硬件加速 */
						transform: translateZ(0);
						-webkit-transform: translateZ(0);
				    }
				}
			}
			
		}
		.userInformation {
		    position: relative;
		    flex: 1;
			width: 100%;
			display: flex;
			flex-direction: column;
		    .wave {
		        box-sizing: border-box;
		        min-width: 100%;
		        height: 120rpx;
				position: relative;
		        padding: 0;
		        border: none;
				box-shadow: 0 0 30rpx 100rpx rgba(253, 248, 245, 0.4);
		        image {
					position: absolute;
					top: -80%;
		            display: block;
		            min-width: 100%;
		            height: 100%;
		            object-fit: fill; /* 或 cover/contain 根据需求调整 */
		        }
				.nickNameBox{
					color: #333;
					box-sizing: border-box;
					width: 100%;
					position: absolute;
					top: -10%;
					left: 0;
					z-index: 88;
					padding: 0rpx 30rpx 20rpx 30rpx;
					font-size: 30rpx;
					.box{
						border-bottom: 1rpx solid #E4E4E4;
						padding-bottom: 20rpx;
					}
				}
		    }
			.shimingBox{
				padding: 30rpx;
				background-color: #fff;
				color: #333;
				position: relative;
				.itemBox{
					z-index: 100;
					margin-bottom: 20rpx;
					font-size: 28rpx;
					.title{
						font-size: 32rpx;
						font-weight: 600;
						color: block;
					}
					.subTit{
						color: #666666;
						font-size: 24rpx;
						display: flex;
						align-items: center;
						padding-bottom: 10rpx;
						border-bottom: 1rpx solid #EFEFEF;
						margin-top: 10rpx;
						
						.icon-circleDuiHao{
							font-size: 26rpx;
							color: #666666;
							margin-right: 5rpx;
						}
					}
					.tips{
						color: #F43530;
						margin: 15rpx 0;
					}
					.formBox{
						.formItem{
							display: flex;
							align-items: center;
							justify-content: space-between;
							border-bottom: 1rpx solid #E8E8E8;
							height: 100rpx;
							position: relative;
							.left{
								font-size: 26rpx;
							}
							.require{
								color: #F43530;
							}
							.user-input{
								color: black;
								font-size: 26rpx;
								text-align: right;
								padding-right: 20rpx;
								width: 70%;
							}
							.iconBox{
								padding: 20rpx;
								background-color: #F2F2F2;
								display: flex;
								align-items: center;
								justify-content: center;
									.icon-zhaoxiangji{
										font-size: 40rpx;
										color:  #ccc;
									}
							}
							.uploadTip{
								color: #A3A3A3;
								font-size: 24rpx;
							}
							
						}
					}
				}
			}
			
		}
		.upBox{
			margin-top: 20rpx;
			box-sizing: border-box;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.upTitle{
				color: #6C6A66;
				font-size: 28rpx;
			}
			.upDes{
				color: #A3A3A3;
				font-size: 25rpx;
			}
			.iconBox{
				padding: 20rpx;
				background-color: #F2F2F2;
				display: flex;
				align-items: center;
				justify-content: center;
					.icon-zhaoxiangji{
						font-size: 40rpx;
						color:  #ccc;
					}
				}
		}
		.imageBox{
			width: 100%;
			box-sizing: border-box;
			padding-left: 30rpx;
			.imageCon{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					width: 400rpx !important;
				}
			}
			
		}
		.cardBtn{
			width: 100%;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: center;
			view{
				background-color: #3639A9;
				font-size: 30rpx;
				color: #fff;
				text-align: center;
				width: 80%;
				padding: 20rpx 0;
				border-radius: 50rpx;
			}
		}
		
	}
	
	
</style>
