<!--
@ 作者: 袁纪菲
@ 时间: 2024-03-03
@ 备注: 奖惩记录
-->
<script lang='ts' setup>
import {jiangchengjilu} from '@/api/hr/people/type'
import { getRewardsAndPunishmentsCont,editRewardsAndPunishmentsContState } from '@/api/hr/people/index'
/**
 * 引入页面
 */
import AddRewardsAndPunishments from '@/views/hr/archives/basicinformation/rewardsandpunishmentsadd.vue'
import EditRewardsAndPunishments from '@/views/hr/archives/basicinformation/rewardsandpunishmentsedit.vue'
const props = defineProps({
	tabsid:{
		type:String,
		default:"1"
	},
	usercont:{
		type:Object,
		default(){
			return {}
		}
	}
});
const addJcjlBoxPage = ref(false)			//新增奖惩记录
const editJcjlBoxPage = ref(false)			//编辑奖惩记录

const tableLoading = ref(false)
const jcjlList = ref<jiangchengjilu[]>([])
const jcjlInfo = ref<jiangchengjilu>()
function getjcjlList(){
	tableLoading.value = true;
	getRewardsAndPunishmentsCont({id:props.usercont.keystr})
		.then(( data )=>{
			// console.log("改变状态-----222---->",data)
			jcjlList.value = data.data
		})
		.finally(()=>{tableLoading.value = false;})
}
/**
 * 监听数据
 */
 watch(() => props.tabsid,() => {
	if(props.tabsid == "6"){
		getjcjlList()
	}
 })
 /**
  * 添加数据
  */
function addJcjlBox(key:string){
	addJcjlBoxPage.value = true;
}
/**
 * 编辑奖惩记录
 */
function editJcjlBox(cont:jiangchengjilu){
	jcjlInfo.value = cont
	editJcjlBoxPage.value = true;
}
/**
 * 删除奖惩记录
 */
 function delJcjlBox(cont:jiangchengjilu){
	ElMessageBox.confirm("确认删除<"+cont.level+">此数据项?", "警告", {
		confirmButtonText: "确定",
		cancelButtonText: "取消",
		type: "warning",
	}).then(() => {
		editRewardsAndPunishmentsContState({id:toString(),state:3,isdel:1}).then(() => {
			ElMessage.success("删除成功");
			getjcjlList()
		});
	});
}
</script>
<template>
    <AddRewardsAndPunishments v-model:addisshow="addJcjlBoxPage" :keyval="props.usercont.keystr" @restdata="getjcjlList" />
	<EditRewardsAndPunishments v-model:editisshow="editJcjlBoxPage" :keyval="props.usercont.keystr" :datacont="jcjlInfo" @restdata="getjcjlList" />
	<el-table
		v-loading="tableLoading"
		highlight-current-row
		:data="jcjlList"
		border 
		:header-cell-style="{background:'#F5F7FA'}"
	>
		<el-table-column  label="奖惩级别" prop="level" width="100"    />
		<el-table-column  label="奖惩类型" prop="type" width="100"    />
		<el-table-column  label="奖惩内容" prop="content" width="120"  />
		<el-table-column  label="奖惩时间" prop="time" />
		<el-table-column  label="奖惩单位" prop="company" />
		<el-table-column fixed="right" align="right"  width="130">
			<template #header>
				<el-button
					type="primary"
					link
					size="small"
					@click.stop="addJcjlBox(props.usercont.keystr)"
				>
					<i-ep-plus /> 新增
				</el-button>
			</template>
			<template #default="scope">
				<el-button
					type="primary"
					link
					size="small"
					@click.stop="editJcjlBox(scope.row)"
				>
					<i-ep-edit />编辑
				</el-button>
				<el-button
					type="primary"
					link
					size="small"
					@click.stop="delJcjlBox(scope.row)"
				>
					<i-ep-delete />删除
				</el-button>
			</template>
		</el-table-column>
	</el-table>
</template>
<style></style>