<template>
	<view class="box">
		<view class="padding-t-20">
			<view class="alertItemTitle">
				职业类型
			</view>
			<view class="flex alertTypeBox">
				<view class="alertTypeItem" @click="search.work_type_id=ltt.id" :key='inde'
					v-for="(ltt,inde) in workTypeList" :class="{action:search.work_type_id==ltt.id}">
					<text>
						{{ltt.title}}
					</text>
				</view>
			</view>
			<view class="alertItemTitle">
				价格类型
			</view>
			<view class="flex alertTypeBox">
				<view class="alertTypeItem" :class="{action:search.timetype===''}" @click="search.timetype=''">
					<text>
						无
					</text>
				</view>
				<view class="alertTypeItem" :class="{action:search.timetype==='hour'}" @click="search.timetype='hour'">
					<text>
						小时
					</text>
				</view>
				<view class="alertTypeItem" :class="{action:search.timetype==='day'}" @click="search.timetype='day'">
					<text>
						每天
					</text>
				</view>
				<view class="alertTypeItem" :class="{action:search.timetype==='month'}"
					@click="search.timetype='month'">
					<text>
						每月
					</text>
				</view>
			</view>
			<view class="alertItemTitle" v-if="search.timetype!==''">
				最低价格
			</view>
			<input v-if="search.timetype!==''" v-model="search.servicePrice" class="minMoney" type="number"
				placeholder-class="placeholderText" placeholder="自定义最低价格">
			<view class="alertItemTitle">
				服务区域
			</view>
			<view class="flex alertTypeBox">
				<view class="alertTypeItem" :class="{action:search.is_china===''}" @click="search.is_china=''">
					<text>
						全部
					</text>
				</view>
				<view class="alertTypeItem" :class="{action:search.is_china===1}" @click="search.is_china=1">
					<text>
						国内
					</text>
				</view>
				<view class="alertTypeItem" :class="{action:search.is_china===0}" @click="search.is_china=0">
					<text>
						国外
					</text>
				</view>
			</view>
			<view v-if="search.is_china===1" class="alertItemTitle">
				区域选择
			</view>
			<view v-if="search.is_china===1" class="right">
				<view class="citylist">
					<view class="">
						<view class="flex margin-b-20" v-for="(item,ind) in search.service_area" :key="ind">
							<view>
								{{item.province+item.city+item.district}}
								<text class="margin-l-10 del" @click="search.service_area.splice(ind,1)">
									删除
								</text>
							</view>
						</view>
					</view>
					<view class="flex">
						<pickerAddress class="buttom" @change="onCityClick">选择地区</pickerAddress>
					</view>
				</view>
			</view>
		</view>
		<view class="flex alertButtomBox">
			<view class="cancel" @click="cancelSearch">
				清空选择
			</view>
			<view class="confirm" @click="confirmSearch">
				确定
			</view>
		</view>
	</view>
</template>
<script>
	import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
	import {
		getUserWorkTypeList
	} from '@/api/model.js';
	export default {
		components: {
			pickerAddress
		},
		props: {
			isCom: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				workTypeList: [],
				search: {
					timetype: '', //hour，month，day
					servicePrice: '',
					work_type_id: '',
					service_area: [],
					is_china: '',
				}
			};
		},
		onReady() {
			this.init()
		},
		methods: {
			init() {
				const that = this;
				getUserWorkTypeList().then(
					(res) => {
						that.workTypeList = res.data.list
					}
				).catch(
					(res) => {
						console.log(res);
					}
				)
			},
			onCityClick({
				data
			}) {
				let address = {};
				address.province = data[0];
				address.city = data[1];
				address.district = data[2];
				this.search.service_area.push(address)
			},
			confirmSearch() {
				const search = this.search
				const address =search.service_area.map(
						(item) => {
							return `${item.province},${item.city},${item.district}`
						}
					)
				uni.navigateTo({
					url:`/pages/index/listModel?type=2&timetype=${search.timetype}&servicePrice=${search.servicePrice}&work_type_id=${search.work_type_id}&service_area=${address.join('-')}&is_china=${search.is_china}`,
				})
			},
			cancelSearch() {
				this.$emit('init')
				this.search = {
					servicePrice: '',
					work_type_id: '',
					timetype: '',
					service_area: [],
					is_china: '',
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.box {
		line-height: 1;
		background-color: #FFF;
		padding: 20rpx 0 30rpx;
		border-radius: 20rpx 20rpx 0 0;
		min-height: 100vh;
		.right {
			color: $font-color-light;
			font-size: $font-base;
			flex-grow: 1;
			justify-content: flex-end;
			padding: 20rpx;

			.timetype {
				width: 100%;
				justify-content: flex-end;
			}

			.citylist {
				.del {
					font-size: $font-sm;
					border-radius: 10rpx;
					background-color: #eee;
					line-height: 1;
					padding: 5rpx 15rpx;
				}
			}

			.img {
				width: 26rpx;
			}

			.buttom {
				border-radius: 10rpx;
				line-height: 1;
				padding: 10rpx 20rpx;
				background-color: #eee;
			}
		}

		.alertTitle {
			font-weight: bold;
			font-size: 32rpx;
			flex-grow: 1;
			text-align: center;
		}

		.alertClose {
			width: 40rpx;
			height: 40rpx;
		}

		.alertItemTitle {
			font-size: 28rpx;
			padding-left: 20rpx;
			font-weight: bold;
		}

		.minMoney {
			margin: 20rpx;
			font-size: 24rpx;
			border-bottom: 1px solid #e9e9e9;
		}

		.placeholderText {
			font-size: 24rpx;
		}

		.alertTypeBox {
			flex-wrap: wrap;
			justify-content: flex-start;
			padding: 0 20rpx 10rpx;
			margin-top: 20rpx;

			.alertTypeItem {
				font-size: 24rpx;
				padding: 10rpx 20rpx;
				background-color: #eee;
				border-radius: 10rpx;
				margin-bottom: 14rpx;
				margin-right: 14rpx;

				&.action {
					background-color: #fee7e4;
					color: #F86859;
				}
			}
		}

		.moneyTitle {
			font-size: 28rpx;
		}

		.alertButtomBox {
			color: #FFF;
			border-top: 1px solid #e3e3e3;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			.confirm {
				background-color: #F86859;
			}

			.cancel {
				background-color: orange;
			}

			.cancel,
			.confirm {
				height: 70rpx;
				line-height: 70rpx;
				text-align: center;
				width: 375rpx;
				font-size: 28rpx;
			}
		}
	}

	.topSearch {
		position: sticky;
		top: 0;
		background-color: #FFF;
		padding-right: 100rpx;
		height: 80rpx;

		.itemBox {
			padding-left: 30rpx;
			align-items: center;

			.itemTip {
				background-color: #FFF;
				position: fixed;
				right: 0;
				top: 0;
				align-items: center;
				height: 80rpx;
				padding: 0 30rpx;
			}

			.typeTtem {
				flex-shrink: 0;
				height: 80rpx;
				align-items: center;
				margin-right: 30rpx;

				&.action {
					color: #F86859;
					border-bottom: 1px solid #F86859;
				}
			}
		}
	}
</style>