<template>
	<div class="all boxMinHeight">
		<PageHead :routePush="pushAssMan">
			<template slot="headMent">
				<div class="flex-box-ce">
					<div class="flex-box-ce" style="width: 500px;">
						<el-cascader
							style="width: 250px;"
							v-model="headValue"
							:options="options"
							:show-all-levels="false"
							:props="{
								expandTrigger: 'hover',
								label: 'name',
								value: 'id',
								children: 'list'
							}"
						></el-cascader>
						<img v-if="all_finish" src="@/assets/image/guidang.png" class="guidang" />
					</div>
					 <el-alert v-if="isShowText"
					    title="考核发起成功，系统将通知到相关员工并在【钉钉待办】中生成绩效待办事项"
					    type="success">
					  </el-alert>
					<!-- <div v-if="!isShowText" style="padding-left: 20px;" class="blue">考核发起成功后，系统将通知到相关员工并在【钉钉待办】中生成绩效待办事项</div> -->
				</div>
			</template>
		</PageHead>
		<header>
			<div class="flex-box flex-d-center" v-loading="isLoad">
				<div class="flex-box">
					<div class="dept_wdiv">
						<div class="dept_inp" @click="show_dept_selector = true">
							<span v-if="deptVisibleName != ''">{{ deptVisibleName }}</span>
							<span v-else style="color: #b9b9b9;">选择部门</span>
						</div>
						<svg-icon slot="reference" icon-class="xArrowsX" />
					</div>
					<EmployeeSelector
						:title="'选择部门'"
						:isChecKedAll="false"
						:can_select_employee="false"
						:can_select_dept="true"
						:dept_children="false"
						:selected="dept_selected"
						:visible.sync="show_dept_selector"
						@confirm="dept_confirm"
					/>
					<el-select v-model="groupValue" @change="groupChange" clearable class="margin-l width-300" placeholder="选择考核表">
						<el-option v-for="item in groupOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
					</el-select>
					<el-select v-model="employee_ids" multiple filterable clearable class="margin-l" placeholder="姓名搜索">
						<el-option v-for="item in employees" :key="item.id" :label="item.name" :value="item.id"></el-option>
					</el-select>
				</div>
				<div>
					<el-button v-if="$getRole(1) || $getRole(2)" class="primaryBtn" @click="isDerive = true">导出执行计划</el-button>
					<template v-if="!all_finish">
						<!-- 主管理员、有【开始评分】权限的子管理员 -->
						<el-button v-if="$getRole(1) && $isAuthoritys($8)" type="primary" @click="startisChecks">开始评分</el-button>
						<!-- 主管理员、有【菜单权限】权限的子管理员 -->
						<el-dropdown v-if="$getRole(1)" style="margin-left:11px;" @command="handleCommand">
							<el-button>更多</el-button>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item v-for="(item, index) in dropdownMenu" :key="index" :command="item.key" :divided="item.bordok" v-if="item.isShow">
									{{ item.name }}
								</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
					</template>
				</div>
			</div>

			<div class="navigationL flex-box-ce">
				<div v-for="(item, index) in navigationList" :key="index" class="flex-box-ce" @click="navClick(item)">
					<template v-if="item.num">
						<el-badge :value="item.num" class="item">
							<span class="flex-box-ce" :class="{ action: navcli == item.id }">
								<div>{{ item.name }}</div>
								<div v-if="item.hint">
									&nbsp;
									<el-tooltip class="item" effect="dark" :content="item.hint" placement="top">
										<svg-icon v-if="item.hint" icon-class="i" class="navsvg1" />
									</el-tooltip>
								</div>
							</span>
						</el-badge>
					</template>
					<span class="flex-box-ce" :class="{ action: navcli == item.id }" v-else>
						<div>{{ item.name }}</div>
						<div v-if="item.hint">
							&nbsp;
							<el-tooltip class="item" effect="dark" :content="item.hint" placement="top"><svg-icon v-if="item.hint" icon-class="i" class="navsvg1" /></el-tooltip>
						</div>
					</span>
					<div v-if="index == 0" class="navsvg2"></div>
					<i v-if="navigationList.length != index + 1 && index != 0" class="el-icon-right navsvg3"></i>
				</div>
			</div>
			<template v-if="$getRole(1)">
				<div style="margin: 15px 0;" class="fontColorB" v-if="navcli != 0 && navcli != 3 && navcli != 11">
					当前“{{ getNode }}”节点人数：{{ total }}人，可联系相关负责“{{ getNode }}"人员推进考核进度
					<span class="blue" style="cursor: pointer;" @click="isPending = true">查看名单</span>
				</div>
			</template>
			<el-table stripe :data="asstabData" v-loading="assDetLoad" @row-click="assDetClick" style="width: 100%">
				<el-table-column label="姓名">
					<template slot-scope="scope">
						<userImage
							class="fl"
							:id="scope.row.employee_id"
							style="margin-top: 9px;"
							:user_name="scope.row.name"
							:img_url="scope.row.img_url"
							width="35px"
							height="35px"
							fontSize="12px"
						></userImage>
						<span style="margin-left: 10px; line-height: 50px;">{{ scope.row.name }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="dept_list" label="部门">
					<template slot-scope="scope">
						<template v-if="scope.row.dept_list.length > 0">
							<span v-for="(item, index) in scope.row.dept_list" :key="index">
								{{ item.name }}
								<span v-if="scope.row.dept_list.length - index > 1">,</span>
							</span>
						</template>
						<span v-else>--</span>
					</template>
				</el-table-column>
				<el-table-column prop="group_name" label="考核表">
					<template slot-scope="scope">
						<span v-if="!scope.row.relevance_group.delete_time">{{ scope.row.relevance_group.name }}</span>
						<span v-else class="red">该考核表已被删除</span>
					</template>
				</el-table-column>
				<el-table-column prop="final_point" width="140" label="考核结果">
					<template slot-scope="scope">
						<span v-if="scope.row.publicity != 0 && scope.row.doing_id == 11">{{ scope.row.final_point }}</span>
						<span v-else>-</span>
					</template>
				</el-table-column>
				<el-table-column prop="final_level" width="140" label="绩效等级">
					<template slot-scope="scope">
						<span v-if="scope.row.publicity != 0 && scope.row.doing_id == 11">{{ scope.row.final_level }}</span>
						<span v-else>-</span>
					</template>
				</el-table-column>
				<el-table-column prop="peoplenum" width="300" label="操作">
					<template slot-scope="scope">
						<el-button type="text" size="medium" @click="assDetClick(scope.row)">查看</el-button>
						<template v-if="$getRole(1) && $isAuthoritys($9) && !all_finish">
							<el-button type="text" size="medium" :disabled="!scope.row.theResultsOf_But" @click.stop="theResultsOf1(scope.row, 1)">调整考核结果</el-button>
						</template>
						<!-- <el-button type="text" size="medium" :disabled="!scope.row.theResultsOf_But" @click.stop="theResultsOf1(scope.row,2)">调整绩效等级</el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<Pagination
				:page="asstabParams.page"
				:page_size="asstabParams.page_size"
				:total="total"
				@handleSizeChange="handleSizeChange"
				@handleCurrentChange="handleCurrentChange"
			></Pagination>
		</header>

		<BrawerBox drawerTitle="请选择开始评分的考核表" :showDrawer.sync="isChecks">
			<template slot="main">
				<div v-loading="isChecksLoad">
					<div style="padding-top:10px;"><JxSearch :screen="2" title="搜索考核表" ref="braSearch" @confirm="braSearch"></JxSearch></div>
					<template v-if="scoreGroup.length > 0">
						<div class="flex-box-ce li" style="margin-top: 20px;">
							<el-checkbox class="flex-box-ce flex-box-ce2" v-model="isAllSelectIndex" label="全选"></el-checkbox>
						</div>
						<ul class="ul">
							<li v-for="(item, index) in scoreGroup" :key="index" class="flex-box-ce li">
								<el-checkbox class="flex-box-ce flex-box-ce2" style="padding: 0;" :disabled="item.disabled" v-model="item.check">
									<div class="flex-box-ce">
										<div class="flex-1">
											<span
												v-if="item.all_exec_over"
												class="blue-box"
												style="padding: 5px 10px; border-radius: 3px; width: 80px;height: 24px; font-size: 12px;"
											>
												已开始评分
											</span>
											<span>{{ item.name }}</span>
										</div>
										<div class="blue" v-if="item.count_employee > 0">{{ item.count_employee }} 人</div>
									</div>
								</el-checkbox>
							</li>
							<div class="fontColorC" style="text-align: center;padding: 10px 0;font-size: 12px;">没有更多了</div>
						</ul>
					</template>
					<NoData v-else></NoData>
				</div>
			</template>
			<template slot="footer">
				<div style="position: absolute;left: 20px;font-size: 14px;color: #2b7ce0">已选择：{{ getLeng }}个</div>
				<el-button plain @click="isChecks = false">取消</el-button>
				<el-button type="primary" @click="beginGrade">开始评分</el-button>
			</template>
		</BrawerBox>
		<!-- 导出执行记录 -->
		<EmployeeSelector
			:title="'选择人员'"
			:isChecKedAll="false"
			:max="20"
			:isRequired="true"
			:can_select_employee="true"
			:is_employee_list="true"
			:employee_list="employee_list"
			:visible.sync="isDerive"
			@confirm="confirmDerive"
		/>

		<!-- 公式结果 -->
		<EmployeeSelector
			:title="'结果公布'"
			:is_filtration_creator="false"
			:can_select_employee="true"
			:is_employee_list="true"
			:employee_list="employee_list"
			:selected="selected"
			:visible.sync="isResult"
			@confirm="confirmResult"
		/>
		<!-- 更多-管理 -->
		<BrawerBox drawerTitle="管理绩效考核" :showDrawer.sync="isManagement">
			<template slot="main">
				<div class="m-content">
					<div>
						<div class="m-title">变更参与考核人员（{{ employee_list.length }}人）</div>
						<div class="flex-box-ce" style="margin-top: 20px;">
							<div style="margin-right: 20px;cursor: pointer;" @click="showSelectUser(1)">
								<i class="el-icon-circle-plus-outline blue"></i>
								添加
							</div>
							<div style="cursor: pointer;" @click="showSelectUser(2)">
								<i class="el-icon-remove-outline red"></i>
								删除
							</div>
						</div>
					</div>
				</div>
			</template>
		</BrawerBox>
		<!-- 更多-管理-人员选择添加 -->
		<EmployeeSelector
			title="添加被考核人员"
			:is_filtration_creator="false"
			:can_select_employee="true"
			:is_employee_list="true"
			:isRequired="true"
			:employee_list="add_employee_list"
			:visible.sync="isShowUser"
			@confirm="confirmUser"
		/>
		<!-- 更多-管理-人员选择删除 -->
		<EmployeeSelector
			:title="packageName + '：选择被删除人员'"
			:is_filtration_creator="false"
			:can_select_employee="true"
			:isRequired="true"
			:is_employee_list="true"
			:employee_list="employee_list"
			:visible.sync="isShowUser2"
			@confirm="confirmUser2"
		>
			<template slot="header">
				<div style="text-align: center;" class="yellow">*当所有人员都被选中删除时，该周期的绩效考核也会自动删除*</div>
			</template>
		</EmployeeSelector>

		<el-dialog :title="theResults == 1 ? '调整考核结果' : '调整绩效等级'" :visible.sync="comtheResults" width="500px" :close-on-click-modal="false">
			<div class="">
				<div>
					员工姓名：
					<span style="padding-left: 14px;">{{ theResultsList.name }}</span>
				</div>
				<br />
				<div v-if="theResults == 1">
					<div>
						原考核结果：
						<span>{{ theResultsList.final_point }}</span>
					</div>
					<br />
					<div class="flex-box" style="margin-bottom: 10px;">
						<span style="line-height:36px;width: 90px;">新考核结果：</span>
						<el-input
							v-model="theResultInp"
							@input="theResultInp = theResultInp.match(/\d+(\.\d{0,2})?/) ? theResultInp.match(/\d+(\.\d{0,2})?/)[0] : ''"
							style="width:350px;"
							placeholder="请输入新考核结果"
						></el-input>
					</div>
					<div class="flex-box">
						<span style="line-height:36px; width: 90px;">调整原因：</span>
						 <el-input type="textarea" v-model="comment" style="width:350px;"  rows="4" placeholder="请输入调整原因" clearable maxlength="200" show-word-limit></el-input>
					</div>
				</div>
				<div v-else>
					<div>
						原绩效等级：
						<span>{{ theResultsList.final_level }}</span>
					</div>
					<br />
					<div>
						新绩效等级：
						<span></span>
					</div>
				</div>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="comtheResults = false">取 消</el-button>
				<el-button type="primary" :disabled="theResultsButid" @click="savecomtheResults(theResultsList.id, theResults)">确 定</el-button>
			</span>
		</el-dialog>

		<el-dialog title="结果" :visible.sync="isShowData" @close="close_list" :append-to-body="true" width="700px">
			<el-table :data="showData" stripe>
				<el-table-column prop="name" label="名称"></el-table-column>
				<el-table-column prop="successText" label="结果">
					<template slot-scope="scope">
						<span v-if="scope.row.successText == '失败'" class="red">失败</span>
						<span v-else class="green">成功</span>
					</template>
				</el-table-column>
				<el-table-column prop="reason" label="描述"></el-table-column>
			</el-table>
		</el-dialog>

		<!-- 待处理人员列表 -->
		<BrawerBox :drawerTitle="'“' + getNode + '” 相关负责人名单'" :showDrawer.sync="isPending">
			<template slot="main">
				<div>
					<div
						class="flex-box-ce"
						style="border-bottom: 1px solid #f1f1f1;padding: 10px 0;"
						v-for="(item, index) in pending_employee_list"
						:key="index"
						v-if="pending_employee_list.length > 0"
					>
						<div class="flex-box-ce">
							<userImage style="margin-right: 10px;" :user_name="item.name" :img_url="item.img_url" width="38px" height="38px" fontSize="12px"></userImage>
							<span>{{ item.name }}</span>
						</div>
						<div style="margin-left: 10px;" class="flex-1">
							<template v-if="item.dept_list.length > 0">
								<span v-for="(e, index2) in item.dept_list" :key="index2" class="fontColorC">
									{{ e.name }}
									<span v-if="item.dept_list.length - index > 1">,</span>
								</span>
							</template>
						</div>
					</div>
					<NoData v-if="pending_employee_list.length == 0"></NoData>
				</div>
			</template>
			<template slot="footer">
				<!-- <el-button plain  @click="isPending = false">取消</el-button> -->
				<el-button type="primary" :disabled="pending" :loading="pending" @click="getPending">一键发DING催办</el-button>
				<!-- <el-button type="primary" @click="getPending">导出人员名单</el-button> -->
			</template>
		</BrawerBox>
	</div>
</template>
<script>
import PageHead from '@/components/public/PageHead'; //头部---返回
import JxSearch from '@/components/public/JxSearch'; //搜索
import EmployeeSelector from '@/components/public/EmployeeSelector';
import BrawerBox from '@/components/public/BrawerBox';
export default {
	name: 'assessDetails',
	data() {
		return {
			pending_employee_list: [], //待处理人员
			isPending: false,
			total: 0,
			nowass: false, //已开始评分显示隐藏
			pushAssMan: null, //头部跳转
			assDetLoad: false, //loading
			isLoad: false,
			headValue: [], //顶部选择考核
			options: [], //顶部考核数据
			groupValue: [], //选择考核表val
			groupOptions: [], //选择考核表数据
			scoreGroup: [], //评分考核表
			isAllSelectIndex: false,
			GroupList: [], //评分考核表备份搜索数据
			navigationList: [
				//导航
				{ id: 0, name: '参与人数', num: 0 },
				{ id: 1, name: '目标制定', num: 0 },
				{ id: 2, name: '目标确认', num: 0 },
				{
					id: 3,
					name: '执行中',
					num: 0,
					hint: '目标制定并确认完毕后，进入到【执行中】阶段，期间员工执行计划，上级跟踪过程。管理员可以点击【开始评分】后，进入结果数据收集和评分阶段'
				},
				{ id: 4, name: '结果值录入', num: 0 },
				{ id: 5, name: '评分', num: 0 },
				{ id: 9, name: '审批', num: 0 },
				{ id: 11, name: '结束', num: 0 }
			],
			navcli: 0, //导航当前选中
			svaeNavcli: 0, //保存的选中
			asstabParams: {
				package_id: 0, //考核包id
				dept_ids: [], //部门id
				group_ids: [], //考核表ID
				doing_id: 0, //状态ID
				employee_ids: [], //搜索人员ID
				page: 1,
				page_size: 10
			},
			employee_ids: [],
			asstabData: [],
			employees: [], //被考核人员列表
			//更多
			dropdownMenu: [
				{ key: 'a', name: '等级配置', isShow: true },
				{ key: 'b', name: '结果公布', isShow: true },
				{ key: 'c', name: '导出明细', bordok: true, isShow: this.$isAuthoritys(this.$11) },
				{ key: 'd', name: '导出结果', isShow: this.$isAuthoritys(this.$11) },
				{ key: 'j', name: '批量转交', isShow: this.$isAuthoritys(this.$17) },
				{ key: 'y', name: '批量修改目标值', isShow: this.$isAuthoritys(this.$18) },
				// { key: 'e', name: '自定义导出' },
				// { key: 'f', name: '批量操作', bordok: true },
				{ key: 'h', name: '归档&统计', bordok: true, isShow: false },
				{ key: 'g', name: '管理', bordok: true, isShow: true }
			],
			// 选择部门
			deptVisibleName: '',
			dept_selected: { dept: [], employee: [] },
			show_dept_selector: false,
			deptList_id: [],
			isChecks: false, //评分开关
			isChecksLoad: false,
			allassList: [], //所有流程数据
			searchList: [], //搜索备份
			searchdet: '', //搜索值
			packageName: '', //考核包名称
			// 公式结果相关
			isResult: false,
			employee_list: [], //人员列表
			// 更多-管理
			isManagement: false,
			ManagementTitle: '删除被考核人员',
			add_employee_list: [], //可以被添加到绩效包的人员
			isShowUser: false, //控制添加人员
			isShowUser2: false, //控制删除人员
			selected: { dept: [], employee: [] }, //已选择公式人员
			isAdmin: false, //是否管理员
			userInfo: this.$getUserData(),
			theResults: 1, //结果点击按钮
			theResultsList: {}, //点击的结果
			comtheResults: false, //切换结果控制
			theResultInp: '', //调整考核结果值
			theResultsButid: false,
			deleteNum: 0, //记录考核包人数

			isShowData: false,
			showData: [],

			all_process_done: false, //是否所有人都完成流程了
			all_finish: false, //是否已经归档

			isDerive: false ,//导出执行人员
			pending:false,
			
			comment:'',//
			isShowText:false,
		};
	},
	components: { PageHead, JxSearch, EmployeeSelector, BrawerBox },
	computed: {
		getNode() {
			let name;
			this.navigationList.some(item => {
				if (item.id == this.navcli) {
					name = item.name;
					return true;
				}
			});
			return name;
		},
		getLeng() {
			let num = 0;
			this.scoreGroup.forEach(item => {
				if (item.check) {
					num += 1;
				}
			});
			return num;
		}
	},
	watch: {
		isChecks(val) {
			if (!val) {
				this.isAllSelectIndex = false;
			}
		},
		isAllSelectIndex(val) {
			this.scoreGroup.forEach(item => {
				if (!item.disabled) {
					item.check = val;
				}
			});
		},
		headValue(val) {
			this.options.some(item => {
				if (item.id == val[0]) {
					item.list.some(e => {
						if (e.id == val[1]) {
							this.packageName = e.name;
							return true;
						}
					});
					return true;
				}
			});
			this.asstabParams.package_id = val[val.length - 1];
			this.asstabParams.group_ids = []; //置空

			if (this.svaeNavcli) {
				this.navcli = this.svaeNavcli;
				this.asstabParams.doing_id = this.svaeNavcli; //置空
				this.svaeNavcli = 0;
			} else {
				this.navcli = 0;
				this.asstabParams.doing_id = 0; //置空
			}
			this.getInitData(this.asstabParams.package_id, () => {});
			this.assDelList(); //请求绩效详情列表
			this.getDcl();
		},
		employee_ids(val) {
			this.asstabParams.employee_ids = JSON.stringify(val);
			this.asstabParams.page = 1;
			this.assDelList();
		}
	},
	created() {
		let amfTabL;
		if (this.$route.query.amfTabLckick) {
			amfTabL = JSON.parse(this.$route.query.amfTabLckick);
			this.pushAssMan = amfTabL.pushs ? amfTabL.pushs : null;
			this.asstabParams.package_id = amfTabL.id;
			this.assessTree(amfTabL.cycle_type, amfTabL.id); //请求绩效树
			this.svaeNavcli = amfTabL.navcli ? amfTabL.navcli : 0;
			this.asstabParams.doing_id = amfTabL.navcli ? amfTabL.navcli : 0;
			this.isShowText=amfTabL.isShowText
		}
		//回显绩效树的选中
		this.theAdministrator(); //管理员列表
	},
	methods: {
		confirmDerive(obj) {
			if (obj.employee.length == 0) {
				this.$message.error('请选择人员');
				return false;
			}
			let employee = obj.employee.map(item => {
				return item.id;
			});
			this.$axios('post', '/api/per/user/download_token').then(res => {
			  let token=res.data.data.token
			  let url = `${this.$serverdomain}/api/download/export/schedule?employee_ids_code=${this.$returnCode(employee)}&package_id=${this.asstabParams.package_id
			 }&searcher_id=${this.$getUserData().id}&token=${token}`;
			window.open(url, '_blank');
			});
		},

		getPending() {
			let that = this;
			let users = this.pending_employee_list.map(item => {
				return item.user_id;
			});
			let corpId = this.$getCache('corpId');
			let str=that.returnText()
			this.pending=true;
			this.$dd.ready(()=> {
				this.$dd.biz.ding.create({
					users: users,
					corpId: corpId,
					type: 1,
					alertType: 2,
					alertDate: { format: 'yyyy-MM-dd HH:mm', value: '2022-02-09 08:00' },
					attachment: {
						images: ['']
					},
					text: str,
					bizType: 0,
					
					confInfo: {
						bizSubType: 0, //子业务类型如会议：0：预约会议；1：预约电话会议；2：预约视频会议；（注：目前只有会议才有子业务类型）
						location: '某某会议室', //会议地点；（非必填）
						startTime: { format: 'yyyy-MM-dd HH:mm', value: '2022-02-09 08:00' }, //会议开始时间
						endTime: { format: 'yyyy-MM-dd HH:mm', value: '2022-02-09 08:00' }, //会议结束时间
						remindMinutes: 30, //会前提醒。单位分钟-1：不提醒；0：事件发生时提醒；5：提前5分钟；15：提前15分钟；30：提前30分钟；60：提前1个小时；1440：提前一天；
						remindType: 2 //会议提前提醒方式。0:电话, 1:短信, 2:应用内
					},

					taskInfo: {
						ccUsers: ['100', '101'], //抄送用户列表，工号
						deadlineTime: { format: 'yyyy-MM-dd HH:mm', value: '2022-02-09 08:00' }, //任务截止时间
						taskRemind: 30 //任务提醒时间，单位分钟0：不提醒；15：提前15分钟；60：提前1个小时；180：提前3个小时；1440：提前一天；
					},

					onSuccess: function() {
						that.$message.success('已催办');
						//onSuccess将在点击发送之后调用
					},
					onFail: function() {}
				});
			});
			setTimeout(()=>{
				this.pending=false;
			},1000);
			return false;
			let site_info = this.$getCache('site_info');
			let url = `${this.$serverdomain}/api/download/doing_list?site_id=${site_info.id}&searcher_id=${this.$getUserData().id}&package_id=${
				this.asstabParams.package_id
			}&node_type=${this.navcli}`;
			window.open(url, '_blank');
		},
		getDcl() {
			if (this.navcli == 0 || !this.$getRole(1)) {
				return false;
			}
			this.$axios('get', 'api/per/package/msg/doing_list', { package_id: this.asstabParams.package_id, node_type: this.navcli }).then(res => {
				let list = res.data.data.list;
				let pending_employee_list = [];
				list.forEach(item => {
					let user = this.$getEmployeeList()[item];
					pending_employee_list.push(user);
				});
				this.pending_employee_list = pending_employee_list;
			});
		},
		// 关闭
		close_list() {
			this.showData = [];
		},
		// 获取可被添加人员
		getAddEmployee(fun = function() {}) {
			this.$axios('get', 'api/per/package/get_subtraction_employee', { package_id: this.asstabParams.package_id }).then(res => {
				this.add_employee_list = res.data.data.list;
				fun();
			});
		},
		// 添加人员
		confirmUser(val) {
			let employee_ids = val.employee.map(item => {
				return item.id;
			});
			let data = {
				package_id: this.asstabParams.package_id,
				employee_ids_code: this.$returnCode(employee_ids)
			};
			this.$axios('post', '/api/per/package/add_package_employee', data).then(res => {
				this.$message.success('添加成功');
				this.isManagement = false;
				this.getInitData(this.asstabParams.package_id, () => {});
				this.assDelList();
			});
		},
		//删除人员
		confirmUser2(val) {
			this.$confirm('被考核人删除后，本次考核相关数据将被清空，无法恢复，请确认是否删除?', '删除确认', {
				confirmButtonText: '确定',
				cancelButtonText: '取消'
			})
				.then(() => {
					let employee_ids = val.employee.map(item => {
						return item.id;
					});
					let data = {
						package_id: this.asstabParams.package_id,
						employee_ids_code: this.$returnCode(employee_ids)
					};
					this.$axios('post', '/api/per/package/delete_package_employee', data).then(res => {
						if (employee_ids.length == this.deleteNum) {
							this.$alert('删除成功,考核包已无考核人员,该周期的绩效考核也会自动删除', '提示', {
								confirmButtonText: '确定',
								showClose: false,
								callback: action => {
									this.$router.go(-1);
								}
							});
						} else {
							this.$message.success('删除成功');
							this.isManagement = false;
							this.getInitData(this.asstabParams.package_id, () => {});
							this.assDelList();
						}
					});
				})
				.catch(() => {});
		},
		savecomtheResults(dataId, db) {
			if(!this.theResultInp){
				this.$message.warning('请输入新的考核结果');
				return;
			}
			if(!this.comment){
				this.$message.warning('请输入调整原因');
				return;
			}
			this.theResultsButid = true;
			let data = {
				id: dataId,
				change_type: db,
				point: this.theResultInp,
				comment:this.comment,
			};
			this.$axios('post', '/api/per/package/adjustment', data)
				.then(res => {
					if (res.data.code == 1) {
						this.comtheResults = false;
						this.assDelList();
					}
				})
				.finally(() => {
					setTimeout(() => {
						this.comment='';
						this.theResultsButid = false;
					}, 300);
				});
		},
		theResultsOf1(data, num) {
			this.theResultsList = data;
			this.theResults = num;
			this.comtheResults = true;
		},
		//管理员列表
		theAdministrator() {
			let params = { range: 2 };
			this.$axios('get', '/api/per/user/manager_info', params).then(res => {
				if (res.data.code == 1) {
					let list = res.data.data.list || [];
					this.isAdmin = false;
					list.forEach(item => {
						if (this.userInfo.id == item.id) {
							this.isAdmin = true;
						}
					});
				}
			});
		},
		// 更多-选择人员
		returnText() {
			let text = `【${this.packageName}】准备中，请及时完成目标制定`;
			let str=this.navcli
			console.log(str)
			switch (str) {
				case 1:
					text = `【${this.packageName}】准备中，请及时完成目标制定`;
					break;
				case 2:
					text = `【${this.packageName}】目标已制定，请及时确认`;
					break;
				case 4:
					text = `【${this.packageName}】已近尾声，请及时录入结果数据`;
					break;
				case 5:
					text = `【${this.packageName}】评分工作开展中，请尽快评分`;
					break;
				case 9:
					text = `【${this.packageName}】考核已结束，请及时审批`;
					break;
			}
			return text;
		},
		// 更多-选择人员
		showSelectUser(index) {
			switch (index) {
				case 1:
					this.getAddEmployee(() => {
						this.isShowUser = true;
					});
					break;
				case 2:
					this.isShowUser2 = true;
					break;
			}
		},
		// 添加考核人
		openManagement() {
			this.$router.push({ path: '/addPersonnel', query: { packageId: this.asstabParams.package_id } });
		},
		// 提交公式结果
		confirmResult(val) {
			let NoData = val.employee.map(item => {
				return item.id;
			});
			let publicity = {
				publicity: NoData, //公布人员id列表
				concealment: [] //未公布人员id列表
			};
			this.$axios('post', '/api/per/package/edit_publicity', { id: this.asstabParams.package_id, publicity: JSON.stringify(publicity) }).then(res => {
				this.$message.success('操作成功');
				this.assDelList();
			});
		},
		// 更多
		handleCommand(val) {
			switch (val) {
				case 'a': //等级配置
					this.$router.push({
						path: '/classDtail',
						query: {
							packageName: this.packageName,
							packageId: this.asstabParams.package_id,
							employee_list: JSON.stringify(this.employee_list)
						}
					});
					break;
				case 'b': //公式结果
					this.isResult = true;
					break;
				case 'c': //导出明细
					this.$axios('post', '/api/per/user/download_token').then(res => {
					  let token=res.data.data.token
					  let url = `${this.$serverdomain}/api/download/export/detail?package_id=${this.asstabParams.package_id}&token=${token}`;
					  window.open(url, '_blank');
					});
					break;
				case 'd': //导出结果
					this.$axios('post', '/api/per/user/download_token').then(res => {
					  let token=res.data.data.token
					  let url = `${this.$serverdomain}/api/download/export/result?package_id=${this.asstabParams.package_id}&token=${token}`;
					  window.open(url, '_blank');
					});
					break;
				case 'g': //管理
					this.isManagement = true;
					break;
				case 'h': //归档
					this.pigeonhole();
					break;
				case 'y': //批量修改目标值
					this.$router.push({ path: '/updateTarget', query: { packageId: this.asstabParams.package_id, packageName: this.packageName, index: '2' } });
					break;
				case 'j': //批量修改目标值
					this.$router.push({ path: '/updateTarget', query: { packageId: this.asstabParams.package_id, packageName: this.packageName, index: '1' } });
					break;
			}
		},
		// 归档
		pigeonhole() {
			this.$confirm('为保证统计数据一致且正确，归档操作不可撤销，归档后不能再修改考核内容，请确认考核信息无误后再归档。', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					this.$axios('post', '/api/per/package/change_finish', { package_id: this.asstabParams.package_id }).then(res => {
						this.$message.success('操作成功');
						this.getInitData(this.asstabParams.package_id);
					});
				})
				.catch(() => {});
		},
		isSelectable(row, index) {
			this.nowass = row.all_exec_over ? true : false;
			if (row.all_exec_over) {
				return false;
			} else {
				return true;
			}
		},
		//开始评分
		startisChecks() {
			this.isChecks = true;
		},
		// 页面变更
		handleCurrentChange(val) {
			this.asstabParams.page = val;
			this.assDelList();
		},
		// 页面跳转
		handleSizeChange(val) {
			this.asstabParams.page_size = val;
			this.assDelList();
		},
		getInitData(id, fun = function() {}) {
			this.isLoad = true;
			this.$axios('get', '/api/per/package/info_v3_aid', { package_id: id })
				.then(res => {
					let groups = res.data.data.groups;
					this.all_finish = res.data.data.all_finish;
					this.all_process_done = res.data.data.all_process_done;employees
					let employees = res.data.data.employees;
					this.dropdownMenu.forEach((item, index) => {
						if (item.key == 'h' && !this.all_finish && this.all_process_done) {
							if (this.all_finish) {
								this.$set(this.dropdownMenu[index], 'isShow', false);
							} else {
								var isTrue = employees.every((x)=>{
									return x.publicity == 1;
								});
								if(this.$isAuthoritys(this.$3)&&isTrue){
									this.$set(this.dropdownMenu[index], 'isShow', true);
								}
							}
						}
					});
					groups.forEach(item => {
						item.check = false;
						if (item.all_exec_over) {
							item.disabled = true;
						}
					});
					this.groupOptions = groups; //考核表下拉
					this.scoreGroup = groups; //评分考核表
					this.GroupList = groups; //考核表搜索
					// 公式结果数据
					// let employees = res.data.data.employees;
					let employee_list = [];
					let employee = [];
					employees.forEach(item => {
						employee_list.push(this.$getEmployeeList()[item.id]);
						if (item.publicity) {
							employee.push(this.$getEmployeeList()[item.id]);
						}
					});
					this.employee_list = employee_list;
					this.selected.employee = employee;
					this.employees = employees;
					// // 设置各节点数量
					// let statistics=res.data.data.statistics;
					// let navigationList=JSON.parse(JSON.stringify(this.navigationList));
					// let sum=0;
					// navigationList.forEach(item=>{
					//   item.num=statistics[item.id]
					//   if(item.id!=0){
					//      sum+=statistics[item.id]
					//   }
					// })
					// navigationList[0].num=sum;
					// this.navigationList=navigationList;
					fun();
				})
				.finally(() => {
					this.isLoad = false;
				});
		},
		assDelList() {
			this.assDetLoad = true;
			this.$axios('get', '/api/per/package/info_v3', this.asstabParams)
				.then(res => {
					if (res.data.code == 1) {
						let list = res.data.data.list || [];
						list.forEach(item => {
							let user = this.$getEmployeeList()[item.employee_id];
							item.dept_list = user.dept_list;
							item.name = user.name;
							item.img_url = user.img_url;
							if (item.doing_id == 11 && item.publicity == 1 && this.isAdmin) {
								//考核是否已完成 11-是 0-否         是否公布 1-公布 0-不公布    是否管理员
								item.theResultsOf_But = true;
							}
							if (item.todo.length > 0) {
								item.todo.forEach(e => {
									e.userInfo = this.$getEmployeeList()[e.employee_id];
								});
							}
						});
						this.asstabData = list;
						this.total = res.data.data.total;
					}
				})
				.finally(() => {
					this.assDetLoad = false;
				});
		},
		groupChange(data) {
			//考核表选中
			this.asstabParams.page = 1;
			if (data) {
				this.asstabParams.group_ids = JSON.stringify([data]);
			} else {
				this.asstabParams.group_ids = JSON.stringify([]);
			}
			this.assDelList();
		},
		beginGrade() {
			let multipleSelection = [];
			let employeeMap = this.$getEmployeeList();
			this.scoreGroup.forEach(item => {
				if (item.check) {
					multipleSelection.push(item.id);
				}
			});
			//开始评分按钮
			if (multipleSelection.length == 0) {
				this.$message.warning('请选择开始评分的考核表');
				return;
			}
			this.$confirm('所选考核表员工的绩效考核将自动进入评分流程，确认开始评分?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消'
			})
				.then(() => {
					let data = {};
					let group = [];
					data.package_id = this.asstabParams.package_id; //绩效包ID
					data.group_ids = JSON.stringify(multipleSelection); //考核表列表
					data.single = 0; //非单人
					this.$axios('post', '/api/per/package/start_score', data).then(res => {
						if (res.data.code == 1) {
							if (!res.data.data.result) {
								let list = res.data.data.list;
								list.forEach(item => {
									item.successText = item.success ? '成功' : '失败';
									item.name = employeeMap[item.employee_id].name;
									item.reason = item.success ? '已开始评分' : item.reason;
								});
								this.showData = list;
								this.isShowData = true;
							} else {
								this.$message.success(res.data.msg);
							}
							this.isChecks = false;
							this.assDelList(); //请求绩效详情列表
						}
					});
				})
				.catch(() => {});
		},
		assessTree(id, id2) {
			//请求绩效树
			this.assDetLoad = true;
			this.$axios('get', '/api/per/package/list', { page: 0, is_manage_scope: 1 }).then(res => {
				if (res.data.code == 1) {
					// let data=res.data.data;
					let data = res.data.data.list;
					let arr = [
						{ name: '月度', id: 2, list: [] },
						{ name: '日', id: 1, list: [] },
						{ name: '季度', id: 3, list: [] },
						{ name: '半年度', id: 4, list: [] },
						{ name: '年度', id: 5, list: [] },
						{ name: '自定义', id: 6, list: [] }
					];
					data.forEach(item => {
						arr.forEach(item2 => {
							if (item2.id == item.cycle_type) {
								item2.list.push(item);
							}
						});
					});
					this.options = arr;
					this.headValue.push(id, id2);
				}
			});
		},
		navClick(item) {
			this.navcli = item.id;
			this.asstabParams.page = 1;
			this.asstabParams.doing_id = item.id;
			this.getDcl();
			this.assDelList();
		},
		dept_confirm(data) {
			//部门选择
			this.dept_selected = { dept: [], employee: [] };
			this.deptList_id = [];
			this.deptVisibleName = '';
			if (data.dept !== null && data.dept.length != 0) {
				this.dept_selected = data;
				data.dept.forEach((element, index) => {
					this.deptList_id.push(element.dept_id);
					this.deptVisibleName += element.dept_name;
					if (data.dept.length - index > 1) {
						this.deptVisibleName += ',';
					}
				});
			}
			this.asstabParams.page = 1;
			this.asstabParams.dept_ids = JSON.stringify(this.deptList_id);
			this.assDelList();
		},
		assDetClick(row) {
			//列表点击
			this.$router.push({
				path: '/staffAssDet',
				query: { assID: this.asstabParams.package_id, employeeID: row.id, employeeIDs: row.employee_id }
			});
		},
		braSearch(data) {
			//评分搜索
			this.scoreGroup = this.GroupList.filter(item => item.name.includes(data));
		}
	},
	beforeRouteLeave(to, from, next) {
		if (to.name != 'staffAssDet') {
			localStorage.removeItem('assessDetails');
		}
		next();
	}
};
</script>
<style scoped lang="scss">
.guidang {
	margin-left: 20px;
	width: 70px;
	animation: example 1s;
}
@keyframes example {
	from {
		transform: scale(1.4);
	}
	to {
		transform: scale(1);
	}
}
.flex-box-ce2 {
	display: flex;
	align-items: center;
	-webkit-align-items: center;
	-webkit-box-align: center;
}
.all {
	position: relative;
	font-size: 14px;
	background-color: #fff;
	padding: 20px;
}
.navsvg1 {
	font-size: 15px;
	position: relative;
	margin-top: 2px;
}
.navsvg2 {
	width: 4px;
	height: 20px;
	background-color: #e1e1e1;
	margin: 0 20px;
}
.navsvg3 {
	margin: 0px 20px;
	color: #e1e1e1;
	display: block;
	font-size: 18px;
}
header {
	margin-top: 25px;
	.dept_wdiv {
		width: 120px;
		position: relative;
		.dept_inp {
			position: absolute;
			top: 0;
			right: 0;
			left: 0;
			bottom: 0;
			z-index: 9;
			border: 1px solid #e0e0e0;
			border-radius: 3px;
			line-height: 40px;
			font-size: 14px;
			padding: 0 10px;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			cursor: pointer;
			color: #676767;
		}
		svg {
			position: absolute;
			top: 14px;
			right: 10px;
			font-size: 14px;
			color: #b5b5b5;
		}
	}
	.navigationL {
		width: 100%;
		height: 50px;
		margin: 15px 0px 15px 0;
		span {
			display: flex;
			cursor: pointer;
			font-size: 14px;
			padding: 10px 20px;
			position: relative;
			width: 100%;
			border: 1px solid #e1e1e1;
			border-radius: 3px;
			justify-content: center;
			color: #303133;
			background-color: #f5f7fa;
		}
		span:hover {
			color: #428eff;
			border: 1px solid #26a2ff;
			background-color: #ecf5ff;
		}
		::v-deep .action {
			color: #428eff;
			border: 1px solid #26a2ff;
			background-color: #ecf5ff;
		}
	}

	::v-deep .el-table tr:hover {
		cursor: pointer;
	}
}

.braTab {
	padding: 20px 0 0 20px;
	::v-deep .el-table tr:hover {
		cursor: pointer;
	}
	::v-deep .el-table__row {
		.cell {
			padding-left: 10px;
		}
	}
	::v-deep td .cell {
		padding: 10px 0;
	}
}
.margin-l {
	margin-left: 10px;
}
.width-300 {
	width: 300px;
}
.m-content {
}
.m-title {
	color: #909399;
}
.ul {
	margin: 20px 0;
	margin-top: 0;
}
.li {
	border-bottom: 1px solid #ebebeb;
}
.li .flex-box-ce {
	padding: 15px 0;
}
.li:hover {
	background-color: #f5f7fa;
}
</style>
