<!-- 菜单悬浮的原理: 通过给菜单添加position:sticky实现, 用法超简单, 仅APP端的低端机不兼容 https://caniuse.com/#feat=css-sticky -->
<template>
	<view>
		<view class="sticky-tabs">
			<me-tabs v-model="tabIndex" nameKey='name' :tabs="tabs" @change="tabChange"></me-tabs>
		</view>

		<view>
			<view class="box" v-for="(item,index) in goods" :key="index">
				<view class="flex align-center justify-between padding-lr padding-tb-sm">
					<view style="color: #00B88F;font-size: 28rpx;font-weight: bold;">{{item.statusName}}</view>
					<view class="text-sm" style="color: #999999;">{{item.createTime}}</view>
				</view>
				<view style="width: 100%;height: 1rpx;background: #EEEEEE;"></view>
				<view class="padding-lr padding-tb-sm">
					<view class="flex align-center justify-between">
						<view class="text-bold" style="color: #1F1F1F;font-size: 38upx;">
							{{item.postPush?item.postPush.stationName:''}}
						</view>
						<view class="" style="color: #00B88F;font-size: 38upx;"><text
								class="text-lg text-bold">{{item.postPush?item.postPush.salaryRange:''}}</text></view>
					</view>
					<!-- <view class="flex" style="margin-top: 20rpx;">
						<view class="" style="width: 25%;">
							面试人：
						</view>
						<view class="" style="width: 75%;">
							{{item.userEntity?item.userEntity.userName:''}}
						</view>
					</view> -->
					<view class="flex" style="margin-top: 10rpx;">
						<view class="" style="width: 25%;">
							面试时间：
						</view>
						<view class="" style="width: 75%;">
							{{item.interviewDateTime}}
						</view>
					</view>
					<view class="flex" style="margin-top: 10rpx;" @click="goMaps(item)">
						<view class="" style="width: 25%;">
							面试地点：
						</view>
						<view class="" style="width: 75%;">
							{{item.detailedAddress}}
							<u-icon name="map-fill" color="#00B88F" size="28"></u-icon>
						</view>
					</view>
					<view class="flex" style="margin-top: 10rpx;">
						<view class="" style="width: 25%;">
							面试备注：
						</view>
						<view class="" style="width: 75%;">
							{{item.remarks}}
						</view>
					</view>

				</view>
				<view style="width: 100%;height: 1rpx;background: #EEEEEE;" v-if="item.status == 1"></view>
				<view class="flex align-center padding-tb justify-end padding-lr">
					<view class="flex align-center">
						<view class="btn" @click.stop="goInfo(item.postPushId)">岗位详情</view>
					</view>
					<view v-if="item.status == 1" class="flex align-center">
						<view class="btn" @click.stop="userUpdateInter(item.recordId,2)">拒绝</view>
					</view>
					<view v-if="item.status == 1" class="flex align-center">
						<view class="btn" @click.stop="userUpdateInter(item.recordId,1)">接受</view>
					</view>
				</view>
			</view>
		</view>
		<empty v-if="goods.length==0" />
	</view>
</template>

<script>
	import meTabs from "@/components/mescroll-uni/me-tabs/me-tabs.vue";
	import empty from '@/components/empty.vue'

	export default {
		components: {
			meTabs,
			empty
		},
		data() {
			return {
				count: 0,
				goods: [], // 数据列表
				tabs: [{
					name: '全部',
					status: 0
				}, {
					name: '待接受',
					status: 1
				}, {
					name: '已接受',
					status: 2
				}, {
					name: '已拒绝',
					status: 3
				}, {
					name: '已过期',
					status: 4
				}],
				tabIndex: 0, // tab下标
				page: 1,
				limit: 10,
			}
		},
		onLoad(option) {
			this.$queue.showLoading("加载中...");
		},
		onShow() {
			this.getlist()
		},
		methods: {
			//岗位详情
			goInfo(postPushId) {
				uni.navigateTo({
					url: '/pages/index/game/order?postPushId=' + postPushId
				})
			},
			userUpdateInter(recordId, type) {
				let content = ''
				let that = this
				if (type == 1) {
					content = '确定接受该面试邀请？'
				} else {
					content = '确定拒绝该面试邀请？'
				}
				uni.showModal({
					title: '提示',
					content: content,
					confirmColor: '#00b88f',
					complete(ret) {
						if (ret.confirm) {
							let data = {
								recordId: recordId,
								type: type
							}
							that.$Request.getT('/app/interviewRecord/userUpdateInter', data).then(res => {
								if (res.code == 0) {
									uni.showToast({
										title: type == 1 ? '已接受' : '已拒绝'
									})
									that.page == 1
									that.getlist()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						}
					}
				})
			},
			//拉起导航
			goMaps(info) {
				uni.openLocation({
					latitude: info.lat,
					longitude: info.lng,
					address: info.detailedAddress,
					name: info.detailedAddress,
					complete(ret) {

					}
				})
			},
			getlist() {
				let data = {
					status: this.tabIndex == 0 ? '' : this.tabIndex,
					page: this.page,
					limit: this.limit,
					userId: uni.getStorageSync('userId')
				}
				this.$Request.getT('/app/interviewRecord/interviewList', data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) this.goods = []; //如果是第一页需手动制空列表
						res.data.records.forEach(ret => {
							if (ret.status == 1) {
								ret.statusName = '待接受'
							} else if (ret.status == 2) {
								ret.statusName = '已接受'
							} else if (ret.status == 3) {
								ret.statusName = '已拒绝'
							} else if (ret.status == 4) {
								ret.statusName = '已过期'
							}
							this.goods.push(ret)
						})
						this.count = res.data.total
					}
					uni.hideLoading()
				})

			},
			// 切换菜单
			tabChange(e) {
				console.log(e)
				this.tabIndex = e
				this.goods = []; // 置空列表,显示加载进度条
				this.getlist()
			},
			goNav(url) {
				uni.navigateTo({
					url
				})
			}
		},
		onReachBottom: function() {
			if (this.goods.length == this.count) {
				uni.showToast({
					title: '已经到底了',
					icon: 'none'
				})
			} else {
				this.page = this.page + 1;
				this.getlist()
			}
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getlist()
		}
	}
</script>

<style lang="scss">
	/*
	sticky生效条件：
	1、父元素不能overflow:hidden或者overflow:auto属性。(mescroll-body设置:sticky="true"即可, mescroll-uni本身没有设置overflow)
	2、必须指定top、bottom、left、right4个值之一，否则只会处于相对定位
	3、父元素的高度不能低于sticky元素的高度
	4、sticky元素仅在其父元素内生效,所以父元素必须是 mescroll
	*/
	.sticky-tabs {
		z-index: 990;
		position: sticky;
		top: var(--window-top);
		// background-color: #fff;
	}

	page {
		background-color: #F7F7F7;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.box {
		background: #FFFFFF;
		border-radius: 24upx;
		margin: 30upx;
	}

	.argrtn {
		background: #F6F6F6;
		color: #666666;
		font-size: 24upx;
		border-radius: 8upx;
		padding: 5upx 20upx;
		margin-right: 20upx;
		margin-bottom: 20upx;
	}

	.btn {
		border: 1px solid #00B88F;
		border-radius: 30px;
		color: #00B88F;
		padding: 14upx 35upx;
		margin-left: 20upx;
	}
</style>