<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="计划名称" prop="TrainName">
				<el-input v-model="queryParams.TrainName" placeholder="请输入计划名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="培训类别" prop="ZcsZhuanYe">
				<el-select v-model="queryParams.ZcsZhuanYe" placeholder="请选择培训类别" clearable>
					<el-option v-for="dict in dict.type.jxjy_zhuanye" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="年" prop="QiciYear">
				<el-input v-model="queryParams.QiciYear" placeholder="请输入年" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="期次" prop="QiCi">
				<el-input v-model="queryParams.QiCi" placeholder="请输入期次" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="学时" prop="XueShi">
				<el-input v-model="queryParams.XueShi" placeholder="请输入学时" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="培训开始时间" prop="StartDate">
				<el-date-picker clearable v-model="queryParams.StartDate" type="date" value-format="yyyy-MM-dd"
					placeholder="请选择培训开始时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="培训结束时间" prop="EndDate">
				<el-date-picker clearable v-model="queryParams.EndDate" type="date" value-format="yyyy-MM-dd"
					placeholder="请选择培训结束时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="报名人数" prop="BmNum">
				<el-input v-model="queryParams.BmNum" placeholder="请输入报名人数" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="报名最大人数" prop="BmNumMax">
				<el-input v-model="queryParams.BmNumMax" placeholder="请输入报名最大人数" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="通知审核 0未审核  1审核" prop="ShenHe">
				<el-select v-model="queryParams.ShenHe" placeholder="请选择通知审核 0未审核  1审核" clearable>
					<el-option v-for="dict in dict.type.jxjy_shenhe" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="添加时间" prop="AddDate">
				<el-date-picker clearable v-model="queryParams.AddDate" type="date" value-format="yyyy-MM-dd"
					placeholder="请选择添加时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="每学时多少分钟" prop="Minute">
				<el-input v-model="queryParams.Minute" placeholder="请输入每学时多少分钟" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="缴费金额" prop="money">
				<el-input v-model="queryParams.money" placeholder="请输入缴费金额" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="选课名称" prop="className">
				<el-input v-model="queryParams.className" placeholder="请输入选课名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="考试名称" prop="ksName">
				<el-input v-model="queryParams.ksName" placeholder="请输入考试名称" clearable
					@keyup.enter.native="handleQuery" />
			</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="['zgks:ZigeTraining: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="['zgks:ZigeTraining: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="['zgks:ZigeTraining: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="['zgks:ZigeTraining:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ZigeTrainingList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="期次" align="center" prop="QiCi" />
			<el-table-column label="培训类别" align="center" prop="ZcsZhuanYe">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.jxjy_zhuanye" :value="scope.row.ZcsZhuanYe" />
				</template>
			</el-table-column>
			<el-table-column label="培训计划名称" align="center" prop="TrainName" />
			<el-table-column label="培训开始时间" align="center" prop="StartDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.StartDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="培训结束时间" align="center" prop="EndDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.EndDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="报名截止时间" align="center" prop="BmEndDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.BmEndDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="地点" align="center" prop="dishi" />
			<el-table-column label="报名人数" align="center" prop="BmNum" />
			<el-table-column label="报名最大人数" align="center" prop="BmNumMax" />
			<el-table-column label="通知审核 0未审核  1审核" align="center" prop="ShenHe">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.jxjy_shenhe" :value="scope.row.ShenHe" />
				</template>
			</el-table-column>
			<el-table-column label="添加时间" align="center" prop="AddDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.AddDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="备注" align="center" prop="BeiZhu" />
			<el-table-column label="通知附件" align="center" prop="TongZhi" />
			<el-table-column label="每学时多少分钟" align="center" prop="Minute" />
			<el-table-column label="选课1" align="center" prop="Undef1" />
			<el-table-column label="考试名称1" align="center" prop="Undef2" />
			<el-table-column label="缴费金额" align="center" prop="Undef3" />
			<el-table-column label="缴费金额" align="center" prop="money" />
			<el-table-column label="选课名称" align="center" prop="className" />
			<el-table-column label="考试名称" align="center" prop="ksName" />
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['zgks:ZigeTraining:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['zgks:ZigeTraining: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="500px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<el-form-item label="类别id字典  监理工程师 监理员" prop="ZYIdList">
					<el-input v-model="form.ZYIdList" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="计划名称" prop="TrainName">
					<el-input v-model="form.TrainName" placeholder="请输入计划名称" />
				</el-form-item>
				<el-form-item label="培训类别" prop="ZcsZhuanYe">
					<el-select v-model="form.ZcsZhuanYe" placeholder="请选择培训类别">
						<el-option v-for="dict in dict.type.jxjy_zhuanye" :key="dict.value" :label="dict.label"
							:value="dict.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="年" prop="QiciYear">
					<el-input v-model="form.QiciYear" placeholder="请输入年" />
				</el-form-item>
				<el-form-item label="期次" prop="QiCi">
					<el-input v-model="form.QiCi" placeholder="请输入期次" />
				</el-form-item>
				<el-form-item label="学时" prop="XueShi">
					<el-input v-model="form.XueShi" placeholder="请输入学时" />
				</el-form-item>
				<el-form-item label="培训开始时间" prop="StartDate">
					<el-date-picker clearable v-model="form.StartDate" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择培训开始时间">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="培训结束时间" prop="EndDate">
					<el-date-picker clearable v-model="form.EndDate" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择培训结束时间">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="地点" prop="dishi">
					<el-input v-model="form.dishi" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="报名人数" prop="BmNum">
					<el-input v-model="form.BmNum" placeholder="请输入报名人数" />
				</el-form-item>
				<el-form-item label="报名最大人数" prop="BmNumMax">
					<el-input v-model="form.BmNumMax" placeholder="请输入报名最大人数" />
				</el-form-item>
				<el-form-item label="通知审核 0未审核  1审核" prop="ShenHe">
					<el-select v-model="form.ShenHe" placeholder="请选择通知审核 0未审核  1审核">
						<el-option v-for="dict in dict.type.jxjy_shenhe" :key="dict.value" :label="dict.label"
							:value="dict.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="添加时间" prop="AddDate">
					<el-date-picker clearable v-model="form.AddDate" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择添加时间">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="备注" prop="BeiZhu">
					<el-input v-model="form.BeiZhu" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="通知附件" prop="TongZhi">
					<el-input v-model="form.TongZhi" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="每学时多少分钟" prop="Minute">
					<el-input v-model="form.Minute" placeholder="请输入每学时多少分钟" />
				</el-form-item>
				<el-form-item label="选课1" prop="Undef1">
					<el-input v-model="form.Undef1" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="考试名称1" prop="Undef2">
					<el-input v-model="form.Undef2" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="缴费金额" prop="Undef3">
					<el-input v-model="form.Undef3" type="textarea" placeholder="请输入内容" />
				</el-form-item>
				<el-form-item label="缴费金额" prop="money">
					<el-input v-model="form.money" placeholder="请输入缴费金额" />
				</el-form-item>
				<el-form-item label="选课名称" prop="className">
					<el-input v-model="form.className" placeholder="请输入选课名称" />
				</el-form-item>
				<el-form-item label="考试名称" prop="ksName">
					<el-input v-model="form.ksName" 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 {
		listZigeTraining,
		getZigeTraining,
		delZigeTraining,
		addZigeTraining,
		updateZigeTraining
	} from "@/api/xiehui/zgks/ZigeTraining";

	export default {
		name: "ZigeTraining",
		dicts: ['jxjy_shenhe', 'jxjy_zhuanye'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 资格考试培训计划表格数据
				ZigeTrainingList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					TID: null,
					ECId: null,
					ClassIdList: null,
					ZYIdList: null,
					TrainName: null,
					ZcsZhuanYe: null,
					ZhuanYeType: null,
					QiciYear: null,
					QiCi: null,
					XueShi: null,
					StartDate: null,
					EndDate: null,
					TContent: null,
					BmEndDate: null,
					dishi: null,
					BmNum: null,
					BmNumMax: null,
					Bzq: null,
					OverFlg: null,
					ShenHe: null,
					AddDate: null,
					BeiZhu: null,
					TongZhi: null,
					Minute: null,
					Undef1: null,
					Undef2: null,
					Undef3: null,
					Undef4: null,
					Undef5: null,
					money: null,
					className: null,
					ksName: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询资格考试培训计划列表 */
			getList() {
				this.loading = true;
				listZigeTraining(this.queryParams).then(response => {
					this.ZigeTrainingList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					TrainName: "啊实打实大所多sad",
					TrainId: null,
					TID: null,
					ECId: null,
					ClassIdList: null,
					ZYIdList: null,
					TrainName: null,
					ZcsZhuanYe: null,
					ZhuanYeType: null,
					QiciYear: null,
					QiCi: null,
					XueShi: null,
					StartDate: null,
					EndDate: null,
					TContent: null,
					BmEndDate: null,
					dishi: null,
					BmNum: null,
					BmNumMax: null,
					Bzq: null,
					OverFlg: null,
					ShenHe: null,
					AddDate: null,
					BeiZhu: null,
					TongZhi: null,
					Minute: null,
					Undef1: null,
					Undef2: null,
					Undef3: null,
					Undef4: null,
					Undef5: null,
					money: null,
					className: null,
					ksName: 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.TrainId)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加资格考试培训计划";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const TrainId = row.TrainId || this.ids
				getZigeTraining(TrainId).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改资格考试培训计划";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.TrainId != null) {
							updateZigeTraining(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addZigeTraining(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const TrainIds = row.TrainId || this.ids;
				this.$modal.confirm('是否确认删除资格考试培训计划编号为"' + TrainIds + '"的数据项？').then(function() {
					return delZigeTraining(TrainIds);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('zgks/ZigeTraining/export', {
					...this.queryParams
				}, `ZigeTraining_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>