<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 label="审核状态" 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>
				<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="['qygl:Qiye: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="['qygl:Qiye: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="['qygl:Qiye: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="['qygl:Qiye:export']">导出</el-button>
			</el-col> -->
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="QiyeList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column type="index" width="55" align="center" />
			<el-table-column label="企业名称" 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="联系人邮箱" align="center" prop="lxryx" />
			<el-table-column label="营业执照" align="center" prop="yyzz">
				<template slot-scope="scope">
					<image-preview :src="scope.row.yyzz" :width="50"/>
				</template>
			</el-table-column>
			<el-table-column label="注册日期" align="center" prop="RegDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="状态" 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" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" v-if="scope.row.shenhe == '0'" type="text" style="color:#E6A23C;"  icon="el-icon-edit" @click="handleUpdate(scope.row)"
						>审核</el-button>
						<el-button size="mini" v-else type="text" icon="el-icon-view" @click="handleUpdate(scope.row)"
							>详细</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" style="color: #F56C6C;" @click="handleDelete(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="open" width="60vw" append-to-body>
			<el-form ref="form" :model="form"  :rules="rules" label-width="120px">
				<div>
					<div style="background-color: #eee;font-weight: bold;text-align: center;font-size: 16px;" class="pd-10 m-b-20">
						基本信息
					</div>
					<el-row :gutter="20">
						<el-col :span="12">
							<el-form-item label="企业名称" prop="qyname">
								<el-input v-model="form.qyname" readonly placeholder="请输入企业名称" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="用户名" prop="username">
								<el-input v-model="form.username" readonly placeholder="请输入用户名" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="负责人姓名" prop="name">
								<el-input v-model="form.name" readonly placeholder="请输入内容负责人姓名" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="联系电话" prop="photo">
								<el-input v-model="form.photo" readonly placeholder="请输入电话" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="电子邮箱" prop="lxryx">
								<el-input v-model="form.lxryx" readonly  placeholder="请输入内容" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="邮政编码" prop="yzbm">
								<el-input v-model="form.yzbm" readonly placeholder="请输入邮政编码" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="通讯地址" prop="Address">
								<el-input v-model="form.Address" readonly type="textarea" placeholder="请输入内容" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="营业执照" prop="yyzz">
								<image-preview :src="form.yyzz" :width="50"/>
							</el-form-item>
						</el-col>
					</el-row>
				</div>
				<div>
					<div style="background-color: #eee;font-weight: bold;text-align: center;font-size: 16px;" class="pd-10 m-b-20">
						邮寄信息
					</div>
					<el-row :gutter="20">
						<el-col :span="12">
							<el-form-item label="收件人姓名" prop="yjSjr">
								<el-input v-model="form.yjSjr" readonly placeholder="请输入收件人姓名" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="收件人手机" prop="yjSjphone">
								<el-input v-model="form.yjSjphone" readonly placeholder="请输入收件人手机" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="邮寄地址" prop="yjAddress">
								<el-input v-model="form.yjAddress" readonly type="textarea" placeholder="请输入内容" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="邮政编码" prop="yjCode">
								<el-input v-model="form.yjCode" readonly placeholder="请输入邮政编码" />
							</el-form-item>
						</el-col>
					</el-row>
				</div>
			</el-form>
			<div slot="footer" class="dialog-footer" v-if="form.shenhe == '0'">
				<el-button type="primary" @click="submitForm">通 过</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listQiye,
		getQiye,
		delQiye,
		addQiye,
		updateQiye
	} 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,
					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,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询企业账号列表 */
			getList() {
				this.loading = true;
				listQiye(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();
			},
			// 多选框选中数据
			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
				getQiye(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) {
							this.form.shenhe = '1'
							updateQiye(this.form).then(response => {
								this.$modal.msgSuccess("操作成功");
								this.open = false;
								this.getList();
							});
						} else {
							addQiye(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 delQiye(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('qygl/Qiye/export', {
					...this.queryParams
				}, `Qiye_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>