<template>
  <div class="uni-flex jccenter aicenter pb10  ">
    <div class="f16 strong "> {{tableHead.title}} <slot name="title"></slot>
    </div>
    <div class="uni-flex uni-flex-item jcend relative ">
      <template v-for="(item,index) in tableHead.item">
        <div v-if="item.type=='search'" :key="index" class=" mr5">
          <el-input size="medium" @input="item.done(data)" clearable :placeholder="'请输入'+(item.label===undefined ? '内容':item.label) " v-model="data[item.keyword]" class="input-with-select">
            <el-button slot="append" @click="item.done(data)" icon="el-icon-search"></el-button>
          </el-input>
        </div>
        <div v-if="item.type=='icon'" @click="item.done()" :key="index" class="bt cursor uni-flex jccenter aicenter mx5">
          <span :class="item.icon" class="c666 f22"></span>
        </div>
        <!-- 显示Column -->
        <div :key="index" v-if="item.type=='column'" class="relative">
          <div @click="isColumn=!isColumn" class="bt  cursor uni-flex jccenter aicenter mx5">
            <span :class="item.icon" class="c666 f22"></span>
          </div>
          <div v-if='isColumn' class="column shadow p10 bfff">
            <span @click="isColumn=!isColumn" class="close cursor p5 el-icon-close"></span>
            <el-checkbox-group v-model="checkList" @change="handleColumn">
              <template v-for="item2 in temColumn">
                <el-checkbox class=" pb10" :key="item2.label" :label="item2.label"></el-checkbox>
              </template>
            </el-checkbox-group>
          </div>
        </div>
        <!-- 显示button -->
        <div v-if="item.type=='button'" @click="item.done()" :key="index" class=" cursor uni-flex jccenter aicenter mx5 ">
          <el-button icon='el-icon-plus' type="primary" @click="item.done(keyWord)">{{item.name}}</el-button>
        </div>
      </template>
    </div>
    <!-- <el-drawer title="选择显示列" :visible.sync="isColumn" direction="rtl" size="500px" append-to-body>
      <div class="p20 f16">
        <el-checkbox-group v-model="checkList">
          <template v-for="item in temColumn">
            <el-checkbox class=" pb10" :key="item.prop" :label="item.prop">{{item.label}}</el-checkbox>
          </template>
        </el-checkbox-group>
      </div>
      <div class="fixbottom uni-flex py10 pl20  ">
        <el-button size='default' @click="isColumn = false">取消</el-button>
        <el-button size='default' type="primary" @click="handleColumn">确定</el-button>
      </div>
    </el-drawer> -->
  </div>
</template>

<script>
export default {
  name: "mgTableHead",
  props: {
    tableHead: {
      type: Object,
      default: {
        title: "列表展示",
      },
    },
    // 表格列配置
    column: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      isColumn: false,
      data: {},
      checkList: [], //已经选择的列
      temColumn: [], //备份原始column
    };
  },
  computed: {},
  created() {
    this.temColumn = JSON.parse(JSON.stringify(this.column));
    this.checkList = this.temColumn.map((item) => item.label);
  },
  methods: {
    init() {
      this.data = {};
    },
    handleColumn() {
      let temp = [];
      this.checkList.forEach((item) => {
        this.temColumn.forEach((item2, index) => {
          if (item2.label === item) {
            temp.splice(index, 1, item2);
          }
        });
      });
      this.$emit("setcolumn", temp);
    },
  },
};
</script>

<style lang="less" scoped>
.column {
  position: absolute;
  top: 45px;
  right: 0;
  z-index: 999;
  border-radius: 6px;
  padding-right: 20px;
  .close {
    position: absolute;
    right: 0;
    top: 0;
    font-size: 18px !important;
  }
}
</style> 