<template>
  <a-layout id="components-layout-demo-top" :class="[$style.layout, $style.audithome]">
    <sd-header>
      <span style="font-size:22px;padding:0 11px;vertical-align:top">
        <a-icon type="sd-module" title="工作台" @click="$router.push('/sd-frame/iam-content')" />
      </span>
      <sd-header-user-action />
    </sd-header>
    <!-- 首页图片 -->
    <table :class="$style.bannertable" border="0" align="center" cellpadding="0" cellspacing="0">
      <img v-if="currentIndex === 0" :class="$style.previewimg" src="./images/banner.png" />
      <img v-if="currentIndex === 1" :class="$style.previewimg" src="./images/banner1.png" />
      <img v-if="currentIndex === 2" :class="$style.previewimg" src="./images/banner2.png" />
    </table>
    <a-layout-content :class="$style.layoutContent">
      <div :class="$style.mainWrap">
        <a-row :gutter="24" :class="$style.maint">
          <a-col v-for="(mk, index) in mklist" :key="index" :span="6">
            <div
              :class="$style.tab"
              :style="'background-color:' + mk.color"
              @click="$router.push(mk.link)"
            >
              <span style="float:left;">
                <span><a-icon slot="image" :type="mk.icon" /> </span>
                <span style="padding-left:10px">{{ mk.name }}</span>
              </span>
              <span v-if="mk.num !== '-1'" style="float:right;font-size:30px;margin-top:-10px">{{
                mk.num
              }}</span></div
            >
          </a-col>
        </a-row>
        <a-row :gutter="24" :class="$style.maint">
          <a-col :span="11">
            <div :class="$style.box">
              <a-card :bordered="false" :class="$style.cardBody">
                <div slot="title">
                  <a-icon
                    type="bell"
                    title="通知公告"
                    @click="$router.push('/sd-frame/audit-information-list')"
                  />
                  通知公告
                </div>
                <div slot="extra">
                  <a-icon
                    slot="tabBarExtraContent"
                    :class="$style.morebtn"
                    type="ellipsis"
                    @click="goMoreNews('audit-information-list')"
                  />
                </div>
                <HomeTzggList
                  :news-id="'tzgg'"
                  type="getInformation"
                  :max-results="4"
                ></HomeTzggList>
              </a-card>
            </div>
          </a-col>
          <a-col :span="2"></a-col>
          <a-col :span="11">
            <div :class="$style.box">
              <a-card :bordered="false" :class="$style.cardBody">
                <div slot="title">
                  <a-icon
                    type="project"
                    title="新闻动态"
                    @click="$router.push('/sd-frame/audit-information-list')"
                  />
                  <!-- <project-outlined /> -->
                  新闻动态
                </div>
                <div slot="extra">
                  <a-icon
                    slot="tabBarExtraContent"
                    :class="$style.morebtn"
                    type="ellipsis"
                    @click="goMoreNews('audit-information-list')"
                  />
                </div>
                <HomeXwdtList
                  :news-id="'xwdt'"
                  type="getInformation"
                  :xwdt="true"
                  :max-results="3"
                ></HomeXwdtList>
              </a-card>
            </div>
          </a-col>
        </a-row>
        <a-row :gutter="24" :class="$style.maint">
          <a-col :span="11">
            <div :class="$style.box">
              <a-card :bordered="false" :class="$style.cardBody">
                <div slot="title"
                  ><a-icon
                    type="read"
                    title="法规政策"
                    @click="
                      $router.push('/sd-frame/iam-audit-auditsource-lawinstitutionquery-list')
                    "
                  />
                  法规政策
                </div>
                <div slot="extra">
                  <a-icon
                    slot="tabBarExtraContent"
                    :class="$style.morebtn"
                    type="ellipsis"
                    @click="goMoreNews('iam-audit-auditsource-lawinstitutionquery-list')"
                  />
                </div>
                <HomeXwdtList
                  :news-id="'law'"
                  :xwdt="false"
                  type="getLawInstitutions"
                ></HomeXwdtList>
              </a-card>
            </div>
          </a-col>
          <a-col :span="2"></a-col>
          <a-col :span="11">
            <div :class="$style.box">
              <a-card :bordered="false" :class="$style.cardBody">
                <div slot="title">
                  <a-icon
                    type="bulb"
                    title="知识库"
                    @click="$router.push('/sd-frame/km-knowledage-base')"
                  />
                  知识库
                </div>
                <div slot="extra">
                  <a-icon
                    slot="tabBarExtraContent"
                    :class="$style.morebtn"
                    type="ellipsis"
                    @click="goMoreNews('km-knowledage-base')"
                  />
                </div>
                <HomeXwdtList :news-id="'km'" type="getKmKnowledges" :xwdt="false"></HomeXwdtList>
              </a-card>
            </div>
          </a-col>
        </a-row>
        <a-row :gutter="24" :class="$style.maint">
          <a-col :span="24">
            <div :class="[$style.yqlj, $style.box]">
              <a-card :bordered="false" :class="$style.cardBody">
                <div slot="title">
                  <a-icon
                    type="link"
                    title="友情链接"
                    @click="$router.push('/sd-frame/km-knowledage-base')"
                  />
                  友情链接
                </div>
                <div slot="extra">
                  <a-icon
                    slot="tabBarExtraContent"
                    :class="$style.morebtn"
                    type="LinkOutlined"
                    @click="goMoreNews('PRODUCT_XXFB_XWDT')"
                  />
                </div>
                <div>
                  <span v-for="(lj, index) in yqlj" :key="index">
                    <a :href="lj.link" target="_blank" :title="lj.title">
                      <img
                        class="linkpreviewimg"
                        :src="
                          `api/flow-mobile/v1/task-form-process/download-attachments/${lj.imgsrc}`
                            | sdResource
                        "
                      />
                    </a>
                  </span>
                </div>
              </a-card>
            </div>
          </a-col>
        </a-row>
      </div>
      <a-layout-footer :class="$style.footer">
        <div>Copyright 2020 WE.iam8.0 All Rights</div>
        <div v-if="false">北京XX科技有限公司 &nbsp; 版权所有</div>
      </a-layout-footer>
    </a-layout-content>
  </a-layout>
