<template>
	<Layout :index="-1" :banner="0"  :img="'/static/img/about.jpg'" :titles="'个人中心'" :title_content="'个人中心'">
		<view class="bg ptm-80">
			<view class="content d-b-c">
				<view class="content_left">
					<memberleft :index="'1'"></memberleft>
				</view>
				<view class="content_right">
					<view class="mtitle">
						<image src="../static/img/member/user.png" class="mimg"></image>
						用户信息
					</view>
					<view class="lines"></view>
					<view class="content_r">
						<view class="content_title">
							账号信息
						</view>
						<view class="content_all">
							<view class="content_all_l">
								登录账号：
							</view>
							<view class="content_phone">
								{{userInfo.mobile}}
							</view>
						</view>
						<view class="content_all">
							<view class="content_all_l">
								登录密码：
							</view>
							<view class="content_pass" @tap="forget()">
								重置
							</view>
						</view>
						<view class="content_titles" v-if="userInfo.company_code">
							认证信息
						</view>
						<view v-if="e_type==333&&!userInfo.company_code">
							
							<view class="content_all">
								<view class="content_all_l">
									姓名：
								</view>
								<view class="content_phone">
									{{userInfo.legal_person||'无'}}
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									手机号：
								</view>
								<view class="content_phone">
									{{userInfo.corporate_phone||'无'}}
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									身份证号：
								</view>
								<view class="content_phone">
									{{userInfo.corporate_idcard||'无'}}
								</view>
							</view>
							
							
							<view class="content_all">
								<view class="content_all_l">
									认证状态：
								</view>
								<view class="apply_status1" v-if="userInfo.apply_status==1">
									审核成功
								</view>
								<view class="apply_status2" v-if="userInfo.apply_status==2">
									审核失败
								</view>
								<view class="apply_status3" v-if="userInfo.apply_status==3">
									待审核
								</view>
							</view>
							<view class="content_all" v-if="userInfo.apply_status==2">
								<view class="content_all_l">
									认证失败原因：
								</view>
								<view class="apply_status2">
									{{userInfo.apply_remark}}
								</view>
							</view>
							
							<view class="uedit" @tap="etype(2)" v-if="userInfo.apply_status!=3&userInfo.third_auth_status==2">编辑</view>
							<view class="uedit" @tap="etype(2)" v-if="userInfo.apply_status!=3&userInfo.third_auth_status==1">编辑</view>
							<view class="uedit" @tap="etype(2)" v-if="userInfo.third_auth_status==0">实名认证</view>
							<view class="uedit uedits" v-if="userInfo.apply_status==3&userInfo.third_auth_status==2">编辑</view>
						</view>
						
						<view v-if="e_type==1&&userInfo.company_code">
							<view class="content_all">
								<view class="content_all_l">
									公司名称：
								</view>
								<view class="content_phone">
									{{userInfo.nickName||'无'}}
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									企业统一信用代码：
								</view>
								<view class="content_phone">
									{{userInfo.company_code||'无'}}
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									法人姓名：
								</view>
								<view class="content_phone">
									{{userInfo.legal_person||'无'}}
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									法人手机号：
								</view>
								<view class="content_phone">
									{{userInfo.corporate_phone||'无'}}
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									法人身份证号：
								</view>
								<view class="content_phone">
									{{userInfo.corporate_idcard||'无'}}
								</view>
							</view>
							<view class="content_all" v-if="userInfo.third_auth_status!=2">
								<view class="content_all_l">
									经办人姓名：
								</view>
								<view class="content_phone">
									{{userInfo.agent||'无'}}
								</view>
							</view>
							<view class="content_all" v-if="userInfo.third_auth_status!=2">
								<view class="content_all_l">
									经办人手机号：
								</view>
								<view class="content_phone">
									{{userInfo.mobile||'无'}}
								</view>
							</view>
							<view class="content_all" v-if="userInfo.third_auth_status!=2">
								<view class="content_all_l">
									经办人身份证号：
								</view>
								<view class="content_phone">
									{{userInfo.agent_idcard||'无'}}
								</view>
							</view>
							
							
							<view class="content_all" v-if="userInfo.third_auth_status!=2">
								<view class="content_all_l">
									第三方机构认证：
								</view>
								<view class="apply_status3" v-if="userInfo.third_auth_status==0">
									待认证
								</view>
								<view class="apply_status1" v-if="userInfo.third_auth_status==1">
									认证成功
								</view>
							</view>
							
							<view class="content_all">
								<view class="content_all_l">
									认证状态：
								</view>
								<view class="apply_status1" v-if="userInfo.apply_status==1">
									审核成功
								</view>
								<view class="apply_status2" v-if="userInfo.apply_status==2">
									审核失败
								</view>
								<view class="apply_status3" v-if="userInfo.apply_status==3">
									待审核
								</view>
							</view>
							<view class="content_all" v-if="userInfo.apply_status==2">
								<view class="content_all_l">
									认证失败原因：
								</view>
								<view class="apply_status2">
									{{userInfo.apply_remark}}
								</view>
							</view>
							
							<view class="uedit" @tap="etype(2)" v-if="userInfo.apply_status!=3&userInfo.third_auth_status==2">编辑</view>
							<view class="uedit" @tap="etype(2)" v-if="userInfo.apply_status!=3&userInfo.third_auth_status==1">编辑</view>
							<view class="uedit" @tap="etype(2)" v-if="userInfo.third_auth_status==0">实名认证</view>
							<view class="uedit uedits" v-if="userInfo.apply_status==3&userInfo.third_auth_status==2">编辑</view>
						</view>
						
						<view v-if="e_type==2&&userInfo.company_code">
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>公司名称：
								</view>
								<view class="content_com">
									 <input class="linput" v-model="formData.nickName" type="text" :placeholder="'请输入公司名称'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>企业统一信用代码：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.company_code" type="text" :placeholder="'请输入企业统一信用代码'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>法人姓名：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.legal_person" type="text" :placeholder="'请输入法人姓名'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>法人手机号：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.corporate_phone" type="text" :placeholder="'请输入法人手机号'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>法人身份证号：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.corporate_idcard" type="text" :placeholder="'请输入法人身份证号'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all" v-if="userInfo.third_auth_status!=2">
								<view class="content_all_l">  
									<text class="xing">*</text>经办人姓名：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.agent" type="text" :placeholder="'请输入经办人姓名'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all" v-if="userInfo.third_auth_status!=2">
								<view class="content_all_l">
									<text class="xing">*</text>经办人身份证号：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.agent_idcard" type="text" :placeholder="'请输入经办人身份证号'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							
							<!-- <view class="tips" v-if="userInfo.third_auth_status!=2">
								温馨提示：经办人姓名和身份证信息需与注册手机号实名信息一致
							</view> -->
						
							<view class="uedit" @tap="useredit()">保存</view>
						</view>
						
						<view v-if="e_type==333&&!userInfo.company_code">
							
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>姓名：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.legal_person" type="text" :placeholder="'请输入法人姓名'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>手机号：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.corporate_phone" type="text" :placeholder="'请输入法人手机号'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
							<view class="content_all">
								<view class="content_all_l">
									<text class="xing">*</text>身份证号：
								</view>
								<view class="content_com">
									<input class="linput" v-model="formData.corporate_idcard" type="text" :placeholder="'请输入法人身份证号'"  maxlength="50" placeholder-class="placeholder-class" >
								</view>
							</view>
						
							<view class="uedit" @tap="useredits()">保存</view>
						</view>
					</view>
					
				</view>
			</view>
			
		</view>
	</Layout>
