content.vue 8.32 KB
<template>
  <div class="daily">
    <!-- 小时分钟合并 -->
    <div class="asis-table-wrapper">
      <h3 class="asis-table-header single-report-header tf-table-header">
        <span
        v-if="isDTabChart"
          class="asis-table-download"
          @click="downloadData(i18nFormatter(trafficFlow_title) + '-' + Time(),'custom')"
        >{{$t('allPages.load')}}</span>
        <span
         v-else
         style="color: #ccc;"
          class="asis-table-download"
          :disabled="!isDTabChart"
        >{{$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>
      </h3>
      <div class="asis-table-content" v-loading="loading">
        <el-row v-if="!isDTabChart">
           <mix-charts
             chart-id="domAgeChart"
             class="age-wrapper"
             :chart-data="chartData"
             chart-type="Line"
           />

        </el-row>
        <el-row v-else>
          <el-table
             id="domBaseTrafficFlow"
             :data="tabOps"
             :max-height="tableHeight"
             style="width: 100%"
             class="asis-table baseasis-table"
             header-row-class-name="asis-table-head"
             row-class-name="manage-row"
           >
             <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>
        </el-row>
        <p style="width: 100%;text-align: center;color: red;">注:受数据隐私保护要求,竞品客流分析不提供客流量绝对值,仅提供商场同期内客流走势和相对高低,即客流指数</p>
      </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 {
      loading: false,
      trafficFlow_title: "competitivePassengerFlowData", //报表
      emitData: {},
      isDTabChart: false,
      chartData: {}, // 图数据
      tabHeadData: [],
      tabOps: []
    };
  },
  computed: {
    barLineIcon() {
      if (this.isDTabChart) {
        return "report-item line-report";
      } 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,
      deep:true
    },
    emitData: {
      handler(){

      },
      immediate: true,
      deep:true
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    refreshHandle(param) {
      if(param){
        this.emitData = param
        this.getData();
      }
    },
    // 获取表格数据
    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)
    },
    getData() {
      this.tabHeadData = [];
      this.chartData = {};
      this.tabOps = [];
      this.loading = true;
      let param = {
        mallId: this.emitData.orgId,
        startDate: this.emitData.startDate,
        endDate: this.emitData.endDate,
        type: this.isDTabChart?"table":'line',
      }
      this.$api.businessAnalysisApi.getPassengerFlow(param).then(res => {
        let resData = res.data.data;
        this.loading = false;
        if (this.isDTabChart) { // 表格
          this.getTableData(resData)
        } else { // 图
          if(resData.series&&resData.series.length>0){
            resData.otherConf = {
              singleUnit:'%',
              yAxisName:'%'
            }
          }
            this.chartData = resData;
          }
      })
      .catch(err => {
        this.catchErrorHandle(err);
        setTimeout(() => {
          this.loading = false;
        }, 500);
      });
    },
    // 新增表格回调
    /**
     * 表头格式化
     * @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')
      }
    },
    selReport(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: `/report/basics/day/${this.emitData.asis_level}/${this.tableKeyToId[chartKey]}/excel`,
          params: `orgIds=${this.emitData.asis_org}&date=${
            this.emitData.asis_time
          }&option=${this.isDTabChart ? "TAB_TABLE" : "TAB_CHART"}`
        }
      };
      this.$refs.exportDialog.dialogInit(exportNeed);
    }
  }
};
</script>

<style scoped>
.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>