<template>
  <div :id="elId"  style="width:100%;height:100%">
      <div id="hsCarousel"  style="width:100%;height:100%">
      <el-carousel  style="width:100%;height:100%">
        <el-carousel-item v-for="(item,index) in dataList" :key="index">
          <h3 class="small">{{ item.text }}</h3>
        </el-carousel-item>
      </el-carousel>
    </div>
      <jsoneditor v-model='jsoneditorVisible'
                  :elInfo='elInfo'
                  :dealWithSourceFun='dealWithSource'
                  :jsoneditorCloseAfter='jsoneditorCloseAfter'
                  :jsoneditorOpenAfter='jsoneditorOpenAfter'
                  >
      </jsoneditor>

  </div>
</template>
<script>
import jsoneditor from '../common/jsoneditor'
import uuidv1 from 'uuid/v1'
import ucComponent from '../ucClass/uc_component'
export default {
  mixins: [ucComponent],
  name: 'hs-carousel',
  components: {
    jsoneditor
  },
  props: {
    allSourceData: {
      default: {}
    },
    elInfo: {
      type: Object,
      default() {
        return {}
      }
    },
    initStyle: {
      type: Object,
      default() {
        return {}
      }
    },
    jsoneditorCloseAfter: {
      type: Function
    },
    jsoneditorOpenAfter: {
      type: Function
    }
  },
  watch: {
    allSourceData: {
      handler: function(newVal, oldVal) {
        this.initData(newVal)
      },
      deep: true
    }
  },
  data() {
    return {
      elId: uuidv1(),
      jsoneditorVisible: false,
      dataList: [],
      jsoneditorConfig: {}, // 配置
      jsoneditorSource: [], // 原始数据
      sourceData: {}
    }
  },
  mounted() {
  },
  methods: {
    dealWithSource(config, sourceData) {
      return {
        config,
        sourceData
      }
    },
    initData(data) {
      if (data && data.sourceData && data.sourceData.length) {
        this.dataList = data.sourceData
        this.jsoneditorConfig = data.config || {}
        this.jsoneditorSource = data.sourceData
      } else {
        this.dataList = [{ id: '1', text: '华晨宝马x5' }, { id: '2', text: '梅赛德斯大G' }, { id: '3', text: '奥迪Q8' }]
        this.jsoneditorConfig = {}
        this.jsoneditorSource = this.dataList
      }
    }
  }
}
</script>
<style scoped>
#hsCarousel >>>  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    margin: 0;
  }

#hsCarousel >>>   .el-carousel__item:nth-child(2n) {
     background-color: #99a9bf;
  }

#hsCarousel >>>   .el-carousel__item:nth-child(2n+1) {
     background-color: #d3dce6;
  }
#hsCarousel  >>> .el-carousel__container{
    height: 100%;
  }
</style>
