content.vue 10.1 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(trafficFlow_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>
      </h3>
      <div class="asis-table-content" v-loading="loading">
        <el-row v-if="!isDTabChart">
            <el-col :span="12" class="download-parent">
              <!-- 性别统计 -->
              <mix-charts
                chart-id="domGenderChart"
                class="gender-wrapper"
                :chart-data="genderOption"
                chart-type="Pie"
              />
            </el-col>
            <el-col :span="12" class="download-parent">
              <!-- 年龄统计 -->
              <mix-charts
                chart-id="domAgeChart"
                class="age-wrapper"
                :chart-data="ageOption"
                chart-type="StackBar"
              />
            </el-col>

        </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"
             show-summary
           >
             <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-column prop="summary" :label="$t('table.total')" align="center" /> -->
           </el-table>
        </el-row>
      </div>
    </div>
    <export-data-dialog ref="exportDialog"></export-data-dialog>
  </div>
</template>

<script>
import echarts from "echarts";
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: "customerAttributeStatistics", //报表
      emitData: {},
      radioDate: "day",
      isDTabChart: false,
      chartData: {}, // 图数据
      tabHeadData: [],
      tabOps: [],
      asisLevel: 'mall',
      genderOption: {},
      ageOption:{}
    };
  },
  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() {
    this.isDTabChart =
      window._vionConfig.reportType && window._vionConfig.reportType == "table"
        ? true
        : false;
  },
  mounted() {
  },
  methods: {
    refreshHandle(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.tabHeadData = this.dealTheadData(flowHeadData,'sum')
      const tbodyData = this.dealTableData(
        originData.reduce((arr, curr) => {
          arr.push(curr.data)
          return arr
        }, []),
        'column',
        'sum'
      )
      this.tabOps = combineHeadAndBody(this.tabHeadData, tbodyData)
    },
    // 获取统计图数据
    getEcartsData(resData) {

    },
    getData() {
      this.tabHeadData = [];
      this.chartData = {};
      this.tabOps = [];
      this.loading = true;

      if(this.isDTabChart){
        let param = {
          orgId: this.emitData.orgId,
          startDate: this.emitData.startDate,
          endDate: this.emitData.endDate,
          type: "table",
        }
        this.$api.analysisReport.getCustomerAgeStatistics(param).then(res => {
            let resData = res.data.data.body.CustomerAgeReport;
            this.chartData = resData;
            this.loading = false;
            this.getTableData(resData)
          })
          .catch(err => {
            this.catchErrorHandle(err);
            setTimeout(() => {
              this.loading = false;
            }, 500);
          });
      }else{
        let param = {
          orgId: this.emitData.orgId,
          startDate: this.emitData.startDate,
          endDate: this.emitData.endDate,
          type: "bar",
        }
        let param1 = {
          orgId: this.emitData.orgId,
          startDate: this.emitData.startDate,
          endDate: this.emitData.endDate,
          type: "pie",
        }
        Promise.all([this.$api.analysisReport.getCustomerGenderStatistics(param1),this.$api.analysisReport.getCustomerAgeStatistics(param)]).then(resArr=>{
          this.loading = false;
          let pieOption = resArr[0].data.data.body.CustomerGenderReport
          pieOption.otherConf = {
            radius: ['0%', '65%'],
            _color: ["#3bb8ff", "#ffc62e","#e35241"]
          }
          this.genderOption = pieOption
          let barOption = resArr[1].data.data.body.CustomerAgeReport
          barOption.otherConf = {
            _color: ["#3BB8FF", "#FFC62E","#e35241"],
            doubleYaxis: true,
            grid: { top: 10, right: 56, bottom: 62, left: 26 },
            isSwapY: true
          }
          this.ageOption = barOption
        }).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: ["domAgeChart","domGenderChart"],
        title: title,
        data: {
          url: `/basePassengerFlow/customerAge/export`,
          params: `orgId=${this.emitData.orgId}&startDate=${this.emitData.startDate}&endDate=${this.emitData.endDate}`
        }
      };
      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>