</template>

<script>
import storeMixin from '@/common/store-mixin'
import axios from '@/common/services/axios-instance'
import loginService from '@/login/login-service'
import homepageService from './homepage-service'
// import oaSearchInput from '../fullsearch/oa-search-input.vue'
import HomeTzggList from './home-tzgg-list.vue'
import HomeXwdtList from './home-xwdt-list.vue'
import components from './_import-components/audit-home-import'

export default {
  name: 'AuditHome',
  components: {
    ...components,
    HomeTzggList,
    HomeXwdtList,
  },
  mixins: [storeMixin],
  metaInfo: {
    title: '首页',
  },

  data() {
    return {
      news: { id: 4 },
      leftActiveKey: '1',
      rightActiveKey: '1',
      imgList: [],
      infolist: [],
      mklist: [
        {
          name: '待办',
          icon: 'sd-notebook',
          num: '-1',
          color: '#ff4a55',
          link: '/sd-frame/sd-mytodolist?type=todo',
        },
        {
          name: '待阅',
          icon: 'sd-notebook',
          num: '-1',
          color: '#ffb74a',
          link: '/sd-frame/sd-mytoreadlist',
        },
        {
          name: '提醒',
          icon: 'sd-notebook',
          num: '-1',
          color: '#54c5eb',
          link: '/sd-frame/sd-message-remind',
        },
        {
          name: '项目',
          icon: 'sd-notebook',
          num: '-1',
          color: '#bb7ec4',
          link: '/sd-frame/audit-project-list',
        },
      ],
      yqlj: [],
      yqljnum: 0,
      currentIndex: 1,
      timer: null,
    }
  },
  created() {
    this.getdbxx()
  },
  mounted() {
    this.startInterval()
  },
  methods: {
    // 开启定时器
    startInterval() {
      this.timer = setInterval(() => {
        this.currentIndex++
        if (this.currentIndex > 2) {
          this.currentIndex = 0
        }
      }, 3000)
    },
    changeInterval(val) {
      if (val) {
        clearInterval(this.timer)
      } else {
        this.startInterval()
      }
    },
    getdbxx() {
      homepageService.getCount().then((res) => {
        this.mklist[0].num = res.data.todoCount
        this.mklist[1].num = res.data.readCount
        this.mklist[2].num = res.data.remindCount
        this.mklist[3].num = res.data.projectCount
      })

      homepageService.getHomeYqlj().then((res) => {
        console.log('获取友情链接')
        this.yqljnum = res.data.length
        res.data.forEach((item) => {
          this.fngetattachment(item, 'entity:iamAuditInformation', '', item.instId)
        })
      })
    },
    fngetattachment(item, formId, beanId, instId) {
      return axios
        .get(`api/xcoa-mobile/v1/attachment-extend/attachments-info-perm/${item.thumbnail}`, {
          params: {
            formId: formId,
            beanId: beanId,
            instId: instId,
          },
        })
        .then((res) => {
          if (res.data.length) {
            console.log(res.data[0].code)
            this.yqlj.push({
              title: item.name,
              link: item.url,
              imgsrc: res.data[0].code,
            })
          }
        })
    },
    goMoreNews(data) {
      const href = '#/sd-frame/' + data
      window.open(href, '_blank')
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
:global(.linkpreviewimg) {
  width: 100px;
  height: 30px;
  padding: 0 10px;
}
.theme {
  color: $primary-color;
}
$importcolor: #e02020;
$nodata-icon: #d9d9d9;
$carousel-title: 64px;
$module-title: 64px;
$fonsicon-bg: 48px;
.pull-right {
  float: right;
  padding: 0 10px;
  cursor: pointer;
  &:hover {
    // 悬浮的颜色，与主题无关
    /* stylelint-disable-next-line */
    background-color: rgba(0, 0, 0, 0.2);
  }
}
.pull-top {
  margin-top: 5px;
}
.gobance {
  cursor: pointer;
}
.navsetting {
  cursor: pointer;
}
.layout {
  height: 100%;
  .logotitle {
    display: flex;
    align-items: center;
    float: left;
    height: 100%;
    .logo {
      width: 55px;
      height: 55px;
      margin-right: 10px;
      border-radius: 50%;
    }
    .title {
      font-size: 1.5em;
      font-weight: 600;
    }
  }
  .layout-content {
    height: calc(100% - 64px);
  }
  .footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: $font-size-sm;
    color: $white;
    background: $layout-header-background;
    width: 100vw;
  }
}
.empty-size {
  margin: 10% 0;
  :global(.ant-empty-image) {
    height: 50px;
    i {
      height: 100%;
      font-size: $fonsicon-bg;
      color: $nodata-icon;
    }
  }
}
.main-wrap {
  height: 100%;
  padding: $padding-lg;
  background-color: #fff;
  .maint {
    // height: 52%;
    // padding-bottom: $padding-lg;
    margin-left: 50px !important;
    margin-right: 50px !important;
    .main-top-l {
      width: calc(50% - 203px);
      height: 100%;
      padding-right: $padding-lg;
      .empty-size {
        display: flex;
        flex-direction: column;
        justify-content: center;
        width: 100%;
        height: 100%;
        margin-left: 0;
        background: $card-background;
        :global(.ant-empty-image) {
          height: 50px;
          i {
            height: 100%;
            font-size: $fonsicon-bg;
            color: $nodata-icon;
          }
        }
      }
    }
    .main-top-c {
      width: calc(50% - 203px);
      height: 100%;
      padding-right: $padding-lg;
    }
    .main-top-r {
      float: left;
      width: 406px;
      height: 100%;
    }
    :global(.ant-list-item-meta-description) {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    :global(.ant-list-item-meta-title) {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .mainb {
    height: 48%;
    .bottomhei {
      height: 100%;
      &.mainb-l {
        padding-right: $padding-lg / 2;
      }
      &.mainb-r {
        padding-left: $padding-lg / 2;
      }
    }
  }
  :global(.ant-card-head) {
    border-bottom: none;
  }
}

.boxslider {
  position: relative;
  .slidebox {
    height: 100%;
    div {
      width: 100%;
      height: 100%;
      overflow: hidden;
      cursor: pointer;
      background: #fff;
    }
    img {
      height: 100%;
      margin: 0 auto;
    }
  }
  .sd-dots {
    bottom: 30px;
    padding: 0 10px;
    text-align: right;
    li {
      margin: 0 4px;
      &:global(.slick-active) {
        button {
          width: 6px;
          background: $primary-color;
        }
      }
      button {
        width: 6px;
        height: 6px;
        background: $white;
        border-radius: 50%;
        opacity: 1;
      }
    }
  }
  .slider-title {
    position: relative;
    bottom: $carousel-title;
    display: inline-block;
    width: 100%;
    height: $carousel-title;
    padding: 0 100px 0 15px;
    overflow: hidden;
    font-size: $font-size-lg;
    line-height: $carousel-title;
    color: $white;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: rgba(0, 0, 0, 0.7);
  }
}

.box {
  height: 100%;
  // height: 430px;
  overflow-y: auto;
  background: $card-background;
  border-radius: 2px;
  :global(.ant-card-head-title) {
    padding: 20px 0;
    font-size: $font-size-base;
    color: $text-color;
    :global(.anticon) {
      color: $primary-color;
    }
  }
  .card-body {
    :global(.ant-card-body) {
      padding: 0 24px;
    }
  }
  :global(.ant-tabs) {
    padding: 0 24px;
    :global(.ant-tabs-bar) {
      border-bottom: none;
      :global(.ant-tabs-tab) {
        padding: 20px 15px;
        margin: 0 8px 0 0;
      }
    }
  }
  :global(.previewimg) {
    height: 150px;
    width: 100%;
  }
  &.box-r {
    padding: 0;
    background: transparent;
  }
  .morebtn {
    cursor: pointer;
  }
  &.boxbottom {
    height: 100%;
  }
  .smart-cart-t {
    padding-bottom: 24px;

    .pending {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 80px;
      border-radius: 2px;
      :global(.ant-card-body) {
        width: 100%;
        padding: 0;
      }
    }
  }
  .smart-cart-b {
    height: calc(100% - 104px);
    overflow: hidden;
    background: $card-background;
    border-radius: 2px;
    .quick {
      height: 100%;
      overflow-y: auto;
    }
    :global(.ant-card-head) {
      min-height: $module-title;
      line-height: $module-title;
      :global(.ant-card-head-title) {
        padding: 0;
      }
      :global(.ant-card-extra) {
        padding: 0;
      }
    }
    :global(.ant-card-body) {
      padding: 0 10px;
      > div {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
      }
    }
  }
}
.worklink {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-right: 1px solid $primary-1;
  .worklinknum {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 30px;
    font-size: $font-size-base;
    span {
      font-size: $font-size-lg;
      color: $text-color;
    }
    span:first-child {
      margin-top: 2px;
    }
    span:last-child {
      font-size: 2.1em;
      font-weight: 700;
      color: $importcolor;
    }
  }
}
.bannertable {
  width: 100%;
  height: 150px;
  background-color: #1b365d !important;
}
.previewimg {
  width: 100%;
  height: 150px;
}
.banner {
  background-image: url(./images/banner.png);
  background-size: 100%;
  background-color: #1b365d !important;
}
.banner1 {
  background-image: url(./images/banner1.png);
  background-size: 100%;
  background-color: #1b365d !important;
}
.banner2 {
  background-image: url(./images/banner2.png);
  background-size: 100%;
  background-color: #1b365d !important;
}
.tab {
  // width: 80%;
  height: 60px;
  border-radius: 5px;
  color: #fff;
  font-size: 20px;
  padding-top: 15px;
  padding-left: 15px;
  padding-right: 15px;
  text-align: center;
  cursor: pointer;
}
.cardBody {
  :global(.ant-card-head-wrapper) {
    border-bottom: 2px solid #efefef;
  }
}
.audithome {
  :global .header_sd-header_common.ant-layout-header {
    width: 100% !important;
    background-color: #1b365d !important;
  }
  :global .right_sd-header_common {
    display: inline;
    color: #fff;
  }
}
</style>
