<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="qyname">
				<el-input v-model="queryParams.qyname" placeholder="请输入企业名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<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="负责人姓名" label-width="120px" prop="name">
				<el-input v-model="queryParams.name" 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-table v-loading="loading" :data="QiyeList">
			<el-table-column type="index" label="序号" width="55" align="center" :index="tableIndex" />
			<el-table-column label="企业名称" width="300" align="center" prop="qyname" />
			<el-table-column label="用户名" align="center" prop="username" />
			<el-table-column label="负责人姓名" align="center" prop="name" />
			<el-table-column label="手机号码" align="center" prop="photo" />
			<el-table-column label="电子邮箱" width="180" align="center" prop="lxryx" />
			<!-- <el-table-column label="营业执照" align="center" prop="yyzz">
				<template slot-scope="scope">
					<image-preview :src="scope.row.yyzz" :width="50" :height="40"/>
				</template>
			</el-table-column> -->
			<el-table-column label="变更日期" align="center" prop="RegDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.createTime) }}</span>
				</template>
			</el-table-column>
			<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-view"
						@click="handleUpdate(scope.row)">详细</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="详细" :visible.sync="show" width="1200px">
			<span>
				<el-descriptions class="margin-top" title="基本信息" :column="2" border>
					<el-descriptions-item label="企业名称">
						<div style="width: 400px;"> 
							<div v-if="newInfo.qyname == oldInfo.qyname">{{newInfo.qyname}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.qyname}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.qyname}}
							</div> 
						</div> 
					</el-descriptions-item>
					<el-descriptions-item label="用 户 名"> 
						<div style="width: 400px;"> 
							<div v-if="newInfo.username == oldInfo.username">{{newInfo.username}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.username}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.username}}
							</div> 
						</div>
					</el-descriptions-item>
					<el-descriptions-item label="负责人姓名"> 
						<div style="width: 400px;">
							<div v-if="newInfo.name == oldInfo.name">{{newInfo.name}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.name}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.name}}
							</div> 
						</div>
					</el-descriptions-item>
					<el-descriptions-item label="手机号码"> 
						<div style="width: 400px;"> 
							<div v-if="newInfo.photo == oldInfo.photo">{{newInfo.photo}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.photo}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.photo}}
							</div> 
						</div>
					</el-descriptions-item>
					<el-descriptions-item label="电子邮箱"> 
						<div style="width: 400px;"> 
							<div v-if="newInfo.lxryx == oldInfo.lxryx">{{newInfo.lxryx}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.lxryx}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.lxryx}}
							</div> 
						</div>
					</el-descriptions-item>
					<el-descriptions-item label="邮政编码"> 
						<div style="width: 400px;"> 
							<div v-if="newInfo.YjCode == oldInfo.YjCode">{{newInfo.YjCode}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.YjCode}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.YjCode}}
							</div>  
						</div> 
					</el-descriptions-item>
					<el-descriptions-item label="通讯地址"> 
						<div style="width: 1000px;"> 
							<div v-if="newInfo.kpzcdz == oldInfo.kpzcdz">{{newInfo.kpzcdz}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.kpzcdz}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.kpzcdz}}
							</div> 
						</div>
					</el-descriptions-item>
					<!-- <el-descriptions-item label="营业执照"> 
						<ImagePreview :src="newInfo.yyzz"></ImagePreview> 
					</el-descriptions-item> -->
				</el-descriptions>
				<el-descriptions size="small" class="m-t-20" title="开票信息" :column="2" border>
					<el-descriptions-item label="开票单位"> 
						<div style="width: 400px;"> 
							<div v-if="newInfo.kpdw == oldInfo.kpdw">{{newInfo.kpdw}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.kpdw}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.kpdw}}
							</div> 
						</div>
					</el-descriptions-item>
					<el-descriptions-item label="纳税人识别号"> 
						<div style="width: 400px;"> 
							<div v-if="newInfo.nsrsbh == oldInfo.nsrsbh">{{newInfo.nsrsbh}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.nsrsbh}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.nsrsbh}}
							</div> 
						</div>
					</el-descriptions-item>
					<el-descriptions-item label="电子发票邮箱">
						<div style="width: 1000px;"> 
							<div v-if="newInfo.dzfpyx == oldInfo.dzfpyx">{{newInfo.dzfpyx}}</div>
							<div style="display: flex;align-items: center;" v-else>
								{{oldInfo.dzfpyx}}
								<span style="color:#F56C6C;margin:0 10px">变更为</span>
								{{newInfo.dzfpyx}}
							</div> 
						</div>
					</el-descriptions-item>
				</el-descriptions>
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="show = false">关 闭</el-button> 
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		qyInfoBgList,
		qyBgInfo
	} from "@/api/xiehui/qygl/qiye";

	export default {
		name: "Qiye",
		dicts: ['jxjy_shenhe', 'jxjy_fplx', 'jxjy_kpfs'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 企业账号表格数据
				QiyeList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					qyname: null,
					username: null,
					name: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {},
				show: false,
				oldInfo:{yyzz:null},
				newInfo:{yyzz:null}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询企业账号列表 */
			getList() {
				this.loading = true;
				qyInfoBgList(this.queryParams).then(response => {
					this.QiyeList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					qyname: null,
					username: null,
					password: null,
					name: null,
					photo: null,
					yyzz: null,
					lxryx: null,
					yzbm: null,
					Address: null,
					yjSjr: null,
					yjSjphone: null,
					yjAddress: null,
					yjCode: null,
					shenhe: null,
					RegDate: null,
					wgsz: null,
					kplx: null,
					kpfs: null,
					kpdw: null,
					nsrsbh: null,
					kpzcdz: null,
					kpzcdh: null,
					kpkhyh: null,
					kpyhzh: null,
					dzfpyx: null,
					wgszdate: 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();
			},
			//查询详情
			handleUpdate(row) {
				this.oldInfo = {yyzz:null}
				this.newInfo = {yyzz:null}
				qyBgInfo(row.qyChangeLogId).then(res => {
					this.oldInfo = JSON.parse(res.data.beforeData)
					this.newInfo = JSON.parse(res.data.afterData)
					this.show = true
				})
			},
			tableIndex(index) {
				return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + 1 + index
			}
		}
	};
</script>