<template>
  <el-button size="mini" @click="drawer = true">
    {{ number ? `隐藏列 ：${number}` : "隐藏列" }}
    <el-drawer
      :modal="false"
      :visible.sync="drawer"
      size="20%"
      title="隐藏列"
      append-to-body
    >
      <el-input
        v-model="key"
        size="mini"
        placeholder="请输入列名称"
        style="width: 100%; padding: 0 16px 16px"
      >
      </el-input>
      <el-row :gutter="20" style="margin: 0">
        <el-draggable
          v-model="columns"
          :group="{ item: 'key' }"
          @end="$emit('hide')"
        >
          <el-col
            v-for="({ item }, index) in searchColumns"
            :key="index"
            :span="24"
            style="
              display: flex;
              justify-content: space-between;
              padding: 12px 16px;
            "
          >
            <span
              style="
                font-size: 13px;
                flex: 1;
                cursor: move;
                padding: 0 12px 0 0;
                text-overflow: ellipsis;
                overflow: hidden;
                word-break: break-all;
                white-space: nowrap;
              "
            >
              <i
                class="el-icon-mouse"
                style="color: #72767b; margin: 0 6px 0 0"
              ></i>
              <i
                class="el-icon-user"
                style="color: #72767b; margin: 0 6px 0 0"
              ></i>
              {{ item.title }}
            </span>
            <div>
              <el-switch
                v-model="item.hidden"
                size="mini"
                @change="$emit('hide')"
              ></el-switch>
            </div>
          </el-col>
        </el-draggable>
      </el-row>
    </el-drawer>
  </el-button>
</template>

<script>
export default {
  name: "",
  components: {
    ElDraggable: () => import("@/components/draggable/index.vue"),
  },
  props: {
    value: {
      type: Array,
      require: true,
    },
  },
  data() {
    return {
      drawer: false,
      key: "",
    };
  },
  computed: {
    columns: {
      get() {
        return this.$props.value;
      },
      set(value) {
        this.$emit("input", value);
      },
    },
    searchColumns: {
      get() {
        return this.columns.filter(
          ({ item }) => item.title.indexOf(this.key) > -1
        );
      },
      set(value) {},
    },
    number: {
      get() {
        return this.columns.filter(({ item }) => !item.hidden).length;
      },
      set(value) {},
    },
  },
  watch: {},
  methods: {},
  created() {},
  mounted() {},
  destroyed() {},
};
</script>
<style scoped></style>
