<template>
  <div class="container">
    <van-nav-bar
      title="会议详情"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="main">
      <div class="title">{{ data.theme || '-' }}</div>
      <div class="time">
        {{ data.startTime && data.startTime.substring(0, 2) }}月
        {{ data.startTime && data.startTime.substring(3, 5) }}日
        {{ data.startTime && data.startTime.substr(6) }}(GMT+8)
      </div>
      <div class="person">发起人: {{ data.createName || '-' }}</div>
      <div class="person">参会人: {{ getUserName(data.users) || '-' }}</div>
      <div class="date">
        <div class="item">
          <van-icon name="clock-o" size="18" />
          <span class="margin">
            {{ data.startTime && data.startTime.substring(0, 2) }}
            /
            {{ data.startTime && data.startTime.substring(3, 5) }}
            {{ data.startTime && data.startTime.substr(6) }}
          </span>
          <span>开始时间</span>
        </div>
        <div class="line"></div>
        <div class="item">
          <van-icon name="clock-o" size="18" />
          <span class="margin">
            {{ data.endTime && data.endTime.substring(0, 2) }}
            /
            {{ data.endTime && data.endTime.substring(3, 5) }}
            {{ data.endTime && data.endTime.substr(6) }}
          </span>
          <span>结束时间</span>
        </div>
      </div>
      <div class="status">
        <span v-if="data.meetingStatus == 1">会议待开始</span>
        <span v-if="data.meetingStatus == 2">会议进行中</span>
        <span v-if="data.meetingStatus == 3">会议已结束</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'detail',
  components: {},
  data() {
    return {
      metData: {},
      data: {},
    }
  },
  computed: {
    isCurrentDay() {
      let today = new Date().setHours(0, 0, 0, 0)
      let metDate = new Date(this.metData.date).setHours(0, 0, 0, 0)
      return today == metDate ? true : false
    },
    week() {
      let year = new Date().getFullYear()
      let weekArr = new Array('日', '一', '二', '三', '四', '五', '六')
      let metDate = new Date(year + '-' + this.metData.startTime).getDay()
      console.log(weekArr, metDate)
      return weekArr[metDate]
    },
    participants() {
      let status = this.metData.meetingStatus
      let participants = this.metData.users
      if (status == 1 || status == 2) {
        return '共' + participants.length + '人'
      } else {
        return participants.length + '人已参会'
      }
    },
    fontColor() {
      return this.metData.meetingStatus == 1
        ? '#f7912f'
        : this.metData.meetingStatus == 2
        ? '#24b84a'
        : '#707070'
    },
  },
  filters: {},
  watch: {},
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      if (to.name == 'unfinished' || to.name == 'history') {
        localStorage.removeItem('metData')
      }
    })
  },
  created() {
    let meetingId = this.$route.query.id

    this.loadDataById(meetingId)
  },
  methods: {
    toPartciDetail() {
      this.$router.push({
        name: 'particiDetail',
        params: {
          partici: JSON.stringify(this.metData.users),
        },
      })
    },
    loadDataById(id) {
      let url = `${window.context.xqhk}/meeting/v1/get/${id}`
      this.$http.get(url).then((res) => {
        this.data = (res && res.data && res.data.value) || {}
      })
    },
    getUserName(arr) {
      if (typeof arr) {
        let arr_ = []
        arr &&
          arr.forEach((item) => {
            arr_.push(item.userName)
          })
        return arr_.join(',')
      }
    },
    onClickLeft() {
      this.$router.go(-1)
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  margin-top: 50px;
  background-color: #f7f8fa;
}
.content-header {
  display: flex;
  justify-content: space-between;
}
.content-bottom {
  display: flex;
  justify-content: space-between;
}

.status {
  font-size: 4vw !important;
  // width: 100%;
  display: flex;
  align-items: center;
}

.theme {
  height: 15vw;
  width: 200px;
  font-size: 8vw;
  line-height: 15vw;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.status img {
  width: 8vw;
  height: 7vw;
}

.status div {
  text-align: center;
}

.time {
  display: flex;
  align-items: center;
  justify-content: space-between;
  * {
    font-size: 18px;
  }
}

.date {
  margin-bottom: 10px;
  margin-right: 5px;
}

.launch {
  display: flex;
}

.participants {
  display: flex;
  align-items: center;
}

.main {
  padding-top: 50px;
  background-color: #f7f8fa;
  .title {
    font-size: 1.8em;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif;
    padding: 0 1em;
  }
  .time,
  .person {
    font-size: 1.2em;
    margin-top: 1.5em;
    padding: 0 1.5em;
  }
  .person {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
  }
  .date {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background-color: #fff;
    padding: 1.2em 0;
    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      .margin {
        margin: 0.5em 0;
        font-size: 1.2em;
        font-weight: bold;
      }
      span {
        font-size: 1em;
      }
    }
    .line {
      width: 1px;
      height: 3em;
      border-left: 1px solid #b2b5be;
    }
  }
  .status {
    width: 100%;
    position: fixed;
    bottom: 0;
    height: 2em;
    display: block;
    text-align: center;
    background-color: #f7f8fa;
    padding-bottom: 1.2em;
    padding-top: 0.5em;
    span {
      font-size: 1em;
      color: #b2b5be;
    }
  }
}
</style>
