<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="beginTime">
				<div class="block">
					<el-date-picker v-model="queryParams.beginTime" value-format="yyyy-MM-dd" type="date"
						placeholder="选择日期" style="width: 200px;">
					</el-date-picker>
				</div>
			</el-form-item>
			<el-form-item label="结束日期" prop="endTime">
				<div class="block">
					<el-date-picker v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd"
						placeholder="选择日期" style="width: 200px;">
					</el-date-picker>
				</div>
			</el-form-item>
			<el-form-item label="店铺名称" v-if="disabled2" prop="shopName">
				<el-select filterable v-model="queryParams.shopId" style="width: 100%" clearable placeholder="请选择店铺名称">
					<el-option v-for="(item,index) in deptOptions" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="游戏" prop="gameAccount">
				<el-select clearable v-model="queryParams.gameId" style="width: 100%" @change="changeGameArea">
					<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-form-item label="账号状态" prop="gameAccount">
				<el-cascader clearable filterable @change='change1()' style="width: 100%" placeholder="请选择账号状态"
					v-model="queryParams.accountType" :options="zhztoptions1">
				</el-cascader>
			</el-form-item>
			<el-form-item label="售后状态" prop="aftermarketStatus">
				<el-select v-model="queryParams.aftermarketStatus" style="width: 200px" clearable placeholder="请选择售后状态">
					<el-option v-for="(item,index) in stoptions" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="是否赔付" prop="paid">
				<el-select style="width: 100%" v-model="queryParams.paid" placeholder="请选择是否赔付">
					<el-option v-for="item in pfoptions" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="游戏账号" prop="gameAccount">
				<el-input v-model="queryParams.gameAccount" style="width: 200px;" placeholder="请输入游戏账号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="收号客服" prop="rCustomerService">
				<el-input v-model="queryParams.rCustomerService" style="width: 200px;" placeholder="请输入收号客服" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="编号" prop="code">
				<el-input v-model="queryParams.code" style="width: 200px;" placeholder="请输入编号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="手机号" prop="boundMobile">
				<el-input v-model="queryParams.boundMobile" style="width: 200px;" 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 style="margin-left: 20px;" 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:gameAccountStockpile:add']">新增
				</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:accountStockpile:export']">导出
				</el-button>
			</el-col>
		</el-row>
		<el-table :data="tableData" border :row-class-name="tableRowClassName"
			:header-cell-style="{background: '#e1effb', color: 'black'}" style="width: 100%">
			<el-table-column prop="stockpileCode" label="系统编号">
			</el-table-column>
			<el-table-column prop="code" label="编号">
			</el-table-column>
			<el-table-column prop="shopName" label="店铺名称">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="boundMobile" label="手机号">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="gameAccount" label="游戏账号">
			</el-table-column>
			<el-table-column prop="gameAccountType" label="账号类型">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.game_account_categorize" :value="scope.row.gameAccountType" />
				</template>
			</el-table-column>
			<el-table-column prop="acquirePrice" label="收购价格">
			</el-table-column>
			<el-table-column prop="offerPrice" label="出售价格">
			</el-table-column>
			<el-table-column prop="rcustomerService" label="收号客服">
			</el-table-column>
			<el-table-column prop="accountSource" label="账号来源">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="gameNpwd" label="新密码">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="gameOpwd" label="旧密码">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="gameName" label="游戏">
			</el-table-column>
			<el-table-column prop="gameAreaName" label="游戏大区">
			</el-table-column>
			<el-table-column prop="realNames" label="实名情况">
				<template slot-scope="scope">
					<span v-if="scope.row.realNames=='real_names_1'">不可二次</span>
					<span v-if="scope.row.realNames=='real_names_0'">可二次</span>
					<span v-if="scope.row.realNames=='real_names_2'">包人脸</span>
				</template>
			</el-table-column>
			<el-table-column prop="rank" label="排位">
				<template slot-scope="scope">
					<span v-if="scope.row.rank=='0'">可排位</span>
					<span v-if="scope.row.rank=='1'">不可排位</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="campsiteNumber" label="营地号">
			</el-table-column>
			<el-table-column width='120px' prop="loggedDevices" label="设备">
			</el-table-column>
			<el-table-column prop="accountType" label="账号状态">
				<template slot-scope="scope">
					<span v-if="scope.row.accountType=='game_account_type_0'">未上架</span>
					<span v-if="scope.row.accountType=='game_account_type_1'">已上架</span>
					<span v-if="scope.row.accountType=='game_account_type_2'">已出售</span>
					<span v-if="scope.row.accountType=='game_account_type_3'">找回</span>
					<span v-if="scope.row.accountType=='game_account_type_8'">未验证</span>
					<span v-if="scope.row.accountType=='game_account_type_4'">冻结</span>
					<span v-if="scope.row.accountType=='game_account_type_5'">人脸</span>
					<span v-if="scope.row.accountType=='game_account_type_6'">手机卡无法使用</span>
					<span v-if="scope.row.accountType=='game_account_type_9'">自用</span>
					<span v-if="scope.row.accountType=='game_account_type_7'">实名被删除等一个月</span>
					<span v-if="scope.row.accountType=='game_account_type_10'">其他</span>
				</template>
			</el-table-column>
			<el-table-column prop="aftermarketStatus" label="售后状态">
				<template slot-scope="scope">
					<span v-if="scope.row.aftermarketStatus=='0'">处理中</span>
					<span v-if="scope.row.aftermarketStatus=='1'">处理失败</span>
					<span v-if="scope.row.aftermarketStatus=='2'">处理成功</span>
					<span v-if="scope.row.aftermarketStatus==null">无状态</span>
				</template>
			</el-table-column>
			<el-table-column prop="paid" label="赔付状态">
				<template slot-scope="scope">
					<span v-if="scope.row.paid=='Y'">是</span>
					<span v-if="scope.row.paid=='N'">否</span>
				</template>
			</el-table-column>
			<el-table-column prop="payType" label="打款状态">
				<template slot-scope="scope">
					<span v-if="scope.row.payType=='0'">是</span>
					<span v-if="scope.row.payType=='1'">否</span>
				</template>
			</el-table-column>
			<el-table-column width="100px" prop="acquireDate" label="收号日期">
			</el-table-column>
			<el-table-column width="160px" prop="createTime" label="创建时间">
			</el-table-column>
			<el-table-column prop="createBy" label="创建人">
			</el-table-column>
			<el-table-column prop="updateTime" label="修改时间">
			</el-table-column>
			<el-table-column prop="updateBy" label="修改人">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="remark" label="备注">
			</el-table-column>
			<el-table-column width="150px" label="操作" fixed="right" align="center"
				class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" v-hasPermi="['system:gameAccountStockpile:edit']"
						icon="el-icon-edit" @click="handleUpdate(scope.row)">修改
					</el-button>
					<el-button size="mini" type="text" v-hasPermi="['system:gameAccountStockpile:remove']"
						icon="el-icon-delete" @click="handleDelete(scope.row)">删除
					</el-button>
					<!-- <el-button size="mini" type="text" v-hasPermi="['system:gameAccountStockpile:remove']"
						icon="el-icon-delete" @click="copyRowData(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 v-if="add" :title="title" :visible.sync="add" append-to-body width="1000px">
			<div style="padding: 10px;overflow: auto">
				<el-form ref="form3" :model="form3" :rules="rules" label-width="80px">
					<el-row>
						<el-col :span="12">
							<el-form-item label="店铺ID" prop="shopId">
								<el-select filterable v-model="form3.shopId" :disabled='disabled' style="width: 100%"
									clearable placeholder="请选择店铺名称">
									<el-option v-for="(item,index) in deptOptions" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="游戏" prop="gameId">
								<el-select filterable v-model="form3.gameId" style="width: 100%"
									@change="changeGameArea">
									<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="gameArea">
								<el-cascader style="width: 100%" v-model="form3.gameArea" :options="qfoptions"
									:props="{ expandTrigger: 'hover' }"></el-cascader>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="编号" prop="code">
								<el-input v-model="form3.code" placeholder="请输入编号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="账号类型" prop="gameAccountType">
								<el-select v-model="form3.gameAccountType" placeholder="请选择账号类型" style="width: 100%">
									<el-option v-for="item in dict.type.game_account_categorize" :key="item.value"
										:label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="游戏账号" prop="gameAccount">
								<el-input v-model="form3.gameAccount" placeholder="请输入游戏账号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="收号日期" prop="acquireDate">
								<el-date-picker style="width: 100%" value-format="yyyy-MM-dd"
									v-model="form3.acquireDate" type="date" placeholder="请选择收号日期">
								</el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="收购价格" prop="acquirePrice">
								<el-input v-model="form3.acquirePrice" placeholder="请输入收购价格" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="新密码" prop="gameNpwd">
								<el-input v-model="form3.gameNpwd" placeholder="请输入新游戏密码" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="旧密码" prop="gameOpwd">
								<el-input v-model="form3.gameOpwd" placeholder="请输入旧游戏密码" />
							</el-form-item>
						</el-col>

						<el-col :span="12"
							v-if="form3.gameId=='5ed2e37abe2249f5a5d6f9d7e0d13dfb'||form3.gameId=='41d76b3c0e654663b622778b16b01837'">
							<el-form-item label="营地号" prop="campsiteNumber">
								<el-input v-model="form3.campsiteNumber" placeholder="请输入营地号" />
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="form3.gameId=='7cf7907cc1e74d259bc3e538239c0132'">
							<el-form-item label="排位" prop="rank">
								<el-select v-model="form3.rank" style="width: 100%" placeholder="请选择排位">
									<el-option v-for="item in pwoptions" :key="item.value" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="form3.gameId=='8ff0b3270ff84bc0b2eec64db2108c18'">
							<el-form-item label="原号主身份证号" prop="idNumber">
								<el-input v-model="form3.idNumber" placeholder="请输入原号主身份证号" />
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="form3.gameId=='2e6581c93f85462a94023e94cf92a24d'">
							<el-form-item label="二级密码" prop="gradePwd">
								<el-input v-model="form3.gradePwd" placeholder="请输入二级密码" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="实名情况" prop="realNames">
								<el-select style="width: 100%" v-model="form3.realNames" placeholder="请选择实名情况">
									<el-option v-for="item in smoptions" :key="item.value" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="账号状态" prop="accountType">
								<!-- <el-select style="width: 100%" v-model="form3.accountType" placeholder="请选择账号状态">
									<el-option v-for="item in zhztoptions" :key="item.value" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select> -->
								<el-cascader @change="change" :disabled='disabled1' filterable style="width: 100%"
									placeholder="请选择账号状态" v-model="form3.accountType" :options="zhztoptions">
								</el-cascader>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="状态补充" prop="accountTypeOther"
								v-if="zhzt||form3.accountType=='game_account_type_10'">
								<el-input v-model="form3.accountTypeOther" placeholder="请输入状态补充" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="购买包赔(淘号玩)" prop="guarantee"
								v-if="bp||form3.accountType=='game_account_type_3'">
								<el-select style="width: 100%" v-model="form3.guarantee" placeholder="请选择购买包赔">
									<el-option v-for="item in bpoptions" :key="item.value" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<!-- <el-col :span="12">
							<el-form-item label="找回日期" prop="retrieveDate"
								v-if="bp||form3.accountType=='game_account_type_3'">
								<el-date-picker style="width: 100%" value-format="yyyy-MM-dd"
									v-model="form3.retrieveDate" type="date" placeholder="请选择找回日期">
								</el-date-picker>
							</el-form-item>
						</el-col> -->
						<el-col :span="12" v-if="bp||form3.accountType=='game_account_type_3'">
							<el-form-item label="是否赔付" prop="paid">
								<el-select style="width: 100%" v-model="form3.paid" placeholder="请选择是否赔付">
									<el-option v-for="item in pfoptions" :key="item.value" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<!-- <el-col :span="12">
							<el-form-item label="包赔来源" prop="baopeiSource">
								<el-select v-model="form3.baopeiSource" placeholder="请选择包赔来源" style="width: 100%">
									<el-option v-for="dict in bplyOptions" :key="dict.value" :label="dict.label"
										:value="dict.value"></el-option>
								</el-select>
								<el-button type="primary" plain icon="el-icon-plus" size="mini"
									@click="handleAddbply">新增包赔来源
								</el-button>
							</el-form-item>
						</el-col> -->
						<el-col :span="12">
							<el-form-item label="账号来源" prop="accountSource">
								<el-select v-model="form3.accountSource" placeholder="请选择账号来源" style="width: 100%">
									<el-option v-for="item in zhlyOptions" :key="item.value"
										:label="item.label" :value="item.value"></el-option>
								</el-select>
								<el-button type="primary" plain icon="el-icon-plus" size="mini"
									@click="handleAddzhly">新增账号来源
								</el-button>
							</el-form-item>
						</el-col>
						<el-col :span="12"
							v-if="form3.accountSource=='其他'||form3.accountSource=='接盘'||form3.accountSource=='回收'||form3.accountSource=='回收其他'">
							<el-form-item label="来源补充" prop="accountSourceOther">
								<el-input v-model="form3.accountSourceOther" placeholder="请输入来源补充" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="手机号" prop="boundMobile">
								<el-select filterable remote reserve-keyword :remote-method="remoteMethod"
									v-model="form3.boundMobile" style="width: 100%" clearable placeholder="请选择绑定手机号">
									<el-option v-for="(item,index) in phoneOptions" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="收号时登录的设备" prop="loggedDevices">
								<el-select v-model="form3.loggedDevices" placeholder="请选择登录设备" style="width: 100%">
									<el-option v-for="dict in dlsbOptions" :key="dict.value" :label="dict.label"
										:value="dict.value"></el-option>
								</el-select>
								<el-button type="primary" plain icon="el-icon-plus" size="mini"
									@click="handleAddsb">新增设备
								</el-button>
							</el-form-item>
						</el-col>

						<el-col :span="12">
							<el-form-item label="收号客服" prop="rcustomerService">
								<el-select v-model="form3.rcustomerService" placeholder="请选择收号客服" style="width: 100%">
									<el-option v-for="dict in shkfOptions" :key="dict.value" :label="dict.label"
										:value="dict.value"></el-option>
								</el-select>
								<el-button type="primary" plain icon="el-icon-plus" size="mini"
									@click="handleAddkf">新增客服
								</el-button>
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="form3.accountType=='game_account_type_2'">
							<el-form-item label="出售价格" prop="offerPrice">
								<el-input disabled v-model="form3.offerPrice" placeholder="请输入出售价格" />
							</el-form-item>
						</el-col>
						<el-col :span="12" v-else>
							<el-form-item label="出售价格" prop="offerPrice">
								<el-input @input="changeZk" v-model="form3.offerPrice" placeholder="请输入出售价格" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="折扣" prop="rebates">
								<el-select style="width: 100%" clearable @change="changeZk" v-model="form3.rebates">
									<el-option v-for="dict in dict.type.rebates_type" :key="dict.value"
										:label="dict.label" :value="dict.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="form3.rebates!=''&&form3.rebates!=undefined">
							<el-form-item label="折扣价" prop="discountedPrice">
								<el-input disabled v-model="form3.discountedPrice" placeholder="请输入游戏账号折扣价" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="打款状态" prop="payType">
								<el-select style="width: 100%" v-model="form3.payType" placeholder="请选择打款状态">
									<el-option v-for="item in dkoptions" :key="item.value" :label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>


					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="备注" prop="remark">
								<el-input type="textarea" v-model="form3.remark" placeholder="请输入备注" />
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm1">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<el-dialog title="新增账号来源" :visible.sync="dialogVisible2" width="50%" :before-close="handleClose">
			<!-- <el-input type="textarea" v-model="form6.gameAccountSource" placeholder="请输入来源名称" />
			<span style="margin-top: 10px;color: red;">例此格式:沐沐/沐风/不求人</span> -->
			<el-checkbox-group v-model="checkedCities" @change="checkedCitie()">
				<el-checkbox style="width: 200px;overflow: hidden;" v-for="city in cities" :label="city.dictLabel"
					:key="city.dictLabel">{{city.dictLabel}}</el-checkbox>
			</el-checkbox-group>
			<p style="color: red;">
				请认真勾选您自己真实的账号渠道来源，会显示到您的号库渠道，方便于您后期的录入。
				如没有您的渠道请联系管理员添加！
			</p>
			<p>
				您的来源有：{{form6.gameAccountSource}}
			</p>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible2 = false">取 消</el-button>
				<el-button type="primary" v-hasPermi="['system:shop:edit']" @click="handleUpdateAll()">确 定</el-button>
			</span>
		</el-dialog>
		<el-dialog title="新增包赔来源" :visible.sync="dialogVisible3" width="30%" :before-close="handleClose">
			<el-input type="textarea" v-model="form7.baopeiSource" placeholder="请输入来源名称" />
			<span style="margin-top: 10px;color: red;">例此格式:淘号玩/盼之/XXX</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible3 = false">取 消</el-button>
				<el-button type="primary" v-hasPermi="['system:shop:edit']" @click="handleUpdateAll()">确 定</el-button>
			</span>
		</el-dialog>
		<el-dialog title="新增收号客服" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
			<el-input type="textarea" v-model="form4.customerService" placeholder="请输入客服名称" />
			<span style="margin-top: 10px;color: red;">例此格式:小马/小张/小王</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" v-hasPermi="['system:shop:edit']" @click="handleUpdateAll()">确 定</el-button>
			</span>
		</el-dialog>
		<el-dialog title="新增登录设备" :visible.sync="dialogVisible1" width="30%" :before-close="handleClose">
			<el-input type="textarea" v-model="form5.loggedDevices" placeholder="请输入登录设备" />
			<span style="margin-top: 10px;color: red;">例此格式:iphoneX/iphone11/iphone12</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible1 = false">取 消</el-button>
				<el-button type="primary" v-hasPermi="['system:shop:edit']" @click="handleUpdateAll()">确 定</el-button>
			</span>
		</el-dialog>


	</div>
