<template>
	<div>
<!--		<el-tabs v-model="activeName" @tab-click="handleClick">-->
<!--			<el-tab-pane label="推广员" name="first">-->
				<div>
					<div style="position: relative;display: inline-block;">
						<span>姓名：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入姓名"
							v-model="userName">
						</el-input>&nbsp;&nbsp;
					</div>
					<div style="position: relative;display: inline-block;">
						<span>电话：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入电话"
							v-model="phone">
						</el-input>&nbsp;&nbsp;
					</div>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="phoneSelect">查询
					</el-button>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleans">重置
					</el-button>&nbsp;&nbsp;
				</div>
				<el-table v-loading="tableDataLoading" :data="tableData.list">
					<el-table-column fixed prop="applyId" label="编号" width="50">
					</el-table-column>
					<el-table-column prop="applyName" label="姓名">
						<template slot-scope="scope">
							　<span style="color: #4f9dec;cursor: pointer;" @click="updatesvideo(scope.row)"
								v-text="scope.row.applyName"></span>
						</template>
					</el-table-column>
					<el-table-column prop="applyPhone" label="电话">
					</el-table-column>
					<!-- <el-table-column prop="applyAge" label="年龄">
					</el-table-column> -->
					<el-table-column prop="applyContent" 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==1">待审核</span>
							<span v-if="scope.row.status==2">通过</span>
							<span v-if="scope.row.status==3">拒绝</span>
						</template>
					</el-table-column>
					<el-table-column prop="status" label="操作">
						<template slot-scope="scope"> <!-- || !isAuth('agent:jujue') -->
							<el-button size="mini" type="primary"
									   :disabled="scope.row.status !== 1|| !isAuth('agent:jujue')  "
									   @click="passClicks(scope.row)">
								通过
							</el-button>
							<el-button size="mini" type="primary"
								:disabled="scope.row.status !== 1 || !isAuth('agent:tongguo')"
								@click="refuseClick(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-tab-pane>-->
<!--			<el-tab-pane label="推广收益排行榜" name="second">-->
<!--				<div>-->
<!--					<div style="position: relative;display: inline-block;">-->
<!--						<span>姓名：</span>-->
<!--						<el-input style="width: 200px;" @keydown.enter.native="phoneSelectP" placeholder="请输入姓名"-->
<!--							v-model="userName">-->
<!--						</el-input>&nbsp;&nbsp;-->
<!--					</div>-->
<!--					<div style="position: relative;display: inline-block;">-->
<!--						<span>电话：</span>-->
<!--						<el-input style="width: 200px;" @keydown.enter.native="phoneSelectP" placeholder="请输入电话"-->
<!--							v-model="phone">-->
<!--						</el-input>&nbsp;&nbsp;-->
<!--					</div>-->
<!--					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="phoneSelectP">查询-->
<!--					</el-button>-->
<!--					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleansP">重置-->
<!--					</el-button>&nbsp;&nbsp;-->
<!--				</div>-->
<!--				<el-table v-loading="tableDataLoading" :data="homeData.list">-->
<!--					<el-table-column fixed prop="rankNum" label="排名" width="80">-->
<!--						<template slot-scope="scope">-->
<!--							<div>{{scope.$index+1}}</div>-->
<!--						</template>-->
<!--					</el-table-column>-->
<!--					<el-table-column prop="userName" label="推广用户昵称" width="120">-->
<!--						<template slot-scope="scope">-->
<!--							<div style="color: #4f9dec;cursor: pointer;" @click="updatesvideo(scope.row)">-->
<!--								{{scope.row.userName?scope.row.userName:'未绑定'}}-->
<!--							</div>-->
<!--						</template>-->
<!--					</el-table-column>-->
<!--					<el-table-column prop="phone" label="手机号">-->
<!--					</el-table-column>-->
<!--					<el-table-column prop="sumMoney" label="总收益">-->
<!--					</el-table-column>-->
<!--					<el-table-column prop="artificerMoney" label="邀请师傅收益">-->
<!--					</el-table-column>-->
<!--					<el-table-column prop="userMoney" label="邀请用户收益">-->
<!--					</el-table-column>-->
<!--					&lt;!&ndash; <el-table-column prop="createTime" label="创建时间" width="160">-->
<!--					</el-table-column> &ndash;&gt;-->
<!--				</el-table>-->
<!--				<div style="text-align: center;margin-top: 10px;">-->
<!--					<el-pagination @size-change="handleSizeChange1" @current-change="handleCurrentChange1"-->
<!--						:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"-->
<!--						layout="total,sizes, prev, pager, next,jumper" :total="homeData.totalCount">-->
<!--					</el-pagination>-->
<!--				</div>-->
<!--			</el-tab-pane>-->

