<template>
  <div class="home-container">


    <!--  快捷菜单  -->
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card>
          <p class="card-title">快捷菜单</p>
          <panel-group />
        </el-card>
      </el-col>


      <!--  待办事项  -->
      <el-col :xs="24" :sm="12" :md="13"  :lg="10">
        <el-card class="card-group">
          <p class="card-title">待办事项</p>
          <el-row :gutter="20">
            <el-col :xs="24" :sm="24" :md="12"  :lg="12" v-for="(v,i) in dataList" :key="i">
              <div class="card-panel">
                <div class="card-panel-icon-wrapper icon-people">
                  <svg-icon icon-class="example" class-name="card-panel-icon" />
                  <div class="card-icon-text">
                    {{v.taskTypeText}}
                  </div>
                </div>
                <div class="card-panel-description">
                  <div class="card-panel-text">
                    {{v.statusText}}
                  </div>
                  <count-to :start-val="0" :end-val="v.nums" :duration="3000" class="card-panel-num" />
                </div>
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>



      <!--  其他  -->
      <el-col :xs="24" :sm="12" :md="11"  :lg="14">
        <el-card class="chart-wrapper">
          <el-tabs type="border-card">
            <el-tab-pane label="通知公告">
              <div class="tab-panel">
                <div class="msg-item" v-for="(v,i) in msgsList" :key="v.id" @click="showMsg(v)">
                    <span>{{v.title}}</span>
                    <span>{{v.publishTime}}</span>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="知识库">
              <div class="tab-panel">
                <div class="file-item" v-for="(v,i) in fileList" :key="i">
                  <a :href="imageUrl(v.url)" target="_blank">
                    <i>{{v.name}}</i>
                    <span>{{v.createTime}}</span>
                  </a>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>

    <!--  新闻详情  -->
    <DialogCom
      title="详情"
      :visible.sync="show"
      width="800px"
      append-to-body
      @close="handleClose">
      <div class="panel-box" v-if="selectMsg">
        <h2>{{selectMsg.title}}</h2>
        <p>{{selectMsg.publishTime}}</p>
        <div class="content-box">
          <p>{{selectMsg.content}}</p>
          <ul v-if="selectMsg.fileList && selectMsg.fileList.length > 0">
            <li v-for="(v,i) in selectMsg.fileList" :key="v.url">
              <a :href="imageUrl(v.url)" target="_blank">
<!--                <i class="el-icon-document"></i>-->
                {{v.name}}
              </a>
            </li>
          </ul>
        </div>
      </div>
    </DialogCom>
  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import CountTo from 'vue-count-to'
import {homeData,fileList} from '@/api/login'
import {imageUrl} from "@/utils/ruoyi";
import dayjs from 'dayjs'
export default {
  name: 'Index',
  components: {
    PanelGroup,
    CountTo
  },
  data() {
    return {
      iconList:[],
      dataList:[],
      fileList:[],
      msgsList:[],
      show:false,
      selectMsg:null,
    }
  },
  mounted(){
    this.getData();
  },
  methods: {
    imageUrl,
    showMsg(v){
      this.show = true;
      this.selectMsg = v;
    },
    handleClose() {
      this.show = false;
      this.selectMsg = null;
    },
    getData(){
      homeData().then(res=>{
        this.dataList = res.data;
      });
      fileList().then(res=>{
        let {index1,index2} = res.data;
        if(index1){
          this.msgsList = index1;
        }
        if(!index2)return;
        this.fileList = index2.map(v=>{
          return JSON.parse(v)
        });
        this.fileList.forEach(v=>{
          v.createTime = dayjs(v.createTime).format('YYYY-DD-MM')
        })
      })
    }
  }
}
</script>
<style lang="scss">
.home-container{
  .el-card__body{
    padding: 10px 20px 20px 20px;
  }
  .card-group{
    .el-card__body {
      padding-bottom: 10px;
    }
  }
  .el-tabs{
    border-radius: 4px;
    box-shadow: none;
  }
  .chart-wrapper{
    .el-card__body{
      padding: 0;
    }
  }
}
</style>
<style lang="scss" scoped>
.home-container {
  padding: 20px;
  background-color: rgb(240, 242, 245);
  .chart-wrapper {
    background: #fff;
    margin-top: 20px;
  }
}
.card-title{
  width: 120px;
  margin: 0 0 10px 0;
  padding-left: 4px;
  color:#fff;
  font-weight: bold;
  letter-spacing: 2px;
  background: linear-gradient(to right, #71bfe3, #fff);
}
.card-group{
  .card-title{
    margin: 0;
  }
}
.tab-panel{
  height: 455px;
  overflow: auto;
}
.msg-item{
  font-size: 15px;
  padding: 0 10px;
  color:#1ea8e9;
  line-height: 39px;
  display: flex;
  justify-content: space-between;
  cursor:pointer;
  &:hover{
    text-decoration: underline;
  }
  >span{
    display: inline-block;
    overflow: hidden;
    white-space:nowrap;
    text-overflow: ellipsis;
    text-align: start;
  }
}
.file-item{
  font-size: 15px;
  padding: 0 10px;
  color:#1ea8e9;
  text-decoration:underline;
  line-height: 39px;
  >a{
    display: flex;
    justify-content: space-between;
    >i{
      width: 70%;
      overflow: hidden;
      white-space:nowrap;
      text-overflow: ellipsis;
      text-align: start;
    }
  }
  &:hover{
    background-color: #1ea8e9;
    color:#fff;
    transition: all .38s ease-out;
  }
}
.card-group {
  margin-top: 20px;
  .card-panel {
    display: flex;
    flex:1;
    justify-content: space-between;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    margin: 10px 0;

    .icon-people {
      color: #40c9c6;
    }

    .card-panel-icon-wrapper {
      height: 120px;
      margin: 10px;
      padding: 10px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }

    .card-panel-icon {
      float: left;
      font-size: 44px;
    }
    .card-icon-text{
      padding-top: 8px;
      text-align: center;
      line-height: 20px;
      color: rgba(0, 0, 0, 0.65);
      font-size: 16px;
    }
    .card-panel-description {
      display: flex;
      flex-direction: column;
      justify-content: center;
      font-weight: bold;
      margin: 10px;
      .card-panel-text {
        text-align: center;
        line-height: 18px;
        color: rgba(0, 0, 0, 0.65);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
.panel-box{
  >h2{
    text-align: center;
  }
  >p{
    font-size: 14px;
    color: #999;
    text-align: end;
  }
  .content-box{
    max-height: 600px;
    overflow: auto;
    >p{
      text-indent: 2em;
      word-break: break-word;
      white-space: pre-wrap;
      text-align: justify;
      width: 100%;
      color: #777;
    }
    >ul{
      font-size: 15px;
      color:#1ea8e9;
      >li{
        margin-bottom: 6px;
      }
      >li:hover{
        text-decoration:underline;
      }
    }
  }
}
@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
