<template>
	<view class="main">
		<view class="detail">
			<view class="item">
				<view class="title">培训主题:</view>
				<view class="info">{{detail.name}}</view>
			</view>
			
			<view class="item">
				<view class="title">组织部门:</view>
				<view class="info">{{detail.org_name}}</view>
			</view>
			
			<view class="item">
				<view class="title">开展时间:</view>
				<view class="info">{{detail.drawup}}</view>
			</view>
			
			<view class="item">
				<view class="title">结束时间:</view>
				<view class="info">{{detail.enddrawup}}</view>
			</view>
			
			<view class="item">
				<view class="title">培训地点:</view>
				<view class="info">{{detail.location}}</view>
			</view>
			
			<view class="item">
				<view class="title">主持人:</view>
				<view class="info" v-if="detail.name">{{detail.anchor}}</view>
			</view>
		</view>
		
		<button size="default" type="primary" style="margin-top: 30rpx;background-color:#008782;" @click="signDo">立即签到</button>

	</view>
</template>

<script>
	import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
	export default {
		data() {
			return {
				id:0,
				detail:'',
				longitude:'',
				latitude:''
			}
		},
		onLoad({m_id}) {
			this.getDetail(m_id);
			this.id = m_id
		},
		computed: {
		  ...mapState(["hasLogin", "userinfo"]),
		},
		methods: {
			getDetail(id)
			{
	            getApp().globalData.request.post(
				  "learn/train/manageInfo",
				  {id:id}
				).then(res=>{
					this.detail = res.data
				})
			},
			signDo()
			{
				if(!this.hasLogin)
				{
					uni.navigateTo({
						url: '/pages/common/login/login?href2=train/sign'
					});
					return false;
				}
				uni.getLocation({
					type: 'wgs84',
					success: (res)=>{
						this.longitude = res.longitude
						this.latitude = res.latitude
					}
				});
				if(!this.longitude)
				{
					uni.showToast({
						title: '获取定位失败',
						duration: 2000
					});
					return false;
				}
				let user_id = this.userinfo.userId
				getApp().globalData.request.post(
				  "learn/train/signUp",
				  {id:this.id,user_id:user_id,longitude:this.longitude,latitude:this.latitude}
				).then(e=>{
					if(e.code == -1)
					{
						uni.showToast({
							title: e.msg,
							duration: 2000
						});
					}else{
						uni.showToast({
							title: '签到成功',
							duration: 2000
						});
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
  .main{
	  padding: 30rpx;
	  font-size: 28rpx;
	  background-color: #f4f9ff;
  }
  .detail{
	  padding: 20rpx;
	  background-color: #fff;
	  border-radius: 20rpx;
  }
  .item{
	  display: flex;
	  justify-content: space-between;
	  margin: 23rpx 0;
	  .title{
		  color:#797979;
		  width: 150rpx;
	  }
	  .info{
		  flex:1;
		  text-align: right;
		  color:#6d6d6d;
	  }
  }
</style>
