<template>
	<view class="page">
		<navbar title="企业信息"
		leftClick 
		@leftClick="$utils.navigateBack"/>
		
		<view class="box">
			<!-- <view class="list">
				<view class="item" 
				v-for="(item, index) in list" 
				:key="index">
					<view class="title">
						{{ item.title }}
					</view>
					<view class="tagList">
						<view :class="{act : i == item.index}" 
						@click="clickTag(item, i)" v-for="(t, i) in item.tag"
							:key="t.id">
							{{ t.name || t.adress }}
						</view>
					</view>
				</view>
			</view> -->
			
			
			<view class="form-sheet-cell">
				<view class="label">
					企业名称
				</view>
				
				<!-- <input placeholder="请输入企业名称"
				v-model="form.companyName" /> -->
				
				<view class="">
					{{ form.companyName }}
				</view>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					您的职位
				</view>
				<input placeholder="请输入您的职位" 
				v-model="detail.ahthenticationCompany.career" />
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					公司电话
				</view>
				<input placeholder="请输入公司电话" 
				v-model="form.phone" />
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					所属行业
				</view>
				<input placeholder="请输入所属行业" 
				v-model="form.industry" />
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					融资轮数
				</view>
				<input placeholder="请输入融资轮数" 
				v-model="form.financing" />
			</view>
			
			<!-- <view class="form-sheet-cell">
				<view class="label">
					您的性别
				</view>
				<uv-radio-group v-model="form.sex">
					<view style="display: flex;justify-content: center;">
						<uv-radio
							:customStyle="{margin: '8px'}" 
							v-for="(item, index) in sexList" 
							:key="index" 
							iconSize="30rpx"
							size="40rpx"
							labelSize="26rpx"
							:label="item.name" 
							:name="item.name">
						</uv-radio>
					</view>
				</uv-radio-group>
			</view> -->
			
			<view class="form-sheet-cell">
				<view class="label">
					企业人数
				</view>
				
				<uv-number-box v-model="form.number"/>
			</view>
			
			<view style="padding: 20rpx;">
				<view class="title">
					上传企业logo
				</view>
				
				<view class="images box">
					<uv-upload 
					:fileList="logoFileList" 
					:maxCount="1" 
					multiple 
					width="150rpx" 
					height="150rpx"
					name="logoFileList"
					@delete="deleteImage"
					@afterRead="afterRead"
					:previewFullImage="true"></uv-upload>
				</view>
			</view>
			
			<view style="padding: 20rpx;">
				<view class="title">
					上传企业背景图片
				</view>
				
				<view class="images box">
					<uv-upload 
					:fileList="imageBackgroundFileList" 
					:maxCount="1" 
					multiple 
					width="150rpx" 
					height="150rpx"
					name="imageBackgroundFileList"
					@delete="deleteImage"
					@afterRead="afterRead"
					:previewFullImage="true"></uv-upload>
				</view>
			</view>
			
			<view style="padding: 20rpx;">
				<view class="title">
					上传企业照片
				</view>
				
				<view class="images box">
					<uv-upload 
					:fileList="imageFileList" 
					:maxCount="9" 
					multiple 
					width="150rpx" 
					height="150rpx"
					name="imageFileList"
					@delete="deleteImage"
					@afterRead="afterRead"
					:previewFullImage="true"></uv-upload>
				</view>
			</view>
			
			
			<!-- <uv-textarea
			v-model="form.brief" 
			count 
			:maxlength="300" 
			autoHeight
			placeholder="请输入个人介绍"></uv-textarea> -->
			
			
			<view class="uni-color-btn"
			@click="submit">
				保存
			</view>
		</view>
		
		<uv-picker ref="picker"
		:columns="columns" 
		@confirm="pickerConfirm"></uv-picker>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				list: [
					{
						title: '您希望从事的工种',
						tag: [],
						index: 0,
						type : 'typeId',
						
					},
					{
						title: '您希望从事工作的地区',
						tag: [],
						index: 0,
						type : 'expectAddress',
					},
					{
						title: '您希望从事工作的性质',
						tag: [],
						index: 0,
						type : 'natureId',
					},
				],
				form : {
					companyName : '',
					industry : '',
					address: "",
					financing: "",
					image: "",
					legalPerson: "",
					license: "",
					logo: "",
					number: 1,
					phone: "",
					socialCode: "",
				},
				sexList : [
					{
						name : '男',
					},
					{
						name : '女',
					},
				],
				picker : {
					qualification : [
						'初中',
						'高中',
						'专科',
						'本科',
						'研究生',
						'博士',
					],
				},
				pickerKey : 'workAge',
				detail : {
					ahthenticationCompany : {
						career : ''
					},
				},
				logoFileList : [],//logo
				imageFileList : [],//企业图片
				imageBackgroundFileList : [],//背景图片
			}
		},
		computed : {
			...mapState(['natureList', 'jobTypeList', 'addressList']),
			columns(){
				return [this.picker[this.pickerKey]]
			},
		},
		onLoad() {
			this.list[0].tag = this.jobTypeList
			this.list[1].tag = this.addressList
			this.list[2].tag = this.natureList
			
			this.getDataByUserId()
		},
		methods: {
			clickTag(item, index){
				item.index = index
			},
			openPicker(key, picker){
				this.pickerKey = key
				if(picker){
					picker.open()
				}else{
					this.$refs.picker.open()
				}
			},
			pickerConfirm(e){
				console.log(e);
				let data = e.value[0]
				if(data && data.id){
					this.form[this.pickerKey] = data.id
					this.form[this.pickerKey + '_dictText'] = data.name || data.adress
				}else{
					this.form[this.pickerKey] = data
				}
			},
			// 提交
			submit(){
				
				// if(this.fileList.length == 0){
				// 	return uni.showToast({
				// 		title: '请上传图片',
				// 		icon : 'none'
				// 	})
				// }
				
				
				this.form.image = this.imageFileList.map(n => n.url).join(',')
				this.form.logo = this.logoFileList.map(n => n.url).join()
				this.form.imageBackground = this.imageBackgroundFileList.map(n => n.url).join(',')
				
				if (this.$utils.verificationAll(this.form, {
						companyName : '请输入企业名称',
						industry : '请输入所属行业',
						// financing: "",
						// image: "",
						// legalPerson: "",
						// license: "",
						logo: "请上传企业logo",
						// number: "",
						// phone: "",
						// socialCode: "",
					})) {
					return
				}
				
				this.$api('updateCompany', this.form, res => {
					if(res.code == 200){
						uni.showToast({
							title: '保存成功!',
							icon: 'none'
						})
						
						setTimeout(uni.navigateBack, 1000, -1)
					}
				})
				
				this.$api('addAuthenticationCompany', {
					id : this.detail.ahthenticationCompany.id,
					career : this.detail.ahthenticationCompany.career,
				}, res =>{
					if(res.code == 200){
					}
				})
			},
			getDataByUserId(){
				this.$api('getDataByUserId', {
					userId : this.userInfo.id,
				}, res => {
					if(res.code == 200){
						this.detail = res.result
						this.form = res.result.company
						
						delete this.form.createBy
						delete this.form.createTime
						delete this.form.updateBy
						delete this.form.updateTime
						
						this.imageFileList = this.form.image ? this.form.image.split(',').map(url => {
							return {
								url
							}
						}) : []
						
						this.logoFileList = this.form.logo ? this.form.logo.split(',').map(url => {
							return {
								url
							}
						}) : []
						
						this.imageBackgroundFileList = this.form.imageBackground ? this.form.imageBackground.split(',').map(url => {
							return {
								url
							}
						}) : []
					}
				})
			},
			deleteImage(e){
				this[e.name].splice(e.index, 1)
			},
			afterRead(e){
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self[e.name].push({
							url
						})
					})
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.page{
		background-color: #fff;
		min-height: 100vh;
		.box{
			padding: 30rpx;
			.list {
				.item {
					margin-top: 20rpx;
			
					.title {
						// font-weight: 900;
						font-size: 30rpx;
					}
			
					.tagList {
						display: flex;
						flex-wrap: wrap;
						padding: 10rpx 0;
			
						view {
							background: rgba($uni-color, 0.1);
							padding: 10rpx 20rpx;
							margin: 10rpx;
							border-radius: 10rpx;
							font-size: 26rpx;
						}
			
						.act {
							color: #fff;
							background: $uni-color;
						}
					}
				}
			}
			
			.form-sheet-cell{
				display: flex;
				background-color: #fff;
				padding: 20rpx;
				align-items: center;
				.label{
					width: 160rpx;
					// font-weight: 900;
				}
				.price{
					display: flex;
					text-align: center;
					input{
						width: 150rpx;
						border: 1px solid $uni-color;
						margin: 0 10rpx;
					}
				}
				input{
					flex: 1;
					background-color: rgba($uni-color, 0.1);
					padding: 10rpx 20rpx;
					border-radius: 10rpx;
				}
				.right-icon{
					margin-left: auto;
				}
			}
		
			/deep/ .uv-textarea{
				background-color: rgba($uni-color, 0.1) !important;
				min-height: 400rpx;
			}
		}
	}
</style>