/* 互动频次 */
<template>
  <div class="interaction-wrapper height100 overview-detail">
    <div class="btn-group" v-if="isExport">
      <el-button
        class="export"
        type="primary"
        icon="el-icon-download"
        @click="handleExport"
        >导出文件</el-button
      >
    </div>
    <div id="bodyCanvas" :class="isExport?'':'export'">
      <div class="ecahrts-panel-box">
        <div class="panel-box-header">
          <span class="title">本月互动频次</span>
          <div class="tip">
            <span class="tip-title">页面说明:</span>
            <span>
              展示所有单位的互动频次统计图及统计表格。</span
            >
          </div>
        </div>
        <div class="panel-box-content">
          <bar :data="echartsData" ref="echarts" />
        </div>
      </div>
      <div class="rank-panel-box">
        <div class="panel-box-header">
          <span class="title">本月互动频次排行</span>
        </div>
        <div class="panel-box-content">
          <rank-table :tList="tList" :data="data" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCurDate } from "@/utils/util.time.js";
import { bar, rankTable } from "./components";
export default {
  data() {
    return {
      tList: ["排名", "机构名称", "互动频次"],
      echartsData: {},
      data: [],
      isExport:false
    };
  },
  components: { bar, rankTable },
  mounted() {
    let roleList = localStorage.getItem('roleList')
    if(roleList){
       this.isExport = localStorage.getItem('roleList').includes('1')
    }
    this.getList();
  },
  methods: {
    getList() {
      let curTime = getCurDate();
      let frequencyDate = curTime.year + curTime.month;
      let _this = this;
      _this
        .$https({
          method: "post",
          url:
            "tBoardStatistic/getInteractionPageList?frequencyDate=" +
            frequencyDate,
          authType: this.backToken,
        })
        .then((res) => {
          if (res.status == 200) {
            if (res.data.resultCode == 200) {
              _this.echartsData = {};
              _this.echartsData.xAxisData = res.data.data.organList;
              _this.echartsData.yAxisData = res.data.data.cntList;
              _this.data = res.data.data.page.records;
            } else {
              _this.echartsData = {};
              _this.data = [];
            }
          } else {
            _this.echartsData = {};
            _this.data = [];
          }
          setTimeout(() => {
            _this.init();
          }, 100);
        })
        .catch((err) => {
          _this.$message.error(err.message);
          _this.echartsData = {};
          _this.data = [];
        });
    },
    init() {
      this.$refs.echarts.init();
    },
     handleExport() {
      let _this = this;
      if (this.timer) {
        return false;
      }
      this.timer = setTimeout(() => {
        clearTimeout(_this.timer);
        _this.timer = null;
      }, 30000);
      _this.getPdf("#bodyCanvas", "互动频次");
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      setTimeout(() => {
        loading.close();
      }, 2000);
    },
  },
};
</script>
<style lang="less" scoped>
.interaction-wrapper {
  .btn-group {
    margin-bottom: 20px;
    height: 36px;
  }
  /deep/ .el-button.export {
    width: 128px;
    float: right;
    .el-icon-download {
      font-size: 18px;
      font-weight: bold;
    }
  }
  #bodyCanvas {
    height: calc(100% - 56px);
    &.export{
      height: 100%;
    }
  }
  .ul-wrapper {
    background-color: @party-white;
  }
}
</style>