<template>
	<div>
		<!-- 列表 -->
		<div style="margin-left:10px;display: inline-block">
			<span>渠道码名称：</span>
			<el-input
				style="width: 200px"
				placeholder="请输入名称"
				v-model="qdmName">
			</el-input>
		</div>
		<div style="margin-left:10px;display: inline-block">
			<span>编码：</span>
			<el-input
				style="width: 200px"
				placeholder="请输入编码"
				v-model="qdsCode">
			</el-input>
		</div>
		<div style="margin-left:10px;display: inline-block">
			<span>渠道商：</span>
			<el-input
				style="width: 200px"
				placeholder="请输入渠道商"
				v-model="qdsName">
			</el-input>
		</div>
		<div style="margin-left:10px;display: inline-block">
			<span>类目：</span>
			<el-select clearable v-model="lm" style="width: 50%">
				<el-option
					v-for="item in lmData"
					:key="item.id"
					:label="item.name"
					:value="item.id"
				>
				</el-option>
			</el-select>
		</div>
		<el-button
			style="margin-left: 10px"
			size="mini"
			type="primary"
			icon="document"
			@click="handleSelect"
		>查询
		</el-button>
		<el-button
			style="margin-left: 10px"
			size="mini"
			type="primary"
			icon="document"
			@click="handleClear"
		>重置
		</el-button>
		<el-table v-loading="tableDataLoading" :data="tableData.list">
			<el-table-column
				prop="id"
				label="序号"
				width="80"
			>
			</el-table-column>
			<el-table-column
				prop="qdmName"
				label="渠道码名称"
				width="220"
			>
			</el-table-column>
			<el-table-column
				prop="qdsCode"
				label="编码"
				width="150"
			>
			</el-table-column>
			<el-table-column prop="lm" label="所属类目">
				<template slot-scope="scope">
					{{ showDictValue(scope.row.lm, lmData) }}
				</template>
			</el-table-column>
			<el-table-column
				prop="qdsName"
				label="渠道商"
				width="200"
			>
			</el-table-column>
			<el-table-column
				prop="userName"
				label="绑定人员"
				width="150"
			>
			</el-table-column>
			<el-table-column
				prop="rate"
				label="渠道分成"
				width="150"
			>
				<template slot-scope="scope">
					<span>{{scope.row.rate}}%</span>
				</template>
			</el-table-column>
			<el-table-column
				prop="smCount"
				label="扫码数量"
				width="150"
			>
			</el-table-column>
			<el-table-column
				prop="ordersCount"
				label="订单数量"
				width="150"
			>
			</el-table-column>
			<el-table-column
				prop="money"
				label="累计获得佣金"
				width="150"
			>
			</el-table-column>
			<el-table-column
				prop="createTime"
				label="创建时间"
				width="150"
			>
			</el-table-column>
			<el-table-column
				prop="startTime"
				label="推广开始时间"
				width="150"
			>
			</el-table-column>
			<el-table-column
				prop="endTime"
				label="推广结束时间"
				width="150"
			>
			</el-table-column>
			<el-table-column label="操作" prop="id" width="260" fixed="right">
				<template slot-scope="scope">
					<el-button
						size="mini"
						type="primary"
						style="margin: 5px"
						@click="handleInvitationView(scope.row)"
					>邀请的用户
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div style="text-align: center; margin-top: 10px">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:page-sizes="[10, 20, 30, 40]"
				:page-size="limit"
				:current-page="page"
				layout="total,sizes, prev, pager, next,jumper"
				:total="tableData.totalCount"
			>
			</el-pagination>
		</div>
		<!-- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 邀请用户列表弹框 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-->
		<el-dialog :title=titles :visible.sync="dialogInvitationListFormVisible" width="60%" center @close="closeInvitation">
			<div style="margin-left: 10px; display: inline-block;">
				<span>姓名：</span>
				<el-input
					style="width: 200px"
					placeholder="请输入姓名"
					v-model="invitationName"
				></el-input>
			</div>
			<div style="margin-left: 10px; display: inline-block">
				<span>手机号：</span>
				<el-input
					style="width: 200px"
					placeholder="请输入手机号"
					v-model="invitationPhone"
				></el-input>
			</div>
			<el-button
				style="margin-left: 10px;"
				size="mini"
				type="primary"
				icon="document"
				@click="handleSelectInvitation">查询
			</el-button>
			<el-button
				style="margin-left: 10px"
				size="mini"
				type="primary"
				icon="document"
				@click="handleClearInvitation">重置
			</el-button>
			<el-table :data="invitationTableData.list" style="width: 100%">
				<el-table-column prop="userId" label="用户ID"></el-table-column>
				<el-table-column prop="avatar" label="头像">
					<template slot-scope="scope">
						<img
							v-if="scope.row.avatar && scope.row.avatar != ''"
							:src="scope.row.avatar"
							width="40"
							height="40"
						/>
						<span v-else>暂无图片</span>
					</template>
				</el-table-column>
				<el-table-column prop="name" label="姓名"></el-table-column>
				<el-table-column prop="phone" label="手机号"></el-table-column>
			</el-table>
			<div style="text-align: center; margin-top: 10px">
				<el-pagination
					@size-change="handleInvitationSizeChange"
					@current-change="handleInvitationCurrentChange"
					:page-size="invitationLimit"
					:current-page="invitationPage"
					layout="total, prev, pager, next,jumper"
					:total="invitationTableData.totalCount"
				></el-pagination>
			</div>
		</el-dialog>
		<!--  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<邀请用户列表<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
	</div>
</template>

<script>

