<template>
  <el-container class="is-vertical fullheight" style="overflow-x: hidden; overflow-y: hidden">
    <div class="home-page">
      <div class="home-left">
        <div class="home-header-left cardBox">
          <div class="info-header">
            <HtAvatar class="avater" :user="currentUser" />
            <div class="header-left-flex">
              <div>
                <div class="basic-title" v-if="currentUser && currentUser.user">{{currentUser.user && currentUser.user.fullname}}，你好！欢迎登录系统</div>
                <div class="basic-rule" v-if="currentUser && currentUser.org">{{currentUser.org[0].postName}}</div>
                <div class="basic-button" v-if="currentUser && currentUser.org">
                  <img src="@/assets/img/homePage/job.png" alt="">
                  <div>{{currentUser.org[0].deptName}}</div>
                </div>
              </div>
              <div>
                <div class="time ellipcs" v-if="currentUser && currentUser.org" :title="currentUser.org[0].orgName">单位：{{currentUser.org[0].orgName}}</div>
                <div class="time ellipcs">上次登录时间：{{loginTime}}</div>
              </div>
            </div>
          </div>
          <div class="cumulative">
            <div class="cumulative-name">累计登录次数</div>
            <div class="cumulative-number">{{loginNumber}}次</div>
          </div>
        </div>
        <div class="apply-inlet cardBox">
          <div class="file-style">
            <div class="flex">
              <img
                src="@/assets/img/homePage/title3.png"
                alt=""
                class="icon-style"
              />
              <div class="home-title-style">系统资料</div>
            </div>
            <el-upload
              v-if="hasRole"
              :data="{bizCode:'FileAndVideo',bizId:'Home-Common-Documents',bizType:'HomeDocuments'}"
              name="files"
              :action="actionUrl + '/file/v1/uploadFileForConfig'"
              :on-success="handleSuccess"
              :on-error="handleError"
              :multiple="false"
              :headers="headers"
              :show-file-list="false"
              ref="upload"
            >
              <i title="上传资料" class="el-icon-upload2 upload"></i>
            </el-upload>
          </div>
          <el-carousel arrow="always" :autoplay="false" indicator-position="none">
            <el-carousel-item v-for="(itemGroup, index) in fileList" :key="index">
              <div class="apply-swipper">
                <div slot="reference" class="apply-main" @click="fileDownloadChange(item)" :title="item.fileName" v-for="item in itemGroup" :key="item.id">
                  <i class="el-icon-delete delete-style" @click.stop="deleteFileChange(item)" v-if="hasRole"></i>
                  <img :src="fileImgChange(item.extensionName)" alt="" class="apply-img" />
                  <div class="apply-title ellipcs" >{{item.fileName}}</div>
                </div>
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
        <div class="feature-inlet cardBox">
          <div class="home-contain-flex">
            <div class="flex">
              <img
                src="@/assets/img/homePage/title2.png"
                alt=""
                class="icon-style"
              />
              <div class="home-title-style">系统运维</div>
            </div>
          </div>
          <div class="feature-swipper">
            <div class="apply-main" @click="problemReporting">
              <img src="@/assets/img/homePage/gn1.png" alt="" class="apply-img" />
              <div class="apply-title">系统问题上报</div>
            </div>
            <div class="apply-main" @click="operations">
              <img src="@/assets/img/homePage/gn2.png" alt="" class="apply-img" />
              <div class="apply-title">系统运维工单</div>
            </div>
            <div class="apply-main" @click="resourceBid">
              <img src="@/assets/img/homePage/other1.png" alt="" class="apply-img" />
              <div class="apply-title">云资源申请</div>
            </div>
          </div>
        </div>
      </div>
      <div class="home-right cardBox">
        <img class="logo" src="@/assets/img/homePage/ai_logo.png" alt="" />
        <div class="ai-box cardBox" @click="talkChange">
          <div class="dialogue">开始对话</div>
          <div class="dialogue-title">建设现在 引领未来 / 品质铁建 连通世界</div>
          <div class="dialogue-title">使用全新旗舰模型</div>
        </div>
      </div>
    </div>
    <!-- 问题工单 -->
    <AddEditDialog :is-show.sync="issueDialog"/>
  </el-container>
