<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="accountId">
				<el-input v-model="queryParams.accountId" placeholder="请输入游戏账号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="游戏名称" prop="gameName">
				<el-input v-model="queryParams.gameName" placeholder="请输入游戏名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="渠道名称" prop="channels">
				<el-input v-model="queryParams.channels" 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:gameBlacklist: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 v-if='yxmc' prop="gameName" label="游戏名称">
			</el-table-column> -->
			<el-table-column prop="gameName" label="游戏名称">
			</el-table-column>
			<el-table-column prop="accountId" label="黑名单游戏账号">
			</el-table-column>
			<el-table-column prop="channels" label="渠道名称">
			</el-table-column>
			<el-table-column prop="idNo" label="身份证号" width="180">
			</el-table-column>
			<el-table-column prop="name" label="姓名" width="80">
			</el-table-column>
			<el-table-column prop="mobile" label="手机号">
			</el-table-column>
			<el-table-column prop="wxNo" label="微信号">
			</el-table-column>
			<el-table-column prop="createTime" label="创建时间">
			</el-table-column>
			<el-table-column prop="remark" 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:gameBlacklist:edit']">修改
					</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['system:gameBlacklist: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="gameId">
								<el-select v-model="form.gameId" style="width: 100%" filterable
									placeholder="请选择游戏名称">
									<el-option v-for="(item,index) in gameList" :key="item.id" :label="item.gameName"
										:value="item.id"></el-option>
								</el-select>

							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="游戏账号" prop="accountId">
								<el-input v-model="form.accountId" placeholder="请输入游戏账号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="身份证号" prop="idNo">
								<el-input v-model="form.idNo" placeholder="请输入身份证号" />
							</el-form-item>
						</el-col>
						<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="mobile">
								<el-input v-model="form.mobile" placeholder="请输入手机号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="微信号" prop="wxNo">
								<el-input v-model="form.wxNo" placeholder="请输入微信号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="备注" prop="remark">
								<el-input v-model="form.remark" 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 {
		addgameBlacklist,
		delgameBlacklist,
		getgameBlacklist,
		listgameBlacklist,
		updategameBlacklist,
		getInitGoodsManager
	} from "@/api/data/gameBlacklist";
	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 {
				gameList: [],
				tableData: [],
				// 遮罩层
				loading: true,
				
				yxmc:false,
				cs:0,
				// 总条数
				total:0,
				// 弹出层标题
				title: "",
				// 显示搜索条件
				showSearch: true,
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					gameName:null,
					name: null,
					gameId:null,
					channels:null,
					accountId:null,
					idNo:null,
					mobile:null,
					wxNo:null,
					remark:null,
				},
				// 表单参数
				form: {
					name: null,
					gameId:null,
					accountId:null,
					idNo:null,
					mobile:null,
					wxNo:null,
					remark:null
				},
				// 表单校验
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						trigger: 'change'
					}],
					mobile: [{
						required: true,
						message: '请输入手机号',
						trigger: 'change'
					}],
					idNo: [{
						required: true,
						message: '请输入身份证号',
						trigger: 'change'
					}],
					gameId: [{
						required: true,
						message: '请输入游戏名称',
						trigger: 'change'
					}],
					wxNo: [{
						required: true,
						message: '请输入微信号',
						trigger: 'change'
					}],
					accountId: [{
						required: true,
						message: '请输入游戏账号',
						trigger: 'change'
					}],

				}
			};
		},
		created() {
			this.getList();
			this.initGoodsManager();
		},
		methods: {
			// 游戏类型
			initGoodsManager() {
				getInitGoodsManager().then(res => {
					this.pictureServerPath = res.pictureServerPath
					this.gameList = res.gameList
				})
			},
			
			/** 查询黑号信息列表 */
			getList() {
				this.loading = true;
				listgameBlacklist(this.queryParams).then(response => {
					this.tableData = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					name: null,
					name: null,
					gameId:null,
					accountId:null,
					idNo:null,
					mobile:null,
					wxNo:null,
					remark: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.names = selection.map(item => item.name)
				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
				getgameBlacklist(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) {
							updategameBlacklist(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addgameBlacklist(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 delgameBlacklist(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},

		}
	};
</script>
