<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small"  :inline="true" v-show="showSearch" label-width="140px">
			<el-form-item label="姓名" prop="username">
				<el-input v-model="queryParams.username" placeholder="请输入姓名" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="身份证" prop="usercord">
				<el-input v-model="queryParams.usercord" placeholder="请输入身份证" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="企业名称" prop="newdeptname">
				<el-input v-model="queryParams.newdeptname" placeholder="请输入企业名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="审核状态" prop="glyshenhe" >
				<el-select v-model="queryParams.glyshenhe" placeholder="请选择审核状态" clearable>
					<el-option label="已审核" value="1" />
					<el-option label="未审核" value="0" />
					<el-option label="不通过" value="2" />
					<el-option label="已完成" value="3" />
					<el-option label="未完成" value="4" />
					<el-option label="已撤回" value="5" />
				</el-select>
			</el-form-item>
			<el-form-item label="监理委员会审核日期" prop="time" >
				<el-date-picker v-model="queryParams.time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" @change="changeTime"></el-date-picker>
			</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:qyBiangeng: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:qyBiangeng: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:qyBiangeng:remove']">删除</el-button>
			</el-col> -->
			<el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-edit" size="mini" @click="piliangShenhe" :disabled="multiple" >批量通过</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" >导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table style="font-size: 12px;" v-loading="loading" :data="qyBiangengList" @selection-change="handleSelectionChange" :selectable="selectable"> 
			<el-table-column  align="center" type="selection" :selectable="selectable" />
			<el-table-column label="序号" align="center" type="index" :index="indexMethod">
			</el-table-column>
			<el-table-column label="姓名" align="center" prop="username" />
			<el-table-column label="身份证" width="160" align="center" prop="usercord" />
			<el-table-column label="转入单位" width="200" align="center" prop="newdeptname" />
			<el-table-column label="转入申请表" width="90" align="center" prop="zhuanruImg">
				<template slot-scope="scope">
					<ImagePreview :src="scope.row.zhuanruImg" width="30px" height="30px"></ImagePreview>
				</template>
			</el-table-column>
			<el-table-column label="转入申请日期" align="center" width="120" prop="addtime" /> 
			<el-table-column label="转出单位" width="200" align="center" prop="olddeptname" /> 
			<el-table-column label="转出申请表" width="90" align="center" prop="zhuanchuImg">
				<template slot-scope="scope">
					<ImagePreview :src="scope.row.zhuanchuImg" width="30px" height="30px"></ImagePreview>
				</template>
			</el-table-column>
			<el-table-column label="原单位审核" align="center" width="160" prop="oldshenhe">
				<template slot-scope="scope">
					<el-tag type="success" v-if="scope.row.oldshenhe == '1'">审核通过</el-tag> 
					<el-popover v-else-if="scope.row.oldshenhe == '2'" placement="left"  width="200" trigger="hover" >
						<template slot="reference">
							<el-tag type="danger">不通过(原因)</el-tag>
						</template> 
						<div v-html="scope.row.oldshyj"></div>
					</el-popover>
					<el-tag v-else-if="scope.row.oldshenhe == '3'">已查看</el-tag>
					<el-tag type="warning"
						v-else-if="scope.row.oldshenhe == '4' && (scope.row.zhuanchusqbtime == '' || scope.row.zhuanchusqbtime == null)">审核通过，请上传申请表</el-tag>
					<el-tag type="warning"
						v-else-if="scope.row.oldshenhe == '4' && scope.row.zhuanchusqbtime != ''">等待提交转出申请表</el-tag>
					<el-tag v-else type="info">未查看</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="转出同意日期" align="center" width="100" prop="oldshtime" />
			<el-table-column label="监理委员会审核" align="center" prop="glyshenhe" width="120">
				<template slot-scope="scope">
					<!-- <dict-tag :options="dict.type.jxjy_shsftg" :value="scope.row.glyshenhe" /> -->
					<el-tag type="success" v-if="scope.row.glyshenhe == 1">审核通过</el-tag>
					<el-popover v-else-if="scope.row.glyshenhe == 2" placement="left"  width="200" trigger="hover" >
						<template slot="reference">
							<el-tag type="danger">不通过(原因)</el-tag>
						</template> 
						<div v-html="scope.row.glyshyj"></div>
					</el-popover>
				</template>
			</el-table-column>
			<el-table-column label="监理委员会审核日期" width="100" align="center" prop="glyshtime" /> 
			<el-table-column label="是否完成变更" align="center" prop="bgflg">
				<template slot-scope="scope">
					<el-tag type="success" v-if="scope.row.bgflg == 1">完成</el-tag>
					<el-tag type="danger" v-if="scope.row.bgflg == 2">撤回</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="完成变更日期" width="100" align="center" prop="bgtime" >
				<template slot-scope="scope">
					{{parseTime(scope.row.bgtime,"{y}-{m}-{d}")}}
				</template>
			</el-table-column>
			<el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width" width="120">
				<template slot-scope="scope">
					<el-button v-if="scope.row.oldshenhe == 1 && scope.row.glyshtime == null" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">审 核</el-button>
					<el-button v-else-if="scope.row.glyshenhe == 1 && scope.row.bgflg != 1 && scope.row.bgflg != 2" size="mini" type="text" icon="el-icon-edit" @click="biangeng(scope.row)">变 更</el-button>
					<el-button v-else-if="scope.row.bgflg == 1 " size="mini" type="text" icon="el-icon-edit" @click="chehui(scope.row)">撤 回</el-button>
					<el-button size="mini" type="text" icon="el-icon-view" @click="handleUpdate(scope.row)">查 看</el-button>
					<!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['jlry:qyBiangeng:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['jlry:qyBiangeng: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 :visible.sync="addShow" top="2vh" width="1200px" append-to-body>
			<div style="height:80vh;overflow-y: auto;" v-if="addShow">
				<bgForm ref="bgForm" :id="bgId" @success="guanbi"></bgForm>
			</div> 
		</el-dialog>
	</div>
</template>

<script>
	import {
		searchXiehui,
		getQyBiangeng,
		delQyBiangeng,
		addQyBiangeng,
		updateQyBiangeng,
		xiehuiBiangeng,
		xiehuiChehui,
		xiehuiPiliangShenhe
	} from "@/api/xiehui/jlrybg/qyBiangeng";
	import bgForm from "../../components/jlrybg/bgForm.vue"
	export default {
		name: "QyBiangeng",
		dicts: ['jxjy_shsftg', 'jxjy_bgsfcg'],
		components:{
			bgForm
		},
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 企业变更表格数据
				qyBiangengList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					username: null,
					params:{
						beginTime:null,
						endTime:null,
					},
					usercord: null,
					time:null, 
					newdeptname:null, 
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {},
				addShow:false,
				bgId:null,
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询企业变更列表 */
			getList() {
				this.loading = true;
				searchXiehui(this.queryParams).then(response => {
					this.qyBiangengList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					username: null,
					usercord: null,
					zhengshu: null,
					newdeptid: null,
					newdeptname: null,
					newphone: null,
					olddeptid: null,
					olddeptname: null,
					oldphone: null,
					zhuanruImg: null,
					zhuanchuImg: null,
					zhuanchusqbtime: null,
					gcszh: null,
					zjzh: null,
					jlyzh: null,
					addtime: null,
					newgt: null,
					oldgt: null,
					oldshenhe: null,
					oldshtime: null,
					oldshyj: null,
					glyshenhe: null,
					glyshtime: null,
					glyshyj: null,
					bgflg: null,
					bgtime: null,
					wgflg: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.queryParams.params.beginTime = null
				this.queryParams.params.endTime = null
				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.bgId = row.id
				this.addShow = true
				// getQyBiangeng(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) {
							updateQyBiangeng(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addQyBiangeng(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 delQyBiangeng(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('jlry/qyBiangeng/export', {
					...this.queryParams
				}, `qyBiangeng_${new Date().getTime()}.xlsx`)
			},
			//计算索引
			indexMethod(index) {
				return ((this.queryParams.pageNum - 1) * this.queryParams.pageSize) + (index + 1)
			},
			guanbi(){
				this.addShow = false
				this.getList()
			},
			biangeng(row){
				this.$confirm('是否进行变更?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					xiehuiBiangeng({id:row.id}).then(res=>{
						this.$message({
							type:"success",
							message:"变更成功"
						})
						this.getList()
					})
				}).catch(() => {
				         
				});
			},
			//撤回变更申请
			chehui(row){
				this.$confirm('是否撤回变更?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					xiehuiChehui({id:row.id}).then(res=>{
						this.$message({
							type:"success",
							message:"撤回成功"
						})
						this.getList()
					})
				}).catch(() => {
				         
				});
			},
			changeTime(e){ 
				if(e != null){
					this.queryParams.params.beginTime = e[0]
					this.queryParams.params.endTime = e[1]
				}else{
					this.queryParams.params.beginTime = null
					this.queryParams.params.endTime = null
				}
			},
			selectable(row){ 
				return row.oldshenhe === 1 && row.glyshenhe != 1
			},
			piliangShenhe(){
				this.$confirm('是否批量通过审核?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let id = this.ids.join(",")
					xiehuiPiliangShenhe({ids:id}).then(res=>{
						this.$message({
							type:"success",
							message:"审核成功"
						})
						this.getList()
					})
				}).catch(() => {
				         
				});
			}
		}
	};
</script>