<template>
	<view class="drawer-content">
		<!--右抽屉-->
		<tui-drawer mode="right" :visible="rightDrawer" @close="closeDrawer">
			<view
				class="drawer-container clearfix"
				scroll-y
				:style="{
					paddingTop: CustomBar - StatusBar + 8 + 'px',
					paddingBottom: isIphoneX ? '180rpx' : '146rpx'
				}"
			>
				<scroll-view class="tui-drawer-scroll" scroll-y :style="{ height: drawerH + 'px' }">
					<view class="drawer-title">更多筛选</view>
					<view class="drawer-main">
						<template v-if="isManage">
							<view class="drawer-main-name">组员：</view>
							<view class="drawer-main-radiov">
								<view class="drawer-main-radio">
									<picker
										@change="bindPickerChange(1, $event)"
										:value="index"
										:range="sellerActions"
										range-key="name"
									>
										<input
											class="input"
											type="text"
											disabled="false"
											v-model="actionsText"
											value=""
											placeholder="请选择"
										/>
										<text class="iconfont icon-xiangyou"></text>
									</picker>
								</view>
							</view>
						</template>
						<template v-else>
							<view class="drawer-main-name">客户分配日期</view>
							<view class="drawer-main-time">
								<view class="drawer-main-time-input">
									<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindStartDateChange">
										<text class="input-text">{{ queryData.startTime }}</text>
									</picker>
									<text class="iconfont icon-riqi"></text>
								</view>
								<view class="line">-</view>
								<view class="drawer-main-time-input">
									<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindEndDateChange">
										<text class="input-text">{{ queryData.endTime }}</text>
									</picker>
									<text class="iconfont icon-riqi"></text>
								</view>
							</view>
							<view class="drawer-main-name">机构类型：</view>
							<view class="drawer-main-radiov">
								<view class="drawer-main-radio">
									<picker @change="bindPickerChange(2,$event)" :value="index" :range="clubTypeActions" range-key="name">
										<input class="input" type="text" disabled="false" v-model="clubTypeText" value="" placeholder="请选择"/>
										<text class="iconfont icon-xiangyou"></text>
									</picker>
								</view>
							</view>
							<view class="drawer-main-name">升级状态<text class="small">（个人机构升级为资质机构）</text>：</view>
							<view class="drawer-main-radiov">
								<view class="drawer-main-radio">
									<picker @change="bindPickerChange(3,$event)" :value="index" :range="clubStatusActions" range-key="name">
										<input class="input" type="text" disabled="false" v-model="clubStatusText" value="" placeholder="请选择"/>
										<text class="iconfont icon-xiangyou"></text>
									</picker>
								</view>
							</view>
							<view class="drawer-main-name">活跃状态：</view>
							<view class="drawer-main-radiov">
								<view class="drawer-main-radio">
									<picker @change="bindPickerChange(4,$event)" :value="index" :range="clubActiveActions" range-key="name">
										<input class="input" type="text" disabled="false" v-model="clubActiveText" value="" placeholder="请选择"/>
										<text class="iconfont icon-xiangyou"></text>
									</picker>
								</view>
							</view>
							<view class="drawer-main-name">客户价值：</view>
							<view class="drawer-main-radiov">
								<view class="drawer-main-radio">
									<picker @change="bindPickerChange(5,$event)" :value="index" :range="customerValueActions" range-key="name">
										<input class="input" type="text" disabled="false" v-model="customerValueText" value="" placeholder="请选择"/>
										<text class="iconfont icon-xiangyou"></text>
									</picker>
								</view>
							</view>
						</template>
					</view>
				</scroll-view>
				<view class="drawer-input btn" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
					<view class="drawer-btn clear" @click="closeDrawer">取消</view>
					<view class="drawer-btn comfrim" @click="handSearchConfirm">确定</view>
				</view>
			</view>
		</tui-drawer>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
	name: 'rightDrawer',
	props: {
		rightDrawer: {
			type: Boolean,
			default: false
		}
	},
	data() {
		const currentDate = this.getDate({
			format: true
		})
		return {
			date: currentDate,
			CustomBar: this.CustomBar, // 顶部导航栏高度
			StatusBar: this.StatusBar,
			isIphoneX: this.$store.state.isIphoneX,
			height: 0,
			drawerH: 0, // 抽屉内部scrollview高度
			categorys: [],
			checkedCategorysList: [],
			actionsText: '',
			queryData: {
				startTime:'',
				endTime:'',
				serviceProviderId: 0
			},
			clubTypeActions:[
				{name:'个人机构',value:4},
				{name:'资质机构',value:2}
			],
			clubStatusActions:[
				{name:'待升级',value:90},
				{name:'升级中',value:1},
				{name:'升级失败',value:92}
			],
			clubActiveActions:[
				{name:'活跃用户',value:90},
				{name:'不活跃用户',value:1}
			],
			customerValueActions:[
				{name:'高价值客户',value:90},
				{name:'一般价值客户',value:1},
				{name:'潜在价值客户',value:1},
				{name:'低价值客户',value:1}
			],
			clubTypeText:'',
			clubStatusText:'',
			clubActiveText:'',
			customerValueText:'',
			sellerActions: []
		}
	},
	created() {
		this.setScrollHeight()
		if(this.isManage){
			this.userSellerServiceTeam()
		}
	},
	computed: {
		...mapState(['isManage']),
		startDate() {
			return this.getDate('start')
		},
		endDate() {
			return this.getDate('end')
		}
	},
	methods: {
		async userSellerServiceTeam() {
			//获取组员协销列表
			try{
				const userInfo = await this.$api.getStorage()
				const res = await this.SellerService.userSellerServiceTeam({ spId: userInfo.serviceProviderId })
				this.sellerActions = res.data
			}catch(e){
				console.log('=========>获取组员协销列表异常')
			}
		},
		bindPickerChange(type, e) {
			//选择筛选条件
			switch (type) {
				case 1:
					this.actionsText = this.sellerActions[e.target.value].name
					this.queryData.serviceProviderId = this.sellerActions[e.target.value].serviceProviderId
					break
				case 2:
					this.clubTypeText = this.clubTypeActions[e.target.value].name
					this.queryData.userIdentity = this.clubTypeActions[e.target.value].value
					break
				case 3:
					this.clubStatusText = this.clubStatusActions[e.target.value].name
					this.queryData.status = this.clubStatusActions[e.target.value].value
					break
				case 4:
					this.clubActiveText = this.clubActiveActions[e.target.value].name
					// this.queryData.status = this.clubActiveActions[e.target.value].value
					break
				case 5:
					this.customerValueText = this.customerValueActions[e.target.value].name
					// this.queryData.status = this.customerValueActions[e.target.value].value
					break
			}
		},
		bindStartDateChange(event){
			//开始时间
			console.log('开始时间==>',event.detail.value)
			this.queryData.startTime = event.detail.value
			console.log('开始时间==>',this.queryData.startTime)
		},
		bindEndDateChange(event){
			//结束时间
			console.log('结束时间==>',event.detail.value)
			this.queryData.endTime = event.detail.value
			console.log('结束时间==>',this.queryData.endTime)
		},
		closeDrawer() {
			this.$parent.rightDrawer = false
		},
		handSearchConfirm() {
			//确定筛选
			this.$emit('handSearchConfirm', this.queryData)
			this.$parent.rightDrawer = false
		},
		setScrollHeight() {
			let obj = {}
			const { windowHeight, pixelRatio } = wx.getSystemInfoSync()
			uni.getSystemInfo({
				success: res => {
					this.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44
					this.drawerH = res.windowHeight - uni.upx2px(180) - this.height
				}
			})
			this.windowHeight = windowHeight - 1
			this.scrollHeight = windowHeight - 1
		},
		getDate(type) {
			const date = new Date()
			let year = date.getFullYear()
			let month = date.getMonth() + 1
			let day = date.getDate()
			if (type === 'start') {
				year = year - 1
			} else if (type === 'end') {
				year = year + 1
			}
			month = month > 9 ? month : '0' + month
			day = day > 9 ? day : '0' + day
			return `${year}-${month}-${day}`
		}
	}
}
</script>