export default {
	data() {
		return {
			apiUrl: "",
			titles: "",
			tableDataLoading: false,
			tableData: {},
			lmData: [],
			qdmName: "",
			qdsCode: "",
			qdsName: "",
			lm: "",
			startTime: "",
			endTime: "",
			page: 1,
			limit: 10,
			dialogInvitationListFormVisible: false,
			invitationName: "",
			invitationPhone: "",
			invitationPage: 1,
			invitationLimit: 10,
			invitationTableData:{},
		};
	},
	methods: {
		showDictValue(data, datas){
			const dictItem = datas.find(item => data === item.id);
			return dictItem ? dictItem.name : '';
		},
		// 获取列表数据
		handleLm() {
			this.$http({
				url: this.$http.adornUrl("commission/qdsCode/lmList"),
				method: "get",
				params: this.$http.adornParams({}),
			}).then(({data}) => {
				if (data.code == 0) {
					this.lmData = data.data;
				} else {
					this.$notify({
						title: "提示",
						duration: 1800,
						message: data.msg,
						type: "warning",
					});
				}
			});
		},
		// 获取列表数据
		handleSelect() {
			this.tableDataLoading = true;
			this.$http({
				url: this.$http.adornUrl("commission/qdsData/findPage"),
				method: "get",
				params: this.$http.adornParams({
					page: this.page,
					limit: this.limit,
					qdmName: this.qdmName,
					qdsCode: this.qdsCode,
					qdsName: this.qdsName,
					lm: this.lm,
					startTime: this.startTime,
					endTime: this.endTime,
				}),
			}).then(({data}) => {
				if (data.code == 0) {
					this.tableData = data.data;
					console.log(this.tableData);
				} else {
					this.$notify({
						title: "提示",
						duration: 1800,
						message: data.msg,
						type: "warning",
					});
				}
				this.tableDataLoading = false;
			});
		},
		// 重置
		handleClear() {
			this.qdmName = "";
			this.qdsCode ="";
			this.qdsName ="";
			this.lm ="";
			this.startTime = "";
			this.endTime = "";
			this.page = 1;
			this.handleSelect();
		},

		//分页
		handleSizeChange(val) {
			this.limit = val;
			this.handleSelect();
		},

		//翻页
		handleCurrentChange(val) {
			this.page = val;
			this.handleSelect();
		},

		handleInvitationView(row){
			this.titles = '邀请的用户列表';
			this.invitationCode = row.qdsCode;
			this.handleSelectInvitation();
			this.dialogInvitationListFormVisible = true;
		},

		handleSelectInvitation(){
			this.invitationTableDataLoading = true;
			this.$http({
				url: this.$http.adornUrl("commission/qdsData/invitationPage"),
				method: "get",
				params: this.$http.adornParams({
					page: this.invitationPage,
					limit: this.invitationLimit,
					qdsCode: this.invitationCode,
					name: this.invitationName,
					phone: this.invitationPhone
				}),
			}).then(({data}) => {
				if (data.code == 0) {
					this.invitationTableData = data.data;
				} else {
					this.$notify({
						title: "提示",
						duration: 1800,
						message: data.msg,
						type: "warning",
					});
				}
				this.invitationTableDataLoading = false;
			});
		},

		//分页
		handleInvitationSizeChange(val) {
			this.invitationLimit = val;
			this.handleSelectInvitation();
		},

		//翻页
		handleInvitationCurrentChange(val) {
			this.invitationPage = val;
			this.handleSelectInvitation();
		},

		// 重置
		handleClearInvitation() {
			this.invitationName = "";
			this.invitationPhone = "";
			this.invitationPage = 1;
			this.invitationLimit = 10;
			this.handleSelectInvitation();
		},

	},
	mounted() {
		this.handleLm();
		this.handleSelect();
	},
};
</script>

<style>
.customWidth {
	width: 80% !important;
}
.el-dialog--center {
	text-align: center;
	margin-top: 1vh !important;
}

.el-tooltip__popper {
	width: 200px;
	padding: 10px;
	color: #000 !important;
	box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.4);
	background-color: #fff !important;
}

.adver_main.box a {
	display: flex;
	justify-content: center;
	height: 150px;
	line-height: 150px;
	text-decoration: none;
}

.bannerManin span {
	display: inline-block;
	margin-left: 5px;
}

.bannerManin img {
	width: 48px;
	height: 48px;
	border-radius: 50%;
}

.bannerbtn a {
	flex: 1;
	text-align: center;
	color: #3e8ef7 !important;
	text-decoration: none;
}

.imgs {
	position: relative;
	border-radius: 6px;
	width: 148px;
	height: 148px;
	margin-right: 10px;
	display: inline-block;
}

.dels {
	position: absolute;
	top: 0;
	left: 0;
	display: none;
}

.dels .el-icon-delete {
	line-height: 148px;
	padding-left: 58px;
	font-size: 25px;
	color: #fff;
}

.imgs:hover .dels {
	width: 100%;
	height: 100%;
	background: #000;
	display: block;
	opacity: 0.5;
}

.bqList {
	padding: 4px 14px;
	margin: 4px;
	border: 1px solid #efefef;
	font-size: 12px;
	color: #999;
	border-radius: 4px;
	margin-right: 15px;
}

.delss {
	display: none;
	position: relative;
}

.delss .el-icon-delete {
	position: absolute;
	top: 0;
}

.bqList:hover .delss {
	display: initial;
	opacity: 0.5;
}

.tj {
	padding: 6px !important;
	margin: 4px;
	font-size: 12px;
	border: 1px solid #ccc;
	border-radius: 4px;
}
</style>
