daily.vue 11.2 KB
<template>
  <div class="daily">
    <!-- 小时分钟合并 -->
    <div class="asis-table-wrapper">
      <h3 class="asis-table-header single-report-header tf-table-header">
        <span
          class="asis-table-download"
          @click="downloadData(i18nFormatter(detailData_title) + '-' + Time(),radioDate)"
        >{{$t('allPages.load')}}</span>
        <span class="report-type-box">
          <span :class="barLineIcon" @click="selReport('bar')"></span>
          <span
            :class="isDTabChart ? 'report-item report-item-tab' : 'report-item'"
            @click="selReport('table')"
          ></span>
        </span>
        <span class="asis-table-alldownload">
          <el-button type="primary" class="primary-btn analysis-collapse-btn" size="samll" @click="allStoreDownload(i18nFormatter(detailData_title) + '-' + Time())">{{$t('button.allStoreDownload')}}</el-button>
        </span>
      </h3>
      <div class="date-radio-wrapper tf-ratio-group single-ratio-group">
        <el-radio-group
          v-model="radioDate"
          size="mini"
          fill="#0069FF"
          @change="changeTabSelect(radioDate)"
        >
          <!-- <el-radio-button label="day" border>{{$t('button.day')}}</el-radio-button> -->
          <el-radio-button label="hour" border>{{$t('button.hour')}}</el-radio-button>
          <el-radio-button label="minute" border>{{$t('button.min')}}</el-radio-button>
        </el-radio-group>
      </div>
      <div class="asis-table-content" v-loading="loading">
        <el-table
            v-show="isDTabChart"
            class="asis-table baseasis-table"
            id="domBaseTrafficFlow"
            :data="tabOps"
            header-row-class-name="asis-table-head"
            style="width: 100%"
            :max-height="tableHeight"
          >
          <el-table-column
              v-if="tabOps.length"
              type="index"
              :label="$t('table.order')"
              align="center"
              width="80"
            >
              <template slot-scope="scope">
                <span>{{ indexFormatter(scope) }}</span>
              </template>
          </el-table-column>
          <el-table-column
            :prop="item.prop"
            :label="item.label"
            align="center"
            v-for="(item,index) in tabHeadData"
            :key="index"
            min-width="100"
          >
          </el-table-column>
        </el-table>
        <!-- echarts 图表 -->
        <mix-charts
          v-show="!isDTabChart"
          chartId="bdlineChart"
          class="area-line-chart"
          :style="{ height: tableHeight + 'px' }"
          :chartData="chartData"
          :chartType="echartsType"
        />
      </div>
    </div>
    <export-data-dialog ref="exportDialog"></export-data-dialog>
  </div>
</template>

<script>
import exportData from "../../public/exportData";
import { columnComputed, rowComputed, curryAvgAndSum, combineHeadAndBody } from '@/utils'

