<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="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>
				<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 class="m-b-10">
			<el-col span="1.5">
				<el-button type="success" icon="el-icon-plus" size="mini" @click="addBg">新增转入申请</el-button>
			</el-col>
		</el-row>
		<el-table v-loading="loading" :data="qyBiangengList" @selection-change="handleSelectionChange">
			<el-table-column label="序号" align="center" type="index" :index="indexMethod" />
			<el-table-column label="姓名" align="center" prop="username" />
			<el-table-column label="身份证号" align="center" prop="usercord" />
			<el-table-column label="转出单位" align="center" prop="olddeptname" />
			<el-table-column label="申请日期" align="center" prop="addtime" />
			<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="监理委员会员审核" width="120" align="center" prop="glyshenhe">
				<template slot-scope="scope">
					<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>
					<el-tag v-else type="warning">未审核</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" v-if="scope.row.oldshenhe == 4 && (scope.row.zhuanchusqbtime == null || scope.row.zhuanchusqbtime == '')" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">上传申请表</el-button>
					<el-button v-else size="mini" type="text" icon="el-icon-view" @click="handleUpdate(scope.row)"  >查 看</el-button>
					<el-button v-if="scope.row.glyshenhe != '1'" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(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 {
		searchZrsq,
		getQyBiangeng,
		delQyBiangeng,
		addQyBiangeng,
		updateQyBiangeng,
		zhuanruDel
	} 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,
					usercord: null,
					newdeptid: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {},
				//新增弹窗
				addShow: false,
				//变更id
				bgId:null,

			};
		},
		created() {
			this.queryParams.newdeptid = this.$store.getters.userInfo.id
			this.getList();
		},
		methods: {
			/** 查询企业变更列表 */
			getList() {
				this.loading = true;
				searchZrsq(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.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
				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.$modal.confirm(`是否确认删除${row.username}的转入申请？`).then(function() {
					return zhuanruDel(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('jlry/qyBiangeng/export', {
					...this.queryParams
				}, `qyBiangeng_${new Date().getTime()}.xlsx`)
			},
			//提交变更申请
			submitBg() {
				this.$refs.bgForm.submit()
			},
			//关闭变更弹窗
			guanbi() {
				this.addShow = false
				this.getList()
			},
			//计算索引
			indexMethod(index) {
				return ((this.queryParams.pageNum - 1) * this.queryParams.pageSize) + (index + 1)
			},
			//添加变更
			addBg(){
				this.bgId = null
				this.addShow = true
			}
		}
	};
</script>