<template>
	<view>
		<view v-if="member!=2">
			<view class="name">
				<text class="text">名称</text>
				<u-input v-model="submitForm.real_name" placeholder="请输入姓名" placeholder-class="input-class" border="bottom"
					color="#A0A0A0" :disabled="disabled" disabledColor="#ffffff"></u-input>
			</view>
			<view class="id">
				<text class="text">身份证号</text>
				<u-input v-model="submitForm.idcard" placeholder="请输入身份证号码" placeholder-class="input-class" border="bottom"
					color="#A0A0A0" :disabled="disabled" disabledColor="#ffffff"></u-input>
			</view>
		</view>
		<view v-if="member==2" class="hhr">
			<image src="../../static/my/hz_bj.png" mode="aspectFit" style="width: 247rpx;height: 189rpx;"></image>
			<view class="hhr-text">已是合伙人</view>
		</view>
		<view class="submit-btn">
			<button v-if="member==2" open-type="contact" session-from="sessionFrom" class="service-btn">
				联系客服
			</button>
			<u-button v-else @click="submit" :color="color" :size="normal" shape="circle" class="submit-btn"
				:disabled="btnDisabled">{{btnText}}</u-button>
		</view>
		<u-modal :show="show" closeOnClickOverlay="false" confirmText="确定" @confirm="confirm">
			<rich-text :nodes="content"></rich-text>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				color: '#CC3333',
				btnText: '提交审核',
				member: '',
				show: false,
				disabled: false,
				btnDisabled: false,
				content: `申请已提交, 请等待后台审核`,
				submitForm: {
					real_name: '',
					idcard: ''
				}
			}
		},
		onShow() {
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$api.getUser().then(res => {
					var data = res.data.data
					if (data) {
						this.member = data.member
						if (data.member == 1) {
							this.disabled = true
							this.btnDisabled = true
							this.color = "#C6C6C6"
							this.btnText = "审核中…"
						}
						// else if (data.member == 2) {
						// 	this.disabled = false
						// 	this.btnDisabled = false
						// 	this.color = "#CC3333"
						// 	this.btnText = "联系客服"
						// }
					}
				})
			},
			confirm() {
				uni.reLaunch({
					url: '/pages/my/my'
				})
				// if (this.needAsk == 1) {
				// 	uni.reLaunch({
				// 		url: '/pages/index/index'
				// 	})
				// }
			},
			submit() {
				if (this.member == 0) {
					let reg =
						/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/; //正则表达式定义身份证号正确格式
					if (!reg.test(this.submitForm.idcard)) { //判断身份证号格式时候正确
						this.$toast.warn('请输入正确的身份证号格式')
						return false
					}
					if (this.submitForm.real_name == "") {
						this.$toast.warn('请完善数据')
						return false
					}
					if (this.submitForm.real_name && this.submitForm.idcard) {
						let data = {
							...this.submitForm,
							uid: uni.getStorageSync('uid')
						}
						console.log('成', data);
						this.$api.toBePartner(data).then(res => {
							if (res.data.msg == "提交成功") {
								this.show = true
							}
						})
					}
				} else if (this.member == 2) {
					console.log('联系客服');
				}
			}
		}
	}
</script>

<style lang="scss">
	.service-btn {
		height: 40px;
		background-color: #CC3333;
		color: #fff;
		border-radius: 25px;

		font-size: 32rpx;
	}

	.hhr {
		margin-top: 50rpx;
		margin-bottom: 50rpx;
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.hhr-text {
			margin-top: 28rpx;
			width: 186rpx;
			height: 50rpx;
			font-size: 36rpx;
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 800;
			color: #F20C0C;
			line-height: 50rpx;
			letter-spacing: 1px;
		}
	}

	.u-modal__button-group__wrapper--hover {
		background: #0EBB5B !important;
	}

	.input-class {
		font-weight: 1rpx;
		color: #A0A0A0;
	}

	.submit-btn {
		width: 80%;
		margin-top: 50rpx;
		translate: 10%;
	}

	.name,
	.id {
		padding: 10rpx;
	}

	.text {
		margin-left: 20rpx;
	}

	.payment {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;

	}

	.left-payment {
		display: flex;
		flex-direction: column;
	}

	.label {
		margin-top: 10rpx;
		margin-left: 17rpx;
		color: #c1c1c1;
		/* font-size: 27rpx; */
	}
</style>