</template>

<script>
	import {
		queryTBusShop,
	} from "@/api/data/goodsPayment";
	import {
		getConfigKey
	} from "@/api/system/config";
	import Treeselect from "@riophae/vue-treeselect";
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";
	import {
		getSysDeptInfo,
		getDeptInfo,
		accountMonitoring,
		edit,
		add,
		view,
		deleteMonitoring,
		getPaymentInfo,
		updateOriginalPrice,
		getTBusGoodsPaymentSum,
		updatePaymentStatus,
		queryTBusPhone,
		getShopInfo,
		shopEdit,
		collectionSource
	} from "@/api/data/numberLibrary";
	import {
		getTBusShopInfo,
	} from "@/api/data/goodsPayment";
	import {
		getInitGoodsManager,
		getGameArea
	} from "@/api/data/goods";
	import Cookies from 'js-cookie';
	import {
		getToken
	} from "@/utils/auth";
	export default {
		dicts: ['game_account_type', 'r_customer_service', 'game_account_categorize', 'rebates_type'],
		data() {
			var checkNumber = (rule, value, callback) => { // 整数价格验证
				if (!value) {
					return callback(new Error('价格不能为空'));
				} else {
					const reg = /^(0|[1-9][0-9]*)$/
					if (reg.test(value)) {
						callback();
					} else {
						return callback(new Error('价格为整数类型'));
					}
				}
			};
			return {
				checkedCities: [],
				cities:[],
				disabled2: false,
				deptOptions: [],
				// 收号客服
				dialogVisible: false,
				form4: {},
				// 登录设备
				dialogVisible1: false,
				form5: {},
				// 账号来源
				dialogVisible2: false,
				form6: {},
				// 包赔来源
				dialogVisible3: false,
				form7: {},
				add: false,
				pictureServerPath: null,
				path: '',
				srcList: [],
				shopId1: '',
				form2: {},
				form3: {},
				qfoptions: [],
				// 表单参数
				form: {},
				// 统计
				originalprice: 0,
				salesprice: 0,
				paidinprice: 0,
				lr: 0,
				bplr: 0,
				allPrice: 0,
				// 筛选
				// activeNames: ['1'],
				cs: 0,
				cs1: 0,
				cs2: 0,
				cs3: 0,
				input: '',
				accountNumer: '0',
				ck: false,
				yxbh: false,
				yxdq: false,
				spbh: false,
				sjbh: false,
				disabled: false,
				disabled1: false,
				block: false,
				originalPrice1open: false,
				originalPriceopen: false,
				xz: false,
				open1: false,
				openPicture: false,
				cbj: false,
				cbj1: false,
				cbj2: true,
				fl: false,
				openFkpz1: false,
				bp: false,
				zybd: true,
				sjbd: false,
				bpLr: false,
				// 付款凭证
				attach_list: [],
				carouselImg: [],
				stoptions: [{
					value: '0',
					label: '处理中'
				}, {
					value: '1',
					label: '处理失败'
				}, {
					value: '2',
					label: '处理成功'
				}, ],
				//账号状态
				zhztoptions: [{

					value: 'zc',
					label: '正常',
					children: [{
							value: 'game_account_type_0',
							label: '未上架'
						},
						{
							value: 'game_account_type_1',
							label: '已上架',
							disabled: true,
						},
						{
							value: 'game_account_type_2',
							label: '已出售',
							disabled: true,
						}
					]

				}, {

					value: 'yc',
					label: '异常',
					children: [{
							value: 'game_account_type_3',
							label: '找回',
						},
						{
							value: 'game_account_type_8',
							label: '未验证',
						}, {
							value: 'game_account_type_4',
							label: '冻结',
						},
						{
							value: 'game_account_type_5',
							label: '人脸'
						},
						{
							value: 'game_account_type_6',
							label: '手机卡无法使用'
						},
						{
							value: 'game_account_type_9',
							label: '自用'
						},
						{
							value: 'game_account_type_7',
							label: '实名被删除等一个月'
						},
						{
							value: 'game_account_type_10',
							label: '其他'
						},
					]

				}],
				//账号状态
				zhztoptions1: [{

					value: 'zc',
					label: '正常',
					children: [{
							value: 'game_account_type_0',
							label: '未上架'
						},
						{
							value: 'game_account_type_1',
							label: '已上架'
						},
						{
							value: 'game_account_type_2',
							label: '已出售'
						}
					]

				}, {

					value: 'yc',
					label: '异常',
					children: [{
							value: 'game_account_type_3',
							label: '找回'
						},
						{
							value: 'game_account_type_8',
							label: '未验证'
						}, {
							value: 'game_account_type_4',
							label: '冻结'
						},
						{
							value: 'game_account_type_5',
							label: '人脸'
						},
						{
							value: 'game_account_type_6',
							label: '手机卡无法使用'
						},
						{
							value: 'game_account_type_9',
							label: '自用'
						},
						{
							value: 'game_account_type_7',
							label: '实名被删除等一个月'
						},
						{
							value: 'game_account_type_10',
							label: '其他'
						},
					]

				}],
				//实名情况
				smoptions: [{
						value: 'real_names_0',
						label: '可二次'
					},
					{
						value: 'real_names_1',
						label: '不可二次'
					}, {
						value: 'real_names_2',
						label: '包人脸'
					},
				],
				//排位
				pwoptions: [{
					value: '0',
					label: '可排位'
				}, {
					value: '1',
					label: '不可排位'
				}, ],
				bpoptions: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}, ],
				//是否打款
				dkoptions: [{
					value: '0',
					label: '是'
				}, {
					value: '1',
					label: '否'
				}, ],
				//是否赔付
				pfoptions: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}, ],
				deptOptions: [],
				phoneOptions: [],
				shkfOptions: [],
				dlsbOptions: [],
				zhlyOptions: [],
				bplyOptions: [],
				rules: {
					accountNumber: [{
						required: true,
						message: '请输入账号',
						trigger: 'blur'
					}],
					shopId: [{
						required: true,
						message: '请选择店铺',
						trigger: 'blur'
					}],
					gameId: [{
						required: true,
						message: '请选择游戏',
						trigger: 'blur'
					}],
					gameArea: [{
						required: true,
						message: '请选择游戏大区',
						trigger: 'blur'
					}],
					gameAccount: [{
						required: true,
						message: '请输入游戏账号',
						trigger: 'blur'
					}],
					code: [{
						required: true,
						message: '请输入编号',
						trigger: 'blur'
					}],
					gameAccountType: [{
						required: true,
						message: '请选择账号类型',
						trigger: 'blur'
					}],
					acquireDate: [{
						required: true,
						message: '请选择收号日期',
						trigger: 'blur'
					}],
					acquirePrice: [{
							required: true,
							message: '请输入收购价格',
							trigger: 'blur'
						},
						{
							validator: checkNumber,
							trigger: 'blur'
						}
					],
					gameNpwd: [{
						required: true,
						message: '请输入新游戏密码',
						trigger: 'blur'
					}],
					gameOpwd: [{
						required: true,
						message: '请输入旧游戏密码',
						trigger: 'blur'
					}],
					idNumber: [{
						required: true,
						message: '请输入原号主身份证号',
						trigger: 'blur'
					}],
					gradePwd: [{
						required: true,
						message: '请输入二级密码',
						trigger: 'blur'
					}],
					rank: [{
						required: true,
						message: '请选择排位',
						trigger: 'blur'
					}],
					realNames: [{
						required: true,
						message: '请选择实名情况',
						trigger: 'blur'
					}],
					accountType: [{
						required: true,
						message: '请选择账号状态',
						trigger: 'blur'
					}],
					accountSource: [{
						required: true,
						message: '请选择账号来源',
						trigger: 'blur'
					}],
					baopeiSource: [{
						required: true,
						message: '请选择包赔来源',
						trigger: 'blur'
					}],
					accountSourceOther: [{
						required: true,
						message: '请输入补充',
						trigger: 'blur'
					}],
					accountTypeOther: [{
						required: true,
						message: '请输入补充',
						trigger: 'blur'
					}],
					guarantee: [{
						required: true,
						message: '请选择是否购买包赔（淘号玩）',
						trigger: 'blur'
					}],
					retrieveDate: [{
						required: true,
						message: '请选择找回日期',
						trigger: 'blur'
					}],
					boundMobile: [{
						required: true,
						message: '请输入绑定手机号',
						trigger: 'blur'
					}],
					loggedDevices: [{
						required: true,
						message: '请输入收号时登录的设备',
						trigger: 'blur'
					}],
					rcustomerService: [{
						required: true,
						message: '请输入收号客服',
						trigger: 'blur'
					}],
					payType: [{
						required: true,
						message: '请选择打款状态',
						trigger: 'blur'
					}],
					offerPrice: [{
						required: true,
						message: '请输入出售价格',
						trigger: 'blur'
					}, {
						validator: checkNumber,
						trigger: 'blur'
					}],
					campsiteNumber: [{
						required: true,
						message: '请输入营地号',
						trigger: 'blur'
					}],
				},
				gameList: [],
				tableData: [],
				// 遮罩层
				loading: true,
				zhzt: false,
				bp: false,
				// open:false

				// 总条数
				total: 0,
				// 弹出层标题
				title: "",
				// 显示搜索条件
				showSearch: true,
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					accountNumber: null,
					accountPhone: null,
					intervalType: null,
					taskType: null,
					autoSwitchType: null,
					beginTime: this.$moment().format("YYYY-MM-DD"), // 获取当前日期,
					endTime: this.$moment().format("YYYY-MM-DD"), // 获取当前日期,
				},

				// 表单参数
				form1: {
					accountNumber: null,
					accountPhone: null,
					intervalType: null,
					taskType: null,
					autoSwitchType: null,
					remark: null
				},
				queryForm: {
					accountNumber: null,
					accountPhone: null,
					intervalType: null,
					taskType: null,
					autoSwitchType: null,
				},
			};
		},
		created() {
			this.getList();
			this.initGoodsManager();
			this.user1();
		},
		mounted() {
			this.loadAll(); //获取店铺
		},
		methods: {
			/** 导出按钮操作 */
			handleExport() {
				this.download('system/accountStockpile/export', {
					...this.queryParams
				}, `账号录入_${this.$moment().format('YYYY-MM-DD')}.xlsx`)
			},
			changeZk() {
				if (Number(this.form3.offerPrice) > 0) {
					if (this.form3.rebates == 'rebates_type_0') {
						this.form3.discountedPrice = (Number(this.form3.offerPrice) * 0.90).toFixed(0)
					} else if (this.form3.rebates == 'rebates_type_1') {
						this.form3.discountedPrice = (Number(this.form3.offerPrice) * 0.80).toFixed(0)
					} else if (this.form3.rebates == 'rebates_type_2') {
						this.form3.discountedPrice = (Number(this.form3.offerPrice) * 0.70).toFixed(0)
					} else if (this.form3.rebates == 'rebates_type_3') {
						this.form3.discountedPrice = (Number(this.form3.offerPrice) * 0.60).toFixed(0)
					} else if (this.form3.rebates == '') {
						this.form3.discountedPrice = 0
					}
				}
			},
			tableRowClassName({
				row,
				rowIndex
			}) {
				if (rowIndex === 1 || rowIndex === 5 || rowIndex === 9) {
					return 'warning-row';
				} else if (rowIndex === 3 || rowIndex === 7) {
					return 'success-row';
				}
				return '';
			},
			user1() {
				getTBusShopInfo().then(res => {
					if (res.data) {
						this.disabled2 = false;
					} else {
						this.disabled2 = true;
					}
				})
			},
			user() {
				this.shkfOptions = [];
				this.zhlyOptions = [];
				this.bplyOptions = [];
				this.dlsbOptions = [];
				getTBusShopInfo().then(res => {
					if (res.data) {
						this.disabled = true;
						this.form3.shopId = res.data.id;
						if (res.data.customerService) {
							let kflist = res.data.customerService.split(/[/]/)
							kflist.forEach(item => {
								this.shkfOptions.push({
									label: item,
									value: item,
								});
							})
						}
						if (res.data.gameAccountSource) {
							let zhly = res.data.gameAccountSource.split(/[/]/)
							zhly.forEach(item => {
								this.zhlyOptions.push({
									label: item,
									value: item,
								});
							})
						}
						if (res.data.baopeiSource) {
							let bply = res.data.baopeiSource.split(/[/]/)
							bply.forEach(item => {
								this.bplyOptions.push({
									label: item,
									value: item,
								});
							})
						}
						if (res.data.loggedDevices) {
							let dlsb = res.data.loggedDevices.split(/[/]/)
							dlsb.forEach(item => {
								this.dlsbOptions.push({
									label: item,
									value: item,
								});
							})
						}
					} else {
						this.disabled = false;
					}
					this.add = true;
					this.disabled1 = true;
					this.form3.accountType = 'game_account_type_0'
					this.title = '新增账号';
				});
			},
			//获取游戏列表
			initGoodsManager() {
				getInitGoodsManager().then(res => {
					this.gameList = res.gameList
				})
			},
			change(e) {
				if (this.form3.accountType[1] == 'game_account_type_10') {
					this.zhzt = true;
				} else {
					this.zhzt = false;
				}
				if (this.form3.accountType[1] == 'game_account_type_3') {
					this.bp = true;
				} else {
					this.bp = false;
				}
			},
			changeGameArea() {
				this.form3.gameArea = ''
				let that = this
				let gm = {
					gameId: this.form3.gameId
				}
				getGameArea(gm).then(res => {
					that.qfoptions = res.gameArea
				})
			},
			changeGameArea1(id) {
				let that = this
				let gm = {
					gameId: id
				}
				getGameArea(gm).then(res => {
					that.qfoptions = res.gameArea
				})
			},
			look(item) {
				this.path = item
				this.srcList.push(this.pictureServerPath + item)
				this.openFkpz1 = true
			},
			loadAll() {
				queryTBusShop().then(response => {
					response.data.forEach((item) => {
						this.deptOptions.push({
							label: item.name,
							value: item.id,
						});
					});
				});
				return this.deptOptions;
			},
			remoteMethod(query) {
				this.loadAll1(query); //获取手机号
			},
			loadAll1(item) {
				this.phoneOptions = []
				let query = {
					phone: item
				}
				queryTBusPhone(query).then(response => {
					response.rows.forEach((item) => {
						this.phoneOptions.push({
							label: item.phone,
							value: item.phone,
						});
					});
				});
				return this.phoneOptions;
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.form3 = {};
				this.form4 = {};
				this.form5 = {};
				this.form6 = {};
				this.resetQuery();
				this.user();
			},
			checkedCitie() {
				this.form6.gameAccountSource = this.checkedCities.join('/')
			},
			/** 新增账号来源按钮操作 */
			handleAddzhly() {
				this.form6 = {};
				this.getgetShopInfo();
				this.dialogVisible2 = true;
			},
			/** 新增包赔来源按钮操作 */
			handleAddbply() {
				this.form7 = {};
				this.getgetShopInfo();
				this.dialogVisible3 = true;
			},
			/** 新增设备按钮操作 */
			handleAddsb() {
				this.form5 = {};
				this.getgetShopInfo();
				this.dialogVisible1 = true;
			},
			/** 新增客服按钮操作 */
			handleAddkf() {
				this.form4 = {};
				this.getgetShopInfo();
				this.dialogVisible = true;
			},
			//修改收号客服等信息
			handleUpdateAll() {
				if (this.dialogVisible == true) {
					this.getshopEdit(this.form4)
				} else if (this.dialogVisible1 == true) {
					this.getshopEdit(this.form5)
				} else if (this.dialogVisible2 == true) {
					this.getshopEdit(this.form6)
				} else if (this.dialogVisible3 == true) {
					this.getshopEdit(this.form7)
				}
			},
			getshopEdit(data) {
				shopEdit(data).then(res => {
					if (res.code == 200) {
						this.$message({
							type: 'success',
							message: '修改成功'
						})
						if (this.dialogVisible == true) {
							this.shkfOptions = [];
							let kflist = this.form4.customerService.split(/[/]/)
							kflist.forEach(item => {
								this.shkfOptions.push({
									label: item,
									value: item,
								});
							})
						} else if (this.dialogVisible1 == true) {
							this.dlsbOptions = [];
							let dlsb = this.form5.loggedDevices.split(/[/]/)
							dlsb.forEach(item => {
								this.dlsbOptions.push({
									label: item,
									value: item,
								});
							})

						} else if (this.dialogVisible2 == true) {
							this.zhlyOptions = [];
							let zhly = this.form6.gameAccountSource.split(/[/]/)
							zhly.forEach(item => {
								this.zhlyOptions.push({
									label: item,
									value: item,
								});
							})
						} else if (this.dialogVisible3 == true) {
							this.bplyOptions = [];
							let bply = this.form7.baopeiSource.split(/[/]/)
							bply.forEach(item => {
								this.bplyOptions.push({
									label: item,
									value: item,
								});
							})
						}

						this.dialogVisible = false;
						this.dialogVisible2 = false;
						this.dialogVisible1 = false;
						this.dialogVisible3 = false;
					}
				})
			},
			xgxr() {
				let kflist = res.data.customerService.split(/[/]/)
				kflist.forEach(item => {
					this.shkfOptions.push({
						label: item,
						value: item,
					});
				})
			},
			handleClose() {
				this.form4 = {};
				this.form5 = {};
				this.form6 = {};
				this.dialogVisible = false;
				this.dialogVisible2 = false;
				this.dialogVisible1 = false;
				this.dialogVisible3 = false;
			},
			getgetShopInfo() {
				getShopInfo(this.form3.shopId).then(res => {
					if (res.data) {
						if (this.dialogVisible == true) {
							this.form4 = res.data
						} else if (this.dialogVisible1 == true) {
							this.form5 = res.data
						} else if (this.dialogVisible2 == true) {
							this.form6 = res.data;
							let cities = this.form6.gameAccountSource.split(/[/]/);
							this.checkedCities = cities;
						} else if (this.dialogVisible3 == true) {
							this.form7 = res.data;
						}
					} else {
						alert('请联系管理员!')
					}
				})
			},
			/** 复制按钮操作 */
			copyRowData(row) {
				// 假设我们要复制name列的内容
				const textToCopy = JSON.stringify(row.gameAccount);
				if (navigator.clipboard && window.isSecureContext) {
					// navigator.clipboard API需要在安全上下文（HTTPS，localhost）中运行
					navigator.clipboard.writeText(textToCopy).then(() => {
						this.$message({
							message: '内容已复制到剪贴板',
							type: 'success',
							duration: 1500
						});
					}, (err) => {
						this.$message.error('复制到剪贴板失败');
					});
				} else {
					// 即使Clipboard API不可用时的后备方法
					let textArea = document.createElement("textarea");
					textArea.value = textToCopy;
					document.body.appendChild(textArea);
					textArea.focus();
					textArea.select();
					try {
						document.execCommand('copy');
						this.$message({
							message: '内容已复制到剪贴板',
							type: 'success',
							duration: 1500
						});
					} catch (err) {
						console.error('无法复制内容: ', err);
						this.$message.error('复制到剪贴板失败');
					}
					document.body.removeChild(textArea);
				}
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const id = row.id
				const names = row.gameAccount
				this.$modal.confirm('是否确认删除["' + names + '"]的数据项？').then(function() {
					return deleteMonitoring(id);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			change1() {
				this.queryParams.accountType = this.queryParams.accountType[1]
			},

			/** 查询账号信息列表 */
			getList() {
				this.loading = true;
				accountMonitoring(this.queryParams).then(response => {
					this.tableData = response.rows;
					this.accountNumer = response.total;
					this.total = response.total;
					this.loading = false;
				});
				collectionSource().then(res=>{
					this.cities=res.data
				})
			},
			//查看
			handleUpdate(row) {
				this.shkfOptions = [];
				this.zhlyOptions = [];
				this.dlsbOptions = [];
				getTBusShopInfo().then(res => {
					if (res.data) {
						this.disabled2 = false;
						this.disabled = true;
						this.form3.shopId = res.data.id;
						if (res.data.customerService) {
							let kflist = res.data.customerService.split(/[/]/)
							kflist.forEach(item => {
								this.shkfOptions.push({
									label: item,
									value: item,
								});
							})
						}
						if (res.data.gameAccountSource) {
							let zhly = res.data.gameAccountSource.split(/[/]/)
							zhly.forEach(item => {
								this.zhlyOptions.push({
									label: item,
									value: item,
								});
							})
						}
						if (res.data.loggedDevices) {
							let dlsb = res.data.loggedDevices.split(/[/]/)
							dlsb.forEach(item => {
								this.dlsbOptions.push({
									label: item,
									value: item,
								});
							})
						}
					} else {
						this.disabled = false;
						this.disabled2 = true;
					}
				})
				view(row.id).then(res => {
					this.add = true;
					this.disabled1 = false;
					this.form3 = res.data;
					this.form3.offerPrice = Number(this.form3.offerPrice);
					this.form3.acquirePrice = Number(this.form3.acquirePrice);
					if (this.form3.guarantee == null) {
						this.form3.guarantee = 'N'
					}
					this.title = '修改账号信息'
					this.changeGameArea1(this.form3.gameId);
				})
			},


			/** 搜索按钮操作 */
			handleQuery() {
				this.block = false;
				this.queryParams.pageNum = 1;
				this.getList();
			},

			/** 重置按钮操作 */
			resetQuery() {
				this.block = false;
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 新增确定按钮
			submitForm1() {
				if (this.$moment().format("YYYY-MM-DD") < this.form3.acquireDate) {
					this.$message.error('又穿越了!');
					return;
				};
				if (this.title == '新增账号') {
					this.$refs["form3"].validate(valid => {
						if (this.form3.gameArea.length == 1) {
							this.form3.gameArea = this.form3.gameArea[0]
						}
						if (this.form3.gameArea.length == 2) {
							this.form3.gameArea = this.form3.gameArea[1]
						}
						if (this.form3.gameArea.length == 3) {
							this.form3.gameArea = this.form3.gameArea[2]
						}
						if (valid) {
							add(this.form3).then(res => {
								if (res.code == 200) {
									this.$message({
										type: 'success',
										message: '添加成功'
									})
									this.add = false;
									this.getList();
								} else {
									this.$message.error(res.msg);
								}
							})
						}
					});
				} else {
					this.$refs["form3"].validate(valid => {
						if (this.form3.gameArea.length == 1) {
							this.form3.gameArea = this.form3.gameArea[0]
						}
						if (this.form3.gameArea.length == 2) {
							this.form3.gameArea = this.form3.gameArea[1]
						}
						if (this.form3.gameArea.length == 3) {
							this.form3.gameArea = this.form3.gameArea[2]
						}
						if (this.form3.accountType.length == 2) {
							this.form3.accountType = this.form3.accountType[1]
						}
						if (valid) {
							console.log(this.form3.gameArea)
							edit(this.form3).then(res => {
								if (res.code == 200) {
									this.$message({
										type: 'success',
										message: '修改成功'
									})
									this.add = false;
									this.getList();
								} else {
									this.$message.error(res.msg);
								}
							})
						}
					});
				}

			},


			cancel() {
				this.ck = false;
				this.add = false;
				this.open1 = false;
				this.resetForm("form2");
				this.resetForm("form");
			},



		}
	};
</script>
<style>
	.father {
		height: 80px;
		line-height: 80px;
		font-size: 25px;
		display: flex;
		justify-content: space-around;
	}

	.el-icon-loading {
		color: green;
		margin-right: 5px;
	}

	.el-icon-message-solid {
		color: green;
		margin-right: 5px;
	}

	.el-icon-check {
		color: green;
		margin-right: 5px;
	}

	.el-icon-coin {
		color: green;
		margin-right: 5px;
	}

	.el-table .warning-row {
		background: oldlace;
	}

	.el-table .success-row {
		background: #f0f9eb;
	}
</style>