<template>
	<!--人员信息管理 -->
	<a-card :bordered="false">
		<div style="cursor: pointer; width: 80px" @click="delCode"><left-outlined />返回</div>
		<br />

		<a-form
			:model="formState"
			name="basic"
			autocomplete="off"
			@finish="onFinish"
			@finishFailed="onFinishFailed"
			v-if="formState"
		>
			<a-row>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="企业名称"
						name="unitName"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!', trigger: 'change' }]"
					>
						<a-select :disabled="codes" v-model:value="formState.unitName" @change="handleChange">
							<a-select-option v-for="item in optionsGender" :key="item.unitInfoId" :value="item.unitInfoId">{{
								item.unitName
							}}</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="企业社会信用代码"
						name="dwdm"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!' }]"
					>
						<a-input disabled placeholder="请输入企业社会信用代码" v-model:value="formState.dwdm" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="企业类型" name="dwlxName" :label-col="{ span: 10 }">
						<a-select disabled v-model:value="formState.dwlxName">
							<a-select-option v-for="item in optionsGender" :key="item.id" :value="item.id">{{
								item.dictLabel
							}}</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="法定代表人"
						name="fddbr"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!' }]"
					>
						<a-input disabled placeholder="请输入法定代表人" v-model:value="formState.fddbr" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="联系方式"
						name="frlxfs"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!', trigger: 'change' }]"
					>
						<a-input placeholder="请输入联系方式" disabled v-model:value="formState.frlxfs" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="邮箱" name="dzyx" :label-col="{ span: 10 }">
						<a-input placeholder="请输入邮箱" disabled v-model:value="formState.dzyx" />
					</a-form-item>
				</a-col>
			</a-row>
			<a-row>
				<a-col :span="8">
					<a-form-item class="form-item" label="注册时间" name="zcrq" :label-col="{ span: 10 }">
						<a-input placeholder="请输入注册时间" disabled v-model:value="formState.zcrq" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label=" 注册地址" name="zcdz" :label-col="{ span: 10 }">
						<a-input placeholder="请输入注册地址" disabled v-model:value="formState.zcdz" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="注册资本"
						name="zczb"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!' }]"
					>
						<a-input placeholder="请输入注册资本" disabled v-model:value="formState.zczb" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label=" 信用评分"
						name="creditScore"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!' }]"
					>
						<a-input placeholder="请输入信用评分" :disabled="code" v-model:value="formState.creditScore" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="信用等级"
						name="creditLevel"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!', trigger: 'change' }]"
					>
						<a-select :disabled="code" v-model:value="formState.creditLevel">
							<a-select-option :value="1">一级</a-select-option>
							<a-select-option :value="2">二级</a-select-option>
							<a-select-option :value="3">三级</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						:rules="[
							{ required: true, message: '请输入!' },

							{ validator: isIntegerDEl, trigger: 'change' }
						]"
						class="form-item"
						label="企业履约次数"
						name="fulfilmentTimes"
						:label-col="{ span: 10 }"
					>
						<a-input placeholder="请输入企业履约次数" :disabled="code" v-model:value="formState.fulfilmentTimes" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="企业违约次数"
						name="breachTimes"
						:label-col="{ span: 10 }"
						:rules="[
							{ required: true, message: '请输入!' },

							{ validator: isIntegerDEl, trigger: 'change' }
						]"
					>
						<a-input placeholder="请输入企业违约次数" :disabled="code" v-model:value="formState.breachTimes" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="评定单位/机构" name="evaluationUnit" :label-col="{ span: 10 }">
						<a-input placeholder="请输入评定单位/机构" :disabled="code" v-model:value="formState.evaluationUnit" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<!-- <a-form-item class="form-item" label="创建时间" name="major" :label-col="{ span: 10 }">
						<a-date-picker
							valueFormat="YYYY-MM-DD HH:mm:ss"
							placeholder="创建时间"
							style="width: 85%"
							:disabled="code"
							v-model:value="formState.major"
						/>
					</a-form-item> -->
				</a-col>
			</a-row>
			<!--  -->

			<a-row>
				<a-col :span="20">
					<a-form-item class="form-item" label="行政处罚信息" name="administrativePenaltyInfo" :label-col="{ span: 4 }">
						<a-textarea
							style="width: 100%; height: 50px"
							placeholder="请输入行政处罚信息"
							:disabled="code"
							v-model:value="formState.administrativePenaltyInfo"
						/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row>
				<a-col :span="20">
					<a-form-item class="form-item" label="经营异常信息" name="businessAbnormalInfo" :label-col="{ span: 4 }">
						<a-textarea
							style="width: 100%; height: 50px"
							placeholder="请输入经营异常信息"
							:disabled="code"
							v-model:value="formState.businessAbnormalInfo"
						/>
					</a-form-item>
					<a-col :span="4"> </a-col>
				</a-col>
			</a-row>
			<a-row>
				<a-col :span="20">
					<a-form-item class="form-item" label="违法失信信息" name="illegalDishonestyInfo" :label-col="{ span: 4 }">
						<a-textarea
							style="width: 100%; height: 50px"
							placeholder="请输入违法失信信息"
							:disabled="code"
							v-model:value="formState.illegalDishonestyInfo"
						/>
					</a-form-item>
					<a-col :span="4"> </a-col>
				</a-col>
			</a-row>

			<a-form-item>
				<div class="item-submit">
					<a-button class="btn1" @click="delCode">取消</a-button>
					<a-button :disabled="code" class="btn1" type="primary" html-type="submit">保存</a-button>
				</div>
			</a-form-item>
		</a-form>
	</a-card>
