<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="100px">
			<el-form-item label="姓名：" prop="Name">
				<el-input v-model="queryParams.Name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="身份证：" prop="ShenFenZheng">
				<el-input v-model="queryParams.ShenFenZheng" placeholder="请输入身份证" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="证书编号：" prop="JLZhengHaoNum">
				<el-input v-model="queryParams.JLZhengHaoNum" placeholder="请输入证书编号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="报名审核：" prop="isJxjyShenheFlg">
				<el-select v-model="queryParams.isJxjyShenheFlg" placeholder="请选择" clearable>
					<el-option v-for="dict in dict.type.jxjy_sfkyjxjy" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- <el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
					v-hasPermi="['jlry:RenCai:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
					v-hasPermi="['jlry:RenCai:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
					@click="handleDelete" v-hasPermi="['jlry:RenCai:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
					v-hasPermi="['jlry:RenCai:export']">导出</el-button>
			</el-col> -->
			<el-col :span="1.5">
				<el-button type="primary" plain :disabled="ids.length>0?false:true"  size="mini" @click="piliang(1)"
					>报名审核</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain :disabled="ids.length>0?false:true"  size="mini" @click="piliang(0)" >取消报名</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="RenCaiList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="姓名" align="center" prop="Name" />
			<el-table-column label="性别" align="center" prop="Sex" />
			<el-table-column label="身份证" align="center" prop="ShenFenZheng" />
			<el-table-column label="职称" align="center" prop="ZhiCheng" />
			<el-table-column label="证书编号" align="center" prop="JLZhengHaoNum" />
			<el-table-column label="有效期至" align="center" prop="JLYxqz" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.JLYxqz, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="证书状态 " align="center" prop="JLYxqz">
				<template slot-scope="scope">
					<span>{{scope.row.zsFlag == 2?'不可参加继续教育':scope.row.zsFlag == 0?'已过期，可参加继续教育':'可参加继续教育'}}</span>
				</template>
			</el-table-column>
			<el-table-column label="报名审核状态" align="center" prop="isJxjyShenheFlg">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.jxjy_sfkyjxjy" :value="scope.row.isJxjyShenheFlg" />
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button type="text" style="color: #F56C6C;"  @click="qvxiaoBm(scope.row)" v-if="scope.row.isJxjyShenheFlg == 1 ">取消审核</el-button>
					<el-button type="text"  @click="baoming(scope.row)" v-else>报名审核</el-button>
					<!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['jlry:RenCai:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['jlry:RenCai:remove']">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />

		<!-- 添加或修改监理人才管理对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<el-form-item label="单位ID" prop="DeptID">
					<el-input v-model="form.DeptID" placeholder="请输入单位ID" />
				</el-form-item>
				<el-form-item label="单位名称" prop="Dept">
					<el-input v-model="form.Dept" placeholder="请输入单位名称" />
				</el-form-item>
				<el-form-item label="姓名" prop="Name">
					<el-input v-model="form.Name" placeholder="请输入姓名" />
				</el-form-item>
				<el-form-item label="身份证" prop="ShenFenZheng">
					<el-input v-model="form.ShenFenZheng" placeholder="请输入身份证" />
				</el-form-item>
				<el-form-item label="监理员证书号" prop="JLYZhengHao">
					<el-input v-model="form.JLYZhengHao" placeholder="请输入监理员证书号" />
				</el-form-item>
				<el-form-item label="监理员证号" prop="JLYZhengHaoNum">
					<el-input v-model="form.JLYZhengHaoNum" placeholder="请输入监理员证号" />
				</el-form-item>
				<el-form-item label="监理员发证日期" prop="JLYfzrq">
					<el-date-picker clearable v-model="form.JLYfzrq" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择监理员发证日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="监理工程师证书号" prop="JLZhengHao">
					<el-input v-model="form.JLZhengHao" placeholder="请输入监理工程师证书号" />
				</el-form-item>
				<el-form-item label="监理工程师证书号(纯数字)" prop="JLZhengHaoNum">
					<el-input v-model="form.JLZhengHaoNum" placeholder="请输入监理工程师证书号(纯数字)" />
				</el-form-item>
				<el-form-item label="监理工程师证书发证日期" prop="JLfzrq">
					<el-date-picker clearable v-model="form.JLfzrq" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择监理工程师证书发证日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="监理工程师证书有效期至" prop="JLYxqz">
					<el-date-picker clearable v-model="form.JLYxqz" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择监理工程师证书有效期至">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="总监证书号" prop="ZJZhengHao">
					<el-input v-model="form.ZJZhengHao" placeholder="请输入总监证书号" />
				</el-form-item>
				<el-form-item label="总监发证日期" prop="ZJfzrq">
					<el-date-picker clearable v-model="form.ZJfzrq" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择总监发证日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="建设部证书号" prop="JSBZhengHao">
					<el-input v-model="form.JSBZhengHao" placeholder="请输入建设部证书号" />
				</el-form-item>
				<el-form-item label="建设部发证日期" prop="JSBfzrq">
					<el-date-picker clearable v-model="form.JSBfzrq" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择建设部发证日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="生日" prop="Birthday">
					<el-input v-model="form.Birthday" placeholder="请输入生日" />
				</el-form-item>
				<el-form-item label="学历" prop="XueLi">
					<el-input v-model="form.XueLi" placeholder="请输入学历" />
				</el-form-item>
				<el-form-item label="专业" prop="ZhuanYe">
					<el-input v-model="form.ZhuanYe" placeholder="请输入专业" />
				</el-form-item>
				<el-form-item label="职称" prop="ZhiCheng">
					<el-input v-model="form.ZhiCheng" placeholder="请输入职称" />
				</el-form-item>
				<el-form-item label="监理工作年限" prop="NianXian">
					<el-input v-model="form.NianXian" placeholder="请输入监理工作年限" />
				</el-form-item>
				<el-form-item label="联系人" prop="LianXiRen">
					<el-input v-model="form.LianXiRen" placeholder="请输入联系人" />
				</el-form-item>
				<el-form-item label="电话" prop="Tel">
					<el-input v-model="form.Tel" placeholder="请输入电话" />
				</el-form-item>
				<el-form-item label="手机" prop="Phone">
					<el-input v-model="form.Phone" placeholder="请输入手机" />
				</el-form-item>
				<el-form-item label="传真" prop="Fax">
					<el-input v-model="form.Fax" placeholder="请输入传真" />
				</el-form-item>
				<el-form-item label="邮编" prop="PostCode">
					<el-input v-model="form.PostCode" placeholder="请输入邮编" />
				</el-form-item>
				<el-form-item label="地址" prop="Address">
					<el-input v-model="form.Address" placeholder="请输入地址" />
				</el-form-item>
				<el-form-item label="邮件" prop="Email">
					<el-input v-model="form.Email" placeholder="请输入邮件" />
				</el-form-item>
				<el-form-item label="${comment}" prop="wangzhi">
					<el-input v-model="form.wangzhi" placeholder="请输入${comment}" />
				</el-form-item>
				<el-form-item label="处罚" prop="ChuFa">
					<el-input v-model="form.ChuFa" placeholder="请输入处罚" />
				</el-form-item>
				<el-form-item label="处罚时间" prop="ChuFaTime">
					<el-input v-model="form.ChuFaTime" placeholder="请输入处罚时间" />
				</el-form-item>
				<el-form-item label="是否有不良记录" prop="BljlFlg">
					<el-select v-model="form.BljlFlg" placeholder="请选择是否有不良记录">
						<el-option v-for="dict in dict.type.jxjy_bljl" :key="dict.value" :label="dict.label"
							:value="parseInt(dict.value)"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="不良记录编号" prop="BljlBianhao">
					<el-input v-model="form.BljlBianhao" placeholder="请输入不良记录编号" />
				</el-form-item>
				<el-form-item label="不良记录内容">
					<editor v-model="form.BljlContent" :min-height="192" />
				</el-form-item>
				<el-form-item label="不良记录定性" prop="BljlDingxing">
					<el-input v-model="form.BljlDingxing" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="不良记录处理依据及决定" prop="BljlClyj">
					<el-input v-model="form.BljlClyj" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="公布期限开始" prop="BljlGbStart">
					<el-date-picker clearable v-model="form.BljlGbStart" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择公布期限开始">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="公布期限结束" prop="BljlGbEnd">
					<el-date-picker clearable v-model="form.BljlGbEnd" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择公布期限结束">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="${comment}" prop="BeiZhu">
					<el-input v-model="form.BeiZhu" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="监理工程师作废标志,0：作废" prop="ShenHe">
					<el-input v-model="form.ShenHe" placeholder="请输入监理工程师作废标志,0：作废" />
				</el-form-item>
				<el-form-item label="添加日期" prop="SendTime">
					<el-date-picker clearable v-model="form.SendTime" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择添加日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="${comment}" prop="DisplayOrder">
					<el-input v-model="form.DisplayOrder" placeholder="请输入${comment}" />
				</el-form-item>
				<el-form-item label="是否删除" prop="DelFlg">
					<el-input v-model="form.DelFlg" placeholder="请输入是否删除" />
				</el-form-item>
				<el-form-item label="删除时间" prop="DelTime">
					<el-date-picker clearable v-model="form.DelTime" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择删除时间">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="监理员作废标志,1：作废" prop="JLYzfFlg">
					<el-select v-model="form.JLYzfFlg" placeholder="请选择监理员作废标志,1：作废">
						<el-option v-for="dict in dict.type.jxjy_jlyzfbz" :key="dict.value" :label="dict.label"
							:value="parseInt(dict.value)"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="是否可以继续教育审核 1可以报名 0不可报名" prop="isJxjyShenheFlg">
					<el-select v-model="form.isJxjyShenheFlg" placeholder="请选择是否可以继续教育审核 1可以报名 0不可报名">
						<el-option v-for="dict in dict.type.jxjy_sfkyjxjy" :key="dict.value" :label="dict.label"
							:value="parseInt(dict.value)"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="总监作废标志位：1为作废" prop="ZJzfFlg">
					<el-select v-model="form.ZJzfFlg" placeholder="请选择总监作废标志位：1为作废">
						<el-option v-for="dict in dict.type.jxjy_jlgcszfbz" :key="dict.value" :label="dict.label"
							:value="parseInt(dict.value)"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="作废原因" prop="ZfResult">
					<el-input v-model="form.ZfResult" type="textarea" placeholder="请输入内容" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listRenCai,
		getRenCai,
		delRenCai,
		addRenCai,
		updateRenCai
	} from "@/api/xiehui/jlry/RenCai";
	import {
		getPeoList,
		plShenhe
	} from "@/api/qiye/jxjy"
	

	export default {
		name: "RenCai",
		dicts: ['jxjy_sfkyjxjy', 'jxjy_jlgcszfbz', 'jxjy_bljl', 'jxjy_jlyzfbz'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 监理人才管理表格数据
				RenCaiList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					DeptID: null,
					Dept: null,
					Name: null,
					ShenFenZheng: null,
					JLYZhengHao: null,
					JLYZhengHaoNum: null,
					JLYfzrq: null,
					JLZhengHao: null,
					JLZhengHaoNum: null,
					JLfzrq: null,
					JLYxqz: null,
					ZJZhengHao: null,
					ZJfzrq: null,
					JSBZhengHao: null,
					JSBfzrq: null,
					Sex: null,
					Birthday: null,
					XueLi: null,
					ZhuanYe: null,
					ZhiCheng: null,
					NianXian: null,
					LianXiRen: null,
					Tel: null,
					Phone: null,
					Fax: null,
					PostCode: null,
					Address: null,
					Email: null,
					wangzhi: null,
					ChuFa: null,
					ChuFaTime: null,
					BljlFlg: null,
					BljlBianhao: null,
					BljlContent: null,
					BljlDingxing: null,
					BljlClyj: null,
					BljlGbStart: null,
					BljlGbEnd: null,
					BeiZhu: null,
					ShenHe: null,
					SendTime: null,
					DisplayOrder: null,
					DelFlg: null,
					DelTime: null,
					JLYzfFlg: null,
					UpdateTime: null,
					isJxjyShenheFlg: null,
					ZJzfFlg: null,
					ZfResult: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		computed: {
			userInfo() {
				return this.$store.state.user.userInfo;
			}
		},
		created() {
			this.queryParams.DeptID = this.userInfo.deptId || this.userInfo.id
			this.getList();
		},
		methods: {
			/** 查询监理人才管理列表 */
			getList() {
				this.loading = true;
				getPeoList(this.queryParams).then(response => {
					this.RenCaiList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					ID: null,
					DeptID: null,
					Dept: null,
					Name: null,
					ShenFenZheng: null,
					JLYZhengHao: null,
					JLYZhengHaoNum: null,
					JLYfzrq: null,
					JLZhengHao: null,
					JLZhengHaoNum: null,
					JLfzrq: null,
					JLYxqz: null,
					ZJZhengHao: null,
					ZJfzrq: null,
					JSBZhengHao: null,
					JSBfzrq: null,
					Sex: null,
					Birthday: null,
					XueLi: null,
					ZhuanYe: null,
					ZhiCheng: null,
					NianXian: null,
					LianXiRen: null,
					Tel: null,
					Phone: null,
					Fax: null,
					PostCode: null,
					Address: null,
					Email: null,
					wangzhi: null,
					ChuFa: null,
					ChuFaTime: null,
					BljlFlg: null,
					BljlBianhao: null,
					BljlContent: null,
					BljlDingxing: null,
					BljlClyj: null,
					BljlGbStart: null,
					BljlGbEnd: null,
					BeiZhu: null,
					ShenHe: null,
					SendTime: null,
					DisplayOrder: null,
					DelFlg: null,
					DelTime: null,
					JLYzfFlg: null,
					UpdateTime: null,
					isJxjyShenheFlg: null,
					ZJzfFlg: null,
					ZfResult: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.ID)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加监理人才管理";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const ID = row.ID || this.ids
				getRenCai(ID).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改监理人才管理";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.ID != null) {
							updateRenCai(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addRenCai(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const IDs = row.ID || this.ids;
				this.$modal.confirm('是否确认删除监理人才管理编号为"' + IDs + '"的数据项？').then(function() {
					return delRenCai(IDs);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('jlry/RenCai/export', {
					...this.queryParams
				}, `RenCai_${new Date().getTime()}.xlsx`)
			},
			//报名审核 1可以报名 0不可报名
			baoming(row){
				this.reset();
				const ID = row.ID || this.ids
				getRenCai(ID).then(response => {
					this.form = response.data;
					this.$confirm('通过审核后，可报名参加网络继续教育，是否继续？', '提示', {
						confirmButtonText: '确定',
					    cancelButtonText: '取消',
					    type: 'primary'
					}).then(() => {
						  // this.$message({
						  //   type: 'success',
						  //   message: '删除成功!'
						  // });
						  this.form.isJxjyShenheFlg = 1
						updateRenCai(this.form).then(response => {
							this.$modal.msgSuccess("审核成功");
							this.getList();
						});
					}).catch(() => {
						       
					});
				});
				
			},
			//取消报名审核
			qvxiaoBm(row){
				this.reset();
				const ID = row.ID || this.ids
				getRenCai(ID).then(response => {
					this.form = response.data;
					this.$confirm('取消审核后，不能报名参加网络继续教育，是否继续？', '提示', {
						confirmButtonText: '确定',
					    cancelButtonText: '取消',
					    type: 'warning'
					}).then(() => {
						  // this.$message({
						  //   type: 'success',
						  //   message: '删除成功!'
						  // });
						  this.form.isJxjyShenheFlg = 0
						updateRenCai(this.form).then(response => {
							this.$modal.msgSuccess("取消成功");
							this.getList();
						});
					}).catch(() => {
						       
					});
				});
			},
			//批量继续教育
			piliang(type){
				const IDS = this.ids.map(item=>{
					let obj = {
						ID:item,
						isJxjyShenheFlg:type
					}
					return obj
				})
				if(type == 1){
					this.$confirm('您是否要对所选人员审核通过，通过后可参加网络继续教育？', '提示', {
						confirmButtonText: '确定',
					    cancelButtonText: '取消',
					    type: 'warning'
					}).then(() => {
						plShenhe(IDS).then(response => {
							this.$modal.msgSuccess("审核成功");
							this.getList();
						});
					}).catch(() => {
						       
					});
				}else{
					this.$confirm('您是否要对所选人员取消审核，取消后不能报名参加网络继续教育？', '提示', {
						confirmButtonText: '确定',
					    cancelButtonText: '取消',
					    type: 'warning'
					}).then(() => {
						 plShenhe(IDS).then(response => {
						 	this.$modal.msgSuccess("取消成功");
						 	this.getList();
						 });
					}).catch(() => {
						       
					});
				}
			}
		}
	};
</script>