<template>
	<view class="search">
		<view class="hd">
			<view class="l">
				<image class="icon-search" src="https://www.lijkj.cn/static/search.png"></image>
				<input type="text" disabled v-model="filter.keyword" placeholder="支持姓名/公司/手机号/标签搜索"/>
				<image class="icon-del" @click="show = true" v-if="filter.keyword" src="https://www.lijkj.cn/static/icon-close.png"></image>
				<image class="icon-filter" @click="show = true" src="https://www.lijkj.cn/static/icon-filter.png"></image>
			</view>
			<view class="btn" @click="show = true">搜索</view>
		</view>
		<view class="bd" v-if="token">
			<view class="l" v-if="info.list && info.list.length> 0">搜索历史<text @click="delsearch()">清除记录</text></view>
			<view class="info" v-if="info.list && info.list.length> 0">
				<view class="item" v-for="(a,i) in info.list" :key="i" @click="toSearch(3,a.title)">{{a.title}}</view>
			</view>
			<view class="l" v-if="info.lixiang && info.lixiang.length> 0">猜你想搜</view>
			<view class="info" v-if="info.lixiang && info.lixiang.length> 0">
				<view class="item" v-for="(a,i) in info.lixiang" :key="i" @click="toSearch(3,a.title)">{{a.title}}</view>
			</view>
		</view>
		<u-popup :show="show" mode="top" @close="close" @open="open" :overlayStyle="overlayStyle" zIndex="10">
			<view class="form">
				<view class="hd">
					<view class="l">
						<image class="icon-search" src="https://www.lijkj.cn/static/search.png"></image>
						<input type="text" v-model="filter.keyword" disabled placeholder="支持姓名/公司/手机号/标签搜索"/>
						<image class="icon-filter" src="https://www.lijkj.cn/static/icon-filter.png"></image>
					</view>
					<view class="btn" @click="toSearch(2)">搜索</view>
				</view>
				<view class="l">当事人身份信息筛选</view>
				<view class="info">
					<view class="item">
						<view class="fl">姓名<text>*</text></view>
						<view class="fr">
							<input v-model="filter.main_realname" placeholder="请输入当事人姓名" type="text" />
						</view>
					</view>
					<view class="item">
						<view class="fl">身份证号</view>
						<view class="fr">
							<input v-model="filter.main_cardno" placeholder="请输入当事人身份证号" type="text" />
						</view>
					</view>
					<view class="item">
						<view class="fl">手机号码</view>
						<view class="fr">
							<input v-model="filter.main_phone"  placeholder="请输入手机号码" type="number" />
						</view>
					</view>
					<view class="item" v-if="systembasicInfoopen.qq">
						<view class="fl">QQ号</view>
						<view class="fr">
							<input v-model="filter.main_qq" placeholder="请输入当事人QQ号" type="text" />
						</view>
					</view>
					<view class="item" v-if="systembasicInfoopen.wechat">
						<view class="fl">微信号</view>
						<view class="fr">
							<input v-model="filter.main_wechat" placeholder="请输入微信号" type="text" />
						</view>
					</view>
					<view class="item">
						<view class="fl">居住地址</view>
						<view class="fr">
							<picker mode="region" @change="changePicker1" :value="filter.main_addressArr">
								<view class="picker">
									{{filter.main_address?filter.main_address:'请选择 省/市/区'}}
									<image src="https://www.lijkj.cn/static/icon-arrow.png"></image>
								</view>
							</picker>
						</view>
					</view>
					<view class="item">
						<view class="fl">籍贯</view>
						<view class="fr">
							<input v-model="filter.main_jiguan" placeholder="请输入籍贯" type="text" />
						</view>
					</view>
					<view class="item">
						<view class="fl">公司</view>
						<view class="fr">
							<input v-model="filter.main_company" placeholder="请输入当事人所在公司" type="text" />
						</view>
					</view>
					<view class="btns">
						<view class="reset" @click="toSearch(1)">重置</view>
						<view class="sure" @click="toSearch(5)">确定</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				overlayStyle: {
					'zIndex': 9
				},
				statusBarHeight: 0,
				info: "",
				show: true,
				token: "",
				filter: {
					main_addressArr: [],
					content_type_id: "",
					main_realname: "",
					main_phone: "",
					main_cardno: "",
					main_qq: "",
					main_wechat: "",
					main_address: "",
					main_jiguan: "",
					main_company: "",
					keyword: "",
					systembasicInfoopen: {}
				}
			};
		},
		onShow() {
			this.systembasicInfoopen = uni.getStorageSync("systembasicInfoopen")
			this.token = uni.getStorageSync("token")
			this.getsearchlist();
		},
		methods: {
			open(){},
			close() {},
			changePicker1(e){
				this.filter.main_addressArr = e.detail.value;
				this.filter.main_address = e.detail.value.join(",");
			},
			async getsearchlist(){
				const { code, data } = await this.$api.getsearchlist({
					token: uni.getStorageSync("token")
				})
				if(code == 1){
					this.info = data;
				}
			},
			async delsearch() {
				const { code, data } = await this.$api.delsearch({
					token: uni.getStorageSync("token")
				})
				if(code == 1){
					uni.showToast({
						icon: "none",
						title: "清除成功"
					})
					this.getsearchlist();
				}
			},
			toSearch(index,title) {
				if(index == 1){
					this.filter = {
						content_type_id: "",
						main_realname: "",
						main_phone: "",
						main_cardno: "",
						main_qq: "",
						main_wechat: "",
						main_address: "",
						main_jiguan: "",
						main_company: "",
						keyword: "",
					}
				}else if(index == 2){
					uni.setStorageSync("filterInfo",this.filter)
					uni.navigateTo({
						url: "/pages/index/searchList"
					})
				}else if(index == 4){
					this.filter.keyword = ""
				}else if(index == 5){
					if(!this.filter.main_realname){
						uni.showToast({
							icon: "none",
							title: "姓名不能为空！"
						})
						return ;
					}
					uni.setStorageSync("filterInfo",this.filter)
					uni.navigateTo({
						url: "/pages/index/searchList"
					})
				}else if(index == 3){
					this.filter.keyword = title
					uni.setStorageSync("filterInfo",this.filter)
					uni.navigateTo({
						url: "/pages/index/searchList"
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
.search{
	min-height: 100vh;
	background-color: #fff;
	overflow: hidden;
	.content{
		width: 100%;
		background: #F3F7F8;
		.l{
			padding: 25rpx 25rpx 0;
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
		}
		.list{
			padding: 0 25rpx;
			.li{
				min-height: 100rpx;
				background: #FFFFFF;
				box-shadow: 0px 3rpx 10rpx 0px rgba(9,44,39,0.05);
				border-radius: 20rpx;
				padding: 20rpx 30rpx;
				box-sizing: border-box;
				margin-top: 20rpx;
				position: relative;
				overflow: hidden;
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				.a{
					width: 100%;
					font-weight: 500;
					font-size: 28rpx;
					color: #666666;
					line-height: 50rpx;
				}
				.c{
					width: 80rpx;
					line-height: 56rpx;
					background: #00C6A9;
					border-radius: 0px 20rpx 0px 20rpx;
					font-weight: 400;
					font-size: 32rpx;
					text-align: center;
					color: #FFFFFF;
					position: absolute;
					right: 0;
					top: 0;
					z-index: 2;
					&-on{
						background: #333333;
					}
				}
			}
		}
	}
	.form{
		padding: 0 0 25rpx;
		background-color: #fff;
		overflow: hidden;
		.btns{
			padding: 40rpx 35rpx 20rpx 55rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.reset{
				width: 300rpx;
				line-height: 90rpx;
				background: #E3F4F1;
				border-radius: 90rpx;
				text-align: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #00C6A9;
			}
			.sure{
				width: 300rpx;
				line-height: 90rpx;
				background: #00C6A9;
				border-radius: 90rpx;
				text-align: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #fff;
			}
		}
		.l{
			padding: 0 25rpx;
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
		}
		.info{
			margin-top: 10rpx;
			padding: 0 25rpx 0 0;
			overflow: hidden;
			.item{
				margin-top: 20rpx;
				overflow: hidden;
				display: flex;
				align-items: center;
				.fl{
					font-weight: 500;
					font-size: 28rpx;
					color: #222222;
					width: 140rpx;
					text-align: right;
					margin-right: 20rpx;
					text{
						color: red;
					}
				}
				.fr{
					flex: 1;
					picker{
						width: 100%;
						line-height: 80rpx;
						height: 80rpx;
						background: #F6F6F6;
						padding: 0 20rpx;
						box-sizing: border-box;
						border-radius: 10rpx;
						font-weight: 500;
						.picker{
							width: 100%;
							font-size: 28rpx;
							color: #212121;
							display: flex;
							align-items: center;
							justify-content: space-between;
							image{
								width: 45rpx;
								height: 45rpx;
							}
						}
						
					}
					input{
						width: 100%;
						line-height: 80rpx;
						height: 80rpx;
						background: #F6F6F6;
						padding: 0 20rpx;
						box-sizing: border-box;
						border-radius: 10rpx;
						font-weight: 500;
						font-size: 28rpx;
						color: #212121;
					}
				}
			}
		}
	}
	.bd{
		background-color: #fff;
		overflow: hidden;
		.empty{
			margin-top: 139rpx;
			text-align: center;
			font-weight: 500;
			font-size: 32rpx;
			color: #222222;
			image{
				width: 460rpx;
				height: 400rpx;
				margin-bottom: 15rpx;
			}
		}
		.l{
			padding: 5rpx 25rpx;
			font-weight: 500;
			font-size: 30rpx;
			color: #333333;
			overflow: hidden;
			text{
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
				float: right;
			}
		}
		.info{
			padding: 0 25rpx 0 0;
			overflow: hidden;
			margin-bottom: 30rpx;
			.item{
				padding: 0 20rpx;
				line-height: 52rpx;
				background: #F6F6F6;
				border-radius: 52rpx;
				font-weight: 500;
				font-size: 24rpx;
				color: #666666;
				float: left;
				margin-top: 25rpx;
				margin-left: 25rpx;
			}
		}
	}
	.hd{
		background-color: #fff;
		padding: 30rpx 25rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.l{
			flex: 1;
			width: 620rpx;
			line-height: 70rpx;
			height: 70rpx;
			background: #F6F6F6;
			border-radius: 70rpx;
			border: 1px solid #EAEAEA;
			padding: 15rpx 30rpx;
			overflow: hidden;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			.icon-search{
				width: 24rpx;
				height: 27rpx;
				margin-right: 15rpx;
			}
			.icon-filter{
				width: 35rpx;
				height: 33rpx;
				margin-left: 15rpx;
			}
			.icon-del{
				width: 50rpx;
				height: 50rpx;
				margin-left: 15rpx;
			}
			input{
				flex: 1;
				font-weight: 500;
				font-size: 24rpx;
				color: #212121;
			}
		}
		.btn{
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
			margin-left: 25rpx;
		}
	}
}
</style>
