<template>
  <div>
    <el-drawer
      :direction="'rtl'"
      :visible.sync="drawer"
      :wrapperClosable="false"
      size="360px"
    >
      <div slot="title" class="drawerTitle">
        <span class="titNmae">消息中心</span>
        <!-- <span class="more" >更多</span> -->
        <el-button class="more" round size="mini" @click="moreMessage()"
          >更多
        </el-button>
      </div>
      <el-scrollbar class="editScroll">
        <div class="messageBox">
          <ul>
            <li v-for="(item, index) in message" :key="index">
              <i class="el-icon-chat-dot-square"></i>
              <div @click="pushNews(item)">
                <div class="title" style="margin-bottom: 5px">
                  {{ item.subject }}
                </div>
                <div class="time">{{ item.createTime }}</div>
              </div>
            </li>
          </ul>
        </div>
      </el-scrollbar>
    </el-drawer>
    <message-info ref="messageDialog" @close="handleClose"></message-info>
  </div>
</template>

<script>
import uc from '@/api/uc.js'
import MessageInfo from '@/components/message/MessageInfo'

export default {
  name: 'ProjectMessageDrawer',
  components: {MessageInfo},
  props: {
    message: {
      type: Array,
      default: () => []
    },
    plat: {
      type: String,
      default: 'sysplat'
    }
  },
  data() {
    return {
      title: '',
      sendpeople: '',
      sendtime: '',
      content: '',
      drawer: false,
      messageList: [],
      dialogVisible: false,
      activeRow: {},
      messageItem: {}
    }
  },
  methods: {
    moreMessage() {
      this.drawer = false
      this.$router.push(`/${this.plat}/messageCenter`)
    },
    pushNews(row) {
      let _self = this
      this.activeRow = row
      this.$http
        .get('${uc}/msg/messageReceiver/v1/get?id=' + row.id)
        .then(res => {
          if (res.data) {
            this.$refs.messageDialog.open(res.data)
          }
        })
    },
    handleClose(done) {
      if (done instanceof Function) {
        done()
      } else {
        this.dialogVisible = false
      }
      this.$emit('readload')
    }
  }
}
</script>

<style lang="scss" scoped>
/* 抽屉布局
--------------------------------------------------- */
::v-deep .el-drawer__wrapper {
  transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
}

::v-deep .el-drawer {
  height: calc(100vh) !important;
  top: 0;
}

::v-deep .el-drawer__header {
  padding: 14px;
  margin: 0;
  background-color: #144871;
  color: #fff;
}

/* 抽屉标题
--------------------------------------------------- */
.drawerTitle {
  margin-top: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .titNmae {
    font-weight: bold;
    font-size: 16px;
    // color: #252b3a;

    color: #fff;
  }

  .more {
    cursor: pointer;
    margin-right: 16px;
    background-color: #409eff;
    border: none;
    color: #fff;

    &:hover {
      background-color: #fff;
      color: #409eff;
    }
  }
}

/* 消息列表
--------------------------------------------------- */
.messageBox {
  border-top: 1px solid #eee;

  ul {
    margin: 0;
    padding: 0;

    li {
      padding: 0 10px;
      color: #fff;
      text-decoration: none;
      overflow: hidden;
      line-height: 18px;
      position: relative;
      cursor: pointer;
      border-bottom: 1px dashed #eee;
      display: flex;
      align-items: center;

      > div {
        padding: 10px;
      }

      .el-icon-chat-dot-square {
        font-size: 25px;
        width: 40px;
        height: 40px;
        background: #66b1ff;
        line-height: 40px;
        text-align: center;
        border-radius: 20px;
        color: #fff;
      }
    }

    li:hover {
      background-color: #164773;
      color: #409eff;

      .title {
        color: #66b1ff;
      }

      .time {
        text-decoration: underline;
      }
    }
  }
}

/* 消息列表滚动
--------------------------------------------------- */
.editScroll {
  height: calc(100vh - 50px);
}

::v-deep .el-scrollbar__wrap {
  height: 100vh;
  overflow-x: hidden !important;
}

::v-deep .el-drawer__close-btn {
  outline: none;
}

/* 消息弹窗
--------------------------------------------------- */
.message-header {
  width: 100%;
}

.message-title {
  font-size: 16px;
  margin-bottom: 10px;
  color: #333;
}

.message-info {
  margin-bottom: 10px;
  color: #666;

  span {
    font-size: 12px;
    padding-right: 20px;
  }
}
</style>
