<template>
	<view>
		<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.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-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>
</template>

<script>
	export default{
		data(){
			return{
				taskList:[
					{
					    "id": "1895062781967736834",
					    "createBy": null,
					    "createTime": "2025-02-27 18:45:50",
					    "updateBy": null,
					    "updateTime": null,
					    "title": "销售兼职",
					    "address": "云南省昆明市官渡区站前路",
					    "categoryOne": "1894724968848064513",
					    "categoryTwo": "1894726005210251265",
					    "salaryMin": 3000,
					    "salaryMax": 10000,
					    "salaryDay": 200,
					    "payType": "1",
					    "phone": "17875426385",
					    "details": "卖衣服",
					    "image": "https://tennis-oss.xzaiyp.top/2025-02-27/45e4b177-f0da-4eba-95e5-2322589a8af7.jpg",
					    "userId": "1891910362819756034",
					    "longitude": 102.72173,
					    "latitude": 25.015772,
					    "tag": null,
					    "startTime": "2015-01-01 00:00:00",
					    "endTime": "2015-01-01 00:00:00",
					    "employAuthenticationPerson": {
					        "id": "1895028819692646402",
					        "createBy": null,
					        "createTime": 1740645053000,
					        "updateBy": "admin",
					        "updateTime": 1741768776000,
					        "name": "安师傅",
					        "password": null,
					        "phone": "17875426385",
					        "address": "云南省文山州凤凰谷",
					        "industry": "1894724665780240386",
					        "cerImageFront": "https://tennis-oss.xzaiyp.top/2025-02-27/9ed9dabf-15a1-4ea4-87cb-d7df3f52c0e8.jpg",
					        "cerImageBack": "https://tennis-oss.xzaiyp.top/2025-02-27/0bf464ca-b275-4db5-8349-6bc9720067b1.jpg",
					        "status": "1",
					        "userId": "1891910362819756034",
					        "industryName": null,
					        "image": "https://tennis-oss.xzaiyp.top/2025-02-27/b176ed2c-499e-40df-bce9-abbb7429f890.jpg"
					    },
					    "employAuthenticationCompany": null,
					    "hanHaiMember": {
					        "id": "1891910362819756034",
					        "createBy": null,
					        "createTime": 1739894400000,
					        "updateBy": "admin001",
					        "updateTime": 1740412800000,
					        "sysOrgCode": null,
					        "nickName": "哦哟",
					        "headImage": "https://tennis-oss.xzaiyp.top/2025-02-25/f209a458-f58c-492d-8887-7295000d9b5f.jpeg",
					        "name": "",
					        "phone": "17875426385",
					        "account": null,
					        "password": null,
					        "passwordSalt": null,
					        "shopName": null,
					        "role": "",
					        "cardId": null,
					        "frozenFlag": "",
					        "deleteFlag": "0",
					        "token": null,
					        "officialOpenid": null,
					        "appletOpenid": "opwCj7Z-ni6VvPuwI8zvebAiU_lk",
					        "appOpenid": null,
					        "wxUnionid": null,
					        "officialAppid": null,
					        "idCard": null,
					        "idCardPassword": null,
					        "idCardSalt": null,
					        "idCardOpen": null,
					        "intentionNum": null,
					        "successNum": null,
					        "addNum": null,
					        "shareId": null,
					        "vid": null,
					        "vtime": null,
					        "isPay": null,
					        "follow": null,
					        "payRole": null,
					        "price": 0,
					        "integerPrice": null,
					        "appletAppid": null,
					        "sex": "2",
					        "isDai": null
					    },
					    "categoryOne_dictText": "兼职",
					    "categoryTwo_dictText": "波音兼职",
					    "payType_dictText": "支付宝支付",
					    "userId_dictText": "哦哟"
					},
					{
					    "id": "1895062781967736834",
					    "createBy": null,
					    "createTime": "2025-02-27 18:45:50",
					    "updateBy": null,
					    "updateTime": null,
					    "title": "销售兼职",
					    "address": "云南省昆明市官渡区站前路",
					    "categoryOne": "1894724968848064513",
					    "categoryTwo": "1894726005210251265",
					    "salaryMin": 3000,
					    "salaryMax": 10000,
					    "salaryDay": 200,
					    "payType": "1",
					    "phone": "17875426385",
					    "details": "卖衣服",
					    "image": "https://tennis-oss.xzaiyp.top/2025-02-27/45e4b177-f0da-4eba-95e5-2322589a8af7.jpg",
					    "userId": "1891910362819756034",
					    "longitude": 102.72173,
					    "latitude": 25.015772,
					    "tag": null,
					    "startTime": "2015-01-01 00:00:00",
					    "endTime": "2015-01-01 00:00:00",
					    "employAuthenticationPerson": {
					        "id": "1895028819692646402",
					        "createBy": null,
					        "createTime": 1740645053000,
					        "updateBy": "admin",
					        "updateTime": 1741768776000,
					        "name": "安师傅",
					        "password": null,
					        "phone": "17875426385",
					        "address": "云南省文山州凤凰谷",
					        "industry": "1894724665780240386",
					        "cerImageFront": "https://tennis-oss.xzaiyp.top/2025-02-27/9ed9dabf-15a1-4ea4-87cb-d7df3f52c0e8.jpg",
					        "cerImageBack": "https://tennis-oss.xzaiyp.top/2025-02-27/0bf464ca-b275-4db5-8349-6bc9720067b1.jpg",
					        "status": "1",
					        "userId": "1891910362819756034",
					        "industryName": null,
					        "image": "https://tennis-oss.xzaiyp.top/2025-02-27/b176ed2c-499e-40df-bce9-abbb7429f890.jpg"
					    },
					    "employAuthenticationCompany": null,
					    "hanHaiMember": {
					        "id": "1891910362819756034",
					        "createBy": null,
					        "createTime": 1739894400000,
					        "updateBy": "admin001",
					        "updateTime": 1740412800000,
					        "sysOrgCode": null,
					        "nickName": "哦哟",
					        "headImage": "https://tennis-oss.xzaiyp.top/2025-02-25/f209a458-f58c-492d-8887-7295000d9b5f.jpeg",
					        "name": "",
					        "phone": "17875426385",
					        "account": null,
					        "password": null,
					        "passwordSalt": null,
					        "shopName": null,
					        "role": "",
					        "cardId": null,
					        "frozenFlag": "",
					        "deleteFlag": "0",
					        "token": null,
					        "officialOpenid": null,
					        "appletOpenid": "opwCj7Z-ni6VvPuwI8zvebAiU_lk",
					        "appOpenid": null,
					        "wxUnionid": null,
					        "officialAppid": null,
					        "idCard": null,
					        "idCardPassword": null,
					        "idCardSalt": null,
					        "idCardOpen": null,
					        "intentionNum": null,
					        "successNum": null,
					        "addNum": null,
					        "shareId": null,
					        "vid": null,
					        "vtime": null,
					        "isPay": null,
					        "follow": null,
					        "payRole": null,
					        "price": 0,
					        "integerPrice": null,
					        "appletAppid": null,
					        "sex": "2",
					        "isDai": null
					    },
					    "categoryOne_dictText": "兼职",
					    "categoryTwo_dictText": "波音兼职",
					    "payType_dictText": "支付宝支付",
					    "userId_dictText": "哦哟"
					}
				]
			}
		},
		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:{
			onMasterDetail(event){
				uni.navigateTo({
					url:"/pages_subpack/work-detail/index?id="+event.id
				})
			}
		}
	}
</script>

<style>
</style>
