<!--
@ 作者: 鲁智强
@ 时间: 2023-08-15 11:34:38
@ 备注: 
-->
<template>
	<el-dialog :model-value="true" :title="title" @close="handleClose">
		<el-form ref="ruleFormRef" :model="formData" label-width="120px" class="demo-ruleForm">
			<el-form-item label="行政组织">
				<el-tree-select ref="orgTreeRef" v-model="formData.deaprtname" show-checkbox clearable node-key="id" class="orgTree" :data="tableData" :props="orgTreeProps" :render-after-expand="false" @check="ge_adds"/>
				<el-table  v-loading="isshow" :data="tablea">
					<el-table-column prop="id" label="Date" width="180">
						</
				<!-- <template #default="scope">
				<el-table v-for="item in scope.row" :key="item.key" :label="item.name">
						<template #default="scope">
							<el-table-column v-prop="scope.row.child" label="指标名称">
							</el-table-column>
						</template>
				</el-table>
			</template> -->
		</el-table>
			</el-form-item>
			<el-form-item label="年度">
				<el-date-picker v-model="formData.value1" type="year"/>
			</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 {tarlist,addPostCont,addtarget,getgroupuser,addposttargetcont,search_orgpost} from '@/api/opk/api'
  import {editPostCont} from '@/api/opk/pulic/api'
  import { ge_add } from '@/api/opk/news/api'
  import "quill/dist/quill.snow.css"; 
  interface FormInfo {
	id: string;
	age: string;
	name: string;
	sex: string;
	ccc: string;
	ade: string;
	sort: number;
	title: string;
	type: number;
  }
const isshow = ref(false)
const props= defineProps( {
	  title: {
		type: String,
		default: "",
	  },
	  addPostBox: {
		type: Boolean,
		default: false,
	  },
	  addrowInfo: {
		type: Object as () => FormInfo,
		default() {
		  return {};
		},
	  },
	  arrayNum: {
		type: Number,
		default: 0,
	  },
	});
const orgTreeProps ={
   label: 'name',
   children:'child',
}
const orgTreeProp = {
	label:'title',
	children:'children'
}
const emit = defineEmits(["update:addPostBox","editRow","addRow"])
const formData = reactive({
	deaprtname:"",
	value1:"",
})
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 handle = (data:any)=>{
	formData.deaprtname = data.id;
	ge_adds()
}
const tablea = ref<any>([])
function ge_adds(){
	const add = formData.deaprtname.toString()
	ge_add({id:add})
	    .then(data => {
        	tablea.value = data.data;
        })
        .catch(error => {
          console.error('Error fetching data:', error);
        }).finally(()=>{
			isshow.value = false
	})
}
ge_adds()
  // 关闭弹窗
 const handleClose = ()=> {
    emit("update:addPostBox", false);
  }
const handleDel = (val:any) => {
	const dictTypeIds = [val.outID || postIds.value].join(",");
    let dictTypeIdAry = dictTypeIds.split(",")
  		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=()=> {
    handleClose()
	const add = formData.acceptdepartmentid.toString()
    formData.acceptdepartmentid = add.split(',')
	formData.dimension = formData.dimension.toString()
	const edd = formData.userlist.toString()
	formData.userlist = edd.split(',')
	if (props.addrowInfo.name) {
      // 修改
      const id = props.addrowInfo; // 假设你有一个唯一的ID来识别要修改的项
      emit("editRow", formData);
    } else {
      // 新增
      addposttargetcont(formData)
        .then((response:any) => {
          // 处理新增成功的情况
          if (response.code === 200) {
            ElMessage.success("新增成功");
            emit("addRow", formData);
          } else {
            // 处理新增失败的情况
            ElMessage.error("新增成功");
          }
        })
    }
  }
  </script>
  
  <style scoped>
  
  
  .avatar-uploader .avatar {
	display: block;
	width: 178px;
	height: 178px;
  }
  </style>
  
  <style lang="scss">
  .avatar-uploader .el-upload {
	position: relative;
	overflow: hidden;
	cursor: pointer;
	border: 1px dashed var(--el-border-color);
	border-radius: 6px;
	transition: var(--el-transition-duration-fast);
  }
  
  .avatar-uploader .el-upload:hover {
	border-color: var(--el-color-primary);
  }
  
  .el-icon.avatar-uploader-icon {
	width: 178px;
	height: 178px;
	font-size: 28px;
	color: #8c939d;
	text-align: center;
  }
  .el-dialog{
	  width:1200px;
  }
  </style>
  