<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="goodsName">
				<el-input v-model="queryParams.goodsName" placeholder="请输入商品名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="商品编号" prop="id">
				<el-input v-model="queryParams.id" placeholder="请输入商品编号" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="游戏账号" prop="gameAccount">
				<el-input v-model="queryParams.gameAccount" placeholder="请输入游戏账号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="所属游戏" prop="gameId">
				<el-select v-model="queryParams.gameId">
					<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 prop="reportsType" label="传号时间">
				<el-date-picker style="70%" v-model="value1" value-format="yyyy-MM-dd" type="daterange"
					range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
				</el-date-picker>
			</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:goods: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">修改
				</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:goods:export']">导出
				</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>
		<el-row :gutter="10" class="mb8">
			<span v-if="ceshi">
				<text>通知上架</text>
				<el-radio v-model="radio" label="500">500</el-radio>
				<el-radio v-model="radio" label="1000">1000</el-radio>
				<el-radio v-model="radio" label="2000">2000</el-radio>
				<el-radio v-model="radio" label="3000">3000</el-radio>
				<el-radio v-model="radio" label="5000">5000</el-radio>
				<el-button @click="startUp()">开始</el-button>
			</span>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table :row-class-name="tableRowClassName" border :data="goodsList"
			@selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="商品名称" show-overflow-tooltip align="center" height="20px" prop="goodsName" />
			<el-table-column label="系统编号" height="20px" prop="systemId" />
			<el-table-column label="商品编号" height="20px" prop="id" />
			<el-table-column label="游戏账号" height="20px" prop="gameAccount" />
			<el-table-column v-if="queryParams.shopId=='e9e38ddf4ea04a28bcf025458df119bd'" label="联系方式" height="20px"
				prop="userName" />
			<el-table-column label="游戏名称" align="center" prop="gameId">
				<template slot-scope="scope">
					<div v-for="(item,index) in gameList" :key="item.id" :label="item.gameName" :value="item.id">
						<span v-if="item.id==scope.row.gameId">{{item.gameName}}</span>
					</div>
				</template>
			</el-table-column>
			<el-table-column label="游戏账号售价" align="center" prop="price" />
			<el-table-column label="排位状态" align="center" prop="ranking">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.ranking" :value="scope.row.ranking" />
				</template>
			</el-table-column>
			<el-table-column label="实名状态" align="center" prop="identifiedName">

				<template slot-scope="scope">
					<dict-tag :options="dict.type.identified_name" :value="scope.row.identifiedName" />
				</template>
			</el-table-column>
			<el-table-column align="center" label="店铺类型" prop="accountSource">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.account_source" :value="scope.row.accountSource" />
				</template>
			</el-table-column>
			<el-table-column label="游戏图片" align="center" v-if="this.$auth.hasPermi('system:goods:picT')">
				<template slot-scope="scope">
					<label style="color: #ff0000;" @click="openPictureDialog(scope.row)">游戏图片</label>
				</template>
			</el-table-column>
			<el-table-column label="商品状态" align="center" prop="goodsStatus">
				<template slot-scope="scope">
					<span v-if="scope.row.goodsStatus=='goods_status_0'">已上架</span>
					<span v-if="scope.row.goodsStatus=='goods_status_1'">已预订</span>
					<span v-if="scope.row.goodsStatus=='goods_status_2'">已下架</span>
					<span v-if="scope.row.goodsStatus=='goods_status_3'">已出售</span>
				</template>
			</el-table-column>
			<el-table-column label="传号时间" align="center" prop="uploadTime" />
			<el-table-column label="操作人" align="center" prop="createBy" />


			<el-table-column label="操作" width="200px" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<div v-show="scope.row.goodsStatus!='goods_status_3'">
						<el-button type="success" size="small" @click="handleSend(scope.row)"
							v-hasPermi="['system:goods:edit1']">出售
						</el-button>
						<el-button size="small" type="primary" @click="handleUpdate(scope.row)">修改
						</el-button>
						<el-button size="small" type="danger" @click="handleDelete(scope.row)"
							v-hasPermi="['system:goods:remove']">下架
						</el-button>
					</div>
					<div v-show="scope.row.goodsStatus=='goods_status_3'">
						<el-button type="success" size="small" @click="handleSend(scope.row)" disabled
							v-hasPermi="['system:goods:edit1']">出售
						</el-button>
						<el-button size="small" type="primary" disabled @click="handleUpdate(scope.row)">修改
						</el-button>
						<el-button size="small" type="danger" disabled @click="handleDelete(scope.row)">下架
						</el-button>
					</div>

				</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" :before-close="handleClose1" :visible.sync="open" high="1500px" width="100%"
			append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<!-- <el-row>
					<el-col :span="24">
						<el-form-item label="精准匹配" prop="goodsName">
							<el-checkbox-group v-model="checkList">
								<el-checkbox class="fxk" :label="item.id" :value="item.gameName" :key="item.id"
									v-for="item in gameList.slice(0,9)">{{item.gameName}}</el-checkbox>
							</el-checkbox-group>
						</el-form-item>
					</el-col>
				</el-row> -->
				<el-row>
					<el-col :span="24">
						<el-form-item label="商品名称" prop="goodsName">
							<el-input type="textarea" @input='fxsx' v-model="form.goodsName" placeholder="请输入商品名称" />
							<!-- <el-button @click="openPictureDialog(scope.row)">上传图片</el-button> -->
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="所属游戏" prop="gameId">
							<el-select v-model="form.gameId" :disabled='disabled' @change="changeGameArea"
								style="width: 100%" filterable placeholder="请选择所属游戏">
								<el-option v-if="openGame&&openGame.find(item1 => item1 == item.id)"
									v-for="(item,index) in gameList" :key="item.id" :label="item.gameName"
									:value="item.id"></el-option>
								<el-option v-if="openGame==null" 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="gameareaId">
							<el-cascader style="width: 100%" :disabled='disabled' v-model="form.gameareaId"
								:options="options" :props="{ expandTrigger: 'hover' }"></el-cascader>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item v-if="bdAccount" label="游戏账号" prop="gameAccount">
							<el-input :disabled='disabled' v-model="form.gameAccount" @blur="blur()"
								placeholder="请输入游戏账号" />
						</el-form-item>
						<el-form-item v-else label="游戏账号" prop="gameAccount">
							<el-input v-model="form.gameAccount" placeholder="请输入游戏账号" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="账号售价" prop="price">
							<el-input @input="changeZk" v-model="form.price" placeholder="请输入游戏账号售价" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="折扣" prop="rebates">
							<el-select style="width: 100%" clearable @change="changeZk" v-model="form.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">
						<el-form-item label="折扣价" prop="discountedPrice">
							<el-input disabled v-model="form.discountedPrice" placeholder="请输入游戏账号折扣价" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
					</el-col>
					<el-col :span="12" v-for="(item,index) in tableData">
						<!-- 输入框 -->
						<el-form-item v-if="item.type==3" :label="item.label" :rules="{ required: true,}">
							<!-- 修改 -->
							<el-input style="width: 100%"
								v-if="item.id==item2.attributeId&&item2.attributeValue!=null&&item2.type==3&&xiugai"
								v-for="(item2,index) in form.gameAttrs" v-model="item2.attributeValue"
								placeholder="请输入内容"></el-input>
							<el-input v-if="xiugai1" style="width: 100%" v-model="input[item.id]"
								placeholder="请输入内容"></el-input>
							<el-input v-if="xiugai2" style="width: 100%" v-model="input[item.id]"
								placeholder="请输入内容"></el-input>
							<!-- 新增 -->
							<el-input v-if="xinzeng" style="width: 100%" v-model="input[item.id]"
								placeholder="请输入内容"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-for="(item,index) in tableData2" :key="index">
						<!-- 下拉框 -->
						<el-form-item v-if="item.type==2" :label="item.label" :rules="{ required: true,}">
							<el-select style="width: 100%" v-model="selectvalue[index]" value-key="item.id"
								placeholder="请选择">
								<el-option v-for="(item1,index1) in item.children" :key="item1.id" :label="item1.label"
									:value="item1.id">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="12" v-for="(item,index) in tableData" :key="index">
						级联下拉
						<el-form-item v-if="item.type==0&&item.children" :label="item.label" :rules="{ required: true,}">
							<el-cascader style="width: 100%" v-model="selectvalue"
								:options="item.children" :props="{ expandTrigger: 'hover' }"></el-cascader>
						</el-form-item>
					</el-col> -->
					<el-col :span="12">
						<el-form-item v-show="block" v-for="(item,index) in type" v-if="item=='account_type'"
							label="账号类型" prop="accountType">
							<el-select v-model="form.accountType" style="width: 100%">
								<el-option v-for="dict in dict.type.account_type" :key="dict.value" :label="dict.label"
									:value="dict.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item v-show="false" label="主营行业" prop="accountSource">
							<el-select v-model="form.accountSource" placeholder="请选择主营行业" style="width: 100%" disabled>
								<el-option v-for="dict in dict.type.account_source" :key="dict.value"
									:label="dict.label" :value="dict.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item v-show="block" v-for="(item,index) in type" v-if="item=='account_type_wg'"
							label="账号类型" prop="accountTypeWg">
							<el-select v-model="form.accountTypeWg" style="width: 100%">
								<el-option v-for="dict in dict.type.account_type_wg" :key="dict.value"
									:label="dict.label" :value="dict.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item v-show="gameAttrs1" label="游戏属性" prop="gameAttributes" v-if="gameAttrs1">
						</el-form-item>
						<table v-show="gameAttrs1" v-if="gameAttrs1" width="100%" border="1"
							style="border-color: #f1f3f5;" cellspacing="0" cellpadding="0" align="center">
							  <tbody>
								<tr v-for="(item,index) in tableData" v-if="item.type==0">
									<th width="100px">{{item.label}}</th>
									<td width="750px">
								<tr v-for="(item1,index) in item.children" style="margin: 0 10px;">
									<th width="100px">{{item1.label}}</th>
									<td>
										<span v-for="(item2,index1) in item1.children" v-if="item1.type==1">
											<el-checkbox-group v-model="gameAttrs" style="display: inline;"
												@change="handleCheckedCitiesChange">
												<el-tooltip class="item" effect="dark" :content="item2.label"
													placement="top-start">
													<el-checkbox @change="handleCheckedCitiesChange1(item2)" class="fxk"
														:label="item2.id" :value="item2.label"
														:key="item2.id">{{item2.label}}</el-checkbox>
												</el-tooltip>
											</el-checkbox-group>
										</span>
									</td>
								</tr>
								</td>
								</tr>
								<tr v-for="(item,index) in tableData" v-if="item.type==1">
									      <th width="100px">{{item.label}}</th>
									<td width="750px">
										<span v-for="(item1,index) in item.children" style="margin: 0 10px;">
											<el-checkbox-group v-model="gameAttrs" style="display: inline;"
												@change="handleCheckedCitiesChange">
												<el-tooltip class="item" effect="dark" :content="item1.label"
													placement="top-start">
													<el-checkbox class="fxk" v-if="item1.type==1" :label="item1.id"
														:value="item1.id" :key="item1.id">{{item1.label}}</el-checkbox>
												</el-tooltip>
											</el-checkbox-group>
										</span>
									</td>
								</tr>
							</tbody>
						</table>
					</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="游戏图片" :before-close="closedialog" :visible.sync="openPicture" width="1000px" append-to-body>

			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<div class="img_list">
					<div style="position: relative;width: 100px;height: 100px;" v-for="item in attach_list">
						<el-image v-if="imgType=='ZC'" @click="deletePicture(item.id)"
							style="width: 100px;height: 100px;" :src="nginx_pictures_path+item.url"></el-image>
						<el-image v-if="imgType=='YC'" @click="deletePicture(item.id)"
							style="width: 100px;height: 100px;" :src="item"></el-image>
					</div>
				</div>
				<!-- <div class="upload-container">
					<h2>文件上传</h2>
					<input type="file" multiple @change="handleFileChange" />
					<button @click="uploadImages" :disabled="isUploading">
						{{ isUploading ? '上传中...' : '上传图片' }}
					</button>
					<div v-if="uploadResult">
						<h3>上传结果：</h3>
						<pre>{{ uploadResult }}</pre>
					</div>
					<div v-if="errorMessage" class="error-message">
						{{ errorMessage }}
					</div>
				</div> -->
				<el-upload ref="upload" :action="uploadImgUrl" list-type="picture-card"
					:before-upload="beforeAvatarUpload" :on-success="handleAvatarSuccess" :on-remove="handleRemove"
					:on-change="changeUpload" :show-file-list="true" accept="image/png, image/jpeg, application/pdf"
					:multiple="true" :headers="headers"></el-upload>
			</el-form>
			<el-button @click="addPictures">添加图片</el-button>
			<el-button type="primary" @click="download(attach_list)">下载所有图片</el-button>
			<el-button @click="cancelPic">取 消</el-button>
		</el-dialog>
		<el-dialog title="刷新记录" :visible.sync="openRefreshRecord" width="500px" append-to-body>
			<div class="">
				刷新纪录
			</div>
			<el-button @click="openRefreshRecord=false">确定</el-button>
			<el-button @click="openRefreshRecord=false">取 消</el-button>
		</el-dialog>
		<el-dialog title="线下出售" :visible.sync="openRefreshRecord1" width="500px" append-to-body>
			<el-form ref="form1" :model="form1" :rules="rules" label-width="80px">
				<el-form-item label="销售渠道" prop="sellChannels">
					<el-radio-group v-model="form1.sellChannels" @change="selectSellChannels">
						<el-radio label="taohaowan">淘号玩</el-radio>
						<el-radio label="waibu">外部</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="用户登录账号" v-show="userphone" prop="userName">
					<el-input v-model="form1.userName" placeholder="请输入客户登录账号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">出售</el-button>
					<el-button @click="openRefreshRecord1=false">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>


	</div>
