<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="游戏账号" 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="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-table :data="tableData" border :row-class-name="tableRowClassName"
			:header-cell-style="{background: '#e1effb', color: 'black'}" style="width: 100%">
			<el-table-column prop="shopName" label="店铺名称">
			</el-table-column>
			<el-table-column prop="retrieveDate" label="找回日期">
				<template slot-scope="scope">
					<span v-if="scope.row.retrieveDate">{{scope.row.retrieveDate.slice(0,10)}}</span>
				</template>
			</el-table-column>
			<el-table-column prop="acquirePrice" label="收购价格">
			</el-table-column>
			<el-table-column prop="gameName" label="游戏名称">
			</el-table-column>
			<el-table-column prop="gameAccount" label="游戏账号">
			</el-table-column>
			<el-table-column prop="service" label="服务商">
				<template slot-scope="scope">
					<span v-if="scope.row.service=='taohaowan'">淘号玩</span>
					<span v-if="scope.row.service=='panzhi'">盼之</span>
				</template>
			</el-table-column>
			<el-table-column prop="level" label="售后等级">
			</el-table-column>
			<el-table-column prop="status" label="状态">
				<template slot-scope="scope">
					<span v-if="scope.row.status=='0'">待处理</span>
					<span v-if="scope.row.status=='1'">已处理(失败)</span>
					<span v-if="scope.row.status=='2'">已处理(成功)</span>
				</template>
			</el-table-column>
			<el-table-column prop="returnNumber" label="是否还号">
				<template slot-scope="scope">
					<span v-if="scope.row.returnNumber=='Y'">是</span>
					<span v-if="scope.row.returnNumber=='N'">否</span>
				</template>
			</el-table-column>
			<el-table-column prop="createName" label="申报人">
			</el-table-column>
			<el-table-column prop="createTime" label="申报日期">
			</el-table-column>
			<el-table-column prop="updateName" label="处理人">
			</el-table-column>
			<el-table-column prop="updateTime" label="处理日期">
			</el-table-column>
			<el-table-column v-if="this.$auth.hasPermi('system:retrieveDetails:hhan')" prop="returnBy" label="还号人">
			</el-table-column>
			<el-table-column v-if="this.$auth.hasPermi('system:retrieveDetails:hhan')" prop="returnTime" label="还号日期">
			</el-table-column>
			<el-table-column prop="remark" label="备注">
			</el-table-column>

			<!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['system:gameAftermarket:edit']" @click="handleUpdate(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="xz" :title="title" :visible.sync="xz" append-to-body width="1000px">
			<div style="padding: 10px;overflow: auto">
				<el-form ref="form" :model="form1" :rules="rules" label-width="80px">
					<el-row>
						<el-col :span="12">
							<el-form-item label="店铺名称" prop="shopId">
								<el-select filterable v-model="form1.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="retrieveDate">
								<el-date-picker style="width: 100%" value-format="yyyy-MM-dd"
									v-model="form1.retrieveDate" 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="form1.acquirePrice" :disabled='disabled' placeholder="请输入收购价格" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="游戏账号" prop="gameAccount">
								<el-input v-model="form1.gameAccount" :disabled='disabled' placeholder="请输入游戏账号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="所属游戏" prop="gameId">
								<el-select style="width: 100%" :disabled='disabled' v-model="form1.gameId" placeholder="请选择所属游戏">
									<el-option v-for="(item,index) in gameList" :key="item.id" :label="item.gameName"
										:value="item.id"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						
						
						<el-col :span="12">
							<el-form-item label="包赔服务商" prop="service">
								<el-select style="width: 100%" :disabled='disabled' v-model="form1.service"
									placeholder="请选择包赔服务商">
									<el-option v-for="item in bpfwsoptions" :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="level">
								<el-select style="width: 100%" :disabled='disabled' v-model="form1.level" placeholder="请选择状态">
									<el-option v-for="item in shdjoptions" :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="status">
								<el-select style="width: 100%" v-model="form1.status" placeholder="请选择状态">
									<el-option v-for="item in stoptions" :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="createName">
								<el-input disabled v-model="form1.createName" placeholder="请输入申报人" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="备注" prop="remark">
								<el-input v-model="form1.remark" placeholder="请输入备注" />
							</el-form-item>
						</el-col>

					</el-row>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>


	</div>
</template>

<script>
	import {
		getSysDeptInfo,
		getDeptInfo,
		accountMonitoring,
		add,
		upData,
		getPhone,
		view,
		deletePhone,
		getPaymentInfo,
		updateOriginalPrice,
		getTBusGoodsPaymentSum,
		updatePaymentStatus
	} from "@/api/data/gameAftermarketNotSell";
	import {
		queryTBusShop,
	} from "@/api/data/goodsPayment";
	import {
		getInitGoodsManager,
	} from "@/api/data/goods";
	import Cookies from 'js-cookie';
	import {
		getToken
	} from "@/utils/auth";
	export default {

		dicts: ['pallet_type','service_name','collection_source'],
		data() {
			return {
				deptOptions: [],
				// 统计
				originalprice: 0,
				salesprice: 0,
				paidinprice: 0,
				lr: 0,
				bplr: 0,
				allPrice: 0,
				// 筛选
				// activeNames: ['1'],
				cs: 0,
				cs1: 0,
				cs2: 0,
				cs3: 0,
				input: '',
				ck: false,
				yxbh: false,
				yxdq: false,
				spbh: false,
				sjbh: false,
				disabled: true,
				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,
				rules: {
					shopId: [{
						required: true,
						message: '请选择店铺名称',
						trigger: 'blur'
					}],
					retrieveDate: [{
						required: true,
						message: '请选择找回日期',
						trigger: 'blur'
					}],
					status: [{
						required: true,
						message: '请选择状态',
						trigger: 'blur'
					}],
					acquirePrice: [{
						required: true,
						message: '请输入收购价格',
						trigger: 'blur'
					}],
					gameId: [{
						required: true,
						message: '请选择游戏',
						trigger: 'blur'
					}],
					gameAccount: [{
						required: true,
						message: '请输入游戏账号',
						trigger: 'blur'
					}],
					service: [{
						required: true,
						message: '请选择服务商',
						trigger: 'blur'
					}],
					level: [{
						required: true,
						message: '请选择售后等级',
						trigger: 'blur'
					}],
				},
				bpfwsoptions: [{
					value: 'taohaowan',
					label: '淘号玩'
				}, {
					value: 'panzhi',
					label: '盼之'
				}, ],
				csoptions: [{
					value: 'goods_status_3',
					label: '已售'
				}, {
					value: '',
					label: '未售'
				}, ],
				shdjoptions: [{
					value: '1',
					label: '售后一级'
				}, {
					value: '2',
					label: '售后二级'
				}, ],
				bpoptions: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}, ],
				stoptions: [{
					value: '0',
					label: '待处理'
				}, {
					value: '1',
					label: '已处理(失败)'
				}, {
					value: '2',
					label: '已处理(成功)'
				},],
				gameList: [],
				tableData: [],
				// 遮罩层
				loading: true,
				// open:false

				// 总条数
				total: 0,
				// 弹出层标题
				title: "",
				// 显示搜索条件
				showSearch: true,
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					realName:null,
					phone:null,
				},

				// 表单参数
				form1: {

				},
			};
		},
		created() {
			let level=this.$route.name.slice(this.$route.name.length-8,this.$route.name.length)
			if(level=='&level=1'){
				this.queryParams.level='1'
			}else{
				this.queryParams.level='2'
			}
			this.getList();
			this.initGoodsManager();
			this.loadAll();
		},
		methods: {
			tableRowClassName({
				row,
				rowIndex
			}) {
				if (rowIndex === 1 || rowIndex === 5 || rowIndex === 9) {
					return 'warning-row';
				} else if (rowIndex === 3 || rowIndex === 7) {
					return 'success-row';
				}
				return '';
			},
			loadAll() {
				queryTBusShop().then(response => {
					response.data.forEach((item) => {
						this.deptOptions.push({
							label: item.name,
							value: item.id,
						});
					});
				});
				return this.deptOptions;
			},
			initGoodsManager() {
				getInitGoodsManager().then(res => {
					this.gameList = res.gameList
				})
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.form1={};
				this.resetQuery();
				this.xz = true;
				this.title = "添加找回信息";
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const id = row.id
				const names = row.phone
				this.$modal.confirm('是否确认删除手机号["' + names + '"]的数据项？').then(function() {
					return deletePhone(id);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},

			/** 查询账号信息列表 */
			getList() {
				this.loading = true;
				accountMonitoring(this.queryParams).then(response => {
					this.tableData = response.rows;
					this.total = response.total
					this.loading = false;
				});
			},
			//修改按钮
			handleUpdate(row) {
				this.form1=[];
				getPhone(row.id).then(res => {
					this.form1 = res.data
					if(this.form1.stockpile>0){
						this.disabled=true
					}else{
						this.disabled=false
					}
					this.xz = true;
					this.title = "修改找回信息";
				})
			},


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

			/** 重置按钮操作 */
			resetQuery() {
				this.block = false;
				this.disabled = false;
				this.resetForm("queryForm");
				this.handleQuery();
			},





			// 新增确定按钮
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.title == '添加手机号信息') {
							add(this.form1).then(res => {
								if (res.code == 200) {
									this.getList();
									this.xz = false;
									this.$modal.msgSuccess("添加成功");
								}else {
									alert(res.msg)
								}
							})
						} else {
							upData(this.form1).then(res => {
								if (res.code == 200) {
									this.getList();
									this.xz = false;
									this.$modal.msgSuccess("修改成功");
								} else {
									alert(res.msg)
								}
							})
						}
					}
				})
			},


			cancel() {
				this.xz = false;
				this.open1 = false;
				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;
	}
</style>