</template>

<script>
import {getUserRegister, getFileData, fileDownload, fileDetele} from '@/api/homePage'
import HtAvatar from '@/components/common/HtAvatar.vue'
import AddEditDialog from '@/views/WorkOrder/AddEdit.vue'
import {mapState} from 'vuex'
import uc from '@/api/uc'

export default {
  name: 'HomePage',
  components: {
    HtAvatar,
    AddEditDialog
  },
  computed: {
    actionUrl: (_) => window.context.portal,
    ...mapState({
      currentUser: state => state.user.currentUserDetail,
      headers: (state) => ({
        Authorization: `Bearer ${state.login.currentUser.token}`,
      }),
    }),
  },
  data() {
    return {
      hasRole:false,
      photoUrl: window.context.front + '/img/defaultPhoto.jpg',
      loginNumber:0,
      loginTime:'',
      issueDialog:false,
      taskShow:0,
      timeShow:'day',
      currentMenu: 'homePage',
      taskData:[
        {
        name:'余郡平在2025-03-07发起养护工单',
        time:'2025-03-07 10:45:46'
      },{
        name:'石亚彬在2025-03-07发起设备维修工单',
        time:'2025-03-07 09:48:27'
      },{
        name:'符永迁在2025-03-07发起养护工单',
        time:'2025-03-07 08:57:14'
      }
      ],
      fileList:[],
    }
  },
  created() {
    this.logintimesChange()
    this.getFileData()
  },
  methods: {
    fileImgChange(type){
      switch (type) {
        case 'jpg':
        case 'png':
        case 'jpeg':
          return require('@/assets/img/homePage/file5.png');
        case 'doc':
        case 'docx':
          return require('@/assets/img/homePage/file7.png');
        case 'xls':
        case 'xlsx':
          return require('@/assets/img/homePage/file3.png');
        case 'pdf':
        case 'pptx':
          return require('@/assets/img/homePage/file6.png');
        case 'mp4':
          return require('@/assets/img/homePage/file4.png');
        default:
          return require('@/assets/img/homePage/file7.png');
      }
    },
    // 获取登录次数
    async logintimesChange(){
      let currentUser = sessionStorage.getItem('currentUser')
      let account = JSON.parse(currentUser).account
      let params = {
        "pageBean": {
          "page": 1,
          "pageSize": 50,
        },
        "sorter": [
          {
            "direction": "DESC",
            "property": "createTime"
          }
        ],
        "querys": [
          {
            "property": "account",
            "value": account,
            "group": "quick",
            "relation": "OR",
            "operation": "LIKE"
          }
        ]
      }
      const { rows } = await getUserRegister(params)
      this.loginNumber = rows[0].loginSum
      this.loginTime = rows[0].updateTime
    },
    // 获取资料列表
    async getFileData(){
      // 判断权限
      let currentUser = sessionStorage.getItem('currentUser')
      let account = JSON.parse(currentUser).account
      uc.getUserByAccount(account, resp => {
        let roleList = resp.roleList.length>0?resp.roleList:[]
        this.hasRole = roleList.some(role => role.roleCode === "sysRole")
      })
      let params = {
        "pageBean": {
          "pageSize": -1,
        },
        "params": {},
        "querys": [
          {
            "group": "main",
            "operation": "EQUAL",
            "parentGroup": "",
            "property": "biz_id_",
            "relation": "AND",
            "value": "Home-Common-Documents"
          }
        ],
      }
      const { rows } = await getFileData(params)
      this.fileList = [];
      for (let i = 0; i < rows.length; i += 6) {
        this.fileList.push(rows.slice(i, i + 6));
      }
    },
    // 文件下载
    async fileDownloadChange(item){
      await fileDownload(item.id)
      this.$message.success('下载成功')
    },
    // 文件删除
    async deleteFileChange(item){
      const {state} = await fileDetele(item.id)
      if(state){
        this.$message.success('删除成功')
        this.getFileData()
      }
    },
    // AI跳转
    talkChange(){
      const newWindow = window.open('', '_blank');
      newWindow.location.href = this.$router.resolve({path: '/aiPage'}).href;
    },
    //问题工单
    problemReporting(){
      this.issueDialog = true
    },
    // 运维工单
    operations(){
      this.$router.push({path:'/platLayout/workListPage'});
    },
    // 资源申请
    resourceBid(){
      this.$router.push({path:'/platLayout/resourceListPage'});
    },
    // 文化上传成功
    handleSuccess(response) {
      const {success} = response
      if (success) {
        this.$message.success('文件上传成功')
        this.getFileData()
      } else {
        this.$message.error('文件上传失败')
      }
      this.saveLoading = false
    },
    // 文件上传失败
    handleError() {
      this.$message.warning('文件上传失败')
    },
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-carousel__container{
  height: calc(100vh - 300px - 365px);
}
::v-deep .el-carousel__arrow{
  color: #3399FF;
  background: #ffffff;
  box-shadow: 4px 4px 10px 0 rgba(53, 152, 220, 0.1);
}
.home-page {
  width: 100%;
  height: 100%;
  display: flex;
  background: #eef8ff;
  padding: 16px 20px;
  box-sizing: border-box;
  .ellipcs{
    display: -webkit-box; /* 使用 flexbox */
    -webkit-box-orient: vertical; /* 垂直排列子元素 */
    -webkit-line-clamp: 1; /* 限制显示的行数为 2 */
    overflow: hidden; /* 隐藏超出部分 */
    text-overflow: ellipsis;
  }
  .andMore {
    cursor: pointer;
  }
  .andMore:hover .evenMore {
    color: #0963c4 !important;
  }
  .edit-style {
    width: 12px;
    height: 14px;
    margin-right: 4px;
  }
  .arrow-style {
    width: 6px;
    height: 10px;
  }
  .cursor {
    cursor: pointer;
  }
  .home-title-style {
    color: #1150a0;
    font-size: 18px;
    font-weight: 700;
  }
  .icon-style {
    width: 20px;
    height: 20px;
    margin-right: 6px;
  }
  .cardBox {
    background: #fff;
    box-shadow: 4px 4px 10px 0 rgba(53, 152, 220, 0.1);
    border-radius: 16px;
  }
  .home-left{
    width: 570px;
    height: 100%;
    margin-right: 16px;
    .home-header-left {
      padding: 30px;
      box-sizing: border-box;
      background: url("~@/assets/img/homePage/avater_bg.png") no-repeat center center;
      background-size: 110% 110%;
      margin-bottom: 16px;
      .info-header{
        width: 100%;
        display: flex;
      }
      .avater {
        width: 170px;
        height: 170px;
        margin-right: 30px;
        border-radius: 20px;
      }
      .header-left-flex {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .basic-title {
          font-size: 20px;
          color: #3399ff;
          font-weight: 700;
          margin-bottom: 10px;
        }
        .basic-rule{
          font-size: 14px;
          color: #0F2A4D;
          font-weight: 700;
          margin-bottom: 10px;
        }
        .basic-button{
          display: inline-flex;
          border-radius: 16px;
          align-items: center;
          background: #3399FF;
          padding: 5px 10px;
          img{
            width: 16px;
            height: 16px;
          }
          div{
            font-size: 14px;
            color: #D9ECFF;
          }
        }
        .time {
          font-size: 14px;
          color: #A1A9B2;
          margin-top: 10px;
        }
      }
      .cumulative{
        display: flex;
        background: rgba(51,153,255,0.1);
        border-radius: 60px;
        padding: 10px 0;
        align-items: center;
        justify-content: center;
        margin: 30px 0 0 0;
        .cumulative-name{
          color: #3399FF;
          font-size: 15px;
          margin-right: 10px;
        }
        .cumulative-number{
          color: #3399FF;
          font-size: 18px;
          font-weight: 700;
        }
      }
    }
    .apply-inlet{
      width: 100%;
      padding: 16px;
      box-sizing: border-box;
      margin-bottom: 16px;
      .file-style{
        display: flex;
        align-items: center;
        justify-content: space-between;
        .upload{
          color: #1150a0;
          font-size: 20px !important;
          cursor: pointer;
        }
      }
    }
    .feature-inlet{
      width: 100%;
      padding: 16px;
      box-sizing: border-box;
    }
    .apply-swipper{
      width: 100%;
      height: 100%;
      display: flex;
      flex-wrap: wrap;
      .apply-main{
        width: 33%;
        height: 50%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        position: relative;
        .apply-img{
          width: 35px;
          height: 35px;
          margin-bottom: 10px;
        }
        .apply-title{
          color: #0F2E4D;
          font-size: 16px;
        }
        .delete-style{
          color: #F56C6C;
          position: absolute;
          top: 20px;
          right: 40px;
          display: none;
        }
      }
      .apply-main:hover .apply-title{
        color: #3399FF;
      }
      .apply-main:hover .delete-style{
        display: block;
      }
    }
    .feature-swipper{
        width: 100%;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        .apply-main{
          display: flex;
          flex-direction: column;
          align-items: center;
          cursor: pointer;
          margin: 10px 10px 20px 10px;
          .apply-img{
            width: 60px;
            height: 60px;
            margin-bottom: 6px;
          }
          .apply-title{
            color: #0F2E4D;
            font-size: 16px;
          }
        }
      }
  }
  .home-right{
    height: 100%;
    flex: 1;
    padding: 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-image: url('~@/assets/img/homePage/ai_bg.png');
    background-size: 120% 130%;
    background-repeat: no-repeat;
    background-position: 20% 90%;
    .logo-title{
      margin-top: 80px;
      font-size: 22px;
      color: #94A3B8;
      //font-weight: bold;
      letter-spacing: 10px;
    }
    .logo{
      width: 400px;
      margin-top: 140px;
      margin-bottom: 50px;
    }
    .ai-font{
      color: #1150a0;
      font-size: 40px;
      font-weight: bold;
    }
    .ai-box{
      width: 600px;
      margin-top: 120px;
      padding: 16px;
      text-align: center;
      cursor: pointer;
      box-sizing: border-box;
      box-shadow: 0 2px 10px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
      border: 1px solid #ffffff;
      background: transparent;
      .dialogue{
        color: #5AACFF;
        font-size: 30px;
        font-weight: bold;
      }
      .dialogue-title{
        font-size: 20px;
        color: #6D7C91;
        margin: 20px 0;
      }
    }
    .ai-box:hover{
      //border: 1px solid #5AACFF;
      box-sizing: border-box;
      box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 12px rgba(0, 0, 0, .04);
    }
  }
  .home-header {
    width: 100%;
    height: 450px;
    display: flex;
    .home-header-center{
      flex: 1;
      height: 100%;
      margin-right: 16px;
      padding: 16px;
      box-sizing: border-box;
      .task-header{
        display: flex;
        justify-content: space-between;
      }
      .task-manger {
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        margin: 32px 0 8px 0;
        .task-container {
          width: 220px;
          height: 110px;
          border-radius: 20px;
          .task-img {
            width: 70px;
            height: 70px;
            margin: 20px 10px 20px 20px;
          }
          .task-title {
            font-size: 16px;
            color: #0f2a4d;
            font-weight: 700;
            margin-bottom: 10px;
          }
          .task-value {
            font-size: 30px;
            color: #3399ff;
            font-weight: 700;
            font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
          }
          .overtime {
            color: #ff4b87;
          }
        }
        .task-active{
          box-shadow: 0 3px 15px 0 rgba(0, 60, 180, 0.15);
        }
      }
      .task-list{
        display: flex;
        justify-content: space-between;
        margin: 0 30px;
        border-bottom: 1px solid;
        border-image: linear-gradient(270deg, #ffffff, #d0dded) 1;
        padding: 20px 0;
        .task-icon{
          width: 18px;
          height: 18px;
          margin-right: 8px;
        }
        .task-name{
          font-size: 16px;
          color: #0F2E4D;
        }
        .task-time{
          font-size: 14px;
          color: #A1A9B2;
        }
      }
      .task-list:last-child{
        border: none;
      }
    }
    .home-header-right {
      width: 160px;
      height: 100%;
      padding: 16px;
      box-sizing: border-box;
      .otherTools{
        padding-bottom: 16px;
        border-bottom: 1px solid;
        border-image: linear-gradient(270deg, #ffffff, #D1DDED) 1;
      }
      .otherBody{
        width: 120px;
        height: 115px;
        border-radius: 8px;
        border: 1px solid #EEF8FF;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-top: 8px;
      }
      .other-img{
        width: 54px;
        height: 54px;
      }
      .other-text{
        font-size: 16px;
        color: #0F2A4D;
      }
    }
  }
  .home-contain {
    display: flex;
    width: 100%;
    height: calc(100vh - 558px);
    margin-bottom: 16px;
    box-sizing: border-box;

    .contain-center{
      flex: 1;
      height: 100%;
      margin: 16px 16px 0 0;
      padding: 16px;
      box-sizing: border-box;
      .notice-contain {
        height: calc(100% - 40px);
      }
      .notice-body {
        height: 17%;
        display: flex;
        line-height: 26px;
        padding: 14px 0;
        align-items: center;
        border-bottom: 1px solid;
        border-image: linear-gradient(270deg, #ffffff, #d0dded) 1;
        .notice-time {
          display: flex;
          flex-direction: column;
          width: 68px;
          margin-right: 16px;
        }
        .notice-flex {
          flex: 1;
          display: flex;
          flex-direction: column;
        }
        .notice-month {
          color: #999999;
          font-size: 20px;
          font-weight: 700;
          margin-top: 2px;
          font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
        }
        .notice-year {
          color: #999999;
          font-size: 14px;
          font-weight: 700;
        }
        .notice-title {
          color: #0f2a4d;
          font-size: 16px;
          display: -webkit-box; /* 使用 flexbox */
          -webkit-box-orient: vertical; /* 垂直排列子元素 */
          -webkit-line-clamp: 1; /* 限制显示的行数为 2 */
          overflow: hidden; /* 隐藏超出部分 */
          text-overflow: ellipsis;
        }
        .notice-content {
          color: #a1a9b2;
          font-size: 16px;
          display: -webkit-box; /* 使用 flexbox */
          -webkit-box-orient: vertical; /* 垂直排列子元素 */
          -webkit-line-clamp: 1; /* 限制显示的行数为 2 */
          overflow: hidden; /* 隐藏超出部分 */
          text-overflow: ellipsis;
        }
      }
      .notice-body:last-child {
        border: none;
      }
      .notice-body:hover {
        border-radius: 10px;
      }
      .notice-body:hover .notice-title {
        color: #0963c4;
      }
      .notice-body:hover .notice-month {
        color: #0963c4;
      }
      .notice-body:hover .notice-year {
        color: #0963c4;
      }
      .home-footer-header {
        display: flex;
        justify-content: space-between;
        padding-bottom: 16px;
        border-bottom: 1px solid #cfdcec;
        .evenMore {
          color: #999999;
          font-size: 14px;
          margin-right: 2px;
        }
      }
    }
    .contain-right{
      width: 340px;
      height: 100%;
      margin: 16px 0 0 0;
      padding: 16px;
      box-sizing: border-box;
      .fileBody{
        padding-bottom: 16px;
        border-bottom: 1px solid #CFDCEC;
      }
      .file-contain{
        width: 100%;
        padding: 16px 0;
        border-bottom: 1px solid;
        border-image: linear-gradient(270deg, #ffffff, #D1DDED) 1;
        img{
          width:18px;
          height:18px;
          margin-right: 6px;
        }
        div{
          color: #0F2E4D;
          font-size: 16px;
          display: -webkit-box; /* 使用 flexbox */
          -webkit-box-orient: vertical; /* 垂直排列子元素 */
          -webkit-line-clamp: 1; /* 限制显示的行数为 2 */
          overflow: hidden; /* 隐藏超出部分 */
          text-overflow: ellipsis;
        }
        .file-contain:last-child{
          border: none;
        }
      }
    }
    .home-contain-flex {
      display: flex;
      justify-content: space-between;
      padding-bottom: 16px;
      border-bottom: 1px solid;
      border-image: linear-gradient(270deg, #ffffff, #d0dded) 1;
      .pspadEditor {
        font-size: 14px;
        color: #0f2a4d;
      }
    }
    .shortcutFunction {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 35px 40px;
      .system-img {
        width: 64px;
        height: 64px;
      }
      .system-text {
        font-size: 16px;
        color: #0f2a4d;
      }
    }
  }
  .home-footer {
    width: 100%;
    height: calc(100vh - 250px - 220px - 64px - 60px);

    .home-footer-left {
      width: 928px;
      height: 100%;
      margin-right: 16px;
      padding: 16px;
      box-sizing: border-box;
      .news-body {
        height: calc(100% - 32px);
        display: flex;
        padding: 16px 0;
        box-sizing: border-box;
        .news-left {
          width: 300px;
          display: flex;
          flex-direction: column;
          align-items: center;
          img {
            width: 300px;
            height: 180px;
            border-radius: 8px;
          }
          .news-title {
            font-size: 20px;
            color: #0963c4;
            font-weight: 700;
            margin: 12px 0;
          }
          .new-content {
            width: 100%;
            font-size: 15px;
            color: #999999;
            line-height: 22px;
            display: -webkit-box; /* 使用 flexbox */
            -webkit-box-orient: vertical; /* 垂直排列子元素 */
            -webkit-line-clamp: 2; /* 限制显示的行数为 2 */
            overflow: hidden; /* 隐藏超出部分 */
            text-overflow: ellipsis;
          }
        }
        .new-right {
          flex: 1;
          margin-left: 16px;
          .company-news {
            width: 100%;
            box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            padding: 10px;
            box-sizing: border-box;
            height: 50%;
            .company-title {
              font-size: 20px;
              color: #333333;
              font-weight: 700;
              display: -webkit-box; /* 使用 flexbox */
              -webkit-box-orient: vertical; /* 垂直排列子元素 */
              -webkit-line-clamp: 1; /* 限制显示的行数为 2 */
              overflow: hidden; /* 隐藏超出部分 */
              text-overflow: ellipsis;
            }
            .company-content {
              font-size: 15px;
              color: #999999;
              line-height: 22px;
              display: -webkit-box; /* 使用 flexbox */
              -webkit-box-orient: vertical; /* 垂直排列子元素 */
              -webkit-line-clamp: 2; /* 限制显示的行数为 2 */
              overflow: hidden; /* 隐藏超出部分 */
              text-overflow: ellipsis;
              margin: 8px 0;
            }
            .company-flex {
              display: flex;
              align-items: center;
              justify-content: space-between;
              .company-time {
                font-size: 15px;
                color: #999999;
              }
              .company-arrow {
                width: 18px;
                height: 12px;
              }
            }
          }
          .company-news:nth-of-type(2) {
            margin-top: 10px;
          }
          .company-news:hover .company-title {
            color: #0963c4;
          }
          .company-news:hover {
            box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
          }
        }
      }
    }

  }
}
</style>