</template>
<style lang="scss">
	.el-table .warning-row {
		background: oldlace;
	}

	.el-table .success-row {
		background: #f0f9eb;
	}

	.fxk {
		width: 140px;
		margin: 0 10px;
		overflow-x: hidden;
		// font-weight: 600;
	}

	.post-information-title {
		font-size: 15px;
		margin: -35px 10px 10px 10px;
		color: dodgerblue;

		span {
			display: inline-block;
			width: 11px;
			height: 100%;

			img {
				width: 100%;
			}
		}
	}

	.staffUpData .el-upload-list--picture-card .el-upload-list__item {
		overflow: inherit;
		float: left;
		background: rgba(255, 94, 94, 1);
		margin-top: 20px;

		img {
			display: block;
		}
	}

	.staffUpData .el-upload-list--picture-card .el-upload-list__item-name {
		display: block;
		width: 100%;
	}

	.staffUpData .el-upload--picture-card {
		margin-top: 20px;
	}

	.el-upload-list__item.is-success .el-upload-list__item-status-label {
		display: none !important;
	}

	.img_list {}

	.img_list div {
		margin: 10px;
		float: left;
	}
</style>

<script>
	import {
		listGoods,
		getGoods,
		delGoods,
		refGoods,
		addGoods,
		updateGoods,
		sell,
		getInitGoodsManager,
		getGameArea,
		getGoodsPictures,
		addGoodsPictures,
		getGoodsByShopId,
		getGameAttrib,
		goodsNoticeList,
		goodsPayment,
		goodsPaymentadd,
		getTBusShopInfo,
		getTBusShopInfo1,
		getGameAttr,
		getGameAttr1,
		addAttr,
		upLoadImages
	} from "@/api/data/goods";
	import {
		noticedown,
		noticeupload,
		noticeupdate
	} from "@/api/data/partnerlist";
	import {
		accountMonitoring,
	} from "@/api/data/numberLibrary";
	import {
		getToken
	} from "@/utils/auth";
	import {
		getInfo,
		getSysDeptInfo,
	} from "@/api/data/goodsPayment";
	import {
		delAttach
	} from '@/api/data/attach'
	import Treeselect from "@riophae/vue-treeselect";
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";
	import {
		deptTreeSelect
	} from '@/api/system/user';
	import Cookies from 'js-cookie';
	import axios from 'axios'
	import FileSaver from 'file-saver'
	import JSZip from 'jszip'

	export default {
		name: "Goods",
		dicts: ['account_source', 'is_multiple', 'by_stages', 'ranking', 'game_platform_mapping', 'identified_name',
			'account_type', 'binding_tap',
			'binding_psn',
			'account_type_wg', 'healthy_status', 'main_industry', 'rebates_type'
		],
		components: {
			Treeselect
		},
		data() {
			var validatePass2 = (rule, value, callback) => {
				if (Number(value) >= Number(this.form.price)) {
					callback(new Error('折扣价必须小于销售价且为数字!'));
				} else {
					callback();
				}
			};
			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 {
				files: [],
				gameId: '7cf7907cc1e74d259bc3e538239c0132',
				isUploading: false,
				uploadResult: null,
				errorMessage: '',
				imgType: 'ZC',
				value1: [],
				timer: null,
				checkList: ['7cf7907cc1e74d259bc3e538239c0132', '5ed2e37abe2249f5a5d6f9d7e0d13dfb'],
				attributeInvert: '',
				warehouse: '',
				userphone: false,
				ordercode: '',
				bdAccount: false,
				gameAttrs: [],
				gameAttrs2: [],
				gameAttrs3: [],
				gameAttrs4: [],
				input: [],
				selectvalue: [],
				resion1: [],
				checkarr: [],
				xinzeng: false,
				xiugai: false,
				xiugai1: false,
				xiugai2: false,
				values: [],
				labels: [],
				labels1: [],
				yxzhOptions: [],
				gameAttrs1: false,
				openGame: [],
				radio: '1000',
				props: {
					multiple: true
				},
				uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传的图片服务器地址
				headers: {
					Authorization: "Bearer " + getToken(),
				},
				options: [],
				nginx_pictures_path: null,
				attach_list: [],
				pictureServerPath: null,
				// 遮罩层
				loading: true,
				sxz: false,
				lb: true,
				// 选中数组
				ids: [],
				ids1: [],
				type: [],
				block: true,
				channelid: false,
				bp1: false,
				bp2: false,
				deptName: '',
				deptName1: '',
				// 部门树选项
				deptOptions: undefined,
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				multiple1: true,
				// 显示搜索条件
				showSearch: true,
				ceshi: false,
				// 总条数
				total: 0,
				total1: 13,
				// 商品信息表格数据
				goodsList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				send: false,
				ck: false,
				xg: false,
				openPicture: false,
				openRefreshRecord: false,
				openRefreshRecord1: false,
				Channel: false,
				Channel1: false,
				bp: false,
				dbbp: false,
				bp1: false,
				form1: {
					userName: '',
				},
				// 付款状态
				options1: [{
					value: 'Y',
					label: '已付款'
				}, {
					value: 'X',
					label: '未付款'
				}],
				// 销售渠道
				options2: [{

					value: 'zichu',
					label: '自出',
					children: [{
						value: 'taohaowan',
						label: '淘号玩'
					}]

				}, {

					value: 'fenxiao',
					label: '分销',
					children: [{
							value: 'game_platform_mapping_1',
							label: '游戏阁'
						}, {
							value: 'game_platform_mapping_3',
							label: '换号吧'
						},
						{
							value: 'game_platform_mapping_4',
							label: '氪金兽'
						},
						{
							value: 'game_platform_mapping_5',
							label: '盼之'
						},
						{
							value: 'game_platform_mapping_6',
							label: '螃蟹'
						},
						{
							value: 'game_platform_mapping_7',
							label: '神仙代售'
						},
						{
							value: 'game_platform_mapping_8',
							label: '看个号'
						}, {

							value: 'game_platform_mapping_9',
							label: '7881'
						},
						{
							value: 'game_platform_mapping_10',
							label: '聚幻游'
						},
						{
							value: 'game_platform_mapping_11',
							label: '破晓网'
						},
						{
							value: 'all',
							label: '其他'
						},
					]

				}],

				options4: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}],
				options5: [{
					value: 'goods_status_0',
					label: '已上架'
				}],
				// disabled:false,

				// 查看表格
				tableData: [],
				tableData1: [],
				tableData2: [], //下拉框
				tableData3: [], //输入框
				tableData4: [], //补全新的下拉框
				// 修改参数
				form: {
					gameId: '',
					name: '',
					region: '',
					date1: '',
					date2: '',
					delivery: false,
					type: [],
					resource: '',
					desc: '',
					selectvalue: [],
					rebates: 'rebates_type_0'
				},
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					pageNum1: 1,
					pageSize1: 10,
					goodsName: null,
					gameId: null,
					gameName: null,
					gameareaId: null,
					gameareaName: null,
					price: null,
					healthyStatus: null,
					accountSource: null,
					gamePicture: null,
					goodsStatus: 'goods_status_0',
					shopId: null,
					sort: null,
					id: null
				},
				disabled: false,
				gameList: [],
				electronicDataList1: [],
				electronicDataList2: [],
				// 表单参数
				form: {
					electronicDataList: [],
					gamePicture: [],
					//创建一个游戏属性数值
					arrayLIst: [],
					sort: null,
				},
				form1: {
					identifiedNames: '',
				},
				// 表单校验
				rules: {
					discountedPrice: [{
						validator: validatePass2,
						trigger: 'blur'
					}],

					sellChannels: [{
						required: true,
						message: "销售渠道不能为空",
						trigger: "blur"
					}],
					goodsName: [{
						required: true,
						message: "商品名称不能为空",
						trigger: "blur"
					}],
					gameId: [{
						required: true,
						message: "游戏不能为空",
						trigger: "blur"
					}],
					gameareaId: [{
						required: true,
						message: "大区不能为空",
						trigger: "blur"
					}],

					gameAccount: [{
							required: true,
							message: "游戏账号不能为空",
							trigger: "blur"
						},
						{
							validator: this.checkData,
							trigger: 'blur'
						}
					],
					selectvalue: [{
						required: true,
						message: "属性不能为空",
						trigger: "blur"
					}],
					ranking: [{
						required: true,
						message: "排位不能为空",
						trigger: "blur"
					}],
					accountType: [{
						required: true,
						message: "账户类型不能为空",
						trigger: "blur"
					}],
					accountTypeWg: [{
						required: true,
						message: "账号类型不能为空",
						trigger: "blur"
					}],
					bindingTap: [{
						required: true,
						message: "绑定tap不能为空",
						trigger: "blur"
					}],
					bindingPsn: [{
						required: true,
						message: "绑定psn不能为空",
						trigger: "blur"
					}],
					originalPrice: [{
						required: true,
						message: "商品原价不能为空",
						trigger: "blur"
					}],
					price: [{
							required: true,
							message: "账号售价不能为空",
							trigger: "blur",
						},
						{
							validator: checkNumber,
							trigger: 'blur'
						}
					],
					distributionChannel: [{
						required: true,
						message: "销售渠道不能为空",
						trigger: "blur"
					}],
					securityPrice: [{
						required: true,
						message: "包赔费用不能为空",
						trigger: "blur"
					}],
					securityRate: [{
						required: true,
						message: "包赔费率不能为空",
						trigger: "blur"
					}],
					isMultiple: [{
						required: true,
						message: "多倍包赔不能为空",
						trigger: "blur"
					}],
					byStages: [{
						required: true,
						message: "分期购买不能为空",
						trigger: "blur"
					}],

					paymentChannels: [{
						required: true,
						message: "付款渠道不能为空",
						trigger: "blur"
					}],
					paymentNumber: [{
						required: true,
						message: "付款流水号不能为空",
						trigger: "blur"
					}],
					isSecurity: [{
						required: true,
						message: "是否包赔不能为空",
						trigger: "blur"
					}],
					channelId: [{
							required: true,
							message: "分销编号不能为空",
							trigger: "blur"
						},
						{
							validator(rule, value, callback) {
								if (/(^[1-9]\d*$)/.test(value)) {
									callback()
								} else {
									callback(new Error('请输入正整数'))
								}
							},
							trigger: 'blur'
						}
					]
				},
				imageLinks: [],
				currentChooseImgList: [],
				currentIndex: 0,
			};
		},
		watch: {
			'$route.query.shopId': {
				handler: function(newValue, oldValue) {
					if (newValue != undefined) {
						this.queryParams.shopId = newValue
					}
					if (oldValue != undefined) {
						this.queryParams.shopId = oldValue
					}
					this.getList();
				}
			}
		},
		created() {
			this.form.shopId = this.$route.query.shopId;
			this.attributeInvert = this.$route.query.attributeInvert;
			this.warehouse = this.$route.query.warehouse;
			if (this.warehouse == 'Y') {
				this.bdAccount = true;
			}
			if (this.$route.query.openGame) {
				this.openGame = this.$route.query.openGame.split(',');
			} else {
				this.openGame = null
			}
			this.queryParams.shopId = this.$route.query.shopId;
			this.queryParams.sort = this.$route.query.sort;
			this.initGoodsManager();
			this.getList();
		},
		methods: {
			startUp() {
				if (this.currentIndex < this.goodsList.length) {
					const currentRes = this.goodsList[this.currentIndex];
					this.handleDelete1(currentRes);
					// 每次处理完一个元素后，更新索引并设置下一次处理的定时器
					this.currentIndex++;
					setTimeout(() => {
						this.startUp();
					}, Number(this.radio));
				} else {
					// 当数组所有元素都处理完后，重置索引，以便后续重新开始处理（如果需要）
					this.currentIndex = 0;
					this.startUp();
				}
			},
			handleFileChange(event) {
				this.files = event.target.files;
				this.errorMessage = '';
			},
			async uploadImages() {
				if (this.files.length === 0) {
					this.errorMessage = '请选择文件';
					return;
				}

				this.isUploading = true;
				this.errorMessage = '';
				this.uploadResult = null;

				const formData = new FormData();
				for (let i = 0; i < this.files.length; i++) {
					formData.append('images', this.files[i]); // 添加文件
				}

				const url = process.env.VUE_APP_BASE_API +
				`/system/goods/uploadImages?gameId=${this.gameId}`; // 使用相对路径
				// const url = `/prod-api/system/goods/uploadImages?gameId=${this.gameId}`; // 使用相对路径

				try {
					const response = await fetch(url, {
						method: 'POST', // 使用 POST 方法
						headers: {
							'Authorization': 'Bearer ' + getToken(), // 添加认证信息
						},
						body: formData, // 设置请求体
					});

					if (!response.ok) {
						throw new Error('上传失败：' + response.statusText);
					}

					const result = await response.json(); // 解析响应数据
					this.uploadResult = result;
					console.log('上传成功:', result);
				} catch (error) {
					this.errorMessage = '上传失败：' + error.message;
					console.error('上传失败:', error);
				} finally {
					this.isUploading = false;
				}
			},
			//批量图片下载
			//this.currentChooseImgList参数是当前选中图片的数组，包含了pictureUrl，pictureName 等
			//我们根据选中图片的数组长度为1进行单张图片下载，大于1进行批量操作，数量为0则提示勾选
			download(imgLists) {
				this.currentChooseImgList = [];
				imgLists.forEach((res, index) => {
					if (this.imgType == 'ZC') {
						let query = {
							pictureUrl: this.nginx_pictures_path + res.url,
							pictureName: '图片' + index
						}
						this.currentChooseImgList.push(query)
					} else {
						let query = {
							pictureUrl: res,
							pictureName: '图片' + index
						}
						this.currentChooseImgList.push(query)
					}
				})
				//多张图片下载成压缩包
				if (this.currentChooseImgList.length > 1) {
					this.exportLoading = true
					const zip = new JSZip()
					const _this = this
					const promises = []
					const cache = {}
					for (const item of this.currentChooseImgList) {
						const promise = _this.getFile(item.pictureUrl).then((data) => {
							// 下载文件, 并存成ArrayBuffer对象
							// const file_name = item.realName // 获取文件名
							zip.file(item.pictureName + '.png', data, {
								binary: true
							}) // 逐个添加文件，需要加后缀".png"
							cache[item.pictureName] = data
						})
						promises.push(promise)
					}
					Promise.all(promises)
						.then(() => {
							zip.generateAsync({
								type: 'blob'
							}).then((content) => {
								// 生成二进制流
								FileSaver.saveAs(content, '图片') // 利用file-saver保存文件  自定义文件名
								_this.$message.success('图片下载完成')
							})
							_this.exportLoading = false
						})
						.catch((res) => {
							_this.$message.warning('文件下载失败!')
							_this.exportLoading = false
						})
				} else {
					//单张图片下载
					this.downloadIamge(
						this.rightList[this.currentIndex].pictureUrl,
						this.rightList[this.currentIndex].pictureName
					)
				}
			},
			//批量
			getFile(url) {
				return new Promise((resolve, reject) => {
					axios({
							method: 'get',
							url,
							responseType: 'blob',
						})
						.then((response) => {
							resolve(response.data)
						})
						.catch((error) => {
							reject(error.toString())
						})
				})
			},
			tableRowClassName({
				row,
				rowIndex
			}) {
				if (rowIndex === 1 || Number.isInteger((rowIndex - 1) / 4)) {
					return 'warning-row';
				} else if (rowIndex === 3 || Number.isInteger((rowIndex - 3) / 4)) {
					return 'success-row';
				}
				return '';
			},

			//单张图片下载
			downloadIamge(imgsrc, name) {
				//下载图片地址和图片名
				var image = new Image()
				// 解决跨域 Canvas 污染问题
				image.setAttribute('crossOrigin', 'anonymous')
				image.onload = function() {
					var canvas = document.createElement('canvas')
					canvas.width = image.width
					canvas.height = image.height
					var context = canvas.getContext('2d')
					context.drawImage(image, 0, 0, image.width, image.height)
					var url = canvas.toDataURL('image/png') //得到图片的base64编码数据

					var a = document.createElement('a') // 生成一个a元素
					var event = new MouseEvent('click') // 创建一个单击事件
					a.download = name || 'photo' // 设置图片名称
					a.href = url // 将生成的URL设置为a.href属性
					a.dispatchEvent(event) // 触发a的单击事件
				}
				image.src = imgsrc
			},


			getBase64(img) {
				// width、height调用时传入具体像素值，控制大小 ,不传则默认图像大小
				function getBase64Image(img, width, height) {
					var canvas = document.createElement('canvas')
					canvas.width = width || img.width
					canvas.height = height || img.height

					var ctx = canvas.getContext('2d')
					ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
					var dataURL = canvas.toDataURL()
					return dataURL
				}
				return new Promise((resolve) => {
					var image = new Image()
					image.crossOrigin = 'Anonymous'
					image.src = img
					if (img) {
						image.onload = function() {
							// 读取图片之后的操作
							resolve(getBase64Image(image))
						}
					}
				})
			},
			checkData(rule, value, callback) {
				if (value) {
					if (/[\u4E00-\u9FA5]/g.test(value)) {
						callback(new Error('不能为中文!'))
					} else {
						callback()
					}
				}
				callback()
			},
			blur() {
				this.form.gameId = null;
				this.form.gameareaId = null;
				this.form.price = null;
				this.form.stockpileId = null;
				if (this.form.gameAccount) {
					let query = {
						accountType: 'game_account_type_0',
						gameAccount: this.form.gameAccount,
					};
					accountMonitoring(query).then(response => {
						if (response.rows.length != 0) {
							response.rows.forEach((item) => {
								this.form.gameId = item.gameId;
								this.form.gameareaId = item.gameArea;
								this.form.price = item.offerPrice;
								this.form.stockpileId = item.id;
								this.form.rebates = item.rebates;
								this.form.discountedPrice = item.discountedPrice;
								this.changeGameArea(this.form.gameId);
								this.disabled = true;
							});
						} else {
							alert('账号有误请核对!')
						}
					});
				}

			},
			//班次循环遍历
			gettimes(postcode) {
				let times = [];
				//当当前postcode的值与总List中某一条的postcode的值相等时，拿出来push到list中
				for (let i = 0; i < this.tableData.length; i++) {
					if (this.tableData[i].id == postcode) {
						times.push(this.tableData[i])
					}
				}
				return times;
			},
			fxsx() {
				if (this.attributeInvert == 'A') {
					let goodsName = this.form.goodsName.split(/,|，|【|】|、|:|[/]|：|·|!|[ ]|[+]/);
					this.values = [];
					let reasult1 = this.checkList.find(item => {
						return item == this.form.gameId
					})
					goodsName.forEach(arr => {
						let reasult = []
						this.tableData1.forEach(item => {
							if (item.label == arr) {
								reasult.push(item)
							}
						})
						if (reasult) {
							reasult.forEach(res => {
								if (res.type != 2) {
									this.values.push(res.id);
								}
							})
						}
						// if (reasult1 != undefined) {
						// 	let reasult = this.tableData1.find(item => {
						// 		return item.label == arr
						// 	})
						// 	if (reasult) {
						// 		if (reasult.type != 2) {
						// 			this.values.push(reasult.id);
						// 		}
						// 	}
						// } else {
						// 	let reasult = this.tableData1.find(item => {
						// 		return item.label.includes(arr)
						// 	})
						// 	if (reasult) {
						// 		if (reasult.type != 2) {
						// 			this.values.push(reasult.id);
						// 		}
						// 	}
						// }
					});
					if (this.title == '添加商品信息,添加完请记得添加商品图片') {
						if (this.values.length != 0) {
							this.values.forEach(res => {
								this.gameAttrs.push(res)
							})
						}
					}
				}
			},
			handleCheckedCitiesChange() {
				if (this.attributeInvert == 'B') {
					this.find(this.gameAttrs)
					this.labels = [...new Set(this.labels)];
					if (this.values.length == 0) {
						this.form.goodsName = this.labels.map(item => item);
						this.form.goodsName = this.form.goodsName.join('/'); //属性label添加到名称当中
					}
				}
			},
			handleCheckedCitiesChange1(item) {
				item.active = !item.active;
				let nameList = []
				if (item.active == true) {
					this.tableData1.forEach(res1 => { //通过id反找label
						if (res1.id == item.id) {
							nameList.push(res1.label)
						}
					})
					const dataList = []
					nameList.forEach(res => {
						this.tableData1.forEach(res1 => {
							if (res1.label == res) {
								dataList.push(res1.id)
							}
						})
					})
					dataList.forEach(res => {
						this.gameAttrs.push(res)
					})
					this.gameAttrs = ([...new Set(this.gameAttrs)])
				} else if (item.active == false) {
					this.tableData1.forEach(res1 => { //通过id反找label
						if (res1.id == item.id) {
							nameList.push(res1.label)
						}
					})
					const dataList = []
					nameList.forEach(res => {
						this.tableData1.forEach(res1 => {
							if (res1.label == res) {
								dataList.push(res1.id)
							}
						})
					})
					// 遍历 array1
					for (let i = 0; i < dataList.length; i++) {
						let index = this.gameAttrs.indexOf(dataList[i]);
						// 如果 array1[i] 存在于 array2 中
						if (index !== -1) {
							// 从 array2 中删除该元素
							this.gameAttrs.splice(index, 1);
						}
					}
				}
			},
			handleClose1() {
				this.gameAttrs1 = false;
				this.open = false;
				this.gameAttrs = [];
				this.selectvalue = [];
				this.tableData2 = [];
				this.tableData3 = [];
				this.tableData4 = [];
				this.xiugai = false;
				this.xiugai1 = false;
				this.xiugai2 = false;
			},
			deletePicture(id) {
				let that = this
				this.$modal.confirm("确定删除此图片吗？").then(function() {
					delAttach(id).then(r => {
						getGoodsPictures({
							goodsId: that.form.id
						}).then(resp => {
							that.nginx_pictures_path = resp.nginx_pictures_path
							if (resp.attachlist.length != 0) {
								that.attach_list = resp.attachlist
							} else {
								that.attach_list = resp.gamePicturelist
							}

						})
					})
				})
			},

			rowClass() {
				return "text-align: rigth;";
			},

			addPictures() {
				let that = this
				this.form.gamePicture = null;
				addGoodsPictures(this.form).then(resp => {
					if (resp.code == 200) {
						setTimeout(this.test, 3000); //3000毫秒后执行test()函数，只执行一次。
					}
				})
			},
			test() {
				this.openPicture = false
				let query = {
					id: this.form.id
				}
				noticeupload(query).then(res => {
					console.log(res)
				})
				location.reload();
			},


			openPictureDialog(rows) {
				this.openPicture = true
				this.form = rows
				this.form.electronicDataList = []
				let that = this
				getGoodsPictures({
					goodsId: this.form.id
				}).then(resp => {
					that.nginx_pictures_path = resp.nginx_pictures_path
					if (resp.attachlist.length != 0) {
						that.attach_list = resp.attachlist
						this.imgType = 'ZC'
					} else {
						that.attach_list = resp.gamePicturelist
						this.imgType = 'YC'
					}
				})
			},

			closedialog(done) {
				this.openPicture = false;
				this.$refs.upload.clearFiles()
			},

			uploadSumit() { // 上传文件
				this.isloading = true
				uploadElectronicData(this.form).then((res) => {
					this.$emit('getUploadSuccess')
					this.$message({
						message: '上传成功',
						type: 'success'
					})
					this.isshow = false
					this.isloading = false
				}).catch((e) => {
					this.$message({
						message: '上传失败',
						type: 'error'
					})
					this.form.electronicDataList = []
					this.isshow = false
					this.isloading = false
				})
			},
			openDialog(employeeId) {
				this.isshow = true
				this.form.employeeId = employeeId
				// employeeId && this.editEmployeeStatusDetail()
			},
			handlePictureCardPreview(file) {
				this.dialogImageUrl = file.url
				this.dialogVisible = true
			},
			handleDownload(file) {},
			// 删除
			handleRemove(file, fileList) {},
			// 上传之前
			beforeAvatarUpload(file) {
				const isJPG = file.type === 'image/jpeg'
				const isPng = file.type === 'image/png'
				const isPdf = file.type === 'application/pdf'
				const isLt50M = file.size / 1024 / 1024 < 50
				if (!isLt50M) {
					this.$message.warning('上传文件大小不能超过 50MB!')
					return false
				}
				if (!isJPG && !isPng && !isPdf) {
					this.$message.warning('只能上传 JPG/PNG/PDF/JPEG 格式!')
					return false
				}
			},
			// 上传成功
			handleAvatarSuccess(res) {
				this.form.gamePicture = res.data.url;
			},
			// 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用
			changeUpload(file, fileList) {
				if (file.status === 'success') {
					this.$refs.upload.uploadFiles = this.$refs.upload.uploadFiles.filter((item) => {
						return item.raw.size / 1024 / 1024 < 50
					})
					this.tobase64(file)
				}
			},
			tobase64(file) {
				let that = this
				var reader = new FileReader()
				reader.readAsDataURL(file.raw)
				reader.onload = (e) => {
					const tempobj = {
						data: file.response.data.webUrl,
						suffix: '.' + file.raw.type.split('/')[1],
						fileName: file.name,
						uid: file.uid,
					}
					if (tempobj.uid == null) {
						this.$message.error('图片uid为空,请稍后重新上传图片!');
					} else if (tempobj.data == null) {
						this.$message.error('图片data为空,请稍后重新上传图片!');
					} else if (tempobj.suffix == null) {
						this.$message.error('图片suffix为空,请稍后重新上传图片!');
					} else if (tempobj.fileName == null) {
						this.$message.error('图片fileName为空,请稍后重新上传图片!');
					} else {
						this.form.electronicDataList.push(tempobj)
					}
				}
			},

			// 强制重新渲染
			forceUpdate() {
				this.$forceUpdate()
			},
			changeZk() {
				if (Number(this.form.price) > 0) {
					if (this.form.rebates == 'rebates_type_0') {
						this.form.discountedPrice = (Number(this.form.price) * 0.90).toFixed(0)
					} else if (this.form.rebates == 'rebates_type_1') {
						this.form.discountedPrice = (Number(this.form.price) * 0.80).toFixed(0)
					} else if (this.form.rebates == 'rebates_type_2') {
						this.form.discountedPrice = (Number(this.form.price) * 0.70).toFixed(0)
					} else if (this.form.rebates == 'rebates_type_3') {
						this.form.discountedPrice = (Number(this.form.price) * 0.60).toFixed(0)
					} else if (this.form.rebates == '') {
						this.form.discountedPrice = 0
					}
				}
			},

			changeGameArea() {
				this.form.arrayList = []
				this.gameAttrs = []
				this.selectvalue = []
				this.tableData2 = []
				this.tableData3 = []
				this.tableData4 = []
				let that = this
				let gm = {
					gameId: this.form.gameId
				}
				getGameArea(gm).then(res => {
					that.options = res.gameArea
				})
				getGameAttrib(gm.gameId).then(res => {

					if (res.data.gameProperties != null) {
						this.block = true;
						let data = res.data.gameProperties.split(",")
						this.type = data
					} else {
						this.block = false
					}
				})
				let query = {
					gameId: gm.gameId
				}
				getGameAttr(query).then(res => {
					if (res.data[0].children) {
						this.gameAttrs1 = true
						this.tableData = res.data[0].children;
						this.tableData.forEach(res => {
							if (res.type == 2) {
								this.tableData2.push(res)
								this.tableData4.push(res.children)
							}
							if (res.type == 3) {
								this.tableData3.push(res.id)
							}
						});
					} else {
						this.gameAttrs1 = false
					}
				})
				getGameAttr1(query).then(res => {
					if (res.data[0].children) {
						this.gameAttrs1 = true;
						this.treeToArr(res.data[0].children);
						this.fxsx();
					} else {
						this.gameAttrs1 = false
					}

				})
			},
			changeGameArea(id) {
				this.form.arrayList = []
				this.gameAttrs = []
				this.selectvalue = []
				this.tableData2 = []
				this.tableData3 = []
				this.tableData4 = []
				let that = this
				let gm = {
					gameId: id
				}
				getGameArea(gm).then(res => {

					that.options = res.gameArea
				})
				getGameAttrib(gm.gameId).then(res => {

					if (res.data.gameProperties != null) {
						this.block = true;
						let data = res.data.gameProperties.split(",")
						this.type = data
					} else {
						this.block = false
					}
				})
				let query = {
					gameId: gm.gameId
				}
				getGameAttr(query).then(res => {
					if (res.data[0].children) {
						this.gameAttrs1 = true
						this.tableData = res.data[0].children;
						this.tableData.forEach(res => {
							if (res.type == 2) {
								this.tableData2.push(res)
								this.tableData4.push(res.children)
							}
							if (res.type == 3) {
								this.tableData3.push(res.id)
							}
						});
					} else {
						this.gameAttrs1 = false
					}

				})
				getGameAttr1(query).then(res => {
					if (res.data[0].children) {
						this.gameAttrs1 = true;
						this.treeToArr(res.data[0].children);
						this.fxsx();
					} else {
						this.gameAttrs1 = false
					}

				})
			},
			changeGameArea2(id) {
				this.form.arrayList = []
				this.gameAttrs = []
				this.selectvalue = []
				this.tableData2 = []
				this.tableData3 = []
				this.tableData4 = []
				// this.form.gameId='';
				let that = this
				let gm = {
					gameId: id
				}
				getGameArea(gm).then(res => {

					that.options = res.gameArea
				})
				getGameAttrib(gm.gameId).then(res => {

					if (res.data.gameProperties != null) {
						this.block = true;
						let data = res.data.gameProperties.split(",")
						this.type = data
					} else {
						this.block = false
					}
				})
				let query = {
					gameId: gm.gameId
				}
				getGameAttr(query).then(res => {
					if (res.data[0].children) {
						this.gameAttrs1 = true
						this.tableData = res.data[0].children;
						this.tableData.forEach(res => {
							if (res.type == 2) {
								this.tableData2.push(res)
								this.tableData4.push(res.children)
							}
							if (res.type == 3) {
								this.tableData3.push(res.id)
							}
						});
					} else {
						this.gameAttrs1 = false
					}
					this.getHxData();
				})
				getGameAttr1(query).then(res => {
					if (res.data[0].children) {
						this.gameAttrs1 = true;
						this.treeToArr(res.data[0].children);
						this.fxsx();
					} else {
						this.gameAttrs1 = false
					}

				})
			},
			getHxData() {
				let id = Cookies.get('idXiu');
				getGoods(id).then(response => {
					this.form = response.data;
					if (this.warehouse == 'Y') {
						this.disabled = true;
						this.bdAccount = true;
					} else {
						this.disabled = false;
						this.bdAccount = false;
					}
					this.open = true;
					if (this.form.gameAttrs.length == 0) {
						this.xiugai1 = true;
						this.xiugai = false;
						this.xiugai2 = false;
					} else {
						let type = this.form.gameAttrs.find(res => {
							return res.type == 3;
						});
						if (type) {
							this.xiugai2 = false;
							this.xiugai1 = false;
							this.xiugai = true;
							//输入框补全
							let inputs = []
							this.form.gameAttrs.forEach(item => {
								if (item.type == 3) {
									inputs.push(Number(item.attributeId))
									return;
								}
							})
							// 赋值
							let reasult = this.getArrDifference(inputs, this.tableData3);
							if (reasult.length != 0) {
								let resu1 = [];
								reasult.forEach(item => {
									let query = {
										attributeId: '',
										attributeValue: '',
										type: 3,
										sxType: 'new',
									}
									query.attributeId = item;
									this.form.gameAttrs.push(query)
								})

							}
						} else {
							this.xiugai2 = true;
							this.xiugai1 = false;
							this.xiugai = false;
						}
					}
					this.xinzeng = false;
					this.title = "修改商品信息";
					let jsonstr = response.data.verticalProperties;
					//获取查询数据中的下拉框
					let selects = []
					this.form.gameAttrs.forEach(item => {
						if (item.type == 2) {
							selects.push(Number(item.attributeId))
							return;
						}
					})
					// 获取下拉框原数组id
					let query = []
					this.tableData4.forEach((res, index) => {
						let query1 = []
						res.forEach((item, index1) => {
							query1.push(item.id)
						})
						query[index] = query1
					})
					let selectvalues = []
					query.forEach(res => {
						let resualt = selects.find(item => {
							return res.includes(item);
						})
						if (resualt == undefined) {
							resualt = ''
						}
						selectvalues.push(resualt)
					})
					this.selectvalue = selectvalues
					console.log(this.selectvalue)
					this.form.gameAttrs.forEach(item => {
						if (item.type != 2) {
							this.gameAttrs.push(Number(item.attributeId))
							return;
						}
					})

					//非空判断，转换json集合
					if (jsonstr != null) {
						let attribute = JSON.parse(jsonstr);
						//回填游戏属性
						this.form.arrayList = attribute;
					}
				});
			},
			/**
			 * 过滤数组 将树状结构转换为平铺数组
			 * @param data 树形结构的数据
			 */
			//将树形结构数据转换为平铺数据
			treeToArr(arr) {
				let result = [];
				let node = [];
				node = node.concat(arr);
				while (node.length) {
					let first = node.shift();
					if (first.children) {
						node = node.concat(first.children);
						delete first.children;
					}
					result.push(first);
				}
				this.tableData1 = result;
			},
			getTree(data, firstId) {
				let temp = [];
				const result = [];
				data.forEach(function(item) {
					if (item.pid === firstId) { // 当递归第一次时创建新对象
						const newObj = {
							'name': item.name,
							'id': item.id
						}; // 重新定义obj
						temp = getTree(data, item.id); // 递归开始
						if (temp.length) { // 多层children
							newObj.children = temp;
						}
						result.push(newObj)
					}
				});
				return result
			},

			find(arr) {
				this.labels = [];
				arr.forEach(arr => {
					let reasult = this.tableData1.find(item => {
						return item.id == arr
					})
					this.labels.push(reasult.label);
				});
			},
			initGoodsManager() {
				getInitGoodsManager().then(res => {
					this.pictureServerPath = res.pictureServerPath
					this.gameList = res.gameList
				})
				getTBusShopInfo1().then(res => {
					if (res.msg) {

					} else { //admin/分销/买号
						this.ceshi = true
					}
				})
			},

			/** 查询商品信息列表 */
			getList() {
				this.loading = true;
				listGoods(this.queryParams).then(response => {
					this.goodsList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancelPic() {
				this.$refs.upload.clearFiles()
				this.openPicture = false;
				this.reset();
				location.href = location.href + "#reloaded";
			},


			cancel() {
				this.open = false;
				this.send = false;
				this.bp = false;
				this.dbbp = false;
				this.bp1 = false;
				this.bp2 = false;
				this.gameAttrs = [];
				this.selectvalue = [];
				this.tableData2 = [];
				this.tableData3 = [];
				this.tableData4 = [];
				this.xiugai = false;
				this.xiugai1 = false;
				this.xiugai2 = false;
				this.gameAttrs1 = false;
				this.channelid = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					goodsName: null,
					gameId: null,
					gameName: null,
					gameareaId: null,
					gameareaName: null,
					createTime: null,
					price: null,
					healthyStatus: null,
					accountSource: null,
					gamePicture: null,
					goodsStatus: null,
					shopId: this.form.shopId,
					electronicDataList: [],
					arrayList: [],
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				if (this.value1 != null) {
					this.queryParams.beginUploadTime = this.value1[0]
					this.queryParams.endUploadTime = this.value1[1]
				} else {
					this.queryParams.beginUploadTime = ''
					this.queryParams.endUploadTime = ''
				}
				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
				this.multiple1 = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.form = [];
				this.form.shopId = this.$route.query.shopId;
				this.block = false;
				this.form.arrayList = [];
				const shopId = this.$route.query.shopId;
				getGoodsByShopId(shopId).then(response => {
					if (response.msg == "true") { //说明 之前上传的号  图片都已经传了
						this.reset();
						this.open = true;
						this.xiugai = false;
						this.xiugai1 = false;
						this.xiugai2 = false;
						this.xinzeng = true;
						Cookies.set('query', null)
						this.title = "添加商品信息,添加完请记得添加商品图片";
						this.form.accountSource = this.$route.query.accountSource
					} else {
						this.$modal.notice("(" + response.msg + "....)订单没有传图片，请完善之后在操作!").then(function() {

						})
					}
				});
			},
			//出售按钮
			handleSend(row) {
				Cookies.set('id', row.id)
				this.openRefreshRecord1 = true;
			},
			selectSellChannels(e) {
				if (e == 'taohaowan') {
					this.userphone = true;
				} else {
					this.form1.userName = null;
					this.userphone = false;
				}
			},
			onSubmit() {
				this.$refs["form1"].validate(valid => {
					if (valid) {
						if (this.form1.sellChannels == 'taohaowan') {
							if (this.form1.userName) {
								this.getsell();
							} else {
								alert('登录账号不能为空!')
							}
						} else {
							this.getsell();
						}
					}
				})
			},
			getsell() {
				let id = Cookies.get('id')
				this.orderCode();
				let query = {
					sellChannels: this.form1.sellChannels,
					userName: this.form1.userName,
					orderCode: this.ordercode,
					id: id,
				}
				sell(query).then(res => {
					this.openRefreshRecord1 = false;
					this.form1.userName = null;
					this.form1.sellChannels = null;
					this.$modal.msgSuccess("出售成功");
					this.getList();
				})
			},
			orderCode() {
				const now = new Date()
				let month = now.getMonth() + 1
				let day = now.getDate()
				let hour = now.getHours()
				let minutes = now.getMinutes()
				let seconds = now.getSeconds()
				month = month < 10 ? "0" + month : month;
				day = day < 10 ? "0" + day : day;
				hour = hour < 10 ? "0" + hour : hour;
				minutes = minutes < 10 ? "0" + minutes : minutes;
				seconds = seconds < 10 ? "0" + seconds : seconds;
				let orderCode = now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math
					.round(Math.random() * 10000000000)).toString();
				this.ordercode = orderCode
				return orderCode;
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.form.arrayList = [];
				this.form.gameAttrs = [];
				this.form.electronicDataList = [];
				Cookies.set('idXiu', row.id || this.ids);
				this.changeGameArea2(row.gameId);
			},
			getArrDifference(arr1, arr2) {
				return arr1.concat(arr2).filter(function(v, i, arr) {
					return arr.indexOf(v) === arr.lastIndexOf(v);
				});
			},

			/** 提交按钮 */
			submitForm() {
				let _this = this;
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (Array.isArray(this.form.gameareaId) != true) {
							_this.form.gameareaId = this.form.gameareaId
						} else {
							_this.form.gameareaId = _this.form.gameareaId[this.form.gameareaId.length - 1]
						}
						let arr2 = []
						this.selectvalue.forEach(arr => {
							let reasult = this.tableData1.find(item => {
								return item.id == arr
							})
							if (reasult) {
								arr2.push(reasult.label);
							}
						});
						arr2.forEach(res => {
							if (res == '可二次实名') {
								this.form.identifiedName = 'identified_name_1'
							}
							if (res == '支持人脸包赔' || res == '支持人脸') {
								this.form.identifiedName = 'identified_name_3'
							}
							if (res == '无排位') {
								this.form.ranking = 'ranking_1'
							}
							if (res == '可排位') {
								this.form.ranking = 'ranking_2'
							}
						})
						let tableData3 = []
						this.selectvalue.forEach(res => {
							if (res) {
								tableData3.push(res)
							}
						})
						if (this.tableData2.length == tableData3.length) {
							if (_this.form.id != null) {
								var arr1 = [];
								// 下拉框
								for (var i in this.selectvalue) {
									let query = {
										attributeId: '',
									}
									query.attributeId = this.selectvalue[i];
									arr1.push(query)
								}
								if (this.xiugai1 == true || this.xiugai2 == true) {
									let ids = [];
									this.tableData.forEach(item => {
										if (item.type == 3) {
											ids.push(item.id)
											return;
										}
									});
									// 输入框
									var resu = [];
									var arr = [];
									for (var i in this.input) {
										let query = {
											attributeId: '',
											attributeValue: ''
										}
										query.attributeId = i;
										query.attributeValue = this.input[i];
										arr.push(i)
										resu.push(query)
									}
									let newArr = ids.filter((x) => !arr.some((item) => x == item));
									var resu1 = [];
									newArr.forEach(item => {
										let query = {
											attributeId: '',
											attributeValue: ''
										}
										query.attributeId = item;
										query.attributeValue = '';
										resu1.push(query)
									})
									let query = resu1.concat(resu)
									let gameAttrs4 = this.gameAttrs.concat(this.gameAttrs3)
									let resion = gameAttrs4.map(item => ({
										attributeId: item
									}))
									gameAttrs4.forEach(arr => {
										let reasult = _this.form.gameAttrs.find(item => {
											return Number(item.attributeId) == arr
										})
										if (reasult) {
											this.gameAttrs4.push(reasult);
										}
									});
									_this.form.gameAttrs = this.gameAttrs4.concat(resion).concat(query).concat(
										arr1);
									_this.form.gameAttrs = [...new Set(_this.form.gameAttrs)];
								} else {
									let query = []
									_this.form.gameAttrs.forEach(res => {
										if (res.sxType == 'new') {
											query.push(res)
										}
									})
									let gameAttrs4 = this.gameAttrs.concat(this.gameAttrs3)
									let resion = gameAttrs4.map(item => ({
										attributeId: item
									}))
									gameAttrs4.forEach(arr => {
										let reasult = _this.form.gameAttrs.find(item => {
											return Number(item.attributeId) == arr && item.type !=
												2 && item.type !=
												1
										})
										if (reasult) {
											this.gameAttrs4.push(reasult);
										}
									});
									// this.gameAttrs4.forEach(res => {
									// 	resion.forEach((e, i) => {
									// 	  if (Number(e.attributeId)== Number(res.attributeId)) delete resion[i];
									// 	});
									// })
									_this.form.gameAttrs = this.gameAttrs4.concat(resion).concat(arr1).concat(
										query)
									_this.form.gameAttrs = [...new Set(_this.form.gameAttrs)];
								}
								_this.form.verticalProperties = JSON.stringify(this.form.arrayList);
								updateGoods(_this.form).then(response => {
									this.gameAttrs1 = false
									this.gameAttrs = [];
									this.selectvalue = [];
									this.tableData2 = [];
									this.tableData3 = [];
									this.tableData4 = [];
									this.gameAttrs4 = [];
									this.$modal.msgSuccess("修改成功");
									this.open = false;
									this.getList();
								});
								// let query = {
								// 	id: this.form.id
								// }
								// noticeupdate(query).then(res => {
								// 	console.log(res)
								// })
							} else {
								let ids = [];
								this.tableData.forEach(item => {
									if (item.type == 3) {
										ids.push(item.id)
										return;
									}
								});
								var resu = [];
								var arr = [];
								for (var i in this.input) {
									let query = {
										attributeId: '',
										attributeValue: ''
									}
									query.attributeId = i;
									query.attributeValue = this.input[i];
									arr.push(i)
									resu.push(query)
								}
								var arr1 = [];
								for (var i in this.selectvalue) {
									let query = {
										attributeId: '',
									}
									query.attributeId = this.selectvalue[i];
									arr1.push(query)
								}
								let newArr = ids.filter((x) => !arr.some((item) => x == item));
								var resu1 = [];
								newArr.forEach(item => {
									let query = {
										attributeId: '',
										attributeValue: ''
									}
									query.attributeId = item;
									query.attributeValue = '';
									resu1.push(query)
								})
								let query = resu1.concat(resu)
								let gameAttrs4 = this.gameAttrs.concat(this.gameAttrs3)
								let resion = gameAttrs4.map(item => ({
									attributeId: item
								}))
								_this.form.gameAttrs = (resion.concat(query)).concat(arr1);
								_this.form.verticalProperties = JSON.stringify(this.form.arrayList);
								_this.form.sort = this.queryParams.sort;
								addGoods(_this.form).then(response => {
									this.gameAttrs1 = false
									this.gameAttrs = []
									this.gameAttrs4 = []
									this.selectvalue = []
									this.tableData2 = []
									this.tableData3 = []
									this.tableData4 = []
									this.$modal.msgSuccess("新增成功,请继续添加商品图片！！！！！");
									this.open = false;
									this.getList();
								})
							}
						} else {
							this.$message.error('请勾选完整下拉菜单属性!');
						}
					}
				});
			},

			/** 下架按钮操作 */
			handleDelete(row) {
				let that = this
				const ids = row.id || this.ids;
				Cookies.set('DeleteId', ids);
				this.$modal.confirm('此商品是否已出售？已出售商品请勿点击确定按钮！').then(function() {

				}).then(() => {
					this.$modal.confirm('是否确认下架商品信息编号为"' + ids + '"的数据项？').then(function() {
						setTimeout(that.test1, 3000); //3000毫秒后执行test()函数，只执行一次。
						return delGoods(ids);
					}).then(() => {
						this.getList();
						this.$modal.msgSuccess("下架成功");
					}).catch(() => {});
				}).catch(() => {});

			},
			/** 下架按钮操作 */
			handleDelete1(row) {
				let that = this
				const ids = row.id || this.ids;
				delGoods(ids).then(res => {
					if (res.code == 200) {
						this.$modal.msgSuccess("下架成功");
						this.getList();
					} else {
						alert(res.msg)
					}
				})
			},
			test1() {
				let id = Cookies.get('DeleteId')
				let query = {
					id: id
				}
				let that = this
				noticedown(query).then(res => {
					clearInterval(that.timer)
				})
			},

			/** 刷新按钮操作 */
			handleRefresh(row) {
				let id = this.$route.query.shopId;
				getTBusShopInfo(id).then(res => {
					let RefreshableTtimes = res.data.refreshCount
					let RefreshedTimes = res.data.useRefreshCount
					const ids = this.ids;
					const shopId = this.$route.query.shopId;
					// 把写的提示信心需要换行的地方分成数组 confirmText
					const confirmText = ['剩余刷新次数：' + RefreshableTtimes + '', '已刷新次数：' + RefreshedTimes + '',
						'是否确认刷新商品信息编号为"' + ids + '"的数据项？'
					]
					const newDatas = []
					const h = this.$createElement
					for (const i in confirmText) {
						newDatas.push(h('p', {
							style: 'color: red'
						}, confirmText[i]))
					}
					this.$confirm(
						'提示', {
							title: '提示',
							message: h('div', null, newDatas),
							showCancelButton: true,
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning'
						}
					).then(() => {
						this.multiple1 = true;
						this.sxz = true;
						this.lb = false;
						let data = {
							ids: ids,
							shopId: shopId
						}
						return refGoods(data).then(res => {
							if (res.code == 200) {
								this.multiple1 = false;
								this.sxz = false;
								this.lb = true;
								this.getList();
								this.$modal.msgSuccess("刷新成功");
							}
						})
					}).then(() => {}).catch(() => {});
				})

			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('system/goods/export', {
					...this.queryParams
				}, `goods_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>