<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="status">
				<el-select style="width: 100%" v-model="queryParams.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-form-item label="店铺" prop="shopId">
				<el-select style="width: 100%" v-model="queryParams.shopId" filterable placeholder="请选择店铺">
					<el-option v-for="item in deptOptions" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</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-button style="margin-left: 20px;" icon="el-icon-plus" type="primary" size="mini" @click="handleAdd">新增
				</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="type" label="类型">
				<template slot-scope="scope">
					<span v-if="scope.row.type=='CZ'">充值</span>
				</template>
			</el-table-column>
			<el-table-column prop="money" label="金额">
			</el-table-column>
			<el-table-column prop="picAddress" label="图片" width="120px" align="center">
				<template slot-scope="scope">
					<image-preview v-if="scope.row.picAddress!=null"
						:src="'https://static.taohaowan.com/'+scope.row.picAddress" :width="50" :height="50" />
					<span v-else>未上传</span>
				</template>
			</el-table-column>
			<el-table-column prop="createBy" label="创建人">
			</el-table-column>
			<el-table-column prop="createTime" label="创建日期">
			</el-table-column>
			<el-table-column prop="status" label="状态">
				<template slot-scope="scope">
					<span v-if="scope.row.status=='Y'">正常</span>
					<span v-if="scope.row.status=='N'">异常</span>
				</template>
			</el-table-column>
			<el-table-column prop="remark" label="备注">
			</el-table-column>

			<!-- <el-table-column label="操作" v-if="this.$auth.hasPermi('system:gameAftermarket:shouhou')" align="center"
				width="200px" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button v-if="scope.row.guaranteeBy!=null&&scope.row.aftermarketBy!=null&&scope.row.status=='N'"
						type="primary" @click="handleUpdate2(scope.row)">托收
					</el-button>
					<el-button v-if="scope.row.status=='T'&&scope.row.voucher==null" type="warning"
						@click="handleUpdate4(scope.row)">上传凭证
					</el-button>
					<el-button v-if="scope.row.status=='N'" type="danger" @click="handleDelete(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="peifu" title="新增信息" :visible.sync="peifu" append-to-body width="1000px">
			<div>
				<el-form ref="form5" :model="form5" :rules="rules1" label-width="120px">
					<el-row>
						<el-col :span="12">
							<el-form-item label="店铺ID" prop="shopId">
								<el-select filterable  v-model="form5.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-col>
						<el-col :span="12">
							<el-form-item label="类型" prop="type">
								<el-select v-model="form5.type" style="width: 100%" clearable
									placeholder="请选择类型">
									<el-option v-for="(item,index) in options3" :label="item.label" :value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="金额" prop="money">
								<el-input v-model="form5.money" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="状态" prop="status">
								<el-select  v-model="form5.status" style="width: 100%" placeholder="请选择审核状态">
									<el-option v-for="(item,index) in options4" :label="item.label" :value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="备注" prop="remark">
								<el-input  v-model="form5.remark" placeholder="请输入备注" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="充值凭证" prop="picAddress">
								<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-item>
						</el-col>
					</el-row>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm5">添加</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<!-- 付款凭证信息 -->
		<el-dialog v-if="openFkpz" title="充值凭证" :visible.sync="openFkpz" append-to-body width="800px">
			<el-form ref="formpz" :model="formpz" :rules="rules3" label-width="80px">
				<el-row>
					<el-col :span="12">
						<el-form-item label="充值凭证" prop="picAddress">
							<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-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm3">确 定
				</el-button>
				<el-button @click="openFkpz=false">取 消</el-button>
			</div>
		</el-dialog>


	</div>
</template>

