<template>
	<view class="center">
		<u-form>
			<view class="modular">
				<u-form-item label="公司名称" label-width="30%" class="title Medium" :border-bottom="topBorder">
					<view style='width:100%;text-align:right;margin-right:10px;'>{{deptList.compName}}</view>
				</u-form-item>
			</view>
			<view style='padding-bottom:10px;' class="modular">
				<view class="title Medium">企业概况</view>
				<!-- <u-input v-model="value" :type="type"  :height="height" :auto-height="autoHeight" placeholder="请输入企业概况，如经营项目、产品类型、企业规模等，不超过300个字" /> -->
				<textarea value="" placeholder="请输入企业概况，如经营项目、产品类型、企业规模等，不超过300个字" class="areaText Regular"
					v-model="deptList.companyContant" placeholder-style="color:#AFB3BF"/>
				<view class="title Regular">添加标签（标签应突出企业特色，最多6个）</view>
				<view style='flex-wrap:wrap;width: 100%;' class="flex ">
					<view class="forLists" v-for="(item,index) in label" :Key="index">
						<u-tag :text="item" mode="dark" class="forList Medium" shape="circle" :show="show"
							:closeable="closeable" color="#22C572" @close="closeForList(index)" />
					</view>
					
				</view>
				<u-tag v-if='label.length<6' text="+" mode="plain" shape="circle" :show="show1" color="#2E2E2D" bg-color="#FFFFFF"
						border-color="#F9F9FA" class="add" @click="add"></u-tag>
				<view class="addinput addlabel flex" v-if="inputShow">
					<u-input class='label' v-model="value" type="type" border focus v-if="inputShow"
					 placeholder="请输入标签内容，不超过6个字" />
					<u-button :type="types" class="inputOk" :class="{active:value.length>0}" shape="circle" @click="addinput">确定</u-button>
				</view>
			</view>
			<view style='padding-bottom:10px;' class="modular">
				<view class="title Regular">场地照片（图片清晰，最多9张）</view>
				<upload class="upload" ref="upload" :action="action" :max-count="9"
					:size-type="['compressed']" @on-success="getImgUrl" @on-remove="onRemove"
					@on-uploaded="isAdd = true" ></upload>
			</view>
			<view  style='padding-bottom:10px;' class="modular">
				<view class="title Medium">联系方式</view>
				<view v-for="(item,index) in Persons">
					<view class="information flex">
						<view class="xinxi">
							<u-form-item label="姓名" label-width="30%" class="Regular" label-position="top"
								style="font-size: 28rpx; color: #71747C;" :border-bottom="topBorder">
								<u-input v-model="item.contacts" class="Regular" placeholder="请输入姓名" />
							</u-form-item>
						</view>
						<view class="xinxi">
							<u-form-item label="电话" label-width="30%" class="Regular" label-position="top"
								style="font-size: 28rpx; color: #71747C;" :border-bottom="topBorder">
								<u-input maxlength="15" type="digit" v-model="item.contactsPhone" class="Regular" placeholder="请输入电话" />
							</u-form-item>
						</view>
						<div class="del" @click="delPerson(index)">
							<span style="font-size: 46rpx; color: #22C572;">×</span>
						</div>
					</view>
				</view>
				<view class="addPerson" @click="addPerson">
					<image src="../../static/img/liangmai/jia@3x.png" mode=""
						style="width: 26rpx;height: 26rpx;top: 2rpx;"></image>
					添加联系人
				</view>
			</view>
			<view class="modular">
				<u-form-item label="邮箱" label-width="30%" class="title Regular">
					<u-input v-model="deptList.email" input-align="right" class="write Regular" placeholder="请输入电子邮箱" />
				</u-form-item>
				<u-form-item label="传真" label-width="30%" class="title Regular" :border-bottom="topBorder">
					<u-input v-model="deptList.fax" input-align="right" class="write Regular" placeholder="请输入传真号" />
				</u-form-item>
			</view>
		</u-form>
		<u-button type="success" shape="circle" style="margin-top: 20rpx;" @click="submit">提交</u-button>
	</view>
</template>

