<template>
	<view class="index-page">
		<view class="index-navbar">
			<view style="position: relative;height: 352rpx;">
				<image class="index-bg" src="../../static/images/index-header.png" mode=""></image>
				<u-navbar :fixed="false" bgColor='rgba(0,0,0,0)' placeholder :safeAreaInsetTop="true">
					<view id="height" class="index-header  u-flex u-row-between" slot="left"
						style="position: relative;">
						<view class="" style="margin-left: -11rpx;">
							<u-tabs :current="tab1" :list="list4" lineWidth="28" lineHeight="5"
								:lineColor="bgImage" :activeStyle="{
							    color: '#303133',
							    fontWeight: 'bold',
							}" :inactiveStyle="{
							    color: '#606266',
							}" itemStyle=" padding-right: 15px; height: 34px;" @click="TabsTop">
							</u-tabs>
						</view>

						<view class="" style="">
							<view class="index-search u-flex" slot="center">
								<u-icon name="search" color="#444444" size="28"></u-icon>
								<input type="text" class="text1" placeholder="搜索职位" :disabled="true">
							</view>
						</view>
					</view>
				</u-navbar>
				<view v-if="tab1 == 1"  class="" >
					<view v-if="is_auth == 0" class="unverified">
						<image style="width: 380rpx;height: 254rpx;" src="/static/images/unverified.png" mode=""></image>
						<text>您的账号未完成学校认证 无法查看校企招聘信息</text>
						<button>前往认证</button>
					</view>
					<view v-if="is_auth == 1"  class="" style="padding:0rpx 24rpx;">
						<hx-school></hx-school>
					</view>
				</view>

				<view v-if="tab1 == 0" class="header-down ">
					<view class="u-flex u-row-between u-row-center">
						<view class="font">
							UX交互设计师
						</view>
						<view class="font" style="font-size: 42rpx;">
							+
						</view>
					</view>
					<view class="u-flex u-row-between" style="margin-left: -11rpx;margin-top: 14rpx;">
						<view class="down-left u-flex u-row-center" @click="showpaixu = true">
							<u-tabs :current="tab2" :list="list1" @click="click"></u-tabs>
						</view>
						<view class="u-flex">
							<view class="right-item u-flex u-row-center" @click="opencity = true">
								<text class="text">{{city.name || '北京'}}</text>
								<u-icon name="arrow-down-fill" size="20"></u-icon>
							</view>
							<view class="right-item u-flex u-row-center" @click="openshaixuan">
								<text class="text">筛选</text>
								<u-icon name="arrow-down-fill" size="20"></u-icon>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="tab1 == 0" class="" style="padding:0rpx 24rpx;background-color: #F3F3F3 ;height: 100%;">
				<view class="content" @click="todetails(item.id)" v-for="(item,index) in positionlist" :key="item.manager_id">
					<view class="u-flex u-row-between">
						<view class="u-flex">
							<view class="font">{{item.job_name}}</view>
							<view class="back" v-if="item.is_urgent == 1">急聘</view>
						</view>
						<view class="money">{{item.salary_min}}-{{item.salary_max}}K
							<text v-if="item.salary_structure">·{{item.salary_structure}}</text>
						</view>
					</view>
					<view class="u-flex" style="margin: 16rpx 0 14rpx 0;">
						<text class="introduce">{{item.companys.name}}</text>
						<text class="introduce">{{item.company_stage.name}}</text>  
						<text class="introduce">{{item.company_scale.name}}</text>
					</view>
					<view class="u-flex" style="margin-bottom: 24rpx;">
						<view class="tabs">
							{{item.education_name}}
						</view>
						<view class="tabs">
							{{item.experience_name}}
						</view>
					</view>
					<view class="u-flex u-row-between u-col-center">
						<view class=" u-flex u-col-center">
							<image :src="item.usermanager.avatar"  mode="" style="width: 50rpx;height: 50rpx;border-radius: 50%;">
							</image>
							<view class="" style="margin-left: 16rpx;">
								<text>{{item.usermanager.name}}</text>·
								<text>{{item.usermanager.company_text}}</text>
							</view>
						</view>
						<view class="u-flex u-col-center ">
							<view class="address" style="margin-right: 10rpx;">{{item.work_province.slice(0,-1)}}</view>
							<view class="address">{{item.work_city}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup border-radius="28" :show="opencity" mode="bottom">
			<view class="change-city-popup u-flex-col">
				<view class="change-city-header u-flex u-row-between">
					<u-icon name="close" size="22" color="#222" @click="opencity = false"></u-icon>
					<text class="text">选择城市</text>
					<u-icon name="close" size="22" color="#fff"></u-icon>
				</view>
				<view class="u-flex-1 u-flex change-city-scroll">
					<scroll-view scroll-y="true" class="change-scroll-left">
						<view class="scroll-left-sheng" v-for="(item,index) in citylist" :key="index" :class="{shengactive:cityleftindex == index}" @click="changeleftcity(index)">{{item.name}}</view>
					</scroll-view>
					<scroll-view scroll-y="true" class="change-scroll-right u-flex-1">
						<view class="scroll-left-shi" v-for="(item,index) in rightcity" :key="index" :class="{shiactive:cityrightindex == index}" @click="changerightcity(index,item)">{{item.name}}</view>
					</scroll-view>
				</view>
				<view class="change-city-down u-flex u-row-between">
					<text @click="chongzhi">重置</text>
					<text @click="changecity">确定</text>
				</view>
			</view>
		</u-popup>
		<zhao-shaixuan ref="shaixuan" @tosearch="shaixuan"></zhao-shaixuan>
	</view>
</template>

<script>
	import {
		getList,getareacity,is_auth
	} from "../../units/inquire.js"
	export default {
		data() {
			return {
				opencity:false,
				citylist: [],
				total:0,
				height: "",
				list1: [
					{
						name: "相关"
					},
					{
						name: "推荐"
					},
					{
						name: "最新"
					},
				],
				list4: [{
						name: "职位"
					},
					{
						name: "校招"
					}
				],
				page:1,
				tab1:0,
				tab2:0,
				positionlist:[],//职位列表
				is_auth:"",//是否认证
			}
		},
		onLoad() {
			this.getlist()
			this.getcity()
			this.auth()
		},
		onReachBottom() {
			if (this.positionlist.length != this.total) {
				this.page++
				this.getlist()
			}
		},
		computed:{
			bgImage(){
				return `url(${require('../../static/images/juxing.png')}) 100% 100%`
			}
		},
		methods: {
			auth(){
				is_auth().then(res=>{
						this.is_auth = res.data.is_auth
				})
			},
			shaixuan(e) {
				this.search_data = e
				this.tosearch()
			},
			chongzhi() {
				this.city = {
					name: '',
					id: ''
				}
				this.opencity = false
				this.tosearch()
			},
			changecity() {
				if (this.cityrightindex == -1) {
					this.$u.toast("请选择城市")
					return
				}
				this.city = {
					name: this.citylist[this.cityleftindex].childlist[this.cityrightindex].name,
					id: this.citylist[this.cityleftindex].childlist[this.cityrightindex].id
				}
				this.opencity = false
				this.tosearch()
			},
			changerightcity(index, item) {
				this.cityrightindex = index
			},
			changeleftcity(index) {
				this.cityleftindex = index
				this.cityrightindex = -1
				this.rightcity = this.citylist[this.cityleftindex].childlist
			},
			getcity() {
				getareacity().then(res => {
					this.citylist = res.data
					this.rightcity = res.data[0].childlist
				})
			},
			tosearch() {
				this.page = 1
				this.positionlist = []
				this.getlist()
			},
			openshaixuan() {
				console.log(111);
				this.$refs.shaixuan.openshaixuan = true
			},
			click(item) {
				this.tab2 = item.index
				console.log(this.tab2);
				this.getlist()
				// console.log('item', item);
			},
			TabsTop(item) {
				if(uni.getStorageSync('token') == "" && this.tab1 == 0){
					uni.reLaunch({
						url:"/pages/login/login"
					})
				}
				this.tab1 = item.index
				// console.log(this.tab1);
			},
			//获取职位列表
			getlist() {
				getList({
					page: this.page,
					type: this.tab2,
					
				}).then(res => {
					if (this.page == 1) {
						this.positionlist = res.data.data
					} else {
						this.positionlist = this.positionlist.concat(res.data.data)
					}
					this.total = res.data.total
				})
			},
			todetails(id) {
				uni.navigateTo({
					url: '../../pagesB/details?id='+id
				})
			}

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F3F3F3;
	}
	.unverified{
		display: flex;
		flex-direction: column;
		justify-content: center;
		background-color: #fff;
		background-image: linear-gradient(to bottom, #fff 20%,  #f3f3f3 50%);
		align-items: center;
		width: 750rpx;
		height: 70vh;
		margin-top: 180rpx;
			text{
				width: 312rpx;
				height: 84rpx;
				margin-top: 34rpx;
				display: block;
			}
			button{
				width: 264rpx;
				height: 100rpx;
				background: #0C66C2;
				border-radius: 12rpx;
				font-size: 36rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				margin-top: 90rpx;
				line-height: 100rpx;
			}
			
	}
	
	.index-page {

		.address {
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #979797;
			line-height: 34rpx;
		}

		.content {
			padding: 24rpx 20rpx;
			margin-top: 20rpx;
			background-color: #fff;
			border-radius: 16rpx;

			.font {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #222222;
				line-height: 44rpx;
				max-width: 326rpx;
				overflow: hidden; //超出隐藏
				white-space: nowrap; //不换行，同一行展示
				text-overflow: ellipsis; //设置超出部分以省略号展示
			}

			.back {
				width: 58rpx;
				height: 32rpx;
				background: #FF5335;
				border-radius: 6rpx;
				font-size: 22rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 32rpx;
				text-align: center;
				margin-left: 16rpx;
			}

			.money {
				font-size: 32rpx;
				font-family: JDZhengHT-Regular, JDZhengHT;
				font-weight: 400;
				color: #0C66C2;
			}

			.introduce {
				height: 40rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #555555;
				line-height: 40rpx;
				margin-right: 16rpx;
			}

			.tabs {
				background: #F3F3F3;
				border-radius: 4rpx;
				padding: 6rpx 14rpx;
				margin-right: 16rpx;
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #5F5F5F;
				height: 34rpx;
				line-height: 34rpx;
			}
		}




		.index-item {
			// width: 702rpx;
			// background: #FFFFFF;
			// border-radius: 20rpx;
			// margin: 20rpx auto;
			// padding: 0 20rpx 24rpx 10rpx;

			.item-down {
				text:first-child {
					font-size: 22rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}

				text:last-child {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}

			.item-gongsi {
				margin-bottom: 16rpx;

				.text2 {
					font-size: 24rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}

				.logo {
					width: 42rpx;
					height: 42rpx;
					border-radius: 10rpx;
					margin-right: 16rpx;
				}

				.text1 {
					max-width: 192rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #444444;
					margin-right: 12rpx;
				}
			}

			.item-label {
				margin-bottom: 20rpx;

				text {
					margin-right: 16rpx;
					line-height: 46rpx;
					background: #F7F7F7;
					border-radius: 4rpx;
					padding: 0 14rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #5F5F5F;
				}
			}

			.item-top {
				height: 88rpx;

				.text1 {
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
					margin-right: 16rpx;
				}

				.text2 {
					width: 50rpx;
					line-height: 32rpx;
					background: rgba(255, 83, 53, 0.1);
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FF5335;
					margin-right: 12rpx;
				}

				.text3 {
					width: 90rpx;
					line-height: 32rpx;
					background: #FFF2E8;
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FF8620;
					margin-right: 12rpx;
				}

				.text4 {
					line-height: 32rpx;
					background: #E6EFF8;
					border-radius: 4rpx;
					padding: 0 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #0C66C2;
				}

				.text5 {
					font-size: 32rpx;
					font-family: JDZhengHT-Regular, JDZhengHT;
					font-weight: 400;
					color: #0C66C2;
				}
			}
		}

		.index-navbar {
			position: sticky;
			top: 0;
			left: 0;
			width: 750rpx;
			z-index: 100;





			.header-down {
				height: 92rpx;
				padding: 20rpx 24rpx;
				box-sizing: border-box;

				.font {
					font-size: 40rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}

				.right-item {
					padding: 0 16rpx;
					height: 52rpx;
					background: #F3F3F3;
					border-radius: 4rpx;
					margin-left: 20rpx;

					.text {
						margin-right: 4rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}

				.down-left {
					.text {
						margin-right: 4rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
			}

			.index-bg {
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
				width: 750rpx;
				height: 352rpx;
			}
		}

		.index-header {
			flex: 1;
			padding: 0 32rpx;
			height: 50rpx;

			.index-search {
				width: 200rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 0 28rpx;

				.text1 {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					margin-left: 16rpx;
				}
			}

			.index-tabs {
				text:first-child {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}

				text:last-child {
					width: 76rpx;
					height: 12rpx;
					background: linear-gradient(270deg, #208EFF 0%, rgba(28, 159, 227, 0) 100%);
					margin-top: -20rpx;
					border-radius: 100rpx;
				}
			}
		}
	}

	::v-deep .u-navbar__content__left {
		padding: 0 !important;
	}
</style>