<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="店铺ID" prop="shopId">
				<el-select v-model="queryParams.shopId" filterable style="width: 200px" clearable placeholder="请选择店铺名称">
					<el-option v-for="(item,index) in deptOptions" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="账号" prop="gameAccount">
				<el-input v-model="queryParams.gameAccount"  style="width: 200px;" placeholder="请输入账号"
					clearable @keyup.enter.native="handleQuery" />
			</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 options4" :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-form-item>
		</el-form>
		<div style="display: flex;align-items: center;justify-content: space-between;">
			<p>账户余额：<span style="color: green;">{{balance}}</span>
				<el-button style="margin-left: 30px;" type="primary" size="small" @click="handleQuery2">提现</el-button>
			</p>
			<div>
				托收金额：<span style="color: red;">{{tsje}}</span>
			</div>
			<p>退款金额：<span style="color: red;">{{tkje}}</span></p>
		</div>
		<el-table  :data="tableData" style="width: 100%">
			<el-table-column prop="id" label="编号">
			</el-table-column>
			<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=='GUARANTEE_TYPE_1'">包赔收入</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_2'">找回赔付</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_3'">提现</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_4'">包赔退款</span>
				</template>
			</el-table-column>
			<el-table-column prop="gameAccount" label="游戏账号">
			</el-table-column>
			<el-table-column prop="gamePrice" label="游戏金额">
			</el-table-column>
			<el-table-column prop="guaranteePrice" label="手续费">
			</el-table-column>
			<el-table-column prop="payPrice" label="金额变动">
				<template slot-scope="scope">
					<span style="color: blue;"v-if="scope.row.type=='GUARANTEE_TYPE_1'">+{{scope.row.payPrice}}</span>
					<span style="color: red;" v-if="scope.row.type=='GUARANTEE_TYPE_2'">-{{scope.row.payPrice}}</span>
					<span style="color: red;" v-if="scope.row.type=='GUARANTEE_TYPE_3'">-{{scope.row.payPrice}}</span>
					<span style="color: red;" v-if="scope.row.type=='GUARANTEE_TYPE_4'">-{{scope.row.payPrice}}</span>
				</template>
			</el-table-column>
			<el-table-column prop="balance" label="余额">
			</el-table-column>
			<el-table-column prop="payTime" label="业务时间">
			</el-table-column>
			<el-table-column prop="status" label="状态">
				<template slot-scope="scope">
					<span v-if="scope.row.type=='GUARANTEE_TYPE_1'&&scope.row.status=='S'">已托收</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_3'&&scope.row.status=='S'">已提现</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_2'&&scope.row.status=='S'">已赔付</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_1'&&scope.row.status=='N'">待托收</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_2'&&scope.row.status=='N'">待赔付</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_3'&&scope.row.status=='N'">提现中</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_4'&&scope.row.status=='TS'">已完成</span>
					<span v-if="scope.row.type=='GUARANTEE_TYPE_1'&&scope.row.status=='TS'">已退款</span>
					<span v-if="scope.row.status=='X'">托收失败</span>
					<span v-if="scope.row.status=='PF'">赔付</span>
				</template>
			</el-table-column>
			<el-table-column prop="remark" label="备注" width="200px">
				<template slot-scope="scope">
					<div
						v-if="scope.row.status=='PF'">
						<p v-for="item in scope.row.remark.split(',')">{{item}}</p>
					</div>
					<div v-else>{{scope.row.remark}}</div>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.type=='GUARANTEE_TYPE_1'&&scope.row.status=='N'" @click="handleUpdate(scope.row)">托收
					</el-button>
					<el-button size="small" type="danger"
						v-if="scope.row.type=='GUARANTEE_TYPE_1'&&scope.row.status=='S'"
						@click="handleUpdate4(scope.row)">退款
					</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" v-if="scope.row.type=='GUARANTEE_TYPE_1'&&scope.row.status=='N'" @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="ck" title="托收信息" :visible.sync="ck" append-to-body width="1000px">
			<div style="padding: 10px;overflow: auto">
				<el-form ref="form2" :model="form2" :rules="rules" label-width="80px">
					<el-row>
						<el-col :span="12">
							<el-form-item label="店铺ID" prop="shopId">
								<el-select disabled v-model="form2.shopId" style="width: 200px" 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 disabled v-model="form2.type" style="width: 200px" 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="gameAccountId">
								<el-input disabled v-model="form2.gameAccountId"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="游戏账号" prop="gameAccount">
								<el-input disabled v-model="form2.gameAccount"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="游戏价格" prop="gamePrice">
								<el-input disabled v-model="form2.gamePrice"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="手续费" prop="guaranteePrice">
								<el-input disabled v-model="form2.guaranteePrice"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="拖款Id" prop="payId">
								<el-input disabled v-model="form2.payId"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
						<el-form-item label="拖款金额" prop="payPrice">
							<el-input disabled v-model="form2.payPrice"/>
						</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="余额" prop="balance">
								<el-input disabled v-model="form2.balance"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="状态" prop="status">
								<el-select disabled v-model="form2.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 disabled v-model="form2.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>
		<el-dialog v-if="open1" title="申请提现" :visible.sync="open1" append-to-body width="1000px">
			<div style="padding: 10px;overflow: auto;">
				<center>
					<el-form ref="form1" :model="form1" :rules="rules1" label-width="200px">
						<el-row>
							<el-col :span="12">
								<el-form-item label="店铺名称" prop="shopId">
									<el-select disabled v-model="form1.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-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="收款名称" prop="payeeAccountName">
									<el-input  v-model="form1.payeeAccountName"  placeholder="如微信、支付宝、某某银行" />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="姓名" prop="payeeName">
									<el-input  v-model="form1.payeeName"  placeholder="请输入姓名" />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="提现账号" prop="payeeAccount">
									<el-input  v-model="form1.payeeAccount"  placeholder="请输入提现账号" />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="余额(元)" prop="withdrawalAmountK">
									<el-input disabled v-model="form1.withdrawalAmountK" placeholder="余额" />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="提现金额(元)" prop="txMoney">
									<el-input v-model="form1.txMoney" placeholder="请输入提现金额" />
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</center>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button v-if="tixian==true" type="primary" @click="submitForm1">确 定
				</el-button>
				<el-button type="primary" v-else :loading="true">等待中</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<!-- 退款信息 -->
		<el-dialog v-if="tuikuan" title="退款" :visible.sync="tuikuan" append-to-body width="800px">
			<div style="display: flex;flex-wrap: wrap;">
				<el-form ref="formtk" :model="queryFormTk" :rules="rules2">
					<el-row>
						<el-col :span="12">
							<el-form-item label="退款原因" prop="remark">
								<el-input style="width: 500px;" v-model="queryFormTk.remark" type="textarea" :rows="2"
									placeholder="请输入退款原因" />
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
				<el-form>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm2()">确 定</el-button>
				<el-button @click="tuikuan=false">取 消</el-button>
			</div>
		</el-dialog>
		

	</div>