<script>
	import upload from '@/components/upload.vue';
	export default {
	   components: {
	   	upload
	   },
		data() {
			return {
				deptList: {},
				label: [],
				closeable: true,
				show: true,
				show1: true,
				types: "",
				inputShow: false,
				value: "", //临时标签内容字段 后期更换
				action: 'https://www.zthymaoyi.com/upload/admin',
				fileList: [],
				imgList: [],
				Persons: [{contacts:'',contactsPhone:''}],
				topBorder: false,
			}
		},
		onLoad(options) {
			if(options.deptList){
				this.deptList=JSON.parse(options.deptList)
				console.log(this.deptList)
			}
		},
		computed: {
			// buttonshow(){
			// 	if(!this.deptList.companyContant&&this.label.length==0&&this.imgList.length==0&&!this.deptList.email&&!this.deptList.fax){
			// 		return false
			// 	}else{
			// 		return true
			// 	}
			// }
		},
		methods: {
			add() {
				if (this.label.length >= 6) {
					this.inputShow = false
				} else {
					this.inputShow = true
				}
			},
			getImgUrl(res) {
				console.log(res)
				this.imgList.push(res);
			},
			addinput() {
				if (!this.value) {
					this.$api.msg('标签内容不能为空')
					return
				}
				if (this.value.length < 2 || this.value.length > 6) {
					this.$api.msg('标签内容输入有误')
					return
				}
				this.label.push(this.value)
				this.value = ""
				this.inputShow = false
			},
			addPerson() {
				this.Persons.push({
					name: "",
					phone: "",
				})
			},
			delPerson(index) {
				this.Persons.splice(index, 1)
			},
			closeForList(index) {
				this.label.splice(index, 1)
			},
			onRemove(e) {
				this.imgList.splice(e, 1)
			},
			uploadSuccess(e) {
				this.imgList.push(e.url)
			},
			submit() {
				
				// let re = /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;
				// if(this.buttonshow){
				// }
				
				var that=this
				for(var i=0;i<this.Persons.length;i++){
					if(this.Persons[i].contacts.length<2||this.Persons[i].contacts.length>10){
						this.$api.msg('联系人姓名2-10个字')
						return
					}
					if(this.Persons[i].contactsPhone.length<2||this.Persons[i].contactsPhone.length>15){
						this.$api.msg('联系人电话7-15位数字')
						return
					}
				}
				// if(!re.test(this.deptList.email)){
				// 	this.$api.msg('邮箱输入错误')
				// 	return
				// }
				// if(this.deptList.fax.length<6||this.deptList.fax.length>20){
				// 	this.$api.msg('传真输入错误')
				// 	return
				// }
				this.deptList.label=this.label.toString()
				this.deptList.sitePhotoAddress=this.imgList.toString()
				this.deptList.settledCompanyContacts=this.Persons
				uni.showModal({
					content: "详细的企业信息有助于客户了解您的企业，是否确定提交？",
					showCancel: true,
					confirmText: '提交',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title:"正在提交"
							})
							that.$api.doRequest('post', '/settledCompanyInfo/api/editSettledCompanyInfo', that.deptList).then(res => {
								if (res.data.code == 200) {
									var data={
										compName:'',
										title:'',
										mainBusinessType:'',
										companyProfile:'',
									}
									that.$store.commit('enterchange',data)
									uni.navigateBack({
										delta:2
									})
								}else{
									this.$api.msg(res.data.message)
								}
								uni.hideLoading()
							})
							.catch(res => {
								console.log("系统异常",res)
								uni.hideLoading()
								uni.showToast({
									title: "系统异常，请联系管理员",
									icon: 'none',
									duration: 2000
								})
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.center {
		padding: 10rpx 20rpx;
	}
.label{
	padding-right:30px;
	border:none;
}
	.title {
		margin-left: 20rpx;
		color: #333333;
		line-height: 70rpx;
	}

	.write {
		margin-right: 20px;
		color: #71747C;
	}

	.modular {
		background-color: #FFFFFF;
		border-radius: 12px;
		margin-top: 10px;
	}

	.areaText {
		width: 83%;
		padding: 30rpx;
		border: 2rpx solid #F9F9FA;
		background-color: #F9F9FA;
		margin: 10rpx auto 20rpx;
		border-radius: 20rpx;
		color: #AFB3BF;
		font-size: 28rpx;
	}

	.add {
		padding: 15rpx 30rpx;
		width: 120rpx;
		height: 65rpx;
		text-align: center;
		margin-left: 24rpx;
		font-size: 30rpx;
		font-weight: 600;
		margin-bottom: 10rpx;
		border:1px solid #DCDDDC;
	}

	.forLists {
		margin-bottom: 10rpx;
	}

	.forList {
		height: 64rpx;
		background-color: #F4FAF8;
		padding: 20rpx 30rpx;
		color: #22C572;
		margin-left: 24rpx;
		text-align: center;
	}

	.addinput {
		width: 70%;
		margin: 20rpx auto;
		border-radius: 50rpx;
	}
.addlabel{
	background:#F6F6F6;
	position:relative;
	border-radius: 50rpx;height: 70rpx;font-size: 10px;
	padding-right:40px;
	line-height: 52rpx;
	margin-bottom:10px;
}
.inputOk.active{
	background:#22C572;
}
	.inputOk {
		width: 100rpx;
		border-radius: 40rpx;
		background-color: #E9EAE9;
		color: #FFFFFF;
		height:70rpx;
		border: none;
		position:absolute;
		right:0;
	}
	.picture {
		width: 144rpx;
		height: 144rpx;
		border: 4rpx dashed #AFB3BF;
	}

	.upload {
		text-align: center;
		margin: 0px 0;
		margin-bottom: 10px;
	}

	.addPerson {
		width: 230rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border: 2rpx solid #979797;
		border-radius: 40rpx;
		margin: 20rpx auto 20rpx;
	}

	.information {
		background-color: #F4FAF8;
		width: 96%;
		height: 180rpx;
		margin: 0 auto;
		border: 1rpx dashed #22C572;
		border-radius: 10rpx;
		margin-top: 30rpx;
	}

	.xinxi {
		margin-left: 70rpx;
	}

	.del {
		justify-content: flex-end;
		margin: 10rpx 20rpx 0 0;
	}
</style>
