<!--
@ 作者: 鲁智强
@ 时间: 2023-09-19 09:13:14
@ 备注: 
-->
<script lang='ts' setup>
import {ref,reactive,onMounted} from 'vue'
import { organdpost,posttarget,set_posttarget } from '@/api/opk/api'
import { addPostCont,tarlist,deltarget } from '@/api/opk/api'
import { editPostCont } from '@/api/opk/pulic/api'
import { departmentprogramme,edit_depart } from '@/api/opk/news/api'
import { formItemValidateStates, TableV2SortOrder } from 'element-plus';
import { getDictFormData } from '@/api/dict'
// eslint-disable-next-line vue/require-prop-types
const { addShow, title } = defineProps(['addShow', 'title'])
const data = reactive({
	formInline:{
		region:'',
	},
	title:"",
	addPostBox: false,
	editPostCont:false,
	edPostCont:false,
})
const orgTreeProps ={
   label: 'name',
   children:'child'
}
const orgTreeProp ={
   label: 'title',
   children:'childen'
}
const formdat = {
	someProp:"",
}
const total =ref(0)
let rowInfo = ref<any>({})
const postIds = ref<number[]>([])
const tableData = ref<any>([]);
const tables = 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()
function editPost(){
	editPostCont({})
		.then(data => {
			tables.value = data.data.list;
		})
}
editPost()
const table = ref<any>([])
const formdate = reactive({
	page:0,
	pagesize:20,
	name:"",
	dimension:"",
	attribute:"",
	orgidlist:[]as String[],
	type:"",
	value1:"",
})
// 获取数据
const tableq = ref([])
const postt = ()=>{
	departmentprogramme({ordig:"",year:formdate.value1,version:formdate.name})		
		.then(data => {
			tableq.value = data.data;
			total.value = data.data.count;
		})
}
postt()
// 新增数据
const addtableData = ()=>{
	data.addPostBox = true;
}
// 添加行
const addRow = (val:any)=> {
        tableData.value.push(val);
}
// 编辑行
const editRow = (val:any)=> {
        let index =tableData.value.findIndex(
          (item:any) => item.id === val.id
        );
        tableData.value.splice(index, 1, val);
}
// 关闭弹窗
const closeDetail = ()=>{
	data.addPostBox = false;
}
// 删除数据
const handleDel = (val:any) => {
		const dictTypeIds = [val.outID || postIds.value].join(",");
        let dictTypeIdAry = dictTypeIds.split(",")
  			ElMessageBox.confirm("你确定删除这条信息吗?", "提示", {
    			confirmButtonText: "确认",
    			cancelButtonText: "取消",
    			type: "warning",
  			})
    		.then(() => {
				const add = val.key.toString()
				handleSure(val)
				console.log(val.id)
				edit_depart({id:add,state:3,istrue:2}).then(()=>
					ElMessage.success("删除成功"))
				postt()
   		 	})	
};
const handleSure = (val:any)=> {
    const index = tableData.value.findIndex((item:any) => item.id === val.id);
    if(index!=-1){
		tableData.value.splice(index, 1);
		}
}
const handle=(data:any)=>{
	formdate.orgidlist = data.id
	console.log(formdate.orgidlist)
}
const handleedit=(val:any)=>{
	data.editPostCont=true,
	rowInfo.value=val;
}
const handleErd=(val:any)=>{
	data.edPostCont=true,
	rowInfo.value=val;
}
onMounted(()=>{
	jjjs()
})
</script>
<template>
	<div>
		<el-row style="width: 100%">
			<el-tree ref="orgTreeRef" v-model="formdate.orgidlist" show-checkbox clearable multiple node-key="id" class="orgTree" :data="tableData" :props="orgTreeProps" :default-expand-all="false" @check="handle"/>
			<el-col :span="22">
				<div class="horizontal-controls">
				<el-form-item label="考核指标">
					<el-input v-model="formdate.name" placeholder="请输入考核指标" clearable/>
				</el-form-item>
				<el-form-item>
					<span class="demonstration">年度</span>
						<el-date-picker v-model="formdate.value1" type="year"/>
				</el-form-item>
					<el-button @click="postt">查询</el-button>
					<el-button class="new_btn" type="success" @click="addtableData">新增</el-button>
				</div>	
				<el-table :data="tableq" border style="width: 100%">
					<el-table-column prop="deaprtname" label="部门"/>
					<el-table-column prop="year" label="年"/>
					<el-table-column prop="key" label="版本号"/>
					<el-table-column prop="time" label="时间" />
					<el-table-column prop="" label="状态" width="70">
					<template #default="scope">
						<el-switch v-model="scope.row.status" />
					</template>
				</el-table-column>
				<el-table-column fixed="right" label="操作" width="200">
					<template #default="{ row }">
					<el-button type="success" link @click="handleErd(row)">编辑</el-button>
					<el-button type="danger" link @click="handleDel(row)">删除</el-button>
					</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<pagination v-if="total > 0" v-model:page="formdate.page" v-model:pagesize="formdate.pagesize" :total="total" @click="postt"/>
	</div>
  </template>
<style  lang='scss' scoped>
*{
	font-weight: bolder;
}
.horizontal-controls {
  display: flex;
  float: left;

}

/* 可以根据需要调整样式 */
</style>
