<template>
	<view>
		<cu-custom bgColor="bg-blue" :isBack="true" v-if="title == '新建企业信息'">
			<block slot="backText">返回</block>
			<block slot="content">新建企业信息</block>
		</cu-custom>
		<cu-custom bgColor="bg-blue" :isBack="true" v-if="title == '修改企业信息'">
			<block slot="backText">返回</block>
			<block slot="content">修改企业信息</block>
		</cu-custom>
		<cu-custom bgColor="bg-blue" :isBack="true" v-if="title == '查看企业信息'">
			<block slot="backText">返回</block>
			<block slot="content">查看企业信息</block>
		</cu-custom>
		<form @submit="formSubmit" class="cu-list menu">

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text> 企业名称
				</view>
				<input v-model="inputForm.name" placeholder="请填写企业名称" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>企业类型
				</view>
				<jp-picker v-model="inputForm.industry" rangeKey="label" rangeValue="value"
					:range="$dictUtils.getDictList('industrial_type')" :disabled="ischeck">
					<view class="picker">
						{{$dictUtils.getDictLabel('industrial_type', inputForm.industry ,'请选择')}}
					</view>
				</jp-picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>所属楼宇
				</view>
				
				<picker @change="changeLYId" :value="lyIndex" :range="showLYList" :disabled="ischeck">
					<view class=" picker action">
						<view class="text-grey ">{{showLYList[lyIndex] || '请选择'}}</view>
					</view>
				</picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					入驻时间
				</view>
				<jp-datetime-picker v-model="inputForm.entryTime" mode="date" :disabled="ischeck"></jp-datetime-picker>
			</view>
			
			<view class="cu-form-group margin-top">
				<view class="title">
					撤场时间
				</view>
				<jp-datetime-picker v-model="inputForm.des5" mode="date" :disabled="ischeck"></jp-datetime-picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					办公面积（平）
				</view>
				<input v-model="inputForm.officeArea" placeholder="请填写办公面积" :disabled="ischeck"></input>
			</view>

			<!-- <view class="cu-form-group margin-top">
				<view class="title">
					年租金（元）
				</view>
				<input v-model="inputForm.annualRent" placeholder="请填写年租金" :disabled="ischeck"></input>
			</view> -->

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					楼层
				</view>
				<input v-model="inputForm.floor" placeholder="请填写楼层" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					房间号
				</view>
				<input v-model="inputForm.des3" placeholder="请填写房间号" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					联系人
				</view>
				<input v-model="inputForm.lxr" placeholder="请填写联系人" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					联系人手机
				</view>
				<input v-model="inputForm.phone" placeholder="请填写联系人手机" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					合约起始时间
				</view>
				<jp-datetime-picker v-model="inputForm.htStime" mode="date" :disabled="ischeck"></jp-datetime-picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					<text class="red-color ">* </text>
					合约到期时间
				</view>
				<jp-datetime-picker v-model="inputForm.htEtime" mode="date" :disabled="ischeck"></jp-datetime-picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					主营内容
				</view>
				<input v-model="inputForm.businessContent" placeholder="请填写主营内容" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					用工总数
				</view>
				<input v-model="inputForm.totalNumber" placeholder="请填写用工总数" :disabled="ischeck" type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					社保人数
				</view>
				<input v-model="inputForm.securityNumber" placeholder="请填写社保人数" :disabled="ischeck"
					type="number"></input>
			</view>
			
			<view class="cu-form-group margin-top">
				<view class="title">
					男生人数
				</view>
				<input v-model="inputForm.des7" placeholder="请填写男生人数" :disabled="ischeck"
					type="number"></input>
			</view>
			
			<view class="cu-form-group margin-top">
				<view class="title">
					女生人数
				</view>
				<input v-model="inputForm.des8" placeholder="请填写女生人数" :disabled="ischeck"
					type="number"></input>
			</view>
			
			<view class="cu-form-group margin-top">
				<view class="title">
					党员人数
				</view>
				<input v-model="inputForm.des9" placeholder="请填写党员人数" :disabled="ischeck"
					type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					本科以下人数
				</view>
				<input v-model="inputForm.belowUndergraduate" placeholder="请填写本科以下人数" :disabled="ischeck"
					type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					本科人数
				</view>
				<input v-model="inputForm.undergraduate" placeholder="请填写本科人数" :disabled="ischeck"
					type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					研究生人数
				</view>
				<input v-model="inputForm.postgraduate" placeholder="请填写研究生人数" :disabled="ischeck"
					type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					博士生人数
				</view>
				<input v-model="inputForm.doctoralStudent" placeholder="请填写博士生人数" :disabled="ischeck"
					type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					实用新型专利授权数
				</view>
				<input v-model="inputForm.num2" placeholder="请填写实用新型专利授权数" :disabled="ischeck" type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					发明专利授权数
				</view>
				<input v-model="inputForm.num3" placeholder="请填写发明专利授权数" :disabled="ischeck" type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					软著数
				</view>
				<input v-model="inputForm.softWritingNumbers" placeholder="请填写软著数" :disabled="ischeck"
					type="number"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					今年准备申报项目明细
				</view>
				<input v-model="inputForm.bz1" placeholder="请填写今年准备申报项目明细" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					今年项目认定明细
				</view>
				<input v-model="inputForm.bz2" placeholder="请填写今年项目认定明细" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					是否是国家高企
				</view>
				<jp-picker v-model="inputForm.bz3" rangeKey="label" rangeValue="value"
					:range="$dictUtils.getDictList('yes_no')" :disabled="ischeck">
					<view class="picker">
						{{$dictUtils.getDictLabel('yes_no', inputForm.bz3 ,'请选择')}}
					</view>
				</jp-picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					意向哪年申报国家高企
				</view>
				<input v-model="inputForm.bz4" placeholder="请填写意向哪年申报国家高企" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					是否是规上企业
				</view>
				<jp-picker v-model="inputForm.bz5" rangeKey="label" rangeValue="value"
					:range="$dictUtils.getDictList('yes_no')" :disabled="ischeck">
					<view class="picker">
						{{$dictUtils.getDictLabel('yes_no', inputForm.bz5 ,'请选择')}}
					</view>
				</jp-picker>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					什么时候能达到规上企业标准
				</view>
				<input v-model="inputForm.bz6" placeholder="请填写什么时候能达到规上企业标准" :disabled="ischeck"></input>
			</view>

			<view class="cu-form-group margin-top">
				<view class="title">
					企业简介
				</view>
				<textarea v-model="inputForm.qyDes" placeholder="请填写企业简介" :disabled="ischeck"></textarea>
			</view>
			
			<view style="height: 40rpx;"></view>



			<view class="padding-xl" v-if="!ischeck">
				<button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	var graceChecker = require("@/common/graceChecker.js");
	import revenueListService from '@/api/revenue/revenueListService'
	import loginService from '@/api/auth/loginService.js'
	export default {
		onShow() {
			this.$auth.checkLogin()
		},
		data() {
			return {
				title: '新建企业信息',
				autoUpload: false,
				inputForm: {
					id: '',
					name: '',
					industry: '',
					des1: '',
					des2: '',
					des3: '',
					entryTime: '',
					officeArea: '',
					annualRent: '',
					floor: '',
					lxr: '',
					phone: '',
					htStime: '',
					htEtime: '',
					qyDes: '',
					businessContent: '',
					totalNumber: '',
					securityNumber: '',
					belowUndergraduate: '',
					undergraduate: '',
					postgraduate: '',
					doctoralStudent: '',
					qyDes: '',
					num2: '',
					num3: '',
					softWritingNumbers: '',
					bz1: '',
					bz2: '',
					bz3: '',
					bz4: '',
					bz5: '',
					bz6: '',
					des5: '',
					des7: '',
					des8: '',
					des9: '',
				},
				parkList: [],
				ischeck: false,
				lyIndex: '',
				showLYList: [],
			}
		},
		created() {
		},
		mounted() {
			
		},
		onLoad(query) {
			console.log(query, '==============>query')
			if (query && query.ischeck) {
				this.ischeck = true
				this.title = "查看企业信息";
			}
			if (query && query.id && !query.ischeck) {
				this.title = "修改企业信息";
			}
			this.getParkList(query)
			
		},
		methods: {
			getParkList(query) {
				loginService.list({
					current: 1,
					size: 1000000,
				}).then(({
					data
				}) => {
					this.parkList = data.records.map((item) => {
						return {
							label: item.buildingName,
							value: item.id
						}
					})
					this.showLYList = this.parkList.map(item => item.label)
					if (query && query.id) {
						loginService.queryByIdCom(query.id).then(({
							data
						}) => {
							this.inputForm = this.recover(this.inputForm, data)
							this.lyIndex = this.parkList.findIndex(item => item.value == this.inputForm.des1)
							console.log(this.lyIndex, '=====================>lyIndex')
						}).catch((e) => {
						
						})
						
					}
				}).catch(e => {
					console.log(e)
				})
			},
			
			changeLYId(e){
				let index = e.detail.value
				this.lyIndex = index
				console.log(index, '===========>index')
				this.inputForm.des1 = this.parkList[index].value
				console.log(this.inputForm.des1, '===========>index')
			},




			formSubmit: function(e) {
				//定义表单规则
				var rule = [{
						name: "name",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写企业名称"
					},{
						name: "industry",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请选择企业类型"
					},{
						name: "des1",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请选择所属楼宇"
					},
					{
						name: "entryTime",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请选择入驻时间"
					},
					{
						name: "floor",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写楼层"
					},
					{
						name: "des3",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写房间号"
					},
					{
						name: "lxr",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写联系人"
					},
					{
						name: "phone",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写联系人手机"
					},
					{
						name: "htStime",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写合约起始时间"
					},
					{
						name: "htEtime",
						checkType: "notnull",
						checkRule: "",
						errorMsg: "请填写合约到期时间"
					},

				];
				//进行表单检查
				var formData = this.inputForm;
				var checkRes = graceChecker.check(formData, rule);
				console.log(checkRes, '===================>checkRes')
				if (checkRes) {
					uni.showLoading()
					loginService.comSave(this.inputForm).then(({
						data
					}) => {
						uni.showToast({
							title: data,
							icon: "success"
						});
						uni.navigateTo({
							url: '/pages/comList/comList'
						})
					}).catch((e) => {

					})
				} else {
					uni.showToast({
						title: graceChecker.error,
						icon: "none"
					});
				}
			}
		}
	}
</script>
<style>
	/* .file-title) {
	    font-size: 17px !important;
	} */
	input,textarea{
		color: #8799a3;
	}
</style>