<template>
	<view>
		<view v-if="agentList == '' " class="mart60 fotct font14 fcor666">
			<image mode="widthFix" style="width: 70vw;" :src="imagewxUrl+imgadres"></image>
		</view>
		<view class="list width90 mart15" v-for="(item, index) in agentList" :key="index" @click="jumpcardlist(item.id)">
			<view class="address-box width90 paddtop15 font16 fcor333">
				{{item.agentName}}
			</view>
			<view class="width90 mart10 font14 fcor999">
				{{item.agentPhone}}
			</view>
			<view class="width90 mart10 bor-botm1"></view>
			<view class="alijusend width90 mart10 paddbotm10">
				<view class="btnsstu backcorf06" @click.stop="jumpcardff(item.id)">分发</view>
				<view class="btnsstu backcolor41"  @click.stop="jumpcardlist(item.id)">查看
				</view>
				<view class="btnsstu backcolorred" v-if="item.status == 1" @click.stop="changeAgentStatus(item.id,0)">禁用
				</view>
				<view class="btnsstu backcor99" v-if="item.status == 0" @click.stop="changeAgentStatus(item.id,1)">解除
				</view>
			</view>
		</view>
		<image src='../static/add.png' mode="widthFix" class="h5xfimg" @click="jumpaddagent()"></image>
	</view>
</template>

<script>
	import {
		getChildAgentList,
		changeAgentStatus
	} from '../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				agentList: [],
				imgadres: 'noorder.png',
				imagewxUrl: app.globalData.imageWxImg,
				pageNum: 1,
				pageSize: 10,
				isNoMoreData: false
			}
		},
		onShow() {
			this.isNoMoreData = false;
			this.agentList = [];
			this.getChildAgentList();
		},
		methods: {
			//跳转详情
			jumpcardlist(item) {
				uni.navigateTo({
					url: '../agentCardList/agentCardList?agid='+item
				})
			},
			//添加代理商
			jumpaddagent() {
				uni.navigateTo({
					url: '../addAgent/addAgent'
				})
			},
			//分发
			jumpcardff(item) {
				uni.navigateTo({
					url: '../agentDistribution/agentDistribution?agentid='+item
				})
			},
			onReachBottom() {
				this.getChildAgentList();
			},
			//查询列表
			getChildAgentList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading()
					return false;
				}
				let pagenum = this.pageNum;
				let datas = {
					agentId: app.globalData.bresthighAgent.id,
					pageNum: pagenum,
					pageSize: this.pageSize
				}
				getChildAgentList(datas).then(res => {
					if (res.return_code == '000000' && res.return_data.list != '') {
						uni.hideLoading();
						this.isNoMoreData = res.return_data.list.length == this.pageSize ? false : true;
						this.agentList = this.agentList.concat(res.return_data.list);
						if (res.return_data.total == (this.pageNum * this.pageSize)) {
							this.isNoMoreData = true;
						}
						this.pageNum = res.return_data.list.length == this.pageSize ? ++pagenum : pagenum;
					} else {
						this.agentList = [];
						uni.hideLoading()
					}
				})
			},
			//禁用
			changeAgentStatus(item,item1) {
				let that = this;
				uni.showModal({
					title: '修改状态',
					content: '确认解除或者禁用代理商?',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '操作中...'
							})
							let datas = {
								"agentId": item,
								"status": item1
							}
							changeAgentStatus(datas).then(res => {
								uni.hideLoading();
								if (res.return_code == '000000') {
									uni.showToast({
										title: '操作成功',
										icon: 'none',
										duration: 2000
									})
									that.pageNum = 1;
									that.isNoMoreData = false;
									that.agentList = [];
									that.getChildAgentList();
									return;
								}
								uni.showToast({
									title: res.return_msg,
									duration: 2000,
									icon: 'none'
								})
							})
						}
					}
				})
			}

		}
	}
</script>

<style lang="less">
	page {
		background-color: #f0f0f0;
	}

	.list {
		border-radius: 10px;
		align-items: center;
		background: #fff;
	}



	.address-box {
		display: flex;
		align-items: center;
	}

	.h5xfimg {
		width: 100rpx;
		bottom: 120rpx;
		position: fixed;
		right: 40rpx;
	}

	.btnsstu {
		width: 70px;
		height: 30px;
		line-height: 30px;
		color: #ffffff;
		font-size: 14px;
		text-align: center;
		border-radius: 10px;
		margin-right: 10px;
	}
</style>