<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.type_info.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" v-if="detail.name">{{detail.anchor_info.nickname}}</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.location}}</view>
			</view>
		</view>
		
		<button size="default" type="primary" style="margin-top: 30rpx;" @click="signDo">立即签到</button>

	</view>
</template>

<script>
	import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
	export default {
		data() {
			return {
				id:0,
				detail:'',
				longitude:'',
				latitude:''
			}
		},
		onLoad({s_id}) {
			this.getDetail(s_id);
			this.id = s_id
		},
		computed: {
		  ...mapState(["hasLogin", "userinfo"]),
		},
		methods: {
			getDetail(id)
			{
	            getApp().globalData.request.post(
				  "responsibility/safeconference/show/"+id,
				  {id}
				).then(res=>{
					this.detail = res.data
				})
			},
			signDo()
			{
				if(!this.hasLogin)
				{
					uni.navigateTo({
						url: '/pages/common/login/login?href2=user/user/index'
					});
					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(
				  "responsibility/safeconference/signUp/"+this.id,
				  {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;
  }
  .detail{
	  padding: 20rpx;
	  background-color: #eee;
	  border-radius: 30rpx;
  }
  .item{
	  display: flex;
	  margin: 20rpx 0;
	  .title{
		  width: 150rpx;
	  }
	  .info{
		  flex:1;
	  }
  }
</style>
