import list from '@/mixins/list'
import routerUserMenu from '@/mixins/router-user-menu'
import breadcrumbComponent from '@/components/breadcrumb.vue'
import reportComponent from '@/components/automatic-report-components/report.vue'

import {kpiColors} from '@/views/Report/ReportManagement/kpi-color'
import {layerClass} from '@/views/Report/ReportManagement/layer-class'
import {echartsThemes} from '@/views/Report/ReportManagement/echarts-color-themes'
import {barLineOption,pieOption} from '@/views/Report/ReportManagement/echarts-option'
import {deepCopy} from "../../../utils/util";
/**
 * 列表页管理
 *
 *  version = "1.0.0";
 *  author = "徐飞";
 *  email = "xu.fei@data-u.com";
 * */
export default {
  name: 'report',
  components: { breadcrumbComponent, reportComponent},
  mixins: [list,routerUserMenu],
  data () {
    return {
      id: '',
      viewRes: {
        layoutId: 1,
        kpis: []
      },

    }
  },
  computed: {
    ifOutsideParamValue: {
      get: function () {
        let {query} = this.$route
        return query.q||''
      },
    },
    // 下钻带过去的附加条件
    drillDownRelated:{
      get: function () {
        let {kpis} = this.viewRes
        return kpis.filter(kpi=>{
          return kpi.ifRelated===1
        })
      },
    },
    /* 布局 */
    layerClass: {
      get: function () {
        let {layoutId} = this.viewRes
        return layerClass[layoutId]
      },
      set: function (val) {}
    },
    /* 表颜色 */
    chartColor: {
      get: function () {
        let {colorGroupId} = this.viewRes
        return echartsThemes[colorGroupId]
      },
      set: function (val) {}
    },
    report: {
      get: function(){
        /* 加载报表对象 */
        let report = deepCopy(this.viewRes)
        return report
      }
    }
  },
  created(){
  },
  mounted () {
    // 获取列表页
    this.init()
  },
  methods: {
    init(){
      // 获取url参数
      let params = this.$route.params
      if(params.hasOwnProperty('id')){
        // 如果有id，则加载组件对象
        this.id = params.id
        this.getView()
      }
    },
    getView(){
      this.$api.report.view({id: this.id}).then(res=>{
        if(res.code==1){
          this.viewRes=res.data
        }
      })
    },
  }
}
