<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="主平台游戏id" prop="gameId">
				<el-input v-model="queryParams.gameId" placeholder="请输入主平台游戏id" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="主平台游戏属性id" prop="attributeId">
				<el-input v-model="queryParams.attributeId" placeholder="请输入主平台游戏属性id" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="主平台游戏属性名称" prop="attributeValue">
				<el-input v-model="queryParams.attributeValue" placeholder="请输入主平台游戏属性名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="第三方平台游戏id" prop="otherGameId">
				<el-input v-model="queryParams.otherGameId" placeholder="请输入第三方平台游戏id" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="第三方游戏属性id" prop="otherAttributeId">
				<el-input v-model="queryParams.otherAttributeId" placeholder="请输入第三方游戏属性id" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="第三方游戏属性名称" prop="otherAttributeValue">
				<el-input v-model="queryParams.otherAttributeValue" placeholder="请输入第三方游戏属性名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="所属平台 (字典项目)" prop="gamePlatformMapping">
				<el-select v-model="queryParams.gamePlatformMapping" placeholder="请选择所属平台 (字典项目)" clearable>
					<el-option v-for="dict in dict.type.game_platform_mapping" :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="['system:gameareamapping: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="['system:gameareamapping: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="['system:gameareamapping:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleTongbu"
					v-hasPermi="['system:gameareamapping:export']">同步属性</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
					v-hasPermi="['system:gameareamapping:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="gameareamappingList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="主键ID" align="center" prop="id" />
			<el-table-column label="主平台游戏id" align="center" prop="gameId" />
			<el-table-column label="主平台游戏属性id" align="center" prop="attributeId" />
			<el-table-column label="主平台游戏属性名称" align="center" prop="attributeValue" />
			<el-table-column label="第三方平台游戏id" align="center" prop="otherGameId" />
			<el-table-column label="第三方游戏属性id" align="center" prop="otherAttributeId" />
			<el-table-column label="第三方游戏属性名称" align="center" prop="otherAttributeValue" />
			<el-table-column label="所属平台 (字典项目)" align="center" prop="gamePlatformMapping">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.game_platform_mapping" :value="scope.row.gamePlatformMapping" />
				</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-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['system:gameareamapping:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['system:gameareamapping: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 :title="title" :visible.sync="open" width="1000px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<el-row>
					<el-col :span="12">
						<el-form-item label="主平台游戏id" prop="gameId">
							<el-input v-model="form.gameId" placeholder="请输入主平台游戏id" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="第三方平台游戏id" prop="othergameId">
							<el-input v-model="form.otherGameId" placeholder="请输入第三方平台游戏id" />
						</el-form-item>


					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="主平台游戏属性id" prop="attributeId">
							<el-input v-model="form.attributeId" placeholder="请输入主平台游戏属性id" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="第三方游戏属性id" prop="otherAttributeId">
							<el-input v-model="form.otherAttributeId" placeholder="请输入第三方游戏属性id" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="主平台游戏属性名称" prop="attributeValue">
							<el-input v-model="form.attributeValue" placeholder="请输入主平台游戏属性名称" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="第三方游戏属性名称" prop="otherAttributeValue">
							<el-input v-model="form.otherAttributeValue" placeholder="请输入第三方游戏属性名称" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="所属平台 (字典项目)" prop="gamePlatformMapping">
							<el-select v-model="form.gamePlatformMapping" placeholder="请选择所属平台 (字典项目)">
								<el-option v-for="dict in dict.type.game_platform_mapping" :key="dict.value"
									:label="dict.label" :value="dict.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<!-- 添加或修改建立区域之间的映射关系对话框 -->
		<el-dialog title="同步属性" :visible.sync="tongbu" width="1000px" append-to-body>
			<el-form ref="form1" :model="form1" :rules="rules" label-width="80px">
				<el-row>
					<el-col :span="12">
						<el-form-item label="主平台游戏id" prop="gameId">
							<el-input v-model="form1.gameId" placeholder="请输入主平台游戏id" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="第三方平台游戏id" prop="othergameId">
							<el-input v-model="form1.otherGameId" placeholder="请输入第三方平台游戏id" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="所属平台 (字典项目)" prop="gamePlatformMapping">
							<el-select v-model="form1.gamePlatformMapping" placeholder="请选择所属平台 (字典项目)">
								<el-option v-for="dict in dict.type.game_platform_mapping" :key="dict.value"
									:label="dict.label" :value="dict.value"></el-option>
							</el-select>
              {{form1.gamePlatformMapping}}
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm1">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listGameareamapping,
		getGameareamapping,
		delGameareamapping,
		addGameareamapping,
		tongbuGameareamapping,
		updateGameareamapping
	} from "@/api/data/attributeConfiguration";

	export default {
		name: "Gameareamapping",
		dicts: ['game_platform_mapping'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 建立区域之间的映射关系表格数据
				gameareamappingList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				tongbu: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					gameareaId: null,
					gameareaName: null,
					othergameareaId: null,
					othergameareaName: null,
					gamePlatformMapping: null
				},
				// 表单参数
				form: {},
				// form: {
				// 	gameId:'5ed2e37abe2249f5a5d6f9d7e0d13dfb',
				// 	otherGameId:'22',
				// 	gamePlatformMapping:'game_platform_mapping_37',
				// },
				form1: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询建立区域之间的映射关系列表 */
			getList() {
				this.loading = true;
				listGameareamapping(this.queryParams).then(response => {
					this.gameareamappingList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.tongbu = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					gameareaId: null,
					gameareaName: null,
					othergameareaId: null,
					othergameareaName: null,
					gamePlatformMapping: null
				};
				this.resetForm("form");
				this.resetForm("form1");
			},
			/** 搜索按钮操作 */
			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 = "添加建立属性之间的映射关系";
			},
			/** 同步按钮操作 */
			handleTongbu() {
				this.reset();
				this.tongbu = true;
				this.title = "同步建立属性之间的映射关系";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				let query = {
					id: id
				}
				getGameareamapping(query).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改建立属性之间的映射关系";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.id != null) {
							updateGameareamapping(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addGameareamapping(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 提交按钮 */
			submitForm1() {
				this.$refs["form1"].validate(valid => {
					if (valid) {
						tongbuGameareamapping(this.form1).then(response => {
							this.$modal.msgSuccess("同步成功");
							this.tongbu = false;
							this.getList();
						});
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				let query = {
					id: ids
				}
				this.$modal.confirm('是否确认删除建立属性之间的映射关系编号为"' + ids + '"的数据项？').then(function() {
					return delGameareamapping(query);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('system/gameareamapping/export', {
					...this.queryParams
				}, `gameareamapping_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>
