<template>
	<view>
		<!-- <view class="se-flex se-flex-h-sb se-px-40 se-py-30 se-bgc-orange se-zi-s">
			<view class="se-c-white se-fs-28">
				<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">
			<u-search height="40" placeholder="搜索" :showAction="false" v-model="keyword"></u-search>
		</view>
		<view class="se-px-20 se-pb-20 se-pt-40 se-zi-s">
			<u-swiper
					height="300rpx"
				    style="background-color: transparent;height: 300rpx;"
					:list="list"
					@change="change"
					@click="click"
			></u-swiper>
		</view> -->
		<!-- <view class="se-p-20">
			<view class="se-flex se-flex-ai-c se-pb-10">
				<view class="line-orange"></view>
				<view class="se-ml-10 se-fs-32 se-c-black se-fw-6">
					信息大厅
				</view>
			</view>
		</view> -->
		<!-- <screenWork :filterData='filterData' :defaultIndex='defaultIndex' @onSelected='onSelected' @onIntellect="onIntellect"></screenWork> -->
		<view class="se-mt-10">
			<view class="se-m-20 se-br-20 se-bs-b se-bgc-white se-py-20 se-px-30" v-for="(items,indexs) in taskList" :key="indexs" @click="onMasterDetail(items)">
				<view class="se-flex se-flex-h-sb">
					<view class="se-flex">
						<text class="se-fw-6 se-c-black se-fs-30">{{items.title}}</text>
					</view>
					<view class="se-c-orange se-fs-32 se-fw-6">
						{{items.salaryMin}}-{{items.salaryMax}}k
					</view>
				</view>
				<view class="se-py-10">
					<!-- <text class="se-c-text-sub se-fs-22 se-mr-10 se-py-5 se-px-20 se-br-5 se-bgc-f5" v-if="items.tag">{{items.tag}}</text> -->
					<text class="se-c-text-sub se-fs-22 se-mr-10 se-py-5 se-px-20 se-br-5 se-bgc-f5" v-if="items.categoryOne_dictText">{{items.categoryOne_dictText}}</text>
					<text class="se-c-text-sub se-fs-22 se-mr-10 se-py-5 se-px-20 se-br-5 se-bgc-f5" v-if="items.categoryTwo_dictText">{{items.categoryTwo_dictText}}</text>
					<text class="se-c-text-sub se-fs-22 se-mr-10 se-py-5 se-px-20 se-br-5 se-bgc-f5"v-if="items.payType_dictText">{{items.payType_dictText}}</text>
				</view>
				<view class="se-flex se-flex-h-sb">
					<view class="se-flex se-flex-h-c">
						<u-icon name="map"></u-icon>
						<text class="se-c-text-sub se-fs-24 se-pr-10">{{items.latitude,items.longitude | getDistance}}km</text>
						<!-- <text class="se-c-text-sub se-fs-24 se-pr-10">100km</text> -->
						<text class="se-c-text-sub se-fs-24 se-pl-10 se-b-l se-toe-3" style="max-width: 220rpx;">{{items.address}}</text>
					</view>
					<view class="se-c-text se-c-text-sub se-fs-24">
						{{items.createTime | formatTime}}
					</view>
					<view class="se-flex se-flex-h-c se-py-10 se-px-20 se-br-12 se-fs-22 se-c-orange se-bgc-ffd se-fw-6">
						<text class="se-ml-5">立即接单</text>
					</view>
				</view>
			</view>
			<u-empty v-if="taskList && taskList.length==0" mode="list"></u-empty>
		</view>
		<!-- <view class="release-box" @click="toNavigator()">
			<image class="se-a-70 se-br-p-50" src="@/static/image/release_btn.png" mode=""></image>
			<text class="se-c-white se-fs-30 se-fw-6">师傅发布</text>
		</view> -->
	</view>
</template>

<script>
	// import screenWork from "./screen-work.vue"
	export default{
		props:["taskList"],
		components:{
			// screenWork
		},
		data(){
			return{
				keyword:"",
				list: [
					'https://cdn.uviewui.com/uview/swiper/swiper2.png'
				],
				filterData:[
					[
						{ text: '全国', value: '', select:true }, 
						{ text: '状态1', value: 1, select:false }, 
						{ text: '状态2', value: 2, select:false }, 
						{ text: '状态3', value: 3, select:false }
					],
					[
						{ text: '选择工种', value: '', select:true },
						{ text: '类型1', value: 1, select:false }, 
						{ text: '类型2', value: 2, select:false }, 
						{ text: '类型3', value: 3, select:false },
					]
				],
				defaultIndex:[0,0]
			}
		},
		
		filters:{
			formatTime(time) {
				const timestamp = new Date(time).getTime();
			  const currentTime = new Date().getTime();
			  console.info("currentTime",currentTime)
			  const diff = (currentTime - timestamp) / 1000; // 时间差，单位：秒
			
			  // 计算月差，判断是否超过一个月
			  const oneMonthInSeconds = 30 * 24 * 60 * 60;
			  if (diff > oneMonthInSeconds) {
			    let date = new Date(timestamp);
			    let year = date.getFullYear();
			    let month = date.getMonth() + 1;
			    let day = date.getDate();
			
			    if (month < 10) month = "0" + month;
			    if (day < 10) day = "0" + day;
			
			    return `${year}-${month}-${day}`;
			  } else {
			    // 计算秒、分钟、小时的差值
			    if (diff < 60) {
			      return `${Math.floor(diff)}秒钟前`;
			    } else if (diff < 60 * 60) {
			      return `${Math.floor(diff / 60)}分钟前`;
			    } else if (diff < 60 * 60 * 24) {
			      return `${Math.floor(diff / 60 / 60)}小时前`;
			    } else {
			      // 显示天数
			      return `${Math.floor(diff / 60 / 60 / 24)}天前`;
			    }
			  }
			},
			formDate(date){
				return dayjs(date).format("YYYY-MM-DD").fromNow();
			},
			getDistance(lat1, lng1) {
				let lng2 = uni.getStorageSync("longitude")
				let lat2 = uni.getStorageSync("latitude")
				if(!lng2 && !lat2){
					return "请授权"
				}
			  const R = 6371; // 地球半径，单位：km
			  const radLat1 = (lat1 * Math.PI) / 180;
			  const radLat2 = (lat2 * Math.PI) / 180;
			  const deltaLat = radLat2 - radLat1;
			  const deltaLng = ((lng2 - lng1) * Math.PI) / 180;
			
			  const a =
			    Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
			    Math.cos(radLat1) *
			      Math.cos(radLat2) *
			      Math.sin(deltaLng / 2) *
			      Math.sin(deltaLng / 2);
			
			  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
			  return (R * c).toFixed(2); // 返回保留两位小数的公里数
			}
		},
		methods:{
			onSelected(res){
				console.info(res)
			},
			change(event){
				console.info(event)
			},
			click(event){
				console.info(event)
			},
			toNavigator(){
				uni.navigateTo({
					url:"/pages_subpack/release/index?status=2"
				})
			},
			onMasterDetail(event){
				console.info(event)
				console.info("------------"+event.id)
				uni.navigateTo({
					url:"/pages_subpack/work-detail/index?id="+event.id
				})
			}
		}
		
	}
</script>

<style>
	.release-box{
		width: 250rpx;
		height: 80rpx;
		background: #ff5d18;
		border: 4rpx solid rgba(255,255,255,0.68);
		border-radius: 44rpx;
		box-shadow: 0px 6rpx 12rpx 0px rgba(0,0,0,0.16); 
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		bottom: 40rpx;
		left: 250rpx;
	}
</style>