<template>
  <div class='mu-card notice-card' @click="handlerOutClick" :class='colorTheme' :data-udc="udc">
    <div class="main">
      <div class="aui-media-list-item-inner"  :data-udc="udc">
        <div class="aui-list-item-media">
          <mu-avatar  :isimg="avatarObj && avatarObj.isImg" :avatarcolor="avatarObj && avatarObj.color" :avatarname="avatarObj && avatarObj.aName" :avatarurl="avatarObj && avatarObj.aUrl"
            size=50  @click='handleAvatarClick($event)'></mu-avatar>
        </div>
        <div class="aui-list-item-inner" @click='handleListClick'>
          <div class="aui-list-item-text">
            <div v-if="isReply" class="aui-list-item-title-container">
              <div class="aui-list-item-title-name">{{title}}&nbsp;</div>
              <div class="aui-list-item-subtitle" v-text="subTitle"></div>
            </div>
            <div v-else class="aui-list-item-title mu__title" v-text="title"></div>
            <div class="aui-list-item-right">{{time}}</div>
          </div>
          <div>
            <div v-if="isReply" class="mu-main-notice" ref="main">
                <p v-html="shortContent" :class="[{'short':lineNum>5 && !isExpand}, {'content-has-arraw': isRightArrow}]"></p>
            </div>
            <div v-else class="mu-main-notice" ref="main">
                <p v-text="shortContent" :class="[{'short':lineNum>5 && !isExpand}, {'content-has-arraw': isRightArrow}]"></p>
                <span v-if="isRightArrow" class="message-right-arrow m-sys-forward"></span>
            </div>
          </div>

          <div class="expand-box" v-if="lineNum > 5" @click.stop.prevent="handleClick" :centerRipple="false">
              <span class="expand-text" v-if="!isExpand" v-text="showAllText"></span>
              <span class="expand-text" v-else v-text="closeShowAllText"></span>
              <span :class="['m-sys-remind_spread',{'noExpand-icon': !isExpand, 'expand-icon':isExpand}]"></span>
           </div>
           <div v-if="isReply && (feedUser || feedText || feedType ||feedContent)" class="attach-feed">
              <div class="attach-feed-title">
                  <span class="attach-feed-title-username">{{feedUser}}</span>
                  <span class="attach-feed-title-message">&nbsp;{{feedText}}</span>
              </div>
              <div class="attach-feed-content">
                <span v-if="feedType" class="attach-feed-content-type">{{feedType}}</span>
                <span class="attach-feed-content-message" v-html="feedContent"></span>
              </div>
           </div>
        </div>

      </div>
    </div>

  </div>
