<template>
	<!-- 搜索 -->
	<view class="serachBox">
		<view class="serach-box" :style="{'width':width+'%'}">
			<view class="searchInput">
				<input :placeholder="placeholder" class="city-serach-input" v-model="name" />
				<uni-icons v-if="name" @click="handlecolse(1)" type="close" size="26px"></uni-icons>
			</view>
			<view class="searchBtn" @click="handleSerach">
				<icon class="iconfont icon-icon-test2"></icon>
			</view>
		</view>
		<view class="address" v-if="isAddress">
			<view class="item">
				<picker mode="selector" :range="industrylist" range-key="name" :value="industryname"
					@change="changeIndustry">
					<view class="uni-input">{{industryname?industryname:"所属行业"}}</view>
					<icon class="iconfont icon-icon-test11" v-if="!industryname"></icon>
				</picker>
				<uni-icons v-if="industryname" @click="handlecolse(2)" type="close" size="26px"></uni-icons>
			</view>
			<view class="item">
				<pickRegions @getRegion="handleGetRegion" class="regions" :isArea="false">
					<view class="city" v-if="province">
						{{province}}{{city}}
					</view>
					<view v-else>所属地区</view>
					<icon class="iconfont icon-icon-test11" v-if="!province"></icon>
				</pickRegions>
				<uni-icons v-if="province" @click="handlecolse(3)" type="close" size="26px" @click.stop></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import pickRegions from "@/uni_modules/pick-regions/pick-regions.vue"
	export default {
		name: "search",
		props: {
			isPost: {
				type: Boolean,
				default: false
			},
			isWork: {
				type: Boolean,
				default: true
			},
			placeholder: {
				type: String,
				default: ''
			},
			width: {
				type: String,
				default: '100'
			},
			isAddress: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				name: "",
				industryname: "",
				industryid: "",
				posname: "",
				posid: "",
				province: "",
				city: ""
			}
		},
		components: {
			pickRegions
		},
		computed: {
			...mapState(["user", "HomeContent"]),
			endDate() {
				return this.$tools.getDate('start')
			},
			industrylist() {
				return this.HomeContent.industrylist
			},
			poslist() {
				return this.HomeContent.poslist
			},
		},
		methods: {
			// 搜索
			handleSerach() {
				if (!this.name) {
					this.$tools.msg('请输入关键字进行搜索')
					return
				}
				this.$emit("handleSearch", this.name, this.province, this.city, this.industryid)
			},
			//取消搜索
			handlecolse(ind) {
				this.name = ind == 1 ? "" : this.name
				this.province = ind == 3 ? "" : this.province
				this.city = ind == 3 ? "" : this.city
				this.industryname = ind == 2 ? "" : this.industryname
				this.industryid = ind == 2 ? "" : this.industryid
				this.$emit("handleSearch", this.name, this.province, this.city, this.industryid)
			},
			// 所属地区
			handleGetRegion(ite) {
				this.province = ite[0].name
				this.city = ite[1].name == '全部' ? '' : ite[1].name
				this.$emit("handleSearch", this.name, this.province, this.city, this.industryid)
			},
			// 所属行业
			changeIndustry(e) {
				this.industryname = this.HomeContent.industrylist[e.target.value].name
				this.industryid = this.HomeContent.industrylist[e.target.value].id
				this.$emit("handleSearch", this.name, this.province, this.city, this.industryid)
			},
		}
	}
</script>

<style scoped lang="scss">
	.address {
		position: fixed;
		top: 45px;
		left: 0;
		right: 0;
		display: flex;
		background: $blue;

		.item {
			width: 47%;
			margin-left: 10px;
			background: #fff;
			height: 28px;
			line-height: 28px;
			text-align: center;
			border-radius: 5px;
			margin-bottom: 10px;
			position: relative;

			.uni-input {
				width: 100%;
				float: left;
			}

			icon,
			uni-icons {
				position: absolute;
				right: 10px;
				top: 0
			}

			/deep/picker {
				width: 100%;
			}
		}
	}

	.searchInput {
		uni-icons {
			z-index: 999;
			top: 6px !important;
		}
	}
</style>