<!--			<el-tab-pane label="推广商家统计" name="three">-->
<!--				<div>-->
<!--					<div style="position: relative;display: inline-block;">-->
<!--						<span>推广来源：</span>-->
<!--						<el-input style="width: 200px;" placeholder="请输入推广来源" v-model="source">-->
<!--						</el-input>&nbsp;&nbsp;-->
<!--					</div>-->
<!--					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="source_Select">查询-->
<!--					</el-button>-->
<!--					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleansSource">重置-->
<!--					</el-button>&nbsp;&nbsp;-->
<!--				</div>-->
<!--				<el-table v-loading="tableDataLoading" :data="sourceData">-->
<!--					<el-table-column prop="scanningChannel" label="推广来源">-->
<!--					</el-table-column>-->
<!--					<el-table-column prop="scanningChannelCount" label="注册次数">-->
<!--					</el-table-column>-->
<!--				</el-table>-->
<!--				<div style="text-align: center;margin-top: 10px;">-->
<!--					<el-pagination @size-change="handleSizeChange1" @current-change="handleCurrentChange1"-->
<!--						:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"-->
<!--						layout="total,sizes, prev, pager, next,jumper" :total="homeData.totalCount">-->
<!--					</el-pagination>-->
<!--				</div>-->
<!--			</el-tab-pane>-->

			<!-- <el-tab-pane label="代理商" name="second">
				<div>
					<div style="position: relative;display: inline-block;">
						<span>姓名：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入姓名"
							v-model="userName">
						</el-input>&nbsp;&nbsp;
					</div>
					<div style="position: relative;display: inline-block;">
						<span>电话：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入电话"
							v-model="phone">
						</el-input>&nbsp;&nbsp;
					</div>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="phoneSelect">查询
					</el-button>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleans">重置
					</el-button>&nbsp;&nbsp;
				</div>
				<el-table v-loading="tableDataLoading" :data="tableData.list">
					<el-table-column fixed prop="applyId" label="编号" width="50">
					</el-table-column>
					<el-table-column prop="applyName" label="姓名">
						<template slot-scope="scope">
							　<span style="color: #4f9dec;cursor: pointer;" @click="updatesvideo(scope.row)"
								v-text="scope.row.applyName"></span>
						</template>
					</el-table-column>
					<el-table-column prop="applyPhone" label="电话">
					</el-table-column>
					<el-table-column prop="applyContent" label="地址">
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间">
					</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-tab-pane> -->
			<!-- 任务拒绝弹框 -->
			<el-dialog title="拒绝" :visible.sync="dialogFormVisible" center>
				<div style="margin-bottom: 10px;">
					<span
						style="width: 200px;display: inline-block;text-align: right;position: relative;top: -70px;">拒绝理由：</span>
					<el-input style="width:50%;" v-model="content" type="textarea" :rows="4" placeholder="请输入拒绝理由">
					</el-input>
				</div>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="refuseto()">确 定</el-button>
				</div>
			</el-dialog>
		</el-tabs>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				tableDataLoading: true,
				tableDataLoading1: true,
				dialogFormVisible: false,
				dialogFormVisible1: false,
				dialogFormVisible2: false,
				tableData: [],
				memberName: '',
				memberImg: '',
				memberId: '',
				sort: '',
				title: '添加',
				activeName: 'first',
				classify: 1,
				userName: '',
				phone: '',
				homeData: {},
				userName: '',
				phone: '',
				content: '',
				source: '',
				sourceData: []

			}
		},
		methods: {
			handleClick(tab, event) {
				this.page = 1
				this.userName = ''
				this.phone = ''
				if (tab._props.label == '推广员') {
					this.classify = 1
					this.dataSelect()
				}
				if (tab._props.label == '代理商') {
					this.classify = 2
					this.dataSelect()
				}
				if (tab._props.label == '推广收益排行榜') {
					this.homeSelect()
				}
				if (tab._props.label == '推广商家统计') {
					this.sourceSelect()
				}

			},
			// 获取数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('apply/selectApplyList'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'applyName': this.userName,
						'applyPhone': this.phone,
						'classify': this.classify
					})
				}).then(({
					data
				}) => {
					if (data && data.code === 0) {
						console.log('列表', data)
						this.tableDataLoading = false
						let returnData = data.data;
						this.tableData = returnData;
					}

				})
			},

			// 推广列表查询
			sourceSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('user/merchantPromotion'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'scanningChannel': this.source,
					})
				}).then(({
					data
				}) => {
					if (data && data.code === 0) {
						console.log('列表', data)
						this.tableDataLoading = false
						let returnData = data.data.records;
						this.sourceData = returnData;
						console.log(this.sourceData);
					}

				})
			},

			phoneSelect() {
				this.page = 1
				this.dataSelect()
			},
			cleans() {
				this.page = 1
				this.userName = ''
				this.phone = ''
				this.dataSelect()
			},

			source_Select() {
				this.page = 1
				this.sourceSelect()
			},

			cleansSource() {
				this.page = 1
				this.source = ''
				this.sourceSelect()
			},
			//上传成功
			handleAvatarSuccess(file) {
				this.memberImg = file.data
			},
			addNotice() {
				this.dialogFormVisible = true
			},
			handleCurrentChange(val) {
				this.page = val
				this.dataSelect()
			},
			handleSizeChange(val) {
				this.limit = val
				this.dataSelect()
			},
			handleSizeChange1(val) {
				this.limit = val
				this.homeSelect()
			},
			handleCurrentChange1(val) {
				this.page = val
				this.homeSelect()
			},
			// 添加banner图
			addNoticeTo() {
				if (this.memberImg == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请上传图片',
						type: 'warning'
					});
					return
				}
				if (this.memberName == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入名称',
						type: 'warning'
					});
					return
				}
				this.classify = 1
				if (this.title == '添加') {
					var url = 'member/insertMember'
				} else {
					var url = 'member/updateMember'
				}
				this.$http({
					url: this.$http.adornUrl(url),
					method: 'post',
					data: this.$http.adornData({
						'memberImg': this.memberImg,
						'memberId': this.memberId,
						'memberName': this.memberName,
						'sort': this.sort
					})
				}).then(({
					data
				}) => {
					this.dialogFormVisible = false
					this.$message({
						message: '操作成功',
						type: 'success',
						duration: 1500,
						onClose: () => {
							this.memberImg = ''
							this.memberId = ''
							this.memberName = ''
							this.sort = ''
							this.title = '添加'
							this.dataSelect()
						}
					})
				})
			},
			// 修改
			amendBanner(index, rows, a) {
				if (a == 1) {
					this.pl = 1
				} else {
					this.pl = 0
				}
				this.dialogFormVisible = true
				this.id = rows.id
				this.memberImg = rows.memberImg
				this.memberId = rows.memberId
				this.sort = rows.sort
				this.memberName = rows.memberName
				this.title = '修改'
			},
			// 修改
			amendNoticeTo() {
				this.$http({
					url: this.$http.adornUrl(
						`?memberId=${this.memberId}&memberImg=${this.memberImg}&sort=${this.sort}&memberName=${this.memberName}`
					),
					method: 'post',
					data: this.$http.adornData({})
				}).then(({
					data
				}) => {
					this.dialogFormVisible = false
					this.$message({
						message: '操作成功',
						type: 'success',
						duration: 1500,
						onClose: () => {
							this.dataSelect()
						}
					})
				})
			},
			//删除一级
			deletes(row) {
				let delid = row.memberId
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl(`member/deleteMemberById/?memberId=${delid}`),
						method: 'post',
						data: this.$http.adornData({})
					}).then(({
						data
					}) => {
						this.$message({
							message: '删除成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.dataSelect()
							}
						})
					})
				}).catch(() => {})
			},
			// 车辆型号列表
			models(row) {
				this.dialogFormVisible1 = true
			},
			// 详情跳转
			updatesvideo(row) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: row.userId
					}
				})
			},
			phoneSelectP() {
				this.page = 1
				this.homeSelect()
			},
			cleansP() {
				this.page = 1
				this.userName = ''
				this.phone = ''
				this.homeSelect()
			},
			// 获取排行数据列表
			homeSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('user/selectAgencyOrdersMoneyList'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'userName': this.userName,
						'phone': this.phone,
						'startTime': '',
						'endTime': ''
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data

					this.homeData = data.data
				})
			},
			//单条任务通过
			passClicks(row) {
				this.status = 1
				this.content = '同意'
				this.$http({
					url: this.$http.adornUrl('apply/auditApply'),
					method: 'post',
					params: this.$http.adornParams({
						'status': this.status,
						'ids': row.applyId,
						// 'remek': '通过'
					})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.content = ''
								this.status = ''
								this.dataSelect()
							}
						})
					} else {
						this.$message({
							message: data.msg,
							type: 'error',
							duration: 1500,
							onClose: () => {
								this.content = ''
								this.status = ''
								this.dataSelect()
							}
						})
					}

				})
			},
			//任务拒绝
			refuseClick(rows) {
				this.status = 2
				this.helpTakeId = rows.userId
				this.ids = rows.applyId
				this.content = ''
				this.refuseto()
				// this.dialogFormVisible = true
			},
			refuseto() {
				// if (this.content == '') {
				// 	this.$notify({
				// 		title: '提示',
				// 		duration: 1800,
				// 		message: '请输入拒绝理由',
				// 		type: 'warning'
				// 	});
				// 	return
				// }
				this.$http({
					url: this.$http.adornUrl('apply/auditApply'),
					method: 'post',
					params: this.$http.adornParams({
						'status': this.status,
						'ids': this.ids,
						// 'remek': this.content
					})
				}).then(({
					data
				}) => {
					this.dialogFormVisible = false
					this.$message({
						message: '操作成功',
						type: 'success',
						duration: 1500,
						onClose: () => {
							this.content = ''
							this.status = ''
							this.dataSelect()
						}
					})
				})
			},
		},
		mounted() {
			this.dataSelect()
		}
	}
</script>

<style>
</style>