export default {
  props: {
    propparam: {
      type: Object,
      default: () => {}
    }
  },
  components: {
    "export-data-dialog": exportData,
  },
  data() {
    return {
      dialogVisible:false,
      loading: false,
      detailData_title: "", //客流报表
      emitData: {},
      radioDate: "hour",
      isDTabChart: false,
      chartTypeOpt: "table",
      chartData: {}, // 图数据
      tabHeadData: [],
      tabOps: [],
      echartsType: "AreaLine",
      createRow: '',
      asisLevel: 'mall'
    };
  },
  computed: {
    barLineIcon() {
      if (this.isDTabChart) {
        if (this.radioDate === "day") {
          return "report-item bar-report";
        } else {
          return "report-item line-report";
        }
      } else {
        if (this.radioDate === "day") {
          return "report-item bar-report report-item-bar";
        } else {
          return "report-item line-report report-item-line";
        }
      }
    },
    tableHeight() {
      let windowHeight = window.innerHeight,
        scale = 0.34

      scale = windowHeight <= 720
        ? 0.4
        : windowHeight <= 768
          ? 0.38
          : windowHeight <= 900
            ? 0.36
            : windowHeight <= 1080
              ? 0.34
              : 0.34
      return windowHeight - windowHeight * scale
    }
  },
  watch: {
    propparam: {
      handler: "refreshHandle",
      immediate: true
    }
  },
  created() {
  },
  methods: {
    refreshHandle(param) {
      if(param.data){
        this.emitData = param.data;
        this.getData();
      }
    },
    getData() {
      this.tabHeadData = [];
      this.chartData = {};
      this.tabOps = [];
      this.loading = true;
      let param = {
        orgId: this.emitData.orgId,
        startDate: this.emitData.startDate,
        endDate: this.emitData.endDate,
        type: this.isDTabChart ? "table" : "line",
        option: this.radioDate
      }
      this.$api.analysisReport.getPassengerFlowStatistics(param)
        .then(res => {
          let resData = res.data.data.body.BasePassengerFlowReport;
          this.detailData_title = "BasicReportdetailData";
          this.chartData = resData;
          this.loading = false;
          // this.getTableData(resData)
          // this.getEcartsData(resData)
          if (this.isDTabChart) { // 表格
            this.getTableData(resData)
          } else { // 图
            this.getEcartsData(resData)
          }
        })
        .catch(err => {
          this.catchErrorHandle(err);
          setTimeout(() => {
            this.loading = false;
          }, 500);
        });
    },
    // 获取表格数据
    getTableData(resData) {
      let originData = JSON.parse(JSON.stringify(resData.series))
      let flowHeadData = JSON.parse(JSON.stringify(resData.xaxis && resData.xaxis.data || []));
      this.tabHeadData = flowHeadData.reduce((arr, curr, index) => {
        arr.push({
          prop: `defaultOrg${index}`,
          label: curr
        })
        return arr
      }, [])
      const tbodyData = originData.reduce((arr, curr) => {
          arr.push(curr.data)
          return arr
        }, [])
      this.tabOps = combineHeadAndBody(this.tabHeadData, tbodyData)
    },
    // 获取统计图数据
    getEcartsData(resData) {
      let chartOption = resData;
      chartOption["otherConf"] = {
        _color:["#3BB8FF", "#FFC62E", "#97c05c", "#154bee", "#d83965",
                "#9036aa", "#e35241", "#4fb9d1", "#3f9488", "#97c05c",
                "#154bee", "#FF9631", "#f39c38", "#e35241"] ,
        hasYaxisName: false,
        periodTime: this.radioDate === "day" ? false : true,
        nextTimeNum: this.radioDate === "minute" ? 10 : undefined,
        chartKey: this.radioDate,
        isRadioObject:true,
        grid: { top: 68, right: 100, bottom: 66, left: 60 },
        yAxisName: [this.$t('format.perTime'), '%'],
        isTwoYaxis:true,
      };
      if (/\,/.test(this.emitData.asis_org)) {
        chartOption["otherConf"][
          "selectedLen"
        ] = this.emitData.asis_org.split(",").length;
      }
      this.chartData = chartOption;
    },
    // 新增表格回调
    /**
     * 表头格式化
     * @param {array} originHeadData
     * @param {string} addColumn { 'avg' | 'sum' | 'avgAndTotal' }
     */
    dealTheadData(originHeadData, addColumn) {
      if (originHeadData.length === 0) return originHeadData
      let copyHeadData = originHeadData.slice(0),
        resultHeadData = []

      if (addColumn === 'avg') {
        copyHeadData.push(this.$t('table.average'))
      } else if (addColumn === 'sum') {
        copyHeadData.push(this.$t('table.total'))
      } else if (addColumn === 'avgAndTotal') {
        copyHeadData.push(this.$t('table.average'))
        copyHeadData.push(this.$t('table.total'))
      }

      return copyHeadData.reduce((arr, curr, index) => {
        arr.push({
          prop: `defaultOrg${index}`,
          label: curr
        })
        return arr
      }, [])
    },
    /**
     * 处理表格数据
     * @param {array} data
     * @param {string} addPlace { 'index' | 'column' | 'row' | 'both' }
     * @param {string} addOption { 'avg' | 'sum' | 'avgAndTotal' }
     * @param {number} startPostion
     * @returns {array} result
     */
    dealTableData(data, addPlace, addOption, startPosition = 0) {
      if (!addPlace) return data
      let result = []
      if (addPlace === 'column') {
        result = columnComputed({data, addOption, startPosition})
      } else if (addPlace === 'row') {
        result = rowComputed({data, addOption, startPosition})
      } else {
        let addColAndRow = curryAvgAndSum(columnComputed, rowComputed)
        result = addColAndRow({data, addOption, startPosition})
      }

      return result
    },
    indexFormatter({ $index, row }) {
      const { createRow, tabOps } = this
      const realDataLen = createRow === 'avgAndTotal' ? tabOps.length - 2 : tabOps.length
      if ($index < realDataLen) {
        return $index + 1
      } else {
        return ((realDataLen - $index) === 0) ? this.$t('table.average') : this.$t('table.total')
      }
    },
    // 切换 button group
    changeTabSelect(val) {
      this.getData();
    },
    selReport(iconType) {
      this.chartTypeOpt = iconType;
      if (iconType === "line" || iconType === "bar") {
        if (this.isDTabChart) {
          this.isDTabChart = false;
          this.getData();
        }
      } else {
        if (!this.isDTabChart) {
          this.isDTabChart = true;
          this.getData();
        }
      }
    },
    downloadData(title, chartKey) {
      if (this.isDTabChart) {
        this.dealExport("domBaseTrafficFlow", title);
      } else {
        this.exportDataHandle(title, chartKey);
      }
    },
    exportDataHandle(title, chartKey) {
      let exportNeed = {
        domId: "bdlineChart",
        title: title,
        data: {
          url: `/basePassengerFlow/passengerFlow/export`,
          params: `orgId=${this.emitData.orgId}&startDate=${this.emitData.startDate}&endDate=${this.emitData.endDate}&option=${this.radioDate}`
        }
      };
      this.$refs.exportDialog.dialogInit(exportNeed);
    },
    allStoreDownload(title){
        const { apiUrl } = window._vionConfig;
        let url = `/basePassengerFlow/passengerFlow/export`;
        let language = localStorage.getItem("lang");
        if (language) {
          const languageObj = {
            mall_CN: "zh_CN",
            zh_CN: "zh_CN",
            en_US: "en_US",
            zh_TW: "zh_TW"
          };
          language = languageObj[language] || window.navigator.language;
        }
        const downloadUrl = `${apiUrl}${url}?accountId=${this.$cookie.get("accountId")}&startDate=${this.emitData.startDate}&endDate=${this.emitData.endDate}&option=${this.radioDate}&localLanguage=${language}&authorization=${this.$cookie.get(
          "atoken"
        )}&title=${encodeURI(title)}`;
        window.open(downloadUrl);
    }
  }
};
</script>

<style scoped>
  .asis-table-alldownload{
      font-size: 14px;
      color: #666;
      float: right;
      cursor: pointer;
      position: relative;
      padding-right: 20px;
  }
.asis-table-wrapper {
  position: relative;
}

.bar-report {
  background: url("~@/assets/img/asis/bar_icon.svg") no-repeat;
  background-size: 100% 100%;
}

.report-item-bar {
  background: url("~@/assets/img/asis/active_bar_icon.svg") no-repeat;
  background-size: 100% 100%;
}
</style>