<template>
	<view class="container avstarBack">
		<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" placeholder="请输入企业名称">
							</u-input>
						</u-form-item>
						<u-form-item prop="companyAbbreviation">
							<view class="redCircle"></view>
							<text class="itemText">企业简称</text>
							<u-input class="inputStyle" v-model="form.companyAbbreviation" placeholder="请输入企业简称">
							</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" 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="buttonStyle mt33 commonMb buttonLang">确认修改</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		editCompanyInfo,
		getCompanyDetail
	} from "@/api/company/company.js"
	export default {
		data() {
			return {
				form: {
					companyName: null,
					companyAbbreviation: null,
					companyCode: null,
					legalPerson: null,
					phoneNumber: null
				},
				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']
					}, ]
				},
				// 企业id
				id: null
			}
		},
		methods: {
			submit() {
				this.$refs.formRef.validate().then(async res => {
					const result = await editCompanyInfo(this.form)
					console.log('修改成功', result);
					this.$tab.navigateBack()
				}).catch(errors => {
					console.log(errors, 'errors');
				})
			},
			// 获取当前企业详情
			async getDetail(id) {
				const res = await getCompanyDetail(id)
				console.log('详情', res);
				this.form = res.data
			}
		},
		onLoad() {
			this.id = this.$store.state.user.companyId
			this.getDetail(this.id)
		}
	}
</script>

<style scoped lang="scss">
	.avstarBack {
		background-image: url(@/static/images/editInfo/editInfo.png);
	}

	.relative {
		position: relative;
	}

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

	.choose-line-bottom {
		overflow: hidden;
		padding: 41rpx 35rpx;
		box-sizing: border-box;

		.small-box-middle {
			position: relative;
			margin-bottom: 27rpx;

			border: 1rpx solid #EBEBEB;
			border-radius: 20rpx;
			padding: 28rpx;
			box-sizing: border-box;

			.small-box-middle-startAndEnd {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-weight: bold;

				uni-text {
					margin-left: 22rpx;
				}
			}

			.small-box-middle-line {
				display: flex;
				justify-content: start;
				align-items: center;
				margin-left: 11rpx;

				.small-box-middle-line-left {
					width: 2rpx;
					height: 26rpx;
					background: #eeeeee;
					border-radius: 1rpx;
					margin: 6rpx 7rpx;
				}

				.small-box-middle-line-right {
					width: 439rpx;
					height: 1rpx;
					background: #eeeeee;
					margin-left: 15rpx;
				}
			}
		}
	}

	.mt33 {
		margin-top: 33rpx;
	}
</style>
