<template>
  <div id="root">
    <el-form ref="form" label-width="100px" label-position="left">
      <el-form-item label="公告标题">
        <span class="activityTile">{{ ruleForm.announcementTitle }}</span>
      </el-form-item>
      <el-form-item label="公告轮播图">
        <span style="color: #99a9bf;">轮播图为横幅位展示图片，不会显示在公告详情页</span>
        <img :src="ruleForm.announcementCarouselImg" width="100" height="100">
      </el-form-item>
      <el-form-item label="公告详细内容">
        <div class="activityContext">
          {{ ruleForm.announcementContent }}
        </div>
      </el-form-item>
      <el-form-item label="公告配图">
        <template v-for="site in ruleForm.contentImg">
          <img :src="site.url" width="100" height="100" >
        </template>
      </el-form-item>
    </el-form>
    <div class="bom-button">
      <el-button v-if="isEdi" type="primary" style="width: 150px;" @click="edi">修改</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Index',
  data() {
    return {
      asOfdate: '2018/10/10 23:59:59',
      ruleForm: {
        id: '',
        announcementTitle: '',
        announcementCarouselImg: '', // 轮播图
        announcementContent: '', // 内容详细
        contentImg: [], // 内容配图
        signUpCount: '', // 报名人数统计
        registrationEndTime: '', // 报名活动结束时间
        sort: 1, // 权重
        status: '' // 状态 0 是已作废 1 是已发布   2 是草稿 3 是已修改
      },
      isEdi: true // 默认显示修改按钮
    }
  },
  mounted() {
    this.ruleForm.id = this.$route.query.id
    this.getById()
  },
  methods: {
    getById() { // 根据ID获取活动信息
      this.$store.dispatch('AnnouncementById', this.ruleForm).then((res) => {
        const resData = res.data
        const announcement = resData.tpAnnouncement
        const imgList = resData.studentList
        this.ruleForm = announcement
        // 多张图片进行遍历
        this.ruleForm.contentImg = []
        for (let i = 0; i < imgList.length; i++) {
          this.ruleForm.contentImg.push({ url: imgList[i].imageUrl })
        }
        if (this.ruleForm.status === '0') {
          this.isEdi = false
        }
      })
    },
    formatDate(val) {
      var value = new Date(val)
      var year = value.getFullYear()
      var month = value.getMonth() + 1
      var day = value.getDate()
      // var hour = value.getHours()
      // var minutes = value.getMinutes()
      // var seconds = value.getSeconds()
      // return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
      return year + '-' + month + '-' + day
    },
    edi() { // 修改活动
      this.$router.push({ name: 'announcement-edit', query: { id: this.ruleForm.id }})
    }
  }
}
</script>

<style scoped>
#root {
  display: flex;
  flex-flow: column;
  width: 500px;
  margin-top: 50px;
  margin-left: auto;
  margin-right: auto;
}
.activityTile{
  text-align: center;
  font-size: 30px;
  margin-bottom: 10px;
}
.activityContext{
  /*margin-top: 20px;*/
  margin-bottom: 20px;
  font-size: 20px;
  justify-items: center;
}
/* .progress {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  margin-bottom: 20px;
} */
/* .text-progress {
  width: 500px;
  float: left;
  align-content: center;
  position: absolute;
  margin-top: 12px;
} */
/* .people-number {
  position: relative;
  margin-left: 180px;
} */
/* .outer-layer {
  background-color: gainsboro;
  height: 3px;
  width: 450px;
  margin-top: -10px;
  position: relative;
} */
.inner-layer {
  background-color: aquamarine;
  height: 6px;
  width: 100px;
  position: relative;
  margin-top: -4px;
}
/* .circular {
  border: 1px #001528 solid;
  border-radius: 10px;
  /*background-color: chartreuse;*/
 /* width: 20px;
  height: 20px;
  position: relative;
  margin-left: 452px;
  margin-top: 11px;
  float: left;
} */
/* .people-limit {
  margin-top: 13px;
} */
.bom-button{
  display: flex;
  justify-content: center;
  margin-top: 20px;
  margin-bottom: 100px;
}
</style>
