<template>
  <div class="detail">
    <template v-if="detailObj">
      <div class="card">
        <header>{{detailObj.title}}</header>
        <u-gap height="16"></u-gap>
        <u-row>
          <span>发布人：</span>
          <span>{{detailObj.releaseUserName}}</span>
        </u-row>
        <u-gap height="8"></u-gap>
        <u-row>
          <span>发布部门：</span>
          <span>{{detailObj.unitName}}</span>
        </u-row>
        <u-gap height="8"></u-gap>
        <u-row>
          <span>发布日期：</span>
          <span>{{detailObj.releaseTime}}</span>
        </u-row>
        <u-gap height="8"></u-gap>
      </div>

      <div class="card">
        <div class="label">公告内容</div>
        <u-parse :html="detailObj.content"></u-parse>
      </div>

      <div class="card" style="padding-top: 0" v-if="detailObj.files && detailObj.files.length">
        <div class="label">相关附件</div>
        <div class="file" v-for="(item,index) in detailObj.files" :key="index" @click="preFile(item)">
          <u-row justify="between">
            <label class="left">
              <img :src="$cdn + 'common/appendix.png'" alt="">
              <span>{{item.name}}.{{item.postfix}}</span>
            </label>
            <span>{{(item.size/1024).toFixed(2)}}KB</span>
          </u-row>
        </div>
      </div>

      <div class="card" @click="handleClick">
        <u-row justify="between" class="item">
          <span>接收对象</span>
          <div class="right">
            <em>{{detailObj.readNum}}人</em>已读
            <em>{{detailObj.unReadNum}}人</em>未读
            <div class="arrow"></div>
          </div>
        </u-row>
      </div>
    </template>
    <AiEmpty description="该通知已撤回" v-else/>
    <AiBack />
  </div>
</template>

<script>
  import AiBack from "../../../components/AiBack";
  import {mapActions} from "vuex";
  import AiEmpty from "../../../components/AiEmpty/AiEmpty";

  export default {
    name: "detail",
    components:{AiBack,AiEmpty},
    props:{
      params:Object
    },
    data() {
      return {
        detailObj: {},
      }
    },
    created() {
      this.getDetail();
    },
    methods: {
      ...mapActions(['previewFile', 'injectJWeixin']),
      preFile(e) {
        if([".jpg",".png",".gif"].includes(e.postfix.toLowerCase())){
          uni.previewImage({
            current: e.url,
            urls: [e.url]
          })
        }else {
          this.previewFile({...e})
        }
      },
      getDetail() {
        this.$http.post("/app/appannouncement/detail", null, {
          params: {
            id: this.params?.id,
            detail: this.params?.flag
          }
        }).then(res=>{
          if(res && res.data){
            this.detailObj = res.data;
          }
        })
      },
      handleClick() {
        this.$parent.params = this.params.id;
        this.$parent.comp = "read";
        this.$parent.showList = false;
      }
    },
  }
</script>

<style lang="scss" scoped>
  .detail {
    min-height: 100%;
    background-color: #F5F5F5;
    padding-bottom: 140px;

    ::v-deep .content {
      padding: 0;
    }

    .card {
      background-color: #FFFFFF;
      margin-bottom: 8px;
      box-sizing: border-box;
      padding: 16px 32px;

      header {
        font-size: 40px;
        font-weight: 600;
        color: #333333;
        line-height: 64px;
        letter-spacing: 1px;
      }

      .u-row {
        & > div {
          border-radius: 50%;
          text-align: center;
          font-size: 22px;
          font-weight: bold;
          color: #FFFFFF;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        & > span:first-child {
          font-size: 30px;
          color: #999999;;
          line-height: 48px;
        }

        & > span:last-child {
          font-size: 30px;
          color: #343D65;
          margin-left: 16px;
          line-height: 48px;
        }

        .title {
          width: 490px;
          height: 112px;
          display: flex;
          align-items: center;
          font-size: 32px;
          color: #333333;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .right {
          font-size: 28px;
          display: flex;
          align-items: center;
          color: #666666;

          .arrow {
            width: 16px;
            height: 16px;
            border-top: 3px solid #CCCCCC;
            border-right: 3px solid #CCCCCC;
            transform: rotate(45deg);
          }
        }
      }

      .item {
        position: relative;
        height: 80px;

        &:after {
          width: 100%;
          height: 1px;
          background-color: rgba(216, 221, 230, 0.5);
          content: "";
          position: absolute;
          left: 0;
          bottom: 0;
        }
      }

      & > span {
        font-size: 32px;
        color: #333333;
        line-height: 48px;
        letter-spacing: 1px;
        display: inline-block;
      }

      .label {
        height: 80px;
        font-size: 32px;
        color: #333333;
        display: flex;
        align-items: center;
        margin-bottom: 16px;

        & > em {
          font-style: normal;
          font-size: 32px;
          color: #1365DD;
        }
      }

      .file {
        height: 128px;
        background: #FFFFFF;
        border-radius: 8px;
        border: 1px solid #CCCCCC;
        box-sizing: border-box;
        padding: 0 16px;
        margin-bottom: 32px;

        & > .u-row {
          height: 100%;

          .left {
            width: 476px;
            display: flex;
            align-items: center;

            & > img {
              flex-shrink: 0;
              width: 96px;
              height: 96px;
            }

            & > span {
              font-size: 32px;
              color: #333333;
              display: inline-block;
              line-height: 44px;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
            }
          }

          & > span {
            font-size: 28px;
            color: #999999;
          }
        }
      }

      .active {
        background-color: #F3F6F9;
      }

      & > text {
        width: 100%;
        display: inline-block;
        font-size: 30px;
        color: #649EFD;
        text-align: center;
      }

      .progress {
        height: 12px;
        background: #F2F4FC;
        border-radius: 12px;
        position: relative;
        margin: 16px 0 64px 0;

        .pro-active {
          height: 12px;
          background: #639EFD;
          border-radius: 12px;
          position: absolute;
          left: 0;
          top: 0;
        }

      }

      em {
        font-style: normal;
        font-size: 28px;
        color: #1365DD;
      }

      ::v-deep .u-collapse {
        position: relative;

        &:after {
          content: "";
          width: 718px;
          height: 1px;
          background-color: rgba(216, 221, 230, 0.5);
          position: absolute;
          left: 0;
          bottom: 0;
        }

        .u-collapse-head {
          padding: 40px 0;
        }

        .u-collapse-content {
          font-size: 32px;
          color: #333333;
          line-height: 48px;
          letter-spacing: 1px;
        }
      }
    }

    .footer {
      height: 112px;
      width: 100%;
      position: fixed;
      left: 0;
      bottom: 0;
      background: #1365DD;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 36px;
      color: #FFFFFF;
    }
  }
</style>
