<template>
		<view class="studentWrapper">
			<view v-for="(item,index) in stuNeeds" :key="index" >
				<view class="studentList" @click="goDetail(item)">
				    <view class="studentLeft">
				        <view class="studentLeftTitle">
				            <text>{{item.name}}<text style="font-weight: 400; margin-left: 4px">学员</text></text>
				        </view>
				        <view class="studentNeedCourse">
				            <text>科目：</text>
				            <text class="needCourse">{{item.subjectBig}}/{{item.subjectSmall}}</text>
				        </view>
				        <view class="studentExpect">
				            <text>期望目标：</text>
				            <text class="expect">{{item.goal}}</text>
				        </view>
				    </view>
				    <view class="studentRight">
				        <view class="studentRightTitle">
				            <text>{{item.salary}}/小时</text>
				        </view>
				        <view class="studentSex">
				            <text>{{item.sex}}</text>
				        </view>
				        <view class="studentRightTitle">
				            <text>{{item.kil}}km</text>
				        </view>
				    </view>
				</view>
			</view>
		    
		</view>
</template>

<script>
	import { mapState } from 'vuex'
	
	export default {
		computed: {
			...mapState('m_user', ['location'])
		},
		data() {
			return {
				stuNeeds: [],
			};
		},
		created() {
			this.getAllStuNeeds()
		},
		methods: {
			async getAllStuNeeds() {
				
				// 发起请求
				const { data: result } = await uni.$http.get('/education/my-favorite-needs/findPersonCollectInfo')
				// console.log(result)
				for (let i = 0; i < result.data.list.length; i++) {
					let arr = result.data.list[i].locationAl.split(",")
					let kil = this.space(arr[0], arr[1], this.location.latitude, this.location.longitude)
					result.data.list[i].kil = kil
				}
				
				this.stuNeeds = result.data.list
				
			},
			space(lat1, lng1, lat2, lng2) {
				// console.log(lat1, lng1, lat2, lng2)
				var radLat1 = lat1 * Math.PI / 180.0;
				var radLat2 = lat2 * Math.PI / 180.0;
				var a = radLat1 - radLat2;
				var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
				var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
						Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
				s = s * 6378.137;
				s = Math.round(s * 10000) / 10000;	// 单位千米
				return s.toFixed(2)	// 保留两位小数
			},
			goDetail(item) {
				uni.navigateTo({
					url: '/subpkg/all_stu_require_detail/all_stu_require_detail?item=' + encodeURIComponent(JSON.stringify(item)) 
				})
			}

		}
	}
</script>

<style lang="scss">
.studentWrapper{
    height: 100%;
    background-color: #E2F0D9;
    padding: 20rpx;
}

.studentList{
    display: flex;
    position: relative;
    /* border: 1rpx solid gray; */
    border-radius: 20rpx;
    background-color: #FFF2CC;
    margin-bottom: 20rpx;
}

/* 左侧部分 */
.studentLeft{
    padding: 10rpx;
    font-weight: bold;
    font-size: 30rpx;
}
.studentLeftTitle,
.studentExpect,
.studentNeedCourse{
    padding: 6rpx 0;
}

/* 科目 */
.studentNeedCourse{
    display: flex;
}


/* 期望目标 */
.studentExpect{
    display: flex;
	font-weight: 400;
	font-size: 26rpx;
}
/* 期望目标和需求科目详情 */
.needCourse,
.expect{
    margin-left: 10rpx;
    width: 240rpx;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 右侧部分定位 */
.studentRight{
    position: absolute;
    left: 65%;
    color: #FF0000;
    font-size: 32rpx;
}

.studentRight,
.studentSex{
    padding: 10rpx 0;
}
/* 设置性别的字体 */
.studentSex{
    font-weight: bold;
    color: #00B050;
}
</style>
