<template>

  <div   class="container">
    <el-row>
      <div class="tool-bar">
        <div>
          <span class="title-name">仪表盘标题</span>
        </div>
        <div style = "position:absolute:top:0px;right:0px">
          <el-button class="miniSuccess" @click="control_edit()">编辑</el-button>
          <el-button class="successBorder" @click="handleLinkChart">
            添加图表
          </el-button>
        </div>
      
    </div>
    </el-row>

    <el-row>
      <div>
        <draggable v-model="boardList" group="itxst"   animation="300" :group="{name: 'dashboard',pull: true}" @start="onStart" @end="onEnd">
          <transition-group>

          <el-card class="box-card board-card" key="1" v-for="item in boardList">
            <div slot="header" class="clearfix">
              <span>{{item.title}}</span>
        

              <div  style="float: right; padding: 3px 0;display:inline-block;">
                <i  class="el-icon-edit" style="color:#009C69;cursor:pointer;" />
                <i  class="el-icon-delete" style="color:#009C69;cursor:pointer;"  />

              </div>

            </div>


            <div  class="board-item"  > 
                表格
 
                 <BarChart v-if = "item.boardtype == 'bar'"   :chart-data="item.chartData" />
                <LineChart v-if = "item.boardtype == 'line'"   :chart-data="item.chartData" />
                <!-- <HorizontalBarChart v-if = "item.boardtype == 'horizontal_bar'"   :chart-data="item.chartData" /> -->
                <PieChart v-if = "item.boardtype == 'pie'"   :chart-data="item.chartData" />
                <!-- <LineBarChart v-if = "item.boardtype == 'line_bar'"   :chart-data="item.chartData" /> -->
            </div>
            <!-- <div  class="board-item" v-if="item.boardtype == 'line'"> 
                 <keep-alive>
                  <component :is="chartLine.myComponent" ref="chartLine" />
                </keep-alive>
            </div> -->
          </el-card>
                    
                        
          </transition-group>
        </draggable>

      </div>
    </el-row>

    <el-row>

    </el-row>

    

    


    <el-dialog  title="我的图表" :visible.sync="showChartList">
      <!-- <el-button type="primary" size="mini" @click="$router.push({ name: 'ChartPanel', params: { id: 'create' , isEdit: 'edit'}})">
        创建新的图表
      </el-button> -->

      <el-button class="save" style="margin-bottom: 10px;" @click="jumpCreate()"> 创建新的图表 </el-button>

      <el-table :data="myChartList" border>
        <el-table-column :label="$t('common.name')" width="200" prop="chart_name" />
        <el-table-column :label="$t('common.desc')" prop="desc" />
        <el-table-column :label="$t('common.operation')" align="center">
          <template slot-scope="scope">
            <el-button class="miniPrimary" :disabled="isExisted(scope.row)" @click="linkChart(scope.row)">添加</el-button>
            <el-button size="mini" type="warning" style="padding: 6px 10px !important;font-size:14px;" @click="jumpEdit2(scope.row)">  编辑 </el-button>

          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose1" @click="showChartList = false">{{$t('common.closed')}}</el-button>
      </div>
    </el-dialog>
 
    
  </div>

</template>

<script>
import draggable from 'vuedraggable'
 
import { GetDataByName } from '@/api/common'

// import { ChartTable } from '@/components/ChartTable'


import ChartTable from '@/componentChart/ChartTable.vue'
import LineChart from '@/componentChart/LineChart.vue'
import BarChart from '@/componentChart/BarChart.vue'
import HorizontalBarChart from '@/componentChart/HorizontalBarChart.vue'
import PieChart from '@/componentChart/PieChart.vue'
import LineBarChart from '@/componentChart/LineBarChart.vue'



import Cookies from 'js-cookie'
 
