<template>
	<view>
		<view class="se-bgc-orange se-pos se-pos-lt se-w-vw-100 se-h-vh-30" style="z-index: -1;border-bottom-left-radius: 120rpx;border-bottom-right-radius: 120rpx;"></view>
		<view class="se-flex se-flex-h-sb se-px-40 se-pb-30 se-pt-10 se-bgc-orange se-zi-s">
			<view class="se-c-white se-fs-28" @click="getLocation()">
				<view class="se-bgc-white se-py-5 se-px-10 se-fw-6 se-br-12 se-c-orange se-fs-24 se-display-ib">
					工
				</view>
				<text class="se-ml-10 se-fw-6 se-fs-28">智选猎头</text>
			</view>
			<!-- <view class="se-br-30 se-bgc-white se-fw-6 se-c-orange se-fs-28 se-px-20 se-py-10">
				企业/个人端
			</view> -->
		</view>
		<view class="se-px-20 se-pt-10 se-zi-s" @click="onCategory()">
			<u-search height="40" placeholder="搜索" :showAction="false" v-model="keyword"></u-search>
		</view>
		<view class="se-pb-20 se-pt-40 se-zi-s">
			<view class="se-px-20">
				<u-swiper height="300rpx" :indicator="true" style="background-color: #f5f5f5;height: 300rpx;" :list="swiperList" keyName="image" @change="change" @click="click"></u-swiper>
			</view>
			<view class="se-pt-10 se-px-0 se-py-10 se-ta-l se-flex se-flex-ai-c se-fs-26">
				 <u-notice-bar direction="column" mode="link" @click="onNoticeDetail" :text="noticeList"></u-notice-bar>
			</view>
		</view>
		<view class="se-my-20 se-bgc-white se-grid">
			<navigator :url="`/pages_subpack/category/index?id=`+item.id" v-for="(item, index) in tabList" :key="index" class="se-flex-v-c se-pt-30 se-mb-20">
				<image class="se-a-100 se-bgc-f5" :src="item.icon" mode=""></image>
				<text class="se-w-150 se-h-60 se-lh-30 se-c-black se-fs-22 se-ta-c se-mt-10 se-toe-2">{{item.name}}</text>
			</navigator>
		</view>
		<view class="se-my-20 se-bgc-white se-p-20 se-flex">
			<view @click="toNavigator(1)" class="se-flex-1 se-flex-h-c se-flex-ai-c se-c-white se-py-20 se-fw-6 enterprise">
				<!-- 找工作 -->
				招聘
			</view>
			<view @click="toNavigator(2)" class="se-flex-1 se-ml-20 se-flex-h-c se-flex-ai-c se-c-white se-py-20 se-fw-6 master">
				<!-- 找师傅 -->
				求职
			</view>
		</view>
		<u-tabs
			:current="current"
			lineWidth="30"
			lineColor="#FF7A31"
			:activeStyle="{
				color: '#303133',
				fontWeight: 'bold',
				transform: 'scale(1.05)'
			}"
			:inactiveStyle="{
				color: '#606266',
				transform: 'scale(1)'
			}"
			itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;" 
			:list="navList" 
			@click="navClick($event)">
		</u-tabs>
		<!-- 企业端 求职大厅 -->
		<enterpriseBox :rolelist="rlist" v-if="current==0" />
		<!-- 师傅端 招聘大厅 -->
		<masterBox :taskList="tList" v-if="current==1" />
		<view class="se-h-80"></view>
	</view>
</template>