</template>

<script>
	import {
		queryTBusShop
	} from "@/api/data/goodsPayment";
	import {
		getShopInfo,
	} from "@/api/data/numberLibrary";
	import {
		getConfigKey
	} from "@/api/system/config";
	import Treeselect from "@riophae/vue-treeselect";
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";
	import {
		getSysDeptInfo,
		getDeptInfo,
		accountMonitoring,
		getBalanceYe,
		tixian,
		edit,
		add,
		view,
		deleteMonitoring,
		getPaymentInfo,
		updateOriginalPrice,
		getTBusGoodsPaymentSum,
		updatePaymentStatus,
		returnAccept
	} from "@/api/data/accountDetails";
	import {
		getTBusShopInfo,
	} from "@/api/data/orderDetails";
	import {
		getInitGoodsManager,
	} from "@/api/data/goods";
	import Cookies from 'js-cookie';
	import {
		getToken
	} from "@/utils/auth";
	export default {

		data() {
			return {
				add:false,
				pictureServerPath: null,
				path:'',
				srcList:[],
				shopId1:'',
				form2:{
					
				},
				form3:{
					yzCode:'THWADD123456',
					accountNumber: '',
					openId: '66778899',
					idCardFront: '补录',
					idCardOpposite: '补录',
					contactAddress: '补录',
					recentPhotos:'补录',
					video: '补录',
				},
				options11: [],
				uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/uploadNew", // 上传的图片服务器地址
				headers: {
					Authorization: "Bearer " + getToken(),
				},
				// electronicDataList: [],
				// 表单参数
				form: {
					electronicDataList: [],
					// electronicDataList: '',
					gamePicture: [],
					//创建一个游戏属性数值
					arrayLIst: []
				},
				// 统计
				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,
				// 付款凭证
				attach_list: [],
				carouselImg:[],
				// 任务类型
				options4: [{
					value: 'S',
					label: '已托收'
				}, {
					value: 'N',
					label: '待托收'
				},
				{
					value: 'X',
					label: '托收失败'
				},{
					value: 'TS',
					label: '包赔退款'
				},
				{
					value: 'PF',
					label: '赔付'
				}
				],
				// 是否黑号
				options5: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'X',
					label: '否'
				}],
				// 是否回收
				options6: [{
					value: 'Y',
					label: '是'
				}, {
					value: 'N',
					label: '否'
				}],
				//包赔
				options2: [{
					value: "Y",
					label: '是'
				}, {
					value: "X",
					label: '否'
				}],
				//包赔
				options3: [{
					value: "GUARANTEE_TYPE_1",
					label: '包赔收入'
				}, {
					value: "GUARANTEE_TYPE_2",
					label: '找回赔付'
				},
				{
					value: "GUARANTEE_TYPE_4",
					label: '包赔退款'
				}],
				rules2:{
					remark: [{
						required: true,
						message: '请输入退款原因',
						trigger: 'blur'
					}],
				},
				deptOptions: [],
				gameList: [],
				tableData: [],
				tixian:true,
				// 遮罩层
				loading: true,
				// open:false

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

				// 表单参数
				form1: {
					shopId:'21739f7ea7024134a7e8f47e245f6fa5',
				},
				queryForm: {
					accountNumber:null,
					accountPhone:null,
					intervalType:null,
					taskType:null,
					autoSwitchType:null,
				},
				balance:0,
				tsje:0,
				tkje:0,
				tuikuan:false,
				queryFormTk:{},
				rules1:{
					payeeAccountName: [{
						required: true,
						message: '请输入账户类型',
						trigger: 'blur'
					}],
					payeeName: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur'
					}],
					payeeAccount: [{
						required: true,
						message: '请输入提现账号',
						trigger: 'blur'
					}],
					withdrawalAmountK: [{
						required: true,
						message: '请输入余额',
						trigger: 'blur'
					}],
					txMoney: [{
						required: true,
						message: '请输入提现金额',
						trigger: 'blur'
					}],
				}
			};
		},
		created() {
			this.getServierPicture();
			this.getList();
			this.initGoodsManager();
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		methods: {
			// 退款按钮
			handleUpdate4(row) {
				Cookies.set('id', row.id)
				Cookies.set('shopId', row.shopId)
				this.tuikuan = true
			},
			submitForm2(){
				this.$refs["formtk"].validate(valid => {
					if (valid) {
						let id = Cookies.get('id')
						let shopId = Cookies.get('shopId')
						let query = {
							shopId:shopId,
							id:id,
							remark:this.queryFormTk.remark,
						}
						returnAccept(query).then(response => {
							window.location.reload()
						});
					}
				});
			},
			submitForm1() {
				this.$refs["form1"].validate(valid => {
					if (valid) {
						if (Number(this.form1.txMoney) > Number(this.form1.withdrawalAmountK)) {
							this.$message.error('提现金额不能大于余额');
						} else {
							if (this.form1.payeeAccountName != null && this.form1.payeeAccountName != '' && this.form1.payeeName !=
								null && this.form1.payeeName != '' && this.form1.payeeAccount != null && this.form1.payeeAccount !=
								'') {
								this.tixian = false;
								let query = {
									shopId: this.form1.shopId,
									txPrice: this.form1.txMoney,
									payee: this.form1.payeeName,
									payeeAccount: this.form1.payeeAccount,
									accountName: this.form1.payeeAccountName,
								}
								tixian(query).then(response => {
									window.location.reload()
								});
							} else {
								alert('请核对提现账户信息!')
							}
						}
					}
				});
				
			},
			/** 提现按钮操作 */
			handleQuery2() {
				if (this.balance == 0 || this.balance == '0' || this.balance == "") {
					this.open1 = false;
				} else {
					// 21739f7ea7024134a7e8f47e245f6fa5
					getShopInfo('21739f7ea7024134a7e8f47e245f6fa5').then(res => {
						this.form1 = res.data;
						this.form1.shopId='21739f7ea7024134a7e8f47e245f6fa5';
						this.form1.withdrawalAmountK=this.balance;
						this.open1 = true;
					})
				}
			},
			initGoodsManager() {
				getInitGoodsManager().then(res => {
					this.gameList = res.gameList
				})
			},
			getServierPicture() {
				let that = this
				getConfigKey('pictureServerPath').then(res => {
					that.pictureServerPath = res.msg
				})
			},
			look(item){
				this.path=item
				this.srcList.push(this.pictureServerPath + item)
				this.openFkpz1 = true
			},
			//店铺名称
			querySearch(queryString, cb) {
				var restaurants = this.restaurants;
				var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
				// 调用 callback 返回建议列表的数据
				cb(results);
			},
			createFilter(queryString) {
				return (restaurant) => {
					return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
				};
			},
			loadAll() {
				queryTBusShop().then(response => {
					response.data.forEach((item) => {
						this.deptOptions.push({
							label: item.name,
							value: item.id,
						});
					});
				});
				return this.deptOptions;
			},
			// handleSelect(item) {
			// 	this.shopId1=item.label
			// },
			/** 新增按钮操作 */
			handleAdd() {
				this.resetQuery();
				this.add = true;
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const id = row.id 
				const names = row.gameAccount
				this.$modal.confirm('是否确认删除["' + names + '"]的数据项？').then(function() {
					return deleteMonitoring(id);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			
			/** 查询账号信息列表 */
			getList() {
				this.loading = true;
				accountMonitoring(this.queryParams).then(response => {
					this.tableData = response.data.table.rows;
					this.tsje=response.data.tuoshou;
					this.tkje=response.data.tuikuan;
					this.total = response.data.table.total;
					this.loading = false;
				});
				getBalanceYe().then(res=>{
					this.balance=res.data.balance
				})
			},
			//查看
			handleUpdate(row){
				view(row.id).then(res=>{
					this.ck=true;
					this.form2=res.data;
				})
			},
			

			/** 搜索按钮操作 */
			handleQuery() {
				this.disabled = true;
				this.block = false;
				this.queryParams.pageNum = 1;
				this.getList();
			},
			
			/** 重置按钮操作 */
			resetQuery() {
				this.block = false;
				this.disabled = true;
				this.resetForm("queryForm");
				this.handleQuery();
			},
			


			
			
			// 编辑确定按钮
			submitForm() {
				this.$refs["form2"].validate(valid => {
					if (valid) {
						edit(this.form2).then(res=>{
							if (res.code==200) {
								this.$message({
									type: 'success',
									message: '托收成功'
								})
								this.ck=false;
								this.getList();
							} else{
								this.$message.error(res.msg);
							}
						})
					}
				});
			},
			
			
			cancel() {
				this.ck=false;
				this.add=false;
				this.open1 = false;
				this.resetForm("form2");
				this.resetForm("form");
			},
			


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

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

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

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

	.el-icon-coin {
		color: green;
		margin-right: 5px;
	}
</style>
