<template>
	<view>
		<view class="headTop">
			<u-dropdown ref="uDropdown" @open="open" z-index="9999">
				<u-dropdown-item :title="titlex1" @click.native="cityShow = true">
				</u-dropdown-item>
				<u-dropdown-item @change="changex2" v-model="titlesx2" :title="titlex2" :options="filterDatas2">
				</u-dropdown-item>
				<u-dropdown-item @change="change1" v-model="titles1" :title="title1" :options="filterData1">
				</u-dropdown-item>
				<u-dropdown-item @change="change2" v-model="titles2" :title="title2" :options="filterData2">
				</u-dropdown-item>
				<!-- <u-dropdown-item @change="changex1" v-model="titlesx1" :title="titlex1" :options="filterDatas1">
				</u-dropdown-item> -->
			</u-dropdown>
		</view>

		<!-- #ifdef H5 -->
		<view style="margin-top: 100upx;">
			<!-- #endif -->
			<!-- #ifndef H5 -->
			<view style="margin-top: 100upx;">
				<!-- #endif -->
				<homeuserList @click="clickItems" :list="lists"></homeuserList>
				<!-- <view class="listbox" v-for="(item,index) in list" :key="index">
				<view class="flex align-center justify-between">
					<view class="text-xl text-bold" style="color: #6696FF;">UI设计师</view>
					<view class="text-lg text-bold" style="color: #FF4A28;">5-7K</view>
				</view>
				<view class="flex align-center margin-top-sm">
					<view class="argrtn" v-for="(ite,index) in item.lable" :key="index">{{ite.name}}</view>
				</view>
				<view class="flex align-center justify-between margin-top">
					<view class="" style="color: #666666;">UI界面交互设计</view>
					<view>西安 莲湖区</view>
				</view>
			</view> -->
			</view>
			<empty v-if="lists.length==0" content="暂无数据"></empty>
			<!-- 省市区选择 -->
			<u-picker cancel-text="重置" :mask-close-able="false" v-model="cityShow" mode="region" :params="params" @cancel="cancel" @confirm="cityConfirm"></u-picker>
		</view>
</template>