<script>
	import {
		getSysDeptInfo,
		getDeptInfo,
		accountMonitoring,
		add,
		upData,
		getPhone,
		view,
		deletePhone,
		getPaymentInfo,
		updateOriginalPrice,
		getTBusGoodsPaymentSum,
		updatePaymentStatus,
		paginQuery,
		paginQueryAdd,
		accept,
		orderInfo,
		deleteById
	} from "@/api/data/storeRecharge";
	import {
		tixian,
	} from "@/api/data/accountDetails";
	import {
		goodsPayment,
	} from "@/api/data/orderDetails";
	import {
		getShopInfo,
	} from "@/api/data/numberLibrary";
	import {
		getInitGoodsManager,
	} from "@/api/data/goods";
	import {
		queryTBusShop,
	} from "@/api/data/goodsPayment";
	import Cookies from 'js-cookie';
	import {
		getToken
	} from "@/utils/auth";
	export default {

		dicts: ['pallet_type', 'service_name', 'collection_source'],
		data() {
			var checkPhone = (rule, value, callback) => { // 手机号验证
				if (!value) {
					return callback(new Error('手机号不能为空'));
				} else {
					const reg = /^1[3456789]\d{9}$/
					if (reg.test(value)) {
						callback();
					} else {
						return callback(new Error('请输入正确的手机号'));
					}
				}
			};
			return {
				uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传的图片服务器地址
				headers: {
					Authorization: "Bearer " + getToken(),
				},
				openFkpz: false,
				zhCount: 0,
				zhPrice: 0,
				open1:false,
				// 统计
				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: false,
				block: false,
				originalPrice1open: false,
				originalPriceopen: false,
				xz: false,
				peifu: false,
				openPicture: false,
				cbj: false,
				cbj1: false,
				cbj2: true,
				fl: false,
				bp: false,
				zybd: true,
				sjbd: false,
				bpLr: false,
				form2: {
					salesPrice: 0,
					merchantsPrice: 0,
					firmsPrice: 0,
				},
				form5:{},
				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'
					}],
					mobile: [{
							required: true,
							message: '请输入电话号码',
							trigger: 'blur'
						},
						{
							validator: checkPhone,
							trigger: 'blur'
						}
					],
					idNo: [{
						required: true,
						message: '请输入身份证',
						trigger: 'blur'
					}],
					name: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur'
					}],
					service: [{
						required: true,
						message: '请选择服务商',
						trigger: 'blur'
					}],
					level: [{
						required: true,
						message: '请选择售后等级',
						trigger: 'blur'
					}],
				},
				rules1: {
					shopId: [{
						required: true,
						message: '请选择店铺',
						trigger: 'blur'
					}],
					money: [{
						required: true,
						message: '请输入充值金额',
						trigger: 'blur'
					}],
					type: [{
						required: true,
						message: '请选择类型',
						trigger: 'blur'
					}],
					remark: [{
						required: true,
						message: '请输入备注',
						trigger: 'blur'
					}],
					status: [{
						required: true,
						message: '请选择状态',
						trigger: 'blur'
					}],
				},
				typeoptions: [{
					value: 'ZHPF',
					label: '找回赔付'
				}],
				options3:[{
					value: 'CZ',
					label: '充值'
				},],
				options4:[{
					value: 'Y',
					label: '正常'
				},{
					value: 'N',
					label: '异常'
				},],

				bpfwsoptions: [{
					value: 'taohaowan',
					label: '淘号玩'
				}, {
					value: 'panzhi',
					label: '盼之'
				}, {
					value: 'nanzhi',
					label: '南栀'
				}, {
					value: 'pangxie',
					label: '螃蟹'
				}, {
					value: 'baiqing',
					label: '白情'
				}, {
					value: 'jiaoyiyou',
					label: '交易游'
				}, {
					value: 'kejinshou',
					label: '氪金兽'
				}, ],
				bpoptions: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}, ],
				csoptions: [{
					value: 'goods_status_3',
					label: '已售'
				}, {
					value: '',
					label: '未售'
				}, ],
				shdjoptions: [{
					value: '1',
					label: '售后一级'
				}, {
					value: '2',
					label: '售后二级'
				}, ],
				hhoptions: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}, ],
				stoptions: [{
					value: '0',
					label: '待处理'
				}, {
					value: '1',
					label: '已处理(失败)'
				}, {
					value: '2',
					label: '已处理(成功)'
				}, ],
				gameList: [],
				deptOptions: [],
				tableData: [],
				// 遮罩层
				loading: true,
				// open:false

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

				// 表单参数
				form1: {},
				form3: {},
				form4: {},//提现
				balance:'',
			};
		},
		created() {
			let query={
				shopName:'售后服务'
			}
			goodsPayment(query).then(response => {
				this.balance = response.rows[0].balance;
			});
			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: {
			handleUpdate4(row) {
				this.form2 = row;
				this.openFkpz = true;
			},
			submitForm3() {
				upData(this.form2).then(res => {
					if (res.code == 200) {
						this.getList();
						this.$modal.msgSuccess("上传成功!");
						this.form2=[]
					} else {
						alert(res.msg)
					}
				})
			},
			// 上传成功
			handleAvatarSuccess(res) {
				this.form5.picAddress = res.data.url
			},
			// 删除
			handleRemove(file, fileList) {
				this.form5.electronicDataList = this.form5.electronicDataList.filter(item => item !== file.response.data
					.webUrl);
			},
			// 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用
			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, fileList)
				}
			},
			tobase64(file, fileList) {
				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
					}
					this.form2.electronicDataList.push(tempobj.data)
				}
			},
			//查看
			handleUpdate2(row) {
				let query = {
					id: row.id
				}
				accept(query).then(res => {
					if (res.code == 200) {
						this.$modal.msgSuccess("已托收!");
						window.location.reload(); //置空form3
					} else {
						alert(res.msg)
					}
				})
			},
			blur() {
				if (this.form2.goodsId) {
					let query = {
						goodsId: this.form2.goodsId,
						shopId: this.form2.shopId,
					};
					orderInfo(query).then(response => {
						if (response.data.length != 0) {
							response.data.forEach((item) => {
								let gameAccount = Cookies.get('gameAccount');
								if (this.form2.gameAccount == gameAccount) {
									this.form2.salesPrice = item.salesPrice;
									this.form2.merchantsPrice = item.settlementPrice;
									this.form2.firmsPrice = (Number(this.form2.salesPrice) - Number(this
										.form2.merchantsPrice)).toFixed(0);
								} else {
									alert('账号有误请核对!')
								}
							});
							console.log(this.form2)
						} else {
							alert('商品编号有误请核对!')
						}
					});
				}

			},
			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.form5 = {};
				this.resetQuery();
				this.peifu = true;
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const id = row.id
				this.$modal.confirm('是否确认删除商品编号为["' + row.goodsId + '"]的数据项吗？').then(function() {
					return deleteById(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.$modal.confirm('请核对您的退款本金' + row.gamePrice).then(function() {

				}).then(() => {
					let data = row;
					data.guaranteeBy = 'Y';
					upData(data).then(res => {
						if (res.code == 200) {
							this.getList();
							this.$modal.msgSuccess("已确认!");
						} else {
							alert(res.msg)
						}
					})
				}).catch(() => {});
			},
			//售后确认按钮
			handleUpdate1(row) {
				this.$modal.confirm('请核对您的退款本金' + row.gamePrice).then(function() {

				}).then(() => {
					let data = row;
					data.aftermarketBy = 'Y';
					upData(data).then(res => {
						if (res.code == 200) {
							this.getList();
							this.$modal.msgSuccess("已确认!");
						} else {
							alert(res.msg)
						}
					})
				}).catch(() => {});
			},


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

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





			// 新增确定按钮
			submitForm() {
				this.gameList.forEach(res => {
					if (res.id == this.form1.gameId) {
						this.form1.gameName = res.gameName
					}
				})
				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)
								}
							})
						}
					}
				})
			},
			// 新增确定按钮
			submitForm1() {
				this.$refs["form2"].validate(valid => {
					if (valid) {
						paginQueryAdd(this.form2).then(res => {
							if (res.code == 200) {
								this.getList();
								this.peifu = false;
								this.$modal.msgSuccess("已赔付!");
								this.form2=[]
							} else {
								alert(res.msg)
							}
						})
					}
				})
			},
			// 新增确定按钮
			submitForm5() {
				this.$refs["form5"].validate(valid => {
					if (valid) {
						this.$modal.confirm('请核对您的充值金额' + this.form5.money).then(function() {
						
						}).then(() => {
							if (this.form5.picAddress == null || this.form5.picAddress == '') {
								return this.$modal.msgError("请上传充值凭证!");
							}
							paginQueryAdd(this.form5).then(res => {
								if (res.code == 200) {
									this.getList();
									this.peifu = false;
									this.$modal.msgSuccess("已添加");
									this.form5=[]
								} else {
									alert(res.msg)
								}
							})
						}).catch(() => {});
					}
				})
			},
			// 新增确定按钮
			submitForm2() {
				this.$refs["form3"].validate(valid => {
					if (valid) {
						accept(this.form3).then(res => {
							if (res.code == 200) {
								this.$modal.msgSuccess("已托收!");
								window.location.reload(); //置空form3
							} else {
								alert(res.msg)
							}
						})
					}
				})
			},


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



		}
	};
</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>