<template>
  <div>
    <el-dialog title="请选择材料加入公共库" :visible.sync="Visible" width="50%">
      <TableHeader>
        <div slot="right" class="flex">
          <el-select
            v-model="department"
            class="autoWidth"
            size="small"
            placeholder="选择部门"
          >
            <template slot="prefix">
              {{ (deptList.find((v) => v.id === department) || {}).name }}
            </template>
            <el-option
              v-for="item in deptList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
          <el-input
            size="small"
            v-model="searchVal"
            style="width: 200px"
            class="ml10 mr10"
            placeholder="请输入事项名称搜索"
          ></el-input>
          <el-button size="small" type="primary" @click="handleSarch"
            >搜索</el-button
          >
          <el-button size="small" @click="resetSearch">重置</el-button>
        </div>
      </TableHeader>
      <el-table
        ref="multipleTable"
        size="small"
        :data="tableData"
        border
        tooltip-effect="dark"
        style="width: 100%"
        max-height="500px"
        :row-key="(row) => row.id"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column
          type="index"
          label="序号"
          width="55"
          align="center"
          :index="(index) => (current - 1) * size + index + 1"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          label="部门"
          align="center"
          prop="department"
          width="80"
        >
        </el-table-column>
        <el-table-column prop="name" show-overflow-tooltip label="材料名称">
          <template slot-scope="scope">
            <p class="short">{{ scope.row.name }}</p>
            <p class="full-name">材料全称：{{ scope.row.name2 }}</p>
          </template>
        </el-table-column>
        <el-table-column
          prop="time"
          label="添加时间"
          align="center"
          width="140"
        >
        </el-table-column>
      </el-table>
      <Pagination
        :total="total"
        :current="current"
        :size="size"
        @currentChange="changePagination"
        @sizeChange="changeSize"
      ></Pagination>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="handleOk"
          >加 入</el-button
        >
        <el-button size="small" @click="Visible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import TableHeader from "@/components/TableHeader.vue";
import Pagination from "@/components/Pagination.vue";
import { mapGetters } from "vuex";
export default {
  components: {
    TableHeader,
    Pagination,
  },
  props: {
    libVisible: {
      type: Boolean,
      required: true,
      default: false,
    },
    depList: {
      type: Array,
      required: true,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      department: "",
      searchVal: "",
      tableData: [],
      current: 1,
      total: 10,
      size: 10,
    };
  },
  computed: {
    Visible: {
      get() {
        return this.libVisible;
      },
      set(val) {
        this.$emit("update:libVisible", val);
      },
    },
    ...mapGetters(["deptList"]),
  },
  methods: {
    handleOk() {
      console.log(11);
    },
    handleSarch() {
      console.log(11);
    },
    resetSearch() {
      this.department = "";
      this.searchVal = "";
    },
    changePagination(cur) {
      this.current = cur;
    },
    changeSize(size) {
      this.size = size;
    },
    handleSelectionChange(select) {
      console.log(select);
    },
  },
};
</script>

<style lang="less" scoped>
.short {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.full-name {
  color: rgb(172, 170, 170);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>