<!--
@ 作者: 鲁智强
@ 时间: 2023-09-28 15:32:37
@ 备注: 岗位指标编辑
-->
<script lang='ts' setup>
import { addPostCont,getgroupusers,neweditpost,getgroupuser,search_orgpost,get_post } from '@/api/opk/api'
// eslint-disable-next-line vue/no-dupe-keys
import { editPostCont } from '@/api/opk/pulic/api'
const formData = reactive({
	"title":"", 
	"relevantdepartmentsmap":[] as {orgid:Number,postid:Number,operator:Array<any>}[],
	"state":"",
	"dimensiontitle":"",
	"unit":"",
	"reportmap":[],
	"jkl":0,
	"cycleattr":0,
	"id":"",
	"cycle":"",
	"name":"",
	"zjr":"",
	"dimensionname":"",
	"postarys":"",
	"deaprtname":"",
})
const tableData = ref<any>([])
function jjjs(){
	addPostCont("/hrapi/org/govthree","post")
	    .then(data => {
        	tableData.value = data.data[3].child[14].child;
        })
        .catch(error => {
          console.error('Error fetching data:', error);
        });
}
jjjs()
const tables = ref<any>([])
function editPost(){
	editPostCont()
		.then(data => {
			tables.value = data.data.list;
		})
}
editPost()
const tablea = ref([])
function getgrou(){
	getgroupusers({ id:309,all:1 })
		.then(data => {
			tablea.value = data.data;
			console.log(tablea.value)
		})
}
getgrou()
const tablee = ref([])
function getuser(){
	getgroupuser({id:309,level:4})
		.then(data => {
			tablee.value = data.data;
		})
}
getuser()
const tableq = ref([])
function orgpost(){
	search_orgpost({name:formData.name,orgid:"309"})
		.then(data =>{
			tableq.value = data.data;
	})
	.finally(()=>{
		isshows.value = false
	})
}
const table = ref([])
const isshows = ref(false)
function orgposts (){
	const ess = props.rowInfo.postary[0].name
	search_orgpost({name:ess,orgid:"309"})
		.then(data =>{
			table.value = data.data;
	})
	.finally(()=>{
		isshows.value = false
	})
}
orgposts()
const tableuio = ref([])
function orgpost(){
	search_orgpost({name:formData.name,orgid:"309"})
		.then(data =>{
			tableiuo.value = data.data;
	})
	.finally(()=>{
		isshows.value = false
	})
}
const props = defineProps({
	title:{
		type:String,
		default:"",
	},
	editPostCont:{
		type:Boolean,
		default:false,
	},
	rowInfo:{
		type:Object,
		default(){
			return {};
		}
	},
	arrayNum:{
		type:Number,
		default:0,
	}
})
const orgTreeProp ={
	label:'name',
	children:'child',
}
const orgTreeProps ={
	label:'title',
	children:'children'
}
const orgTreePropa ={
	label:'name',
	children:'children'
}
const num =ref(1)
const emit = defineEmits(["update:editPostCont"])
const handClose=()=>{
	emit("update:editPostCont",false)
}
const submitForm = ()=>{
	const yuu = new Number(formData.deaprtname)
	const opp = new Number(formData.zjr)
	const oop = formData.name.toString().split(',')
	formData.relevantdepartmentsmap = [{orgid:yuu,postid:opp,operator:oop}]
	const edd = formData.id.toString()
	const add = new Number(formData.cycle)
	const err = new Number(formData.state)
	neweditpost({otherposttarget:formData.relevantdepartmentsmap,id:edd,title:formData.title,cycle:add,cycleattr:formData.cycleattr,dimension:formData.dimensionname,scoringmethod:err,type:num.value,unit:formData.unit})
		.then(()=>
			ElMessage.success("编辑成功"))
	handClose()
	jjjs()
}
onMounted(()=>{
	Object.assign(formData,props.rowInfo);
})
</script>
<template>
	<el-dialog :model-value="true" :title="title" style="width:40%" @close="handClose">
		{{props.rowInfo}}
		<el-form ref="ruleFormRef" :model="formData" label-width="120px" class="demo-ruleForm">
			<el-form-item label="指标名称：" prop="title">
				<el-input v-model="formData.title" placeholder="请输入名称"/>
			</el-form-item>
			<el-form-item label="岗位/人员：" prop="dimensionname">
				<el-input v-model="formData.postarys" placeholder="请输入指标名称"></el-input> 
		<el-button @click="orgposts">查询</el-button>
		<el-table v-loading="isshows" :data="table">
			<el-table-column label="行政组织">
				<el-tree-select ref="orgTreeRef" v-model="formData.deaprtname" show-checkbox clearable node-key="id" class="orgTree" :data="tablea" :props="orgTreePropa" :render-after-expand="false" :disable-branch-nodes="true"/>
			</el-table-column>
			<el-table-column prop="" label="相关岗位">
				<template #default="scope">
				<el-select v-model="formData.zjr">
					<el-option v-for="item in scope.row.postlist" :key="item.id" :label="item.name" :value="item.id"></el-option>
				</el-select>			
				</template>	
			</el-table-column>
			<el-table-column label="提报人">
				<el-tree-select ref="orgTreeRef" v-model="formData.name" multiple show-checkbox node-key="key" class="orgTree" :data="tablee" :props="orgTreeProp" :render-after-expand="false"/>
			</el-table-column>
		</el-table>	
	</el-form-item>		
			<el-form-item label="指标性质：" prop="">
				<el-select v-model="formData.state">
					<el-option label="定性指标" :value="1"></el-option>
					<el-option label="定量指标" :value="2"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="指标：" prop="dimensiontitle">
				<el-tree-select ref="orgTreeRef" v-model="formData.dimensionname" clearable node-key="outId" class="orgTree" :data="tables" :props="orgTreeProps" :render-after-expand="false"/>
			</el-form-item>
			<el-form-item label="计量单位：" prop="unites">
				<el-input v-model="formData.unit"/>
			</el-form-item>
			<el-form-item label="计分方式：" prop="cycleattr">
				<el-select v-model="formData.cycleattr">
					<el-option label="自动计数" :value="1"></el-option>
					<el-option label="手动技术" :value="2"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="考核周期：" prop="">
				<el-select v-model="formData.cycle">
					<el-option label="班" :value="1"></el-option>
					<el-option label="天" :value="2"></el-option>
					<el-option label="周" :value="3"></el-option>
					<el-option label="月" :value="4"></el-option>
					<el-option label="季度" :value="5"></el-option>
					<el-option label="年" :value="6"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="辅助计数：" prop="state">
				<el-input-number v-model="num" :min="1"/>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm()">确定</el-button>
			</el-form-item>
		</el-form>
	</el-dialog>
</template>
<style  lang='scss' scoped>

</style>
