<!--
@ 作者: 鲁智强
@ 时间: 2023-08-15 11:34:38
@ 备注: 部门指标点击考核指标点击修改
-->
<template>
	<el-dialog :model-value="true" title="编辑细则内容" style="width:40%" @close="handleClose">
	<el-form ref="ruleFormRef" :data="zjr" class="demo-ruleForm">
		<el-form-item  label-width="100px" label="考核内容">
			<el-input v-model="formData.title"/> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="考核标准">
			<el-input v-model="formData.standard"/> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="计量单位">
			<el-input v-model="formData.company"/> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="操作类型">
			<el-select v-model="zjr.censorrate">
				<el-option label="减分" :value="1" />
				<el-option label="加分" :value="2" />
				<el-option label="加减分" :value="3" />
			</el-select> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="检查方式">
			<el-select v-model="zjr.addorreduce">
				<el-option label="现场检查" :value="1" />
				<el-option label="资料审查" :value="2" />
				<el-option label="事件触发" :value="3" />
			</el-select> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="检查周期">
			<el-select v-model="zjr.cycle">
				<el-option label="月" :value="4" />
				<el-option label="季度" :value="5" />
				<el-option label="年" :value="6" />
			</el-select> 	
		</el-form-item>
		<el-form-item label="辅助计数：" label-width="100px">
			<el-input-number v-model="num" :min="1" />
		</el-form-item>
		<el-form-item  label-width="100px" label="检查依据">
			<el-input v-model="zjr.content" placeholder="请输入检查依据"/> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="备注说明">
			<el-input v-model="zjr.censorcont"  placeholder="请输入备注说明" /> 	
		</el-form-item>
		<el-form-item  label-width="100px" label="接受考核部门">
			<el-tree-select ref="orgTreeRef" v-model="zjr.departmentidlist" show-checkbox multiple :data="lzq" node-key="id" :props="orgTreeProps" />
		</el-form-item>
		<el-form-item  label-width="100px" label="执行人">
			<el-tree-select ref="orgTreeRef" v-model="zjr.reportmanlist" show-checkbox multiple :data="chl" node-key="key" :props="orgTreeProps" />
		</el-form-item>
		<el-form-item>
        	<el-button type="primary" @click="submitForm()">确定</el-button>
    	</el-form-item>
	</el-form>	
	</el-dialog>
  </template>
  <script lang="ts" setup>
  import { reactive } from "vue";
  import {get_target_details} from '@/api/opk/news/api'
  import { addPostCont,getgroupuser } from '@/api/opk/api'
  import { getonedetailedtarget,getcompany,edit_detail } from '@/api/opk/opk/api'

const isshow = ref(false)
const num = (1)
const props= defineProps( {
	  title: {
		type: String,
		default: "",
	  },
	  lzqPostBox: {
		type: Boolean,
		default: false,
	  },
	  rowInfo: {
		type: Object,
		default() {
		  return {};
		},
	  },
	  arrayNum: {
		type: Number,
		default: 0,
	  },
	});
const orgTreeProps ={
   label: 'name',
   children:'child',
}
const orgTreeProp = {
	label:'title',
	children:'children'
}
const emit = defineEmits(["update:lzqPostBox","editRow","addRow"])
const formData = reactive({
	id:"",
	orgidlist:"",
	title:"",
	censortype:"",
	standard:"",
	company:"",
	cycleattr:"1",
})
const formDatas = reactive({})
const zjr = ref<any>({})
function getoned(){
	const add = props.rowInfo.id.toString()
	getonedetailedtarget({id:add})
		.then(data=>{
			zjr.value = data.data
		})
}
getoned()
const lzq = ref<any>([])
function getcomp(){
	getcompany({id:309,idstr:309})
		.then(data=>{
			lzq.value = data.data
		})
}
getcomp()
const chl = ref([])
function getgroup(){
	getgroupuser({id:309,level:4})
		.then(data=>{
			chl.value = data.data
		})
}
getgroup()
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 handleClose = ()=> {
    emit("update:lzqPostBox", false);
  }
const handleDel = (val:any) => {
  		ElMessageBox.confirm("你确定删除这条信息吗?", "提示", {
    		confirmButtonText: "确认",
    		cancelButtonText: "取消",
    		type: "warning",
  		})
			handleSure(val)
			//console.log(val.id)	
};
const handleSure = (val:any)=> {
    const index = tableData.value.findIndex((item:any) => item.id === val.id);
    if(index!=-1){
		tableData.value.splice(index, 1);
		}
}
 const submitForm=()=> {
	const add = zjr._value.departmentidlist.toString(',').split(',')
	const yrb = zjr._value.id
	const chl = zjr._value.addorreduce.toString().split(',')
	const zz = zjr._value.cycle
	const xy = zjr._value.content
	const lzq = zjr._value.censorrate
	const wyc = zjr._value.censorcont
	const lyt = zjr._value.reportmanlist
	edit_detail({executor:lyt,remarks:wyc,frequency:num,types:lzq,evidence:xy,cycle:zz,id:yrb,title:formData.title,standard:formData.standard,unit:formData.company,department:add,inspemethod:chl})
		.then(()=>{
			ElMessage({
				type:'success',
				message:'成功',
			})
		})
	handleClose()
  }  
  onMounted(()=>{
	Object.assign(formData,props.rowInfo);
  })
  </script>
  
  <style scoped> 
  </style>
  