<template>
	<div class="app-container">
		<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" style="width: 100%">
			<el-table-column prop="productName" label="产品名称">
			</el-table-column>
			<el-table-column prop="productCode" label="产品代码">
			</el-table-column>
			<el-table-column prop="version" label="版本">
			</el-table-column>
			<el-table-column label="是否更新" align="center" prop="switchgear">
				<template slot-scope="scope">
					<el-tag v-if="scope.row.switchgear=='true'">是</el-tag>
					<el-tag v-if="scope.row.switchgear=='false'" type="danger">否</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="updateContent" label="更新内容">
			</el-table-column>
			<el-table-column prop="url" 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" @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="productName">
								<el-input v-model="form1.productName" placeholder="请输入产品名称" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="产品代码" prop="productCode">
								<el-input v-model="form1.productCode" placeholder="请输入产品代码" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="版本" prop="version">
								<el-input v-model="form1.version" placeholder="请输入版本" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="是否更新" prop="switchgear">
								<el-switch v-model="form1.switchgear" active-text="是" inactive-text="否">
								</el-switch>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="更新内容" prop="updateContent">
								<el-input v-model="form1.updateContent" placeholder="请输入更新内容" />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="下载链接" prop="url">
								<el-input v-model="form1.url" 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,
		getInitGoodsManager,
		getPaymentInfo,
		updateOriginalPrice,
		getTBusGoodsPaymentSum,
		updatePaymentStatus
	} from "@/api/data/appVersion";
	import Cookies from 'js-cookie';
	import {
		getToken
	} from "@/utils/auth";
	export default {

		dicts: ['pallet_type','service_name'],
		data() {
			return {
				// 统计
				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'
					}],
				},
				gameList: [],
				tableData: [],
				// 遮罩层
				loading: true,
				// open:false

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

				// 表单参数
				form1: {

				},
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 新增按钮操作 */
			handleAdd() {
				this.form1={};
				this.resetQuery();
				this.xz = true;
				this.title = "添加app版本信息";
			},
			/** 删除按钮操作 */
			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=[];
				let query={
					id:row.id
				}
				getPhone(query).then(res => {
					this.form1 = res.data
					this.xz = true;
					this.title = "修改app版本信息";
				})
			},


			/** 搜索按钮操作 */
			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.title == '添加app版本信息') {
							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>