<template>
	<view id="warp">
		<view class="warp_search">
			<view class="top_search">
				<uni-search-bar 
					style="width: 100%; height: 56rpx" 
					bgColor="white" 
					placeholder="请输入姓名/手机号"
					v-model="serchValue" 
					@input="onSearch" 
					clearButton="none"
				></uni-search-bar>
			</view>
			<view class="top_img">
				<image 
					:src="!show_shaixuan? '/static/images/common/shaixuan.png': '/static/images/common/shaixuan_have.png'" 
					@click="click_shaixuan"
				></image>
				<image src="/static/images/common/searchPx.png" @click="searchPx"></image>
				<image src="/static/images/common/adds.png" @click="addsfun"></image>
			</view>
			<!-- 筛选框 -->
			<view class="search_box" v-if="show_shaixuan">
				<view class="search_box_item" :class="isEnabled==0?'isEnabled':''" @click="isEnabled_fn(0)">全部</view>
				<view class="search_box_item" :class="isEnabled==1?'isEnabled':''" @click="isEnabled_fn(1)">启用</view>
				<view class="search_box_item" :class="isEnabled==-1?'isEnabled':''" @click="isEnabled_fn(-1)">停用</view>
			</view>
		</view>
		<lndexlist 
			@onclick="changeUser" 
			@onRefresh="onRefresh" 
			:list="peopleList" 
			type="user" 
			:is_no="is_no"
			:triggered="triggered"
			:userPx="orderby=='role'?true:false"
		></lndexlist>
		<!-- 普通弹窗 -->
		<uni-popup ref="popup" background-color="transparent">
			<view class="popup_box">
				<view class="popup_box_title"> 请选择邀请人员的角色： </view>
				<view class="popup_box_role">
					<radio-group name="radio" class="input_radio" @change="selectRole">
						<label 
							class="radio_list" 
							v-for="(item, index) in roleLists" 
							:key="index"
						>
							<radio 
								color="#1B64F8FF" 
								:value="item.id" 
								:checked="item.checked" 
							/>
							<text>{{ item.name }}</text>
						</label>
					</radio-group>
				</view>
				<view class="popup_box_btn">
					<view class="btn1" @click="close"> 取消 </view>
					<button class="btn" open-type="share"></button>
					<view class="btn2"> 确定 </view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	const {urlList,https} = require("@/static/api");
	import lndexlist from "@/components/index-list2/index-list2.vue";
	export default {
		data() {
			return {
				peopleList: [],
				showNone: false,
				isLoading: false, //是否在加载中
				currentPage: 1,
				pageSize: 99999,
				serchValue: "", //查找
				show_shaixuan: false, //筛选
				isEnabled:1, //筛选启用停用
				is_no: false,
				triggered: false,
				roleLists: [
					{
						"id": 1001,
						"name": "车组人员",
						"intro": null,
						"checked":true
					}, {
						"id": 1002,
						"name": "调度",
						"intro": null,
						"checked":false
					}, {
						"id": 1005,
						"name": "管理员",
						"intro": null,
						"checked":false
					},
					{
						"id": 1004,
						"name": "财务",
						"intro": null,
						"checked":false
					},{
						"id": 1006,
						"name": "业务",
						"intro": null,
						"checked":false
					}, {
						"id": 1007,
						"name": "车队长",
						"intro": null,
						"checked":false
					}, {
						"id": 1008,
						"name": "仓管",
						"intro": null,
						"checked":false
					}, {
						"id": 1009,
						"name": "工地施工员",
						"intro": null,
						"checked":false
						
					}, {
						"id": 1010,
						"name": "外租伙伴",
						"intro": null,
						"checked":false
					}, {
						"id": 1011,
						"name": "兼职业务",
						"intro": null,
						"checked":false
					},
				], //角色列表
				roleId: 1001,
				orderby:'',
			};
		},
		components: {
			lndexlist,
		},
		onLoad() {},
		onShow() {
			const that = this;
			that.currentPage = 1;
			let orderby = uni.getStorageSync('orderby');
			if(orderby){
				console.log('有缓存orderby---',orderby)
				that.orderby = orderby;
			}else{
				console.log('没有缓存orderby---')
				that.orderby = '';
				uni.setStorage({
					key:'orderby',
					data:'',
				})
			}
			that.get_list();
		},
		// 邀请好友
		onShareAppMessage(res) {
			let id = uni.getStorageSync("userCompany").id;
			this.close();
			return {
				title: "一键派工,高效调度",
				path: "/pages/login_driver/login_driver?companyId="+id+"&roleId="+this.roleId,
				imageUrl: "/static/images/common/fx.png",
			};
		},
		methods: {
			// 分享
			addsfun() {
				let roleId = uni.getStorageSync("userinfo").roleId;
				if(roleId==1002){
					this.roleLists= [{
						"id": 1001,
						"name": "车组人员",
						"intro": null,
						"checked":true
					}, {
						"id": 1010,
						"name": "外租伙伴",
						"intro": null,
						"checked":false
					},{
						"id": 1006,
						"name": "业务",
						"intro": null,
						"checked":false
					},{
						"id": 1011,
						"name": "兼职业务",
						"intro": null,
						"checked":false
					}] //角色列表
				}
				this.$refs.popup.open("center");
			},
			// 选择分享id
			selectRole(e) {
				const val = e.detail.value;
				this.roleId = val;
			},
			// 关闭分享按钮
			close() {
				this.$refs.popup.close()
			},
			onRefresh() {
				if (!this.isLoading) {
					this.triggered = true;
					this.isLoading = true;
					this.get_list();
				}
			},
			changeUser(item) {
				uni.navigateTo({
					url: "/pages/userAdd/userAdd?id=" + item.id,
				});
			},
			onSearch() {
				console.log(this.serchValue);
				if (!this.isLoading) {
					this.isLoading = true;
					this.currentPage = 1;
					this.peopleList = [];
					this.get_list();
				}
			},
			click_shaixuan() {
				//点击筛选
				this.show_shaixuan = !this.show_shaixuan;
			},
			Scrolltolower() {
				if (this.is_no == true) {
					return;
				}
				this.currentPage = this.currentPage + 1;
				this.get_list();
			},
			isEnabled_fn(e) {
				//确认筛选
				this.isEnabled = e;
				if (!this.isLoading) {
					this.isLoading = true;
					this.currentPage = 1;
					this.peopleList = [];
					this.get_list();
				}
				this.show_shaixuan = false;
			},
			// 排序
			searchPx(){
				const that = this;
				if(that.orderby != 'role'){
					that.orderby = 'role'
				}else{
					that.orderby = ''
				}
				uni.setStorage({
					key:'orderby',
					data:that.orderby,
					success() {
						that.get_list()
					}
				})
			},
			get_list() {
				let url =
					urlList.getemployee +
					"?currentPage="+this.currentPage+
					"&pageSize="+this.pageSize+
					"&status="+this.isEnabled+
					"&key="+this.serchValue+
					"&roleId=-1"+ 
					"&orderby="+this.orderby;
				https(url, "GET", "", "").then((res) => {
					this.isLoading = false;
					this.triggered = false;
					this.peopleList = res.data.employeeList;
					if(res.data.total==0){
						this.is_no=true
					}
				}).catch((err) => {
					console.log(err);
				});
			},
		},
	};