</template>

<script>
	import Layout from './part/layouts.vue';
	import memberleft from './part/member_left.vue';
	export default {
		components:{
			Layout,
			memberleft
		},
		data(){
			return {
				page: 1,
				list_rows: 10,
				listData: [],
				total: 0,
				newData: [],
				formData: {
					
				},
				e_type: 1,
				userInfo:''
			}
		},
		created() {
			const width = window.innerWidth;
			const height = window.innerHeight;
			const mobileWidth = 768; // 可以根据需要调整这个值
			const isMobile = width <= mobileWidth || height <= mobileWidth;
			if(isMobile){
				this.list_rows = 30;
			}
			let obj = this.$Route.query;
			if(obj.hasOwnProperty('index')){
				this.category_id = Number(obj.index);
			}
			
		},
		onShow() {
			this.getuser();
		},
		
		methods:{
			etype(e){
				this.e_type=2;
				this.formData.nickName=this.userInfo.nickName;
				this.formData.legal_person=this.userInfo.legal_person;
				this.formData.corporate_phone= this.userInfo.corporate_phone;
				this.formData.corporate_idcard=this.userInfo.corporate_idcard;
				this.formData.company_code=this.userInfo.company_code;
				this.formData.agent=this.userInfo.agent;
				this.formData.agent_idcard=this.userInfo.agent_idcard;
			},
			forget(){
				uni.navigateTo({
				  url: '/forget'
				});
			},
			getuser(){
				this._get('user.user/detail',{},res=>{
					this.userInfo = res.data.userInfo;
					uni.setStorageSync('apply_status',this.userInfo.apply_status)
					uni.setStorageSync('third_auth_status',this.userInfo.third_auth_status)
					console.log(this.formData,222)
				}
				,err=>{
					uni.showToast({
						icon:'none',
						title: err.data.msg
					})
					return;
					// this.$message(err.data.msg);
				}
				);
			},
			useredit(){
				if(this.formData.nickName==''){
					uni.showToast({
						icon:'none',
						title: '请输入公司名称',
						duration:1500
					})
					return;
				}
				if(this.formData.legal_person==''){
					uni.showToast({
						icon:'none',
						title: '请输入法人姓名',
						duration:1500
					})
					return;
				}
				if(this.formData.corporate_phone==''){
					uni.showToast({
						icon:'none',
						title: '请输入法人手机号',
						duration:1500
					})
					return;
				}
				if(this.formData.corporate_idcard==''){
					uni.showToast({
						icon:'none',
						title: '请输入法人身份证号',
						duration:1500
					})
					return;
				}
				if(this.formData.company_code==''){
					uni.showToast({
						icon:'none',
						title: '请输入企业统一信用代码',
						duration:1500
					})
					return;
				}
				// this.formData.nickName=this.formData.nickName?this.formData.nickName:this.userInfo.nickName;
				// this.formData.legal_person=this.formData.legal_person?this.formData.legal_person:this.userInfo.legal_person;
				// this.formData.corporate_phone=this.formData.corporate_phone?this.formData.corporate_phone:this.userInfo.corporate_phone;
				// this.formData.corporate_idcard=this.formData.corporate_idcard?this.formData.corporate_idcard:this.userInfo.corporate_idcard;
				// this.formData.company_code=this.formData.company_code?this.formData.company_code:this.userInfo.company_code;
				// if(this.formData.nickName=="undefined"){
				// 	console.log(this.userInfo.nickName,333333)
				// 	this.formData.nickName=this.userInfo.nickName;
				// }
				// if(this.formData.legal_person=="undefined"){
				// 	this.formData.legal_person=this.userInfo.legal_person;
				// }
				// if(this.formData.corporate_phone=="undefined"){
				// 	this.formData.corporate_phone= this.userInfo.corporate_phone;
				// }
				// if(this.formData.corporate_idcard=="undefined"){
				// 	this.formData.corporate_idcard=this.userInfo.corporate_idcard;
				// }
				// if(this.formData.company_code=="undefined"){
				// 	this.formData.company_code=this.userInfo.company_code;
				// }
				// console.log(this.formData,333333);return;
				this._post('user.User/updateInfo',{
					nickName: this.formData.nickName,
					legal_person: this.formData.legal_person,
					corporate_phone: this.formData.corporate_phone,
					corporate_idcard: this.formData.corporate_idcard,
					company_code: this.formData.company_code,
					agent: this.formData.agent,
					agent_idcard: this.formData.agent_idcard,
					apply_status:3,
				},res=>{
					uni.showToast({
						icon:'none',
						title: '操作成功',
						duration:1500
					})
					setTimeout(() => {
					   uni.reLaunch({
					           url: '/pages/member' // 替换为你实际的首页路径
					       });
					}, 1500);
				}
				,err=>{
					uni.showToast({
						icon:'none',
						title: err.data.msg
					})
					return;
					// this.$message(err.data.msg);
				}
				);
			},
		useredits(){
			
			if(this.formData.legal_person==''){
				uni.showToast({
					icon:'none',
					title: '请输入姓名',
					duration:1500
				})
				return;
			}
			if(this.formData.corporate_phone==''){
				uni.showToast({
					icon:'none',
					title: '请输入手机号',
					duration:1500
				})
				return;
			}
			if(this.formData.corporate_idcard==''){
				uni.showToast({
					icon:'none',
					title: '请输入身份证号',
					duration:1500
				})
				return;
			}
			this._post('user.User/updateInfo',{
				nickName: this.formData.nickName,
				legal_person: this.formData.legal_person,
				corporate_phone: this.formData.corporate_phone,
				corporate_idcard: this.formData.corporate_idcard,
				apply_status:3,
			},res=>{
				uni.showToast({
					icon:'none',
					title: '操作成功',
					duration:1500
				})
				setTimeout(() => {
				   uni.reLaunch({
				           url: '/pages/member' // 替换为你实际的首页路径
				       });
				}, 1500);
			}
			,err=>{
				uni.showToast({
					icon:'none',
					title: err.data.msg
				})
				return;
				// this.$message(err.data.msg);
			}
			);
		},
		}
	}
