<template>
  <div>
    <designCommon :pagePath='pagePath'
    :getPageConfig='getPageConfig'
    :layout='layout'
    :getConfig='getConfig'
    :getData='getData'
    :saveConfigData='saveConfigData'
    :savePageConfig='savePageConfig'
    ></designCommon>
  </div>
</template>

<script>
import designCommon from './queryBiBaseView'
export default {
  components: { designCommon },
  data() {
    return {
      pagePath: '',
      layout: [],
      buttonSaveShow: false
    }
  },
  inject: ['reload'],
  watch: {
    '$route.params': {
      handler(newVal) {
        const pagename = newVal.pagename
        if (pagename) {
          this.reload()
          this.pagePath = pagename
        }
      }
    }
  },
  mounted() {
    const pagename = this.$route.params.pagename
    this.pagePath = pagename
  },
  methods: {
    // 获取页面的配置信息(坐标，每个控件的信息)
    getPageConfig(pagePath) {
      const params = {
        page: pagePath || this.pagePath,
        position: 'pageConfig'
      }
      this.$API.getData(params).then(res => {
        this.layout = res.filter(x => x.control)
      })
    },
    // 获取控件的详细配置信息
    getConfig(params) {
      return this.$API.getConfig(params)
    },
    // 获取控件的详细源数据
    getData(params) {
      return this.$API.getData(params)
    },
    // 保存配置和源数据
    saveConfigData(params, config, data, sql) {
      this.$API.runSave(params, config, data, sql)
    },
    // 保存queryBIView页面的配置信息
    savePageConfig(data) {
      const parm = {
        page: this.pagePath,
        position: 'pageConfig'
      }
      this.$API.runSave(parm, {}, data).then(_ => {
        this.getPageConfig(this.pagePath)
      })
    }
  }
}
</script>
