<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="店铺名称" v-if="disabled3" prop="shopName">
				<el-select filterable v-model="queryParams.shopId" style="width: 100%" clearable placeholder="请选择店铺名称">
					<el-option v-for="(item,index) in deptOptions" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="绑定手机" prop="phone">
				<el-input v-model="queryParams.phone" style="width: 200px;" placeholder="请输入手机号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="卡编号" prop="code">
				<el-input v-model="queryParams.code" style="width: 200px;" placeholder="请输入卡编号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="异常原因" prop="anomalies">
				<el-input v-model="queryParams.anomalies" style="width: 200px;" placeholder="请输入异常原因" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="机位" prop="placement">
				<el-input v-model="queryParams.placement" style="width: 200px;" placeholder="请输入机位" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="状态" prop="code">
				<el-select style="width: 100%" clearable v-model="queryParams.statuses" 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="monthly">
				<el-select style="width: 100%" clearable v-model="queryParams.monthly" placeholder="请选择月租状态">
					<el-option v-for="item in yzoptions" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="姓名" prop="realName">
				<el-input v-model="queryParams.realName" style="width: 200px;" placeholder="请输入手机号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>

			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
				</el-button>

				<el-button style="margin-left: 20px;" icon="el-icon-refresh" size="mini" @click="resetQuery">重置
				</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" plain v-hasPermi="['system:gameBindingPhone:add']" icon="el-icon-plus"
					size="mini" @click="handleAdd">新增
				</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>
		<el-table :data="tableData" border style="width: 100%">
			<!-- <el-table-column prop="id" label="序号">
			</el-table-column> -->
			<el-table-column prop="code" label="卡编号">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="phone" label="手机号">
			</el-table-column>
			<el-table-column prop="serviceName" label="运营商">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.service_name" :value="scope.row.serviceName" />
				</template>
			</el-table-column>
			<el-table-column prop="realName" label="姓名">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" width="150px" prop="identityCards"
				label="身份证">
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" width="150px" prop="homeAddress"
				label="家庭住址">
			</el-table-column>
			<el-table-column prop="sites" align="center" label="卡位">
			</el-table-column>
			<el-table-column prop="qq" align="center" label="QQ">
				<template slot-scope="scope">
					<el-button type="primary" @click="handleGetzh(scope.row.phone,'game_account_categorize_0')"
						plain>{{scope.row.qq}}</el-button>
				</template>
			</el-table-column>
			<el-table-column prop="weixin" align="center" label="微信">
				<template slot-scope="scope">
					<el-button type="primary" @click="handleGetzh(scope.row.phone,'game_account_categorize_1')" plain>{{scope.row.weixin}}</el-button>
				</template>
			</el-table-column>
			<el-table-column prop="wangyi" align="center" label="网易">
				<template slot-scope="scope">
					<el-button type="primary" @click="handleGetzh(scope.row.phone,'game_account_categorize_2')" plain>{{scope.row.wangyi}}</el-button>
				</template>
			</el-table-column>
			<el-table-column prop="mihayou" align="center" label="米哈游">
				<template slot-scope="scope">
					<el-button type="primary" @click="handleGetzh(scope.row.phone,'game_account_categorize_3')" plain>{{scope.row.mihayou}}</el-button>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip align="center" height="20px" prop="palletType" label="卡板类型">
			</el-table-column>
			<el-table-column prop="placement" label="机位">
			</el-table-column>
			<el-table-column prop="statuses" label="状态">
				<template slot-scope="scope">
					<span v-if="scope.row.statuses=='0'">正常</span>
					<span v-if="scope.row.statuses=='1'">异常</span>
				</template>
			</el-table-column>
			<el-table-column prop="anomalies" label="异常原因">
			</el-table-column>
			<el-table-column prop="monthly" label="缴费状态">
				<template slot-scope="scope">
					<span v-if="scope.row.monthly=='Y'">已缴</span>
					<span v-if="scope.row.monthly=='N'">未缴</span>
				</template>
			</el-table-column>
      <el-table-column prop="mbalance" label="月租金额">
      </el-table-column>
			<el-table-column prop="remark" label="备注">
			</el-table-column>
			<!-- <el-table-column prop="createTime" label="创建时间">
				<template slot-scope="scope">
					<span>{{scope.row.createTime}}</span>
				</template>
			</el-table-column> -->
			<el-table-column prop="createBy" label="创建人">
			</el-table-column>
			<!-- <el-table-column prop="updateTime" label="修改时间">
				<template slot-scope="scope">
					<span>{{scope.row.createTime}}</span>
				</template>
			</el-table-column> -->
			<el-table-column prop="updateBy" label="修改人">
			</el-table-column>

			<el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="small" v-if="scope.row.monthly=='N'" type="success"
						@click="handleYupdate(scope.row)">已交
					</el-button>
					<el-button size="small" type="primary" v-hasPermi="['system:gameBindingPhone:edit']"
						@click="handleUpdate(scope.row)">修改
					</el-button>
					<el-button size="small" type="danger" v-hasPermi="['system:gameBindingPhone:remove']"
						@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 title="提示" :visible.sync="dialogVisible2" width="30%" :before-close="handleClose">
			<el-table :data="tableData1" border style="width: 100%">
				<el-table-column prop="code" label="编号">
				</el-table-column>
				<el-table-column prop="boundMobile" label="手机号">
				</el-table-column>
				<el-table-column prop="gameAccount" label="游戏账号">
				</el-table-column>
				<el-table-column prop="gameAccountType" label="账号类型">
					<template slot-scope="scope">
						<dict-tag :options="dict.type.game_account_categorize" :value="scope.row.gameAccountType" />
					</template>
				</el-table-column>
			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible2 = false">取 消</el-button>
				<el-button type="primary" @click="dialogVisible2 = false">确 定</el-button>
			</span>
		</el-dialog>




		<!-- 添加手机号信息对话框 -->
		<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="code">
								<el-input v-model="form1.code" placeholder="请输入卡编号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="手机号" prop="phone">
								<el-input v-model="form1.phone" placeholder="请输入手机号" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="运营商" prop="serviceName">
								<el-select v-model="form1.serviceName" placeholder="请选择运营商" style="width: 100%">
									<el-option v-for="dict in dict.type.service_name" :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="realName">
								<el-input v-model="form1.realName" placeholder="请输入姓名" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="缴费状态" prop="monthly">
								<el-select style="width: 100%" v-model="form1.monthly" placeholder="请选择缴费状态">
									<el-option v-for="item in yzoptions" :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="mbalance">
                <el-input v-model="form1.mbalance" placeholder="请输入月租金额" />
              </el-form-item>
            </el-col>
						<el-col :span="12">
							<el-form-item label="身份证" prop="identityCards">
								<el-input v-model="form1.identityCards" placeholder="请输入身份证" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="家庭住址" prop="homeAddress">
								<el-input v-model="form1.homeAddress" placeholder="请输入家庭住址" />
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="title=='修改手机号信息'">
							<el-form-item label="卡位" prop="sites">
								<el-input disabled v-model="form1.sites" placeholder="请输入卡位" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="手机卡位置" prop="palletType">
								<el-select v-model="form1.palletType" placeholder="请选择手机卡位置" style="width: 100%">
									<el-option v-for="dict in ppOptions" :key="dict.value" :label="dict.label"
										:value="dict.value"></el-option>
								</el-select>
								<el-button type="primary" plain icon="el-icon-plus" size="mini"
									@click="handleAddpp">新增手机卡位置
								</el-button>
							</el-form-item>
						</el-col>
						<el-col :span="12" v-if="form1.palletType=='猫池'||form1.palletType=='卡板'">
							<el-form-item label="机位" prop="placement">
								<el-input v-model="form1.placement" placeholder="请输入机位" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="状态" prop="statuses">
								<el-select style="width: 100%" v-model="form1.statuses" 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" v-if="form1.statuses=='1'">
							<el-form-item label="异常原因" prop="anomalies">
								<el-input v-model="form1.anomalies" placeholder="请输入异常原因" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item v-if="form1.palletType=='其他'" label="备注" prop="remark1">
								<el-input type="textarea" v-model="form1.remark1" placeholder="请输入备注" />
							</el-form-item>
							<el-form-item v-else label="备注" prop="remark">
								<el-input type="textarea" 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>
		<el-dialog title="手机卡位置" :visible.sync="dialogVisible1" width="30%" :before-close="handleClose">
			<el-input type="textarea" v-model="form5.phonePlace" placeholder="请输入手机卡位置" />
			<span style="margin-top: 10px;color: red;">例此格式:猫池/飞猫池</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible1 = false">取 消</el-button>
				<el-button type="primary" v-hasPermi="['system:shop:edit']" @click="handleUpdateAll()">确 定</el-button>
			</span>
		</el-dialog>


	</div>