<style lang="scss">
/*screen*/
.drawer-container {
	width: 580rpx;
	height: 100%;
	padding: 80rpx 0;
	overflow: hidden;
	box-sizing: border-box;
	background-color: #ffffff;
	.drawer-title {
		width: 100%;
		height: 72rpx;
		line-height: 72rpx;
		box-sizing: border-box;
		padding: 0 30rpx;
		float: left;
		background-color: #f7f7f7;
		font-size: $font-size-26;
		color: #333333;
		font-weight: bold;
		text-align: left;
	}
	.drawer-main {
		width: 100%;
		height: auto;
		box-sizing: border-box;
		float: left;
		.drawer-main-name {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: left;
			font-size: $font-size-26;
			color: #333333;
			box-sizing: border-box;
			padding: 0 20rpx;
			font-weight: bold;
			.small{
				font-weight: normal;
				color: #999999;
			}
		}
		.drawer-main-time{
			width: 100%;
			height: 56rpx;
			box-sizing: border-box;
			.line{
				color: #999999;
				float: left;
				line-height: 56rpx;
			}
			.drawer-main-time-input{
				width: 228rpx;
				height: 56rpx;
				background: #F7F7F7;
				border-radius: 28rpx;
				box-sizing: border-box;
				padding: 0 20rpx;
				line-height: 56rpx;
				float: left;
				margin: 0 20rpx;
				position: relative;
				.input-text{
					display: block;
					height: 56rpx;
					font-size: 26rpx;
					color: #666666;
				}
				.icon-riqi{
					color: #FF5B00;
					display: block;
					width: 40rpx;
					height: 56rpx;
					position: absolute;
					right: 10rpx;
					top: 0;
					line-height: 56rpx;
				}
			}
		}
		.drawer-main-radiov {
			width: 100%;
			height: auto;
			box-sizing: border-box;
			padding: 0 20rpx;
			.drawer-main-radio {
				width: 100%;
				height: 80rpx;
				box-sizing: border-box;
				padding: 0 10rpx;
				border: 1px solid rgba(0, 0, 0, 0.2);
				border-radius: 6rpx;
				margin-bottom: 30rpx;
				position: relative;
				&.btn {
					border: none;
					margin-top: 40rpx;
				}
				.input {
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;
					float: left;
					box-sizing: border-box;
					font-size: $font-size-24;
					color: #333333;
					padding: 0 10rpx;
					padding-right: 68rpx;
				}
				.iconfont {
					width: 50rpx;
					height: 80rpx;
					display: block;
					line-height: 80rpx;
					text-align: center;
					font-size: 30rpx;
					color: #999999;
					position: absolute;
					right: 0;
					top: 0;
				}
			}
		}
	}
	.drawer-input {
		width: 100%;
		float: left;
		box-sizing: border-box;
		padding: 24rpx 10rpx 0 10rpx;
		border: 1px solid rgba(0, 0, 0, 0.2);
		border-radius: 4rpx;
		position: relative;
		background-color: #ffffff;
		&.btn {
			border: none;
			display: flex;
			position: fixed;
			left: 0;
			bottom: 0;
		}
		.drawer-btn {
			width: 210rpx;
			height: 84rpx;
			border-radius: 42rpx;
			background: $btn-confirm;
			line-height: 84rpx;
			text-align: center;
			font-size: $font-size-26;
			color: #ffffff;
			flex: 1;
			margin: 0 10rpx;
			&.comfrim {
				background: $btn-confirm;
			}
			&.clear {
				background: #ffe6dc;
				color: $color-system;
			}
		}
	}
}
</style>