export default {
  name: 'Addboard2',
 
  components: {  draggable , ChartTable ,LineChart,BarChart ,HorizontalBarChart, PieChart, LineBarChart},
  data() {
    return {
      isRoleEdit: [],


 

      boardList: [
        {
          title:'图表1',boardId:1,boardtype:'bar',
          chartData:{
            chartType:'bar',
            xAxisArr: ['2019-01', '2019-02', '2019-03', '2019-04', '2019-05', '2019-06', '2019-07', '2019-08', '2019-09', '2019-10', '2019-11', '2019-12'],
            legendArr: ['数据1', '数据2', '数据3'],
            dataArr:[
              [1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
              [1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
              [1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
        
            ]
          }
        },
        {
          title:'图表2',boardId:2,boardtype:'line',
          chartData:{
            chartType:'line',
            xAxisArr: ['2019-01', '2019-02', '2019-03', '2019-04', '2019-05', '2019-06', '2019-07', '2019-08', '2019-09', '2019-10', '2019-11', '2019-12'],
            legendArr: ['数据1', '数据2', '数据3'],
            dataArr:[
              [1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
              [1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
              [1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
            ]
          }
        },
        {
          title:'图表3',boardId:3,boardtype:'pie',
          chartData:{
            chartType:'pie',
            xAxisArr: ['2019-01', '2019-02', '2019-03', '2019-04', '2019-05', '2019-06', '2019-07', '2019-08', '2019-09', '2019-10', '2019-11', '2019-12'],
            legendArr: ['数据1', '数据2', '数据3', '数据4', '线条1'],
            dataArr:[1, 10, 7, 0, 1, 7, 7, 6, 4, 4, 1, 6],
          
          }
        },
        {title:'图表3'},
        {title:'图表3'},

        {title:'图表3'},
        {title:'图表3'},
       ],


       chartTable: {
        dialogFormVisible: false,
        dialogStatus: '',
        myComponent: null
      },

      chartLine: {
        dialogFormVisible: false,
        dialogStatus: '',
        myComponent: null
      },



       myChartList: [],
      showChartList: false,
      chartLoading: {},



      isEdit: 'view',
      dashboardList: [],
      currentDashboard: undefined,
      editDialogVisible: false,
      dbObj: {},
      loading: false,
      isCollapse: false,
      did: undefined,
      isTitle: '2',
      editBtn: false,
      control_btn: '编辑',
      control_btn_l: false,

 

    }
  },

  created() {
    // console.log('this.$route.params.id', this.$route.params.id)
    // const isEdit = this.$route.params.isEdit

    // this.isEdit = isEdit
 
    this.getList()

     this.chartTable.dialogFormVisible = true
     this.chartLine.dialogFormVisible = true

      const vue = this
      // var myComponent1 = () => import('./chartTable.vue')
      // vue.chartTable.myComponent = myComponent1
      // var myComponent2 = () => import('./chartLine.vue')
      // vue.chartTable.myComponent = myComponent2
  },

  methods: {




       onStart(){
      console.log(2222)
    },
    onEnd(){
      console.log(this.boardList)

  
    },
     

    getList() {


  // const vue = this
  //     var myComponent = () => import('./chartTable.vue')
  //     return vue.chartTable.myComponent = myComponent
      

      this.loading = true

      // if (this.$route.params.id) {
      //   this.did = this.$route.params.id
      // } else {
      //   this.did = this.did
      // }

     
    },
    //添加图表
    handleLinkChart() {
      var send_data = {
        name: 'getChartListV2',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureid: Cookies.get('pastureid'),
          empid: Cookies.get('employeid')
        }
      }
      GetDataByName(send_data).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.myChartList = response.data.list
          this.showChartList = true
        } else {
          this.myChartList = []
          this.showChartList = true
        }
      })
    },
   
  }
}
</script>
<style scoped>
.board{
  width:300px;height:300px;border:1px soild #333;display:inline-block;background: #2ed1f9;padding: 5px 5px;margin-right: 15px;margin-bottom: 15px;
}


.tool-bar {
  display: block; border-top: none;
  height: 80px;
  line-height: 4;
  color: #303133;
  padding: 0 10px;
  position: relative;
 
}
 .title-name {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-left: 0;
  }
  /* span {
    color: #c0c4cc;
    font-size: 12px;
    margin-left: 10px;
  }

  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  } */

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .board-card {
    width: 400px;min-height: 360px;
    padding: 20px 10px;
    display: inline-block;
    margin: 0px 0px 20px 20px;
  }
</style>

<style lang="scss" scoped>


</style>