</template>
<script>
import avatar from '../avatar';
import abstractButton from '../internal/abstractButton';
export default {
  name: 'mu-card-notice',
  props: {
    //标题
    title: {
      type: String,
    },
    subTitle:{
      type: String,
    },
    //附件数量
    atta_count:{
      type: Number,
    },
    //时间
    time:{
      type: String,
    },
    content:{
      type: String,
    },
    colorTheme:{
      type: String,
    },
    avatarObj:{
      type: Object,
    },
    showFooter: {
      type: Boolean,
      default: false,
    },
    //谁@和回复我
    isReply:{
      type: Boolean,
    },
    feedUser: {
      type: String
    },
    feedText:{
      type: String
    },
    feedType: {
      type: String
    },
    feedContent: {
      type: String
    },
    key:{
      type:String
    },
    isRightArrow:{
      type: Boolean
    },
    showAllText: {
      type: String,
      default: '展开全部'
    },
    closeShowAllText: {
      type: String,
      default: '收起'
    }
  },
  mounted: function() {
    this.computeLineNum();
  },
  computed: {
    shortContent() {
        return this.content;
    }
  },
  methods:{
    computeLineNum(){
      var height = this.$refs.main.getBoundingClientRect().height;
      var lineHeight = parseInt(document.defaultView.getComputedStyle(this.$refs.main,null).lineHeight, 10);
      this.lineNum = height / lineHeight;
    },
    handleClick(){
        this.isExpand = !this.isExpand;

    },
    handlerOutClick (e) {
      this.$emit('handle-click', e);
    },
    handleAvatarClick(e) {
       e.stopPropagation();
       this.$emit('handle-avatar-click');
    },
    handleListClick() {
       this.$emit('handle-list-click');
    }
  },
  data(){
    return {
      isExpand: false,
      lineNum: 0,
      udc: encodeURIComponent(window.JSON.stringify({
        ext: {
          type: 'globalNotice',
          id: this.key || this.appid,
          appid: this.appid,
        }
      }))
    };
  },
  components:{
    'mu-avatar': avatar,
    'abstract-button': abstractButton,
  },
};
</script>
<style lang="less">
.short{
  display: -webkit-box; //必须结合的属性 ，将对象作为弹性伸缩盒子模型显示 。
  text-overflow: ellipsis;//可以用来多行文本的情况下，用省略号“…”隐藏超出范围的文本 。
  overflow : hidden;
  //-webkit-line-clamp: 5;
  //-webkit-box-orient: vertical;  //必须结合的属性 ，设置或检索伸缩盒对象的子元素的排列方式 。
  max-height: 100px;
  line-height: 20px;
}
//主题
.notice-card .aui-list-item-title {
    color: #6B7175;
    line-height: 16px;
    font-size: 14px;
    display: inline-block;
}
.aui-list-item-title-name{
  color: #3A4247;
  font-size: 14px;
  line-height: 16px;
}
.aui-list-item-subtitle{
  color: #9DA1A3;
  line-height: 16px;
  font-size: 14px;
}
.aui-list-item-title-container{
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  position: absolute;
}
.replay {
  .aui-list-item-title{
    color: #ffc300;
  }
  &:after{
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    bottom: 0;
    border-left: 4px solid #ffc300;
    color:#ffc300;
    transform-origin: 0 0;
    transform: scaleX(0.5);
  }
}
.atta_count_inner{
  height:30px;
  line-height:30px;
  font-family:PingFangSC-Regular;
  font-size:14px;
  color:#6b7175;
  margin-top:10px;
}
.mu-step-tag {
  background:#00e099;
  color:#fff;
  width:113px;
  text-align:center;
  position: absolute;
  right: -34px;
  top: 15px;
  padding:1px;
  transform:rotate(45deg);
}
.notice-card .mu-card-footer{
   flex-direction: row;
}
.notice-card .m-sys-remind_spread {
    top: -1px;
    color: #1695f0;
    font-size: 10px;
    position: relative;
}
.mu-card {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius:3px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  color: #212121;
  background-color: #fff;
  position: relative;
  min-height: 2.2rem;
  margin-bottom: 12px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
}
.mu-card .mu-main-notice{
  line-height:20px;
  position: relative;
}
.mu-card-footer{
  position: relative;
  padding: 0.5rem 0;
  font-size: 0.7rem;
  height:30px;
  line-height:30px;
  color: #757575;
  background-color: rgba(0, 0, 0, 0);
  -webkit-box-sizing: border-box;
  flex-direction: row-reverse;
  box-sizing: border-box;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  margin-top:12px;
  &:after {
    width: 100%;
    height: 1px;
    background-color:#e6e7e8;
    display: block;
    content: '';
    position: absolute;
    top: 0;
    right: auto;
    left: 0;
    z-index: 2;
    transform-origin: 0 0;
    pointer-events: none;
  }
}
.aui-media-list-item-inner {
  -webkit-box-sizing: border-box;
      box-sizing: border-box;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
     width:100%;
}
.aui-media-list-item-inner + .aui-info {
  margin-right: 0.75rem;
}
.aui-list-item-media-list {
  padding-right: 0;
  display: block;
}
.aui-list-item-media{
  padding-top: 10px;
  padding-left: 10px;
  width: 70px;
  height: 70px;
}
.aui-list-item-right{
      font-size: 12px;
      color: #bfc4c7;
      text-align: right;
      line-height: 14px;
      -webkit-box-self: flex-start;
      -webkit-align-self: flex-start;
      align-self: flex-start;
      -webkit-box-flex: 1.0;
      -webkit-flex-shrink: 1;
      flex-shrink: 0;
      align-content: flex-end;
      display: inline-block;
      position: absolute;
      right: 0;
      border:1px solid #fff;
}
.mu-main-notice{
  width:100%;
  font-size: 16px;
  color: #3A4247;
  line-height: 20px;
  margin-top: 24px;
  margin-bottom: 8px;
  word-wrap: break-word;
  word-break: break-all;
  text-overflow: ellipsis;
  color: #3a4247;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  display: flex;
  align-items: center;
}
.expand-box {
    text-align: right;
    margin-top: 8px;
    margin-bottom: 12px;
}
.expand-text {
    font-size: 14px;
    color: #1e80c7;
}
.expand-icon {
    -webkit-transform:rotate(180deg);
    transform:rotate(180deg);
}
.noExpand-icon {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
}
.attach-feed{
  width:100%;
  height: 54px;
  background: #F5F8FA;
  padding: 8px 12px;
  color: #3A4247;
  font-size: 14px;
  margin-bottom: 14px;
  word-wrap: break-word;
  word-break: break-all;
}
.attach-feed-title{
  line-height: 16px;
  height: 16px;
  display: flex;
}
.attach-feed-title-username{
  color: #3A4247;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.attach-feed-title-message{
  color: #9DA1A3;
  min-width: 48px;
}
.attach-feed-content{
  line-height: 16px;
  height: 16px;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.attach-feed-content-type{
  background: #94C8F7;
  color: #fff;
  font-size: 12px;
  height: 16px;
  padding: 0 2px;
}
.project-todo{
  min-width: 28px;
}
.aui-list-item-inner{
  position: relative;
  //margin-left: 8px;
  margin-right: 12px;
  width: 100%;
  box-sizing: border-box;
  padding-top: 12px;
  padding-left: 10px;
}
.message-right-arrow{
  padding: 0 8px;
  color: #bfc4c7;
  position: absolute;
  right: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center
}
.content-has-arraw{
  padding-right: 25px;
}
</style>