</template>
<script setup>
	import { required } from '@/utils/formRules'
	import { onMounted } from 'vue'
	import { reactive, ref, watch } from 'vue'
	import { useRouter, useRoute } from 'vue-router'
	import { defineComponent } from 'vue'
	import business from '@/api/basic.info/verifyQuery.js'
	import { isInteger, isIntegerDEl } from '@/utils/validator'

	const router = useRouter()
	const route = useRoute()
	const formState = ref({
		unitName: '',
		dwdm: '',
		dwlxName: '',
		fddbr: '',
		frlxfs: '',
		dzyx: '',
		zcrq: '',
		zcdz: '',
		zczb: '',
		// --
		unitInfoId: '',
		creditScore: '',
		creditLevel: '',
		fulfilmentTimes: '',
		breachTimes: '',
		evaluationUnit: '',
		administrativePenaltyInfo: '',
		businessAbnormalInfo: '',
		illegalDishonestyInfo: ''
	})

	const huiXian_managementDel = async () => {
		const res = await business.XYDAXview({ id: route.query.id })
		formState.value = res
	}
	const optionsGender = ref([])
	const getGender = async () => {
		const res = await business.XYDAXla()
		optionsGender.value = res
	}
	const code = ref(null)
	const codes = ref(null)
	watch(
		() => route.query.codeACC,
		async (newVal) => {
			const codeDel = route.query.codeACC
			if (codeDel == 1) {
				codes.value = true
				code.value = false
				huiXian_managementDel()
			} else if (Boolean(route.query.codeACC) == true) {
				codes.value = true
				code.value = true
				await huiXian_managementDel()
				console.log(44)
			} else {
				codes.value = false
				code.value = false
				getGender()
			}
		},
		{ immediate: true, deep: true }
	)
	// onMounted(() => {})

	const handleChange = (val) => {
		const d = optionsGender.value.filter((item) => {
			return val == item.unitInfoId
		})
		Object.assign(formState.value, ...d)
	}
	// 新增
	const pustFrom = async (value) => {
		const res = await business.XYDAXadd(value)
	}
	// 编辑
	const pustEdit = async (value) => {
		const res = await business.XYDAXedit(value)
	}

	// 回显示
	const onFinish = (values) => {
		if (route.query.id) {
			pustEdit({ id: route.query.id, ...values })
		} else {
			pustFrom(formState.value)
		}
		delCode()
	}
	const delCode = () => {
		if (formState.value) {
			for (let key in formState.value) {
				formState.value[key] = ''
			}
		}
		router.back()
	}
	const onFinishFailed = (errorInfo) => {
		console.log('Failed:', errorInfo)
	}
</script>
<style lang="less" scoped>
	.item-submit {
		display: flex;
		justify-content: center;
		margin-top: 100px;
		.btn1 {
			width: 100px;
			margin-right: 20px;
		}
	}
	.ant-select {
		width: 250px;
	}
	.ant-input {
		width: 250px;
	}
	.ant-form-item-label {
		width: 150px;
	}
</style>
