<template>
	<view>
		<!-- #ifdef MP-ALIPAY -->
		<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择盲票天使" leftIconSize="0">
		</u-navbar>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择盲票天使"></u-navbar>
		<!-- #endif -->
		<!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
		<view v-if="pagesNum > 1">
			<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择盲票天使" />
		</view>
		<view v-else>
			<u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff" :border="true" title="选择盲票天使">
				<view class="nav-left flex" slot="left" @click="$toIndex()">
					<u-icon name="arrow-left" size="20" color="#333"></u-icon>
				</view>
			</u-navbar>
		</view>
		<!-- #endif -->
		<view class="coupon-title">
			<u-search placeholder="请输入名字或工号" v-model="searchValue" @blur="pageList()" :showAction="false"></u-search>
		</view>
		<view class="coupon-list">
			<u-radio-group v-model="radiovalue1" placement="column" @change="changeChechk()">
				<view class="flex coupon-list-item" v-for="(item,index) in list" :key="index">
					<view class="block">
						<view class="title">{{item.name}}</view>
						<text>工号：{{item.workNo}}</text>
					</view>
					<view class="uradio">
						<u-radio :customStyle="{ marginBottom: '8px' }" :name="item.channelId" activeColor="#F9822C"
							size="24">
						</u-radio>
					</view>
				</view>
				<u-loadmore :line="true" v-if="list.length>20" :status="status" :loading-text="'努力加载中'"
					:nomore-text="'已经到底了'" />
			</u-radio-group>
		</view>
		<view class="footer-fixed">
			<view class="flex btn">
				<button type="default" @click="exchange">确认</button>
			</view>
		</view>
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import appId from '@/config/appId.js'
	import $http from '@/utils/request.js'
	export default {
		data() {
			return {
				pageNum: 1,
				total: 0,
				list: [],
				radiovalue1: '', //选中项的下标
				channelId: '', //选中项的id
				id: '', //门店的channelId
				status: 'nomore', //上拉刷新状态
				searchValue: '', //搜索
				pagesNum: '',
			};
		},
		onShow() {
			this.pagesNum = getCurrentPages().length
			this.pageList()
		},
		onLoad(opthios) {
			if (opthios.channelId) {
				this.id = opthios.channelId
				this.channelId = opthios.index
				this.radiovalue1 = Number(opthios.index) 
			}

		},
		methods: {
			pageList() {
				this.list = []
				this.pageNum = 1
				this.getList()
			},

			getList() {
				let _this = this
				$http.post(`/api/v1/mp/channel/promoter/list?pageNum=${_this.pageNum}&pageSize=20`, {
					channelId: this.id,
					searchValue: this.searchValue,
				}).then(
					res => {
						if (res.code == 0) {
							this.total = res.total
							this.list = [...this.list, ...res.rows]
						}

					}).catch(() => {})
			},

			// 点击切换事件
			changeChechk(e) {
				if (this.channelId == e) {
					this.radiovalue1 = -1
					this.channelId = ''
					return
				} else {
					this.channelId = e
					return
				}
			},

			// 点击确认事件
			exchange() {
				let promoters = {}
				for (var i = 0; i < this.list.length; i++) {
					if (this.list[i].channelId == this.channelId) {
						promoters = {
							channelId: this.channelId,
							name: this.list[i].name,
							workNo: this.list[i].workNo,
						}
					}
				}
				uni.$emit('promoters', promoters)

				uni.navigateBack({
					delta: 1
				})
			}
		},
		onReachBottom() {
			// 判断是否有数据
			if (this.total < this.pageNum * 20) return;
			this.status = 'loading';
			++this.pageNum
			if (this.total < this.pageNum * 20) this.status = 'nomore';
			else this.status = 'loading';
			this.getList()
		},
	}
</script>

<style lang="scss" scoped>
	.coupon {

		&-title {
			position: fixed;
			z-index: 10;
			width: 100%;
			padding: 24rpx 32rpx;
			background-color: #FFFFFF;
		}

		&-list {
			margin-top: 110rpx;
			padding-bottom: 200rpx;

			&-item {
				justify-content: space-between;
				padding: 20rpx 50rpx;
				background-color: #FFFFFF;
				margin-bottom: 20rpx;
				background-size: 100%;

				.block {
					color: #333;

					.title {
						line-height: 60rpx;
						font-size: 32rpx;
					}

					text {
						font-size: 26rpx;
					}
				}


				.uradio {
					position: absolute;
					right: 40rpx;
				}

				.circle {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					border: 1px solid;
				}

				.action {
					width: 30rpx;
					height: 30rpx;
					border-radius: 50%;
					background-color: $uni-bg-color;
				}
			}
		}
	}

	.footer-fixed {
		position: fixed;
		bottom: var(--window-bottom);
		left: 0;
		right: 0;
		z-index: 11;
		box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
		background: #fff;
		// 设置ios刘海屏底部横线安全区域
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.btn {
			padding: 20rpx 0;

			::v-deep button {
				width: 441rpx;
				height: 88rpx;
				line-height: 88rpx;
				font-size: 36rpx;
				color: #fff;
				background-color: #F9822C;
				border: none;
				border-radius: 44rpx;
			}
		}
	}
</style>