</script>

<style lang="scss">
	.tips{
		margin-top: 12px;
		font-size: 14px;
		color: #fe0000;
		margin-left: 16px;
	}
	.bg{
		width: 100%;
		background: #F1F1F1;
		min-height: 800px;
	}
	.content{
		width: 1290px;
		margin: 0 auto;
		padding-top: 14px;
	}
	.content_left{
		width: 245px;
		min-height: 789px;
		background: #FFFFFF;
		box-shadow: 0px 4px 10px 0px rgba(78,89,105,0.06);
		border-radius: 0px 0px 0px 0px;
	}
	.content_right{
		width: 1024px;
		height: 789px;
		background: #FFFFFF;
		box-shadow: 0px 4px 10px 0px rgba(78,89,105,0.06);
		border-radius: 0px 0px 0px 0px;
	}
	.mtitle{
		font-weight: 500;
		font-size: 16px;
		color: #3D3D3D;
		width: 985px;
		margin:0 auto;
		height: 48px;
		line-height: 48px;
		display: flex;
		    align-items: center;
	}
	.lines{
		width: 985px;
		height: 0px;
		border: 1px solid #D8D8D8;
		opacity: 0.6;
		margin:0 auto;
	}
	.mimg{
		width: 20px;
		height: 20px;
		margin-right: 10px;
		margin-left: 23px;
	}
	.content_r{
		padding: 36px 71px;
	}
	.content_title{
		font-weight: 400;
		font-size: 16px;
		color: #767676;
	}
	.content_titles{
		font-weight: 400;
		font-size: 16px;
		color: #767676;
		margin-top: 40px;
	}
	.content_all{
		display: flex;
		margin-top: 16px;
		font-weight: 400;
		font-size: 14px;
		color: #3D3D3D;
		align-items: center;
	}
	.content_pass{
		width: 60px;
		height: 32px;
		background: #F78A30;
		border-radius: 6px 6px 6px 6px;
		text-align: center;
		line-height: 32px;
		font-weight: 500;
		font-size: 14px;
		color: #FFFFFF;
		cursor: pointer;
	}
	.content_phone{
		font-weight: 400;
		font-size: 14px;
		color: #767676;
	}
	.xing{
		color: #F53F3F;
		margin-right: 10px;
	}
	.uedit{
		width: 80px;
		height: 32px;
		background: #F78A30;
		border-radius: 6px 6px 6px 6px;
		text-align: center;
		line-height: 32px;
		color: #ffffff;
		margin-top: 20px;
		font-size: 14px;
		cursor: pointer;
	}
	.uedits{
		background: #dddddd;
	}
	.apply_status1{
		font-weight: 400;
		font-size: 14px;
		color: #20BC30;
	}
	.apply_status2{
		font-weight: 400;
		font-size: 14px;
		color: #F72929;
	}
	.apply_status3{
		font-weight: 400;
		font-size: 14px;
		color: #4886FF;
	}
	.content_com{
		width: 244px;
		height: 32px;
		background: #F2F3F5;
		border-radius: 2px 2px 2px 2px;
		display: flex;
		align-items: center;
		padding: 0 12px;
	}
	.placeholder-class{
		font-weight: 400;
		font-size: 14px;
		color: #767676;
	}
	.linput{
		font-size: 14px;
		color: #767676;
	}
	@media screen and (max-width: 768px) {
	
	}
</style>
