<!--
 * @Author: zhp
 * @Date: 2024-03-26 09:20:18
 * @LastEditTime: 2024-03-26 09:20:18
 * @LastEditors: zhp
 * @Description:
-->
<template>
  <div class="visual-base-table-container scroll_table">
    <div style="display: inline-block; width: 100%">
      <el-table class="top" v-loading="isLoading"
        :header-cell-style="{ background: 'rgba(32, 55, 96, 1)', color: '#fff', height: '33px', }"
        :row-style="setRowStyle" :data="renderData" border style="width: 100%; background: transparent">
        <el-table-column prop="_pageIndex" label="序号" :width="50" align="center" />
        <el-table-column v-for="item in renderTableHeadList" :key="item.prop" :show-overflow-tooltip="showOverflow"
          v-bind="item">
          <template slot-scope="scope">
            <component :is="item.subcomponent" v-if="item.subcomponent" :inject-data="{...scope.row, ...item}"
              @emitData="emitData" />
            <span v-else>{{ scope.row[item.prop] | commonFilter(item.filter) }}</span>
          </template>
        </el-table-column>
        <slot name="content" />
      </el-table>
      <vue-seamless-scroll :data="renderData" class="seamless-warp" style="width: 100%" :class-option="classOption">
        <el-table class="bottom" v-loading="isLoading"
          :header-cell-style="{background:'rgba(4, 74, 132, .19)',color:'#fff',}" :row-style="setRowStyle"
          :data="renderData" border style="width: 100%; background: transparent">
          <el-table-column prop="_pageIndex" label="序号" :width="50" align="center" />
          <el-table-column v-for="item in renderTableHeadList" :key="item.prop" :show-overflow-tooltip="showOverflow"
            v-bind="item">
            <template slot-scope="scope">
              <component :is="item.subcomponent" v-if="item.subcomponent" :inject-data="{...scope.row, ...item}"
                @emitData="emitData" />
              <span v-else>{{ scope.row[item.prop] | commonFilter(item.filter) }}</span>
            </template>
          </el-table-column>
          <slot name="content" />
        </el-table>
      </vue-seamless-scroll>
    </div>
  </div>
</template>
<script>
import { isObject, isString } from 'lodash'
export default {
  name: 'BaseTable',
  filters: {
    commonFilter: (source, filterType = a => a) => {
      return filterType(source)
    }
  },
  props: {
    tableData: {
      type: Array,
      required: true,
      validator: val => val.filter(item => !isObject(item)).length === 0
    },
    tableConfig: {
      type: Array,
      required: true,
      validator: val => val.filter(item => !isString(item.prop) || !isString(item.label)).length === 0
    },
    isLoading: {
      type: Boolean,
      required: false
    },
    page: {
      type: Number,
      required: false,
      default: 1
    },
    limit: {
      type: Number,
      required: false,
      default: 5
    },
    beilv: {
      type: Number,
      default: 1
    },
    showOverflow: {
      type: Boolean,
      default: true
    },
    showIndex: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      tableConfigBak: [],
      selectedBox: new Array(100).fill(true)
    }
  },
  computed: {
    renderData() {
      if (this.tableData.length && !this.tableData[0]._pageIndex) {
        this.tableData.forEach((item, index) => {
          item._pageIndex = (this.page - 1) * this.limit + index + 1
        })
      }
      return this.tableData.slice((this.page - 1) * this.limit, this.page * this.limit)
    },
    renderTableHeadList() {
      return this.tableConfig.filter((item, index) => {
        return this.selectedBox[index]
      })
    },
    classOption() {
      return {
        step: 0.2, // 数值越大速度滚动越快
        limitMoveNum: 10, // 开始无缝滚动的数据量 this.list
        hoverStop: true, // 是否开启鼠标悬停stop
        direction: 1, // 0向下 1向上 2向左 3向右
        openWatch: true, // 开启数据实时监控刷新dom
        singleHeight: 0/1, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
        singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
        waitTime: 1000, // 单步运动停止的时间(默认值1000ms)
      };
    },
  },
  beforeMount() {
    this.selectedBox = new Array(100).fill(true)
  },
  methods: {
    emitData(val) {
      this.$emit('emitFun', val)
    },
    setRowStyle(v) {
      if (v.rowIndex % 2 === 0) {
        return {
          background: 'rgba(14, 32, 62, 1)',
          color: 'rgba(255,255,255,0.5)',
          height: 26  + 'px',
          lineHeight: 26 + 'px',
          padding: 0,
          fontSize: 12  + 'px'
        }
      } else {
        return {
          background: 'rgba(32, 55, 96, 1)',
          color: 'rgba(255,255,255,0.5)',
          height: 26  + 'px',
          lineHeight: 26  + 'px',
          padding: 0,
          fontSize: 12  + 'px'
        }
      }
    },
    setCellStyle() {
      return {
        // lineHeight: 23  + 'px'
      }
    }
  }
}
</script>
<style lang="scss">
// @import "../styles/index.scss";
.visual-base-table-container {
  .el-table {
    border: 0;
  }
  .el-table::before,.el-table--border::after {
    background-color: transparent;
  }
  .el-table th,td{
    border-color: #0D1728 !important;
    padding: 0;
  }
  .el-table tr {
    background: transparent;
  }
  .el-table__row:hover > td {
    background-color: rgba(79,114,136,0.29) !important;
    }

  .el-table__row--striped:hover > td {
    background-color: rgba(79,114,136,0.29) !important;
  }
}
</style>

<style lang="scss">
 .seamless-warp {
  height: 308px;
  overflow: hidden;
}
 .min {
  display: flex;
  width: 100%;
}
 .top  .el-table__body-wrapper {
  display: none;
}
 .bottom .el-table__header-wrapper {
  display: none;
  width: 100%;
}

</style>