</template>

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

		dicts: ['pallet_type', 'service_name','game_account_categorize'],
		data() {
			return {
				tableData1:[],
				dialogVisible2: false,
				disabled3: false,
				deptOptions: [],
				dialogVisible1: false,
				form5: {},
				// 统计
				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: [],
				rules: {
					phone: [{
						required: true,
						message: '请输入手机号',
						trigger: 'blur'
					}],
					code: [{
						required: true,
						message: '请输入卡编号',
						trigger: 'blur'
					}],
					serviceName: [{
						required: true,
						message: '请输入运营商',
						trigger: 'blur'
					}],
					sites: [{
						required: true,
						message: '请输入卡位',
						trigger: 'blur'
					}],
					palletType: [{
						required: true,
						message: '请选择卡板类型',
						trigger: 'blur'
					}],
					placement: [{
						required: true,
						message: '请输入机位',
						trigger: 'blur'
					}],
					statuses: [{
						required: true,
						message: '请选择状态',
						trigger: 'blur'
					}],
					anomalies: [{
						required: true,
						message: '请输入异常原因',
						trigger: 'blur'
					}],
					remark1: [{
						required: true,
						message: '请输入备注',
						trigger: 'blur'
					}],
				},
				gameList: [],
				tableData: [],
				// 遮罩层
				loading: true,
				yzoptions: [{
					value: 'Y',
					label: '已缴'
				}, {
					value: 'N',
					label: '未缴'
				}],
				stoptions: [{
					value: '0',
					label: '正常'
				}, {
					value: '1',
					label: '异常'
				}],
				// open:false

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

				// 表单参数
				form1: {

				},
				// 表单参数
				form3: {

				},
			};
		},
		created() {
			this.user1();
			this.getList();
		},
		methods: {
			user1() {
				getTBusShopInfo().then(res => {
					if (res.data) {
						this.disabled3 = false;
					} else {
						this.disabled3 = true;
					}
				})
				queryTBusShop().then(response => {
					response.data.forEach((item) => {
						this.deptOptions.push({
							label: item.name,
							value: item.id,
						});
					});
				});
				return this.deptOptions;
			},
			handleUpdateAll() {
				shopEdit(this.form5).then(res => {
					if (res.code == 200) {
						this.ppOptions = [];
						this.$message({
							type: 'success',
							message: '修改成功'
						})
						this.dialogVisible1 = false;
						let pplist = this.form5.phonePlace.split(/[/]/)
						pplist.forEach(item => {
							this.ppOptions.push({
								label: item,
								value: item,
							});
						})
					}
				})
			},
			handleClose() {},
			handleGetzh(phone, type) {
				let query = {
					gameAccountType: type,
					boundMobile: phone,
				}
				getlistkw(query).then(res => {
					this.tableData1=res.rows
					this.dialogVisible2 = true;
				})
			},
			user() {
				this.ppOptions = [];
				this.xz = true;
				this.title = "添加手机号信息";
				getTBusShopInfo().then(res => {
					if (res.data) {
						this.form3.shopId = res.data.id;
						if (res.data.phonePlace) {
							let pplist = res.data.phonePlace.split(/[/]/)
							pplist.forEach(item => {
								this.ppOptions.push({
									label: item,
									value: item,
								});
							})
						}
					}
				})
			},
			handleAddpp() {
				this.form5 = {};
				this.getgetShopInfo();
				this.dialogVisible1 = true;
			},
			getgetShopInfo() {
				if (this.form3.shopId) {
					getShopInfo(this.form3.shopId).then(res => {
						if (res.data) {
							if (this.dialogVisible1 == true) {
								this.form5 = res.data
							}
						} else {
							alert('请联系管理员!')
						}
					})
				}

			},
			/** 新增按钮操作 */
			handleAdd() {
				this.form1 = {};
				this.resetQuery();
				this.user();
			},
			/** 删除按钮操作 */
			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;
				});
			},
			//已交按钮
			handleYupdate(row) {
				const names = row.phone
				this.$modal.confirm('是否确认手机号["' + names + '"]的月租已缴费？').then(function() {
					row.monthly = 'Y';
					return upData(row);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("确认成功");
				}).catch(() => {});
			},
			//修改按钮
			handleUpdate(row) {
				this.user();
				this.form1 = [];
				this.ppOptions = [];
				getTBusShopInfo().then(res => {
					if (res.data) {
						if (res.data.phonePlace) {
							let kflist = res.data.phonePlace.split(/[/]/)
							kflist.forEach(item => {
								this.ppOptions.push({
									label: item,
									value: item,
								});
							})
						}
					}
				})
				getPhone(row.id).then(res => {
					this.form1 = res.data
					this.form1.remark1 = this.form1.remark
					this.xz = true;
					this.title = "修改手机号信息";
				})
			},


			/** 搜索按钮操作 */
			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["form"].validate(valid => {
					if (valid) {
						if (this.form1.palletType == '其他') {
							this.form1.remark = this.form1.remark1
						}
						if (this.form1.statuses == '0') {
							this.form1.anomalies = ''
						} //异常原因置空
						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 {
							if (this.form1.palletType == '其他') {
								this.form1.remark = this.form1.remark1
							}
							if (this.form1.statuses == '0') {
								this.form1.anomalies = ''
							} //异常原因置空
							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>
