<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="name">
				<el-input v-model="queryParams.name" placeholder="请输入客服姓名" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="手机号" prop="phone">
				<el-input v-model="queryParams.phone" placeholder="请输入客服手机号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="QQ号" prop="qqNumber">
				<el-input v-model="queryParams.qqNumber" placeholder="请输入客服QQ号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="微信号" prop="wxNumber">
				<el-input v-model="queryParams.wxNumber" 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="['system:gameCustomer:add']">新增
				</el-button>
			</el-col>
			

			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table :data="tableData" style="width: 100%">
			<el-table-column prop="name" label="姓名" width="80">
			</el-table-column>
			<el-table-column prop="gender" label="性别" width="60">
			</el-table-column>
			<el-table-column prop="idCard" label="身份证号" width="180">
			</el-table-column>
			<el-table-column prop="phone" label="手机号">
			</el-table-column>
			<el-table-column prop="screenName" label="客服名称">
			</el-table-column>
			<el-table-column prop="qqNumber" label="QQ号">
			</el-table-column>
			<el-table-column prop="wxNumber" label="微信号">
			</el-table-column>
			<el-table-column prop="createTime" label="创建时间">
			</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-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['system:gameCustomer:edit']">修改
					</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['system:gameCustomer: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 v-if="open" :title="title" :visible.sync="open" append-to-body width="1000px">
			<div style="padding: 10px;overflow: auto">
				<el-form ref="form" :model="form" :rules="rules" label-width="80px">
					<el-row>
						<el-col :span="12">
							<el-form-item label="姓名" prop="name">
								<el-input v-model="form.name" placeholder="请输入姓名" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="性别" prop="gender">
								<el-input v-model="form.gender" placeholder="请输入性别" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="年龄" prop="age">
								<el-input v-model="form.age" placeholder="请输入年龄" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="身份证号" prop="idCard">
								<el-input v-model="form.idCard" placeholder="请输入身份证号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="手机号" prop="phone">
								<el-input v-model="form.phone" placeholder="请输入手机号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="客服名称" prop="screenName">
								<el-input v-model="form.screenName" placeholder="请输入客服名称" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="QQ号" prop="qqNumber">
								<el-input v-model="form.qqNumber" placeholder="请输入QQ号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="微信号" prop="wxNumber">
								<el-input v-model="form.wxNumber" placeholder="请输入微信号" />
							</el-form-item>
						</el-col>

					</el-row>
				</el-form>
			</div>
			<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 {
		addgameCustomer,
		delgameCustomer,
		getgameCustomer,
		listgameCustomer,
		updategameCustomer
	} from "@/api/data/gameCustomer";
	import {
		getConfigKey
	} from "@/api/system/config";
	import {
		deptTreeSelect
	} from '@/api/system/user'
	import Treeselect from "@riophae/vue-treeselect";
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";
	export default {
		data() {
			return {
				tableData: [],
				// 遮罩层
				loading: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					name: null,
					wxNumber: null,
					qqNumber: null,
					phone: null,
					screenName: null,
					gender: null,
					age: null,
					idCard: null
				},
				// 表单参数
				form: {
					shopType: '1',
					dialogImageUrl: '',
					name: null,
					wxNumber: null,
					qqNumber: null,
					phone: null,
					screenName: null,
					gender: null,
					age: null,
					idCard: null
				},
				// 表单校验
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						trigger: 'change'
					}],
					phone: [{
						required: true,
						message: '请输入手机号',
						trigger: 'change'
					}],
					idCard: [{
						required: true,
						message: '请输入身份证号',
						trigger: 'change'
					}],
					age: [{
						required: true,
						message: '请输入年龄',
						trigger: 'change'
					}],
					screenName: [{
						required: true,
						message: '请输入客服名称',
						trigger: 'change'
					}],
					qqNumber: [{
						required: true,
						message: '请输入QQ号',
						trigger: 'change'
					}],
					wxNumber: [{
						required: true,
						message: '请输入微信号',
						trigger: 'change'
					}],
					gender: [{
						required: true,
						message: '请输入性别',
						trigger: 'change'
					}],
					
				}
			};
		},
		created() {
			this.getList();
		},
		methods: {

			/** 查询店铺信息列表 */
			getList() {
				this.loading = true;
				listgameCustomer(this.queryParams).then(response => {
					this.tableData = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					shopType: '1',
					id: null,
					name: null,
					wxNumber: null,
					qqNumber: null,
					phone: null,
					screenName: null,
					gender: null,
					age: null,
					idCard: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加客服信息";
			},

			

			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				getgameCustomer(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) {
							updategameCustomer(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addgameCustomer(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				const names = row.name || this.names
				this.$modal.confirm('是否确认删除店铺["' + names + '"]的数据项？').then(function() {
					return delgameCustomer(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			
		}
	};
</script>