<script>
	import homeuserList from '../../components/home-list/homeuserList.vue'
	import empty from '@/components/empty.vue'
	export default {
		components: {
			homeuserList,
			empty
		},
		data() {
			return {
				params:{
					province: true,
					city: true,
					area: true
				},
				cityShow:false,
				lists: [],
				defaultIndex: [0, 0],
				titlesx1: '',
				titlex1: '项目位置',
				titlesx2: '',
				titlex2: '项目类型',
				filterDatas1: [],
				filterDatas2: [],
				page: 1,
				limit: 10,
				projectType: '',
				count: '',
				postPrice: '',
				titles1: '',
				title1: '岗位',
				titles2: '',
				title2: '专业',
				filterData1: [{
					label: '全部',
					value: '',
				}, ],
				filterData2: [],
				resumesPost: '', //岗位id
				resumesMajor: '', //专业
			}
		},
		onLoad() {
			this.getuserList(2)
			//项目类型
			this.getObjectType();
			//薪资列表
			this.getMonyList();
			//岗位
			this.getruleList();
		},
		onReachBottom() {
			if (this.lists.length == this.count) {
				uni.showToast({
					title: '已经到底了',
					icon: 'none'
				})
			} else {
				this.page = this.page + 1;
				this.getuserList(2)
			}
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getuserList(2)
		},
		methods: {
			cancel(){
				this.titlex1 = '项目位置'
				this.getuserList(2)
				this.$refs.uDropdown.close();
			},
			open(e){
				console.log(e)
				if(e==0){
					this.cityShow = true
				}else if(e==2){
					this.title2 = '专业'
					this.resumesMajor = ''
				}else if(e==3){
					if(this.resumesPost==''){
						this.$refs.uDropdown.close();
						uni.showToast({
							title:'请先选择岗位',
							icon:'none'
						})
					}
				}
				
			},
			cityConfirm(e){
				console.log(e)
				this.titlex1 = e.area.label
				this.getuserList(2)
				this.$refs.uDropdown.close();
			},
			//查询岗位
			getruleList() {
				this.$Request.get("/app/rule/selectRuleClassifyList", {
					status: 1
				}).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/ruleClassifyName/g, 'label'))
						arr = JSON.parse(JSON.stringify(arr).replace(/ruleClassifyId/g, 'value'))
						this.filterData1 = [{
							label: '全部',
							value: ''
						}]
						this.filterData1 = [...this.filterData1, ...arr]
					}

				})
			},
			//岗位
			change1(e) {
				this.filterData1.map(res => {
					if (res.value == this.titles1) {
						if (res.label == '全部') {
							this.title1 = '岗位'
							this.page = 1
							this.resumesPost = res.value
							this.getuserList(2)
						} else {
							this.title1 = res.label
							this.page = 1
							// this.resumesPost = res.label
							this.resumesPost = res.value
							this.getuserList(2)
							this.getPostList();
						}
					}
				})
			},
			//获取专业
			getPostList() {
				let data = {
					ruleClassifyId: this.resumesPost
				}
				this.$Request.post('/app/rule/selectRulePostList', data).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/rulePostName/g, 'label'))
						arr = JSON.parse(JSON.stringify(arr).replace(/rulePostId/g, 'value'))
						this.filterData2 = arr
					}
				})
			},
			//专业
			change2(e) {
				this.filterData2.map(res => {
					if (res.value == this.titles2) {
						if (res.label == '全部') {
							this.title2 = '专业'
							this.page = 1
							this.resumesMajor = res.label
							this.getuserList(2)
						} else {
							this.title2 = res.label
							this.page = 1
							this.resumesMajor = res.label
							this.getuserList(2)
						}
					}
				})
			},
			//薪资
			changex1(e) {
				this.filterDatas1.map(res => {
					if (res.value == this.titlesx1) {
						if (res.label == '全部') {
							this.titlex1 = '薪资'
							this.postPrice = res.value //薪资
							this.page = 1
							this.getuserList(2)
						} else {
							this.titlex1 = res.label
							this.page = 1
							this.postPrice = res.value //薪资
							this.getuserList(2)
						}
					}
				})
			},
			//项目类型
			changex2(e) {
				this.filterDatas2.map(res => {
					if (res.value == this.titlesx2) {
						if (res.label == '全部') {
							this.titlex2 = '项目类型'
							this.page = 1
							this.projectType = res.value //项目类型
							this.getuserList(2)
						} else {
							this.titlex2 = res.label
							this.page = 1
							this.projectType = res.value //项目类型
							this.getuserList(2)
						}
					}
				})
			},
			//薪资列表
			getMonyList() {
				this.$Request.get('/app/dict/list', {
					type: '薪资'
				}).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/code/g, 'label'))
						this.filterDatas1 = [{
							label: '全部',
							value: ''
						}]
						this.filterDatas1 = [...this.filterDatas1, ...arr]
					}
				})
			},
			//获取项目类型
			getObjectType() {
				this.$Request.get("/app/dict/list", {
					type: '项目类型'
				}).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/code/g, 'label'))
						this.filterDatas2 = [{
							label: '全部',
							value: ''
						}]
						this.filterDatas2 = [...this.filterDatas2, ...arr]
					}
				})
			},
			//详情
			clickItems(item, index) {
				uni.navigateTo({
					url: '/pages/index/game/order?postPushId=' + item.item.postPushId
				})
			},
			//获取数据
			getuserList(stauts) {
				let userId = uni.getStorageSync('userId')
				let data = {
					page: this.page,
					limit: this.limit,
					status: stauts,
					classify: 2,
					projectType: this.projectType, //项目类型
					postPrice: this.postPrice, //薪资
					ruleClassifyId: this.resumesPost, //岗位
					rulePostName: this.resumesMajor, //专业
					address:this.titlex1=='项目位置'?'':this.titlex1,//项目位置
				}
				this.$Request.get("/app/postPush/selectPostPushList", data).then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						res.data.records.map(item => {
							switch (item.address) {
								case '北京市北京市':
									item.address = '北京市'
									break;
								case '北京市市辖区':
									item.address = '北京市'
									break;
								case '天津市天津市':
									item.address = '天津市'
									break;
								case '上海市上海市':
									item.address = '上海市'
									break;
								case '重庆市重庆市':
									item.address = '重庆市'
									break;
								default:
									break;
							}
						})
						this.count = res.data.total
						if (this.page == 1) {
							this.lists = res.data.records
							for (var i = 0; i < this.lists.length; i++) {
								this.lists[i].projectType = this.lists[i].projectType.split(',')
							}
						} else {
							this.lists = [...this.lists, ...res.data.records]
							for (var i = 0; i < this.lists.length; i++) {
								this.lists[i].projectType = this.lists[i].projectType.split(',')
							}
						}
					}
					uni.stopPullDownRefresh();
				})
			},
		},

	}
</script>

<style lang="less">
	page {
		background: #F2F2F7;
	}

	.headTop {
		background: #ffffff;
		position: fixed;
		/* #ifndef H5 */
		top: 0upx;
		/* #endif */
		/* #ifdef H5 */
		top: 80upx;
		/* #endif */
		left: 0;
		right: 0;
		z-index: 999;
	}

	.navs {
		background: #ffffff !important;
	}

	.listbox {
		background: #FFFFFF;
		border-radius: 24upx;
		margin: 20upx 30upx;
		padding: 30upx;
	}

	.argrtn {
		background: #F6F6F6;
		color: #666666;
		font-size: 24upx;
		border-radius: 8upx;
		padding: 5upx 20upx;
		margin-right: 20upx;
	}
</style>
