<template>
  <div class="flex h-full w-full flex-col gap-2" v-loading="loading">
    <div class="flex w-full items-center justify-between">
      <div class="title">
        {{ title }}
      </div>
      <div class="flex gap-4">
        <el-button type="primary" size="small" @click="handleExport"
          >导出</el-button
        >

        <el-select
          v-if="type == 'business'"
          size="small"
          filterable
          v-model="form.businessName"
          placeholder="请选择业务"
          clearable
        >
          <el-option
            v-for="v in businessList"
            :key="v.id"
            :label="v.businessName"
            :value="v.businessName"
          >
          </el-option>
        </el-select>
        <el-select
          v-else-if="type == 'dept'"
          size="small"
          filterable
          v-model="form.deptName"
          placeholder="请选择部门"
          clearable
        >
          <el-option
            v-for="v in deptList"
            :key="v.id"
            :label="v.name"
            :value="v.name"
          >
          </el-option>
        </el-select>
        <el-select
          v-else-if="type == 'window'"
          size="small"
          filterable
          v-model="form.windowNum"
          placeholder="请选择窗口"
          clearable
        >
          <el-option
            v-for="v in windowList"
            :key="v.id"
            :label="v.name + '-' + v.fromnum"
            :value="v.fromnum"
          >
          </el-option>
        </el-select>
        <el-button
          type="primary"
          size="small"
          v-if="type != 'hall'"
          @click="handleSearch"
          >搜索</el-button
        >
      </div>
    </div>
    <div
      :class="[
        'w-full',
        'grid',
        data.length > 5 ? 'grid-cols-2' : 'grid-cols-1',
      ]"
    >
      <y-table
        size="small"
        border
        :column="leftColumn"
        :data="letTableData"
      ></y-table>
      <y-table
        v-show="data.length > 5"
        size="small"
        border
        :column="rightColumn"
        :data="rightTableData"
      ></y-table>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import storage from "@/utils/storage";
export default {
  props: {
    data: {
      required: true,
      type: Array,
      default: () => [],
    },
    type: {
      required: true,
      type: String,
      default: "",
    },
    loading: {
      type: Boolean,
      default: false,
    },
    current: {
      required: true,
      type: Number,
      default: 1,
    },
    size: {
      required: true,
      type: Number,
      default: 10,
    },
    column: {
      required: true,
      type: Array,
      default: () => [],
    },
    title: {
      required: true,
      type: String,
      default: "",
    },
    border: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      searchVal: "",
      siteId: storage.get(2, "siteId"),
      form: {
        businessName: "",
        deptName: "",
        windowNum: "",
      },
    };
  },
  computed: {
    ...mapState("user", ["businessList", "deptList", "windowList"]),
    leftColumn() {
      let index = {
        label: "排序",
        type: "index",
        align: "center",
        index: (index) => {
          return (this.current - 1) * this.size + index + 1;
        },
      };
      return [index, ...this.column];
    },
    rightColumn() {
      let index = {
        label: "排序",
        type: "index",
        align: "center",
        index: (index) => {
          return (this.current - 1) * this.size + index + 6;
        },
      };
      return [index, ...this.column];
    },
    letTableData() {
      let arr = this.data.slice(0, 5);
      if (arr.length) {
        while (arr.length < 5) {
          arr.push(null);
        }
      }
      return arr;
    },
    rightTableData() {
      let arr = this.data.slice(5, 10);
      if (arr.length) {
        while (arr.length < 5) {
          arr.push(null);
        }
      }
      return arr;
    },
  },
  created() {},
  methods: {
    handleSearch() {
      this.$emit("search", this.type, this.form);
    },
    handleExport() {
      this.$emit("export", this.type, this.form);
    },
  },
};
</script>

<style lang="less" scoped>
.title {
  font-weight: 600;
}
:deep(.el-table__header-wrapper) {
  th {
    background: #e6f1f9;
  }
}
:deep(.el-table) {
  border-color: #dfe9f2 !important ;
  th {
    border-color: #dfe9f2 !important ;
  }
}
</style>
