<script>
export default {
  name: "AppKgTable",
  label: "表格",
  components: {
    tableColumn: {
      functional: true,
      props: {
        column: {default: () => ({})}
      },
      render(h, vm) {
        const config = vm.props.column
        return h('el-table-column', {props: config}, h('template', {
          slotScope: {
            default: ({row}) => {
              config.custom ? h('div', {style: {color: row.preSaleNum > row.stockNum ? 'red' : '#fff'}}, '周边库存情况') :
                  config.children?.map(col => h('table-column', {props: {column: col}})) || h('span', row[config.prop] || '')
            }
          }
        }))
      },
    }
  },
  data() {
    return {
      tableData: [
        {name: "商品1", targetNum: 100, saleNum: 50, stockNum: 20, preSaleNum: 30, remind: 1},
        {name: "商品2", targetNum: 100, saleNum: 50, stockNum: 20, preSaleNum: 30, remind: 0},
        {name: "商品3", targetNum: 100, saleNum: 50, stockNum: 20, preSaleNum: 30, remind: 1},
      ],
      columns: [
        {label: "重点单品", prop: "name"},
        {label: "当日目标", prop: "targetNum", width: "70px"},
        {label: "销售数量", prop: "saleNum", width: "70px"},
        {label: "库存数量", prop: "stockNum", width: "70px"},
        {label: "预计销售数量", prop: "preSaleNum"},
        {
          label: "合并表头示例", children: [
            {"label": "当日目标", "prop": "targetNum", "width": "70px"},
            {"label": "销售数量", "prop": "saleNum", "width": "70px"},
          ]
        },
        {label: "提醒", custom: 1, width: 70, align: 'center', prop: "remind"},
      ]
    }
  }
}
</script>

<template>
  <section class="AppKgTable">
    <div class="subTiltle" v-text="'表格标题'"/>
    <el-table :data="tableData" size="mini" header-cell-class-name="tableHeader" cell-class-name="tableCell" max-height="440px" show-summary stripe>
      <table-column v-for="(column,i) in columns" :key="i" :column="column"/>
    </el-table>
  </section>
</template>

<style>
.AppKgTable {
  color: #fff;
  box-sizing: border-box;
}

.AppKgTable .tableHeader {
  background: rgba(13, 48, 99, 0.6) !important;
  color: #fff;
  border-color: transparent !important;
}

.AppKgTable .el-table tr {
  background-color: transparent !important;
}

.AppKgTable .el-table {
  background: transparent;
  border-color: transparent;
}

.AppKgTable .el-table .el-table__footer-wrapper tr {
  background: linear-gradient(90deg, rgba(1, 196, 236, 0.5) 0%, rgba(1, 196, 236, 0.01) 100%);
}

.AppKgTable .el-table .el-table__footer-wrapper .is-leaf {
  color: #66FFFF;
  background: transparent;
  border-color: transparent;
}

.AppKgTable .el-table:before {
  background: transparent;
}

.AppKgTable .tableCell {
  color: #fff;
  border-color: transparent !important;
}

.AppKgTable .el-table tr.el-table__row--striped {
  --odd-bg: #09265B;
  background-color: #081F48;
  background-image: linear-gradient(
      -45deg, var(--odd-bg) 0, var(--odd-bg) 10%, transparent 10%, transparent 50%,
      var(--odd-bg) 50%, var(--odd-bg) 60%, transparent 60%, transparent);
  background-size: 10px 10px;
}

.AppKgTable .el-table tr.el-table__row--striped .tableCell {
  background-color: transparent !important;
}

.AppKgTable .el-table tr:hover > .tableCell {
  background-color: rgba(255, 255, 255, .1) !important;
}

.AppKgTable .subTiltle {
  line-height: 20px;
  width: fit-content;
  margin: 24px auto 12px;
  background-image: url("http://10.0.97.209/img/kengee/kengee5.png");
  background-repeat: no-repeat;
  background-size: 100% 2px;
  background-position: center bottom;
}
</style>
