<template>
   <div class="table-box" ref="tableBox">
     <template v-if="isShowYd">
       <div class="rightBtn" @click="showDeleteButton(true)"><i class="el-icon-d-arrow-right"></i></div>
       <div class="rightBtn2" @click="showDeleteButton(false)"><i class="el-icon-d-arrow-left"></i></div>
     </template>
      <el-table :data="tableData" stripe :show-summary="showSummary" ref="tableDataRef" :span-method="objectSpanMethod" border :style="'width: 100%;' + Styles" :cell-style="cellStyle" :header-cell-style="headerCellStyle">
        <slot></slot>
      </el-table>
   </div>
</template>

<script>
var that;
export default {
  name: 'TableBox',
  props: {
    tableData: {
      type: Array,
      default:()=>{
        return []
      }
    },
    headerCellStyle:{
      type:Object,
      default:()=>{
        return {background: '#ECF5FF'}
      }
    },
    cellStyle:{
      type:Object,
      default:()=>{
        return {}
      }
    },
    Styles:{
      type:String,
      default:'',
    },
    objectSpanMethod:{
      type:Function,
      default:()=>{
        return {}
      }
    },
    showSummary:{
      type:Boolean,
      default:false
    },
    isShowYd:{
      type:Boolean,
      default:false
    },
  },
  data() {
    return {
    };
  },
  watch: {
    tableData(){
      this.$nextTick(()=>{
        this.$refs.tableDataRef.doLayout()
      })
    }
  },
  methods:{
    showDeleteButton(is){
        let dome = this.$refs.tableDataRef.bodyWrapper
        let maxWidth=dome.scrollWidth-dome.offsetWidth
        if(is){
          if(dome.scrollLeft>=maxWidth){
            return false
          }
          let interval=setInterval(()=>{
            dome.scrollLeft+=10;
            if(dome.scrollLeft>=maxWidth){
              clearInterval(interval)
            }
          },10);
        }else{
          if(dome.scrollLeft<=0){
            return false
          }
          let interval=setInterval(()=>{
            dome.scrollLeft-=10;
            if(dome.scrollLeft<=0){
              clearInterval(interval)
            }
          },10);
        }

    },
  }
};
</script>

<style scoped="scoped" lang="scss">
.rightBtn{
  position: absolute;
  right: -10px;
  width: 40px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  background-color: #999;
  color: #fff;
  box-shadow: 0 0 3px #ccc;
  top: 50%;
  margin-top: -20px;
  z-index: 999;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.rightBtn2{
  position: absolute;
  left: -10px;
  width: 40px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  background-color: #999;
  color: #fff;
  box-shadow: 0 0 3px #ccc;
  top: 50%;
  margin-top: -20px;
  z-index: 999;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.el-table__body {
    width: 100%;
    table-layout: fixed !important;
}
.table-box{
   padding: 20px 0;
   width: 100%;
   position: relative;
   transition: all 3s;
  ::v-deep .el-table__body{
    box-sizing: border-box;
    overflow: hidden;
    width: 100%;
    table-layout: fixed !important;
  }
  ::v-deep th .cell {
    color: #989898;
    font-size: 14px;
    overflow: hidden;
  }
  ::-webkit-scrollbar {
    width: 6px;
    height: 10px;
  }
  /*外层轨道。可以用display:none让其不显示，也可以添加背景图片，颜色改变显示效果*/
  ::-webkit-scrollbar-track {
    width: 6px;
    background-color: #fff0;
    border-radius: 2em;
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    -o-border-radius: 2em;
    -ms-border-radius: 2em;
  }
  /*滚动条的设置*/
  ::-webkit-scrollbar-thumb {
    background-color: #fff0;
    background-clip: padding-box;
    min-height: 28px;
    border-radius: 2em;
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    -o-border-radius: 2em;
    -ms-border-radius: 2em;
  }
  ::-webkit-scrollbar-thumb {
    background-color: rgba(144, 147, 153, 0.3);
  }
}
</style>