<script>
	import {
		bannerList,
		taskList,
		rolelist,
		industryList,
		getSysText,
		getNotice,
		noticeList,
		queryConfigList
	} from "@/common/api.js"
	import enterpriseBox from "./component/enterprise.vue"
	import masterBox from "./component/master.vue"
	import QQMapWX from "@/util/qqmap-wx-jssdk.min.js"
	export default{
		components:{
			enterpriseBox,
			masterBox
		},
		data(){
			return {
				notice:[],
				noticeList:[],
				status:1,
				list: [
					"https://cdn.uviewui.com/uview/swiper/swiper1.png"
				],
				tabList:[],//导航栏
				swiperList:[],//轮播
				current:0,
				navList:[
					{
						name: '求职大厅',
					}, 
					{
						name: '招聘大厅',
					}
				],
				rpageNo:1,
				rpageSize:20,
				rlist:[],
				
				latitude:'34.00',
				longitude:'134.65',
				tpageNo:1,
				tpageSize:20,
				tList:[]
			}
		},
		mounted() {
			this.onBannerList()
			this.onTaskList()
			this.onRolelist()
			this.onIndustryList()
			this.getLocation()
			this.onSysText()
			this.onNotice()
		},
		onPullDownRefresh() {
			let that = this
			that.rpageNo =  1
			that.rlist = []
			that.onRolelist()
		},
		onReachBottom() {
			let that = this
			that.rpageNo = that.rpageNo + 1
			that.onRolelist()
		},
		methods:{

			onNoticeDetail(index){
				uni.navigateTo({
					url:"/pages_subpack/notice/index?id="+this.notice[index].id
				})
			},
			onNotice(){
				let that = this
				let params={}
				let arr=[]
				noticeList(params).then(response=>{
					console.info(response)
					response.result.forEach(items=>{
						arr.push(items.title)
					})
					that.noticeList = arr
					that.notice = response.result
				}).catch(error=>{
					
				})
			},
			onSysText(){
				let that = this
				let params={}
				getSysText(params).then(response=>{
					console.info("onSysText",response.result)
					uni.setStorageSync('sysList', result.result)
				}).catch(error=>{
					
				})
			},
			getLocation(){
				const that = this;
				console.log('当前位置的经度：');
				wx.getLocation({
				    type: 'wgs84',
					success: function (res) {
						console.log('位置',res);
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						uni.setStorageSync("longitude",res.longitude)
						uni.setStorageSync("latitude",res.latitude)
						const qqmapsdk = new QQMapWX({
						    key: 'TT7BZ-Z3LW4-KOAUB-KWHOA-SBJJ6-Y5B6R' // 必填
						});
						qqmapsdk.reverseGeocoder({
						    location: {
						        latitude: res.latitude,
						        longitude: res.longitude
						    },
						    success: function(response) {
								// that.city = response.result.ad_info.city
						        console.log('逆地理编码结果：', response);
						    },
						    fail: function(error) {
						        console.error('逆地理编码失败：', error);
						    }
						});
					}
				})
			},
			onIndustryList(){
				industryList({}).then(response=>{
					console.info("industryList",response);
					this.tabList = response.result
				}).catch(error=>{
					
				})
			},
			onBannerList(){
				bannerList({type:0}).then(response=>{
					this.swiperList = response.result.records
				}).catch(error=>{
					
				})
			},
			onTaskList(){
				taskList({
					latitude:this.latitude,
					longitude:this.longitude,
					pageNo:this.tpageNo,
					pageSize:this.tpageSize
				}).then(response=>{
					if(this.tpageNo==1){
						this.tList = response.result.records
					}else{
						this.tList = this.tList.concat(response.result.records)
					}
					
					console.info("taskList",response)
				}).catch(error=>{
					
				})
			},
			onRolelist(){
				rolelist({
					pageNo:this.rpageNo,
					pageSize:this.rpageSize
				}).then(response=>{
					console.info("response",response)
					if(this.rpageNo==1){
						this.rlist = response.result.records
					}else{
						this.rlist = this.rlist.concat(response.result.records)
					}
				}).catch(error=>{
					
				})
			},
			navClick(event){
				this.current=event.index
			},
			change(event){
				console.info(event)
			},
			click(event){
				console.info(event)
			},
			toNavigator(event){
				uni.navigateTo({
					url:"/pages_subpack/release/index?status="+event
				})
			},
			onCategory(){
				uni.navigateTo({
					url:"/pages_subpack/category/index"
				})
			}
		}
		
	}
</script>
<style>
	page{
		background-color: #f5f5f5;
	}
	.enterprise{
		background: #ff7a31;
		border: 4rpx solid rgba(255,255,255,0.50);
		border-radius: 14rpx;
	}
	.master{
		background: #f0b744;
		border: 4rpx solid rgba(255,255,255,0.50);
		border-radius: 14rpx;
	}
</style>