<template>
	<view class="examineStyle" :style="{'height':contentHeight}">
		<view style="width: 100%;height: 100%;">
			<u-empty v-if="g.length==0" text="暂无数据" mode="data"></u-empty>
			<template v-if="g.length > 0">
				<view style="height: calc(100vh - 50px);width: calc(100vw);overflow: hidden;">
					<scroll-view :scroll-y="true" :enable-back-to-top="true" :enable-flex="true" @scrolltolower="lower" :style="{ height: '100%' }">
						<view style="display: flex;flex-direction: column;align-items: center;">
							<view v-for="(item, index) in g" :key="index" class="listbox">
								<view class="box_top">
									<u-avatar :src="item.Photo" size="110"></u-avatar>
									<view class="box_r">
										<view style="width: 100%;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
											<view style="width: 190px;">
												<Text class='l_name'>{{item.UserName}}</Text>
											</view>
											<Text style='font-size: 12px;'>来源：{{item.SourceName}}</Text>
										</view>
										<Text style='font-size: 12px;'>申请时间：{{item.CreateDate}}</Text>
									</view>
								</view>
								<view class="box_b">
									<Text style='font-size: 13px;'>分销商名称：{{item.Name}}</Text>
									<Text style='font-size: 13px;'>分销商电话：{{item.Mobile}}</Text>
								</view>
								<view class="box_bootom">
									<u-button type="error" size="mini" style='margin-right: 15px;' @click='handle(2,item.UserId)'>拒绝</u-button>
									<u-button type="success" size="mini" @click='handle(1,item.UserId)'>同意</u-button>
								</view>
							</view>
						</view>
						<u-loadmore :status="status" :load-text="loadText" :font-size="24" :margin-top="20" :margin-bottom="20" bg-color="#f3f4f6" />
					</scroll-view>
				</view>
			</template>
		</view>
		<u-modal v-model="showModal" :content="timsg.Type==1?'通过审核':'拒绝通过'" :show-cancel-button="true" :show-title="false"
		 @confirm="confirm" :border-radius="20"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "分销商审核",
				contentHeight: 0,
				mainColor: '',
				secondary: '',
				current: 0,
				g: [],
				timsg: {
					UserId: 0,
					Type: 0,
				},
				showModal: false,
				msg: {
					pageIndex: 1,
					pageSize: 10,
					Name: '',
					Source: '',
					NickName: '',
					Mobile: '',
				},
				page_count: 1,
				status: "loadmore",
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多了",
				},
			}
		},
		created() {
			this.contentHeight = this.$utils.calcContentHeight(-40) + 'px';
			this.mainColor = this.$uiConfig.mainColor;
			this.secondary = this.$uiConfig.secondary;
			this.init()
		},
		mounted() {
			let currentPages = getCurrentPages();
			let u = "/" + currentPages[currentPages.length - 1].route;
			let pages = wx.getStorageSync("basedata") ?
				wx.getStorageSync("basedata").bar_title : [];
			pages.forEach((x) => {
				if (x.value == u) {
					this.pageTitle = x.new_name ? x.new_name : x.name;
				}
			});
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		},
		methods: {
			init() {
				uni.showLoading({
					title: '加载中'
				});
				this.request2({
						url: '/api/AppletUser/GetHpUserReferralsAuditList',
						data: this.msg
					},
					(res) => {
						uni.hideLoading();
						this.g = this.g.concat(res.data.pageData);
						this.page_count = res.data.pageCount;
						if (this.page_count == 1) {
							this.status = "nomore";
						}
					}
				);
			},
			lower(e) {
				if (this.msg.pageIndex < this.page_count) {
					this.msg.pageIndex++;
					this.status = "loading";
					this.init();
				} else {
					this.status = "nomore";
				}
			},
			handle(type, UserId) {
				this.timsg.Type = type;
				this.timsg.UserId = UserId;
				this.showModal = true;
			},
			confirm() {
				uni.showLoading({
					title: '加载中'
				});
				this.request2({
						url: '/api/AppletUser/SetHpUserReferralsAudit',
						data: this.timsg
					},
					(res) => {
						uni.hideLoading();
						this.g = [];
						this.msg.pageIndex = 1;
						this.init();
					}
				);
			}
		}
	}
</script>

<style>
	.examineStyle {
		background: #f3f4f6;
	}

	.examineStyle .loading {
		width: 200rpx;
		height: 200rpx;
		background: #000000;
		opacity: 0.7;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: fixed;
		left: 50%;
		top: 30%;
		margin-left: -100rpx;
		z-index: 999;
	}

	.examineStyle .listbox {
		width: 100%;
		background: #fff;
		padding: 0 15px;
		margin-bottom: 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.examineStyle .box_top {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 10px 0;
		border-bottom: 1px solid #f5f5f5;
	}

	.examineStyle .box_r {
		width: calc(100vw - 30px - 55px - 20px);
		height: 55px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.box_r .l_name {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.examineStyle .box_b {
		width: 100%;
		padding: 15px 0;
		display: flex;
		flex-direction: column;
	}

	.examineStyle .box_bootom {
		width: 100%;
		height: 60px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
	}

	.examineStyle .box_bootom .box_bo_item {
		width: 50px;
		height: 30px;
		border-radius: 15px;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 1px solid #c8c9cc;
	}
</style>