</script>
<style lang="scss" scoped>
	#warp {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		.warp_search {
			box-sizing: border-box;
			width: 100%;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			height: 88rpx;
			box-sizing: border-box;
			background: white;
			.top_search {
				width: 560rpx;
			}
			.top_img {
				width: 190rpx;
				height: 65rpx;
				display: flex;
				align-items: center;
				image {
					width: 48rpx;
					height: 48rpx;
					margin-left: 10rpx;
				}
			}
			.search_box {
				position: fixed;
				width: 120rpx;
				top: 88rpx;
				box-shadow: #ebebeb 2px 2px 2px;
				text-align: center;
				background: white;
				border-radius: 10rpx;
				font-size: 24rpx;
				left: 530rpx;
				border: solid 1rpx #ebebeb;
				z-index: 9999;
				.search_box_item {
					padding: 10rpx 0;
				}
				.isEnabled {
					background: #5597ed;
					color: white;
					border-radius: 10rpx;
				}
			}
		}

		.bottom {
			height: calc(100vh - 88rpx);
			box-sizing: border-box;
			.item {
				font-size: 24rpx;
				padding: 20rpx;
				border-bottom: 2rpx solid #eee;
				display: flex;
				justify-content: space-between;

				.item_1 {
					flex: 1;
				}

				.item_2 {
					color: #45b1e2;
					// width: 300rpx;
				}

				.item_3 {
					width: 80rpx;
					color: #45b1e2;
				}

				.item_4 {
					width: 80rpx;
					color: #eee;
				}
			}
		}

		.top_user {
			width: 94%;
			height: 140rpx;
			margin: 0 auto;
			border-bottom: 1rpx solid #ebebeb;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;

			.user_lef_name {
				display: flex;
				flex-direction: column;
				font-size: 36rpx;

				text:nth-child(2) {
					font-size: 28rpx;
					margin-top: 7rpx;
					color: #353535;
				}
			}

			.rig_icon {
				width: 28rpx;
				height: 28rpx;
			}
		}

		.bottomTitle {
			width: 100%;
			height: 100rpx;
			color: #666666;
			font-size: 24rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.bot_yq {
			height: 80rpx;
			width: 80rpx;
			position: fixed;
			bottom: 124rpx;
			right: 12rpx;
		}

		.popup_box {
			background: white;
			border-radius: 10rpx;
			padding-top: 20rpx;
			width: 500rpx;
			position: relative;

			.popup_box_title {
				margin: 20rpx;
			}

			.popup_box_role {
				margin: 20rpx auto;

				.input_radio {
					display: flex;
					flex-direction: column;

					.radio_list {
						margin-left: 100rpx;
						margin-bottom: 20rpx;
					}
				}
			}

			.popup_box_btn {
				border-top: #ebebeb solid 2rpx;
				text-align: center;
				height: 80rpx;
				line-height: 80rpx;

				.btn1 {
					width: 50%;
					box-sizing: border-box;
					display: inline-block;
					border-right: #ebebeb solid 1rpx;
					color: #a5a5a5;

				}

				.btn2 {
					border: none;
					width: 50%;
					box-sizing: border-box;
					display: inline-block;
					color: #45b1e2;
					border-left: #ebebeb solid 1rpx;
				}

				.btn {
					width: 50%;
					height: 80rpx;
					position: absolute;
					bottom: 0;
					right: 0;
					opacity: 0;
				}
			}
		}
	}

	/* 隐藏滚动条 */
	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}
</style>
