<!--
@ 作者: 鲁智强
@ 时间: 2023-08-15 11:34:38
@ 备注: 
-->
<template>
	<el-dialog :model-value="true" title="新增方案" style="width:40%" @close="handleClose">{{tablea}}
		<el-form ref="ruleFormRef" :model="formData" label-width="80px" class="demo-ruleForm" style="width:100%">
			<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-form-item label="年度">
					<el-date-picker v-model="formData.value1" type="year"/>
				</el-form-item>
			</el-form-item>
			<el-form-item v-loading="isshow" :data="tablea">
				<el-row>
					<el-col v-for="item in tablea" :key="item.id" label="item.name" style="width:200px">
						<el-card>
							<template #header>
								<div>
									<span>考核维度：{{item.name}}</span>
									<span>指标合计分：{{item.zhiFraction}}</span>
								</div>
								<el-table border :data="item.child">
									<el-table-column label="指标名称" prop="name" />
									<el-table-column label="说明" prop="content">
										<template #default="scope">
											<el-input v-model="scope.row.content" />
										</template>
									</el-table-column>
									<el-table-column label="指标权重" prop="referencescore">
										<template #default="scope">
											<el-input v-model="scope.row.referencescore" />
										</template>
									</el-table-column>
									<el-table-column label="状态" prop="status">
										<template #default="scope">
										<el-select v-model="scope.row.status">
											<el-option label="使用" :value="1"/>
											<el-option label="禁用" :value="2"/>		
											<el-option label="观察" :value="3"/>
										</el-select>
										</template>
									</el-table-column>
								</el-table>
							</template>
						</el-card>
					</el-col>
				</el-row>
			</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 { create_scheme } from '@/api/opk/zxy/news/api'
  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:"",
	asd:[] as string[],
	lzq:"",
})
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) => {
  		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.deaprtname.toString()
	const edd = new Number(tablea.referencescore)
	tablea.referencescore = edd
	const ess = new Date(formData.value1).getFullYear()
	const see = ess.toString()
	if (props.addrowInfo.name) {
      // 修改
      const id = props.addrowInfo; // 假设你有一个唯一的ID来识别要修改的项
      emit("editRow", formData);
    } else {
      // 新增
      create_scheme({orgid:add,year:see,child:tablea._value})
        .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>
  