<template>
	<view class="container avstarBack relative">
		<uni-navbar title="忘记账号"></uni-navbar>
		<view class="box commonMt relative">
			<view class="absolute">
				<view class="choose-line-bottom commonBj ">
					<u--form :model="form" ref="formRef" :rules="rules" labelWidth="0" class="formStyle">
						<u-form-item prop="companyName" ref="form1">
							<view class="redCircle"></view>
							<text class="itemText">企业名称</text>
							<u-input class="inputStyle" v-model="form.companyName" maxlength="30" placeholder="请输入企业名称">
							</u-input>
						</u-form-item>
						<u-form-item prop="companyAbbreviation">
							<view class="redCircle"></view>
							<text class="itemText">企业简称</text>
							<u-input maxlength="4" class="inputStyle" v-model="form.companyAbbreviation"
								placeholder="请输入企业简称 长度小于等于4">
							</u-input>
						</u-form-item>
						<u-form-item prop="companyCode">
							<view class="redCircle"></view>
							<text class="itemText">信用代码</text>
							<u-input class="inputStyle" v-model="form.companyCode" placeholder="请输入信用代码">
							</u-input>
						</u-form-item>
						<u-form-item prop="legalPerson">
							<view class="redCircle"></view>
							<text class="itemText">企业法人</text>
							<u-input class="inputStyle" v-model="form.legalPerson" maxlength="20"
								placeholder="请输入企业法人姓名" />
						</u-form-item>
						<u-form-item prop="phoneNumber">
							<view class="redCircle"></view>
							<text class="itemText">联系电话</text>
							<u-input class="inputStyle" v-model="form.phoneNumber" placeholder="请输入联系电话" />
						</u-form-item>
					</u--form>
				</view>
				<u-button @click="submit" shape="circle" color="linear-gradient(to top, #F59A02, #FFD334 )"
					class="custom-style mt33 commonMb buttonLang">确认</u-button>
			</view>
		</view>

		<tooltipNew :show="isSuccess" type='type4' @close='close' :username='username'></tooltipNew>
	</view>
</template>

<script>
	import {
		getUserName
	} from "@/api/login.js"
	export default {
		data() {
			return {
				username: '',
				// 查询成功过后的弹出框
				isSuccess: false,
				form: {
					companyName: '',
					companyAbbreviation: '',
					companyCode: '',
					legalPerson: '',
					phoneNumber: ''
				},
				rules: {
					companyName: [{
						required: true,
						message: '请输入企业名称',
						trigger: ['blur', 'change']
					}, ],
					companyAbbreviation: [{
						required: true,
						message: '请输入企业简称',
						trigger: ['blur', 'change']
					}, ],
					companyCode: [{
						required: true,
						message: '请输入18位企业统一信用代码',
						validator: (rule, value, callback) => {

							if (value.length === 18) {
								return true;
							} else {
								return false;
							}

						},
						trigger: ['blur', 'change']
					}, ],
					legalPerson: [{
						required: true,
						message: '请输入企业法人姓名',
						trigger: ['blur', 'change']
					}, ],
					phoneNumber: [{
						required: true,
						message: '请输入联系电话',
						trigger: ['blur', 'change']
					}, {
						// 自定义验证函数
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// uni.$u.test.mobile()就是返回true或者false的
							return uni.$u.test.mobile(value);
						},
						message: '手机号码不正确',
						// 触发器可以同时用blur和change
						trigger: ['blur'],
					}]
				}
			}
		},
		methods: {
			close() {
				this.isSuccess = false;
			},
			submit() {
				this.$refs.formRef.validate().then(res => {
					getUserName(this.form).then(res => {
						// console.log(res);
						// uni.reLaunch({
						// 	url: '/pages/login/index'
						// })
						this.username = res.data
						this.isSuccess = true
					})
				}).catch(errors => {
					console.log(errors, 'errors');
					// uni.$u.toast('校验失败')
				})

			},

		}
	}
</script>

<style lang="scss" scoped>
	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
		bottom: 46rpx;
		width: 100%;
	}

	.avstarBack {
		background-image: url(@/static/images/editInfo/forgetUsername.png);
	}

	.choose-line-bottom {
		padding: 41rpx 35rpx;
	}

	.mt33 {
		margin-top: 33rpx;
	}

	.mt {
		margin-top: 26rpx;
	}
</style>
