<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>
      <div class="pagination" v-if="total">
        <el-pagination
          background
          layout="total,sizes,prev,pager,next,jumper"
          :pager-count="5"
          :total="total"
          :current-page="current"
          :page-size="size"
          :page-sizes="pageSizes"
          @current-change="changePagination"
          @size-change="changeSize"
        >
        </el-pagination>
      </div>
      <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 { mapGetters } from "vuex";
export default {
  components: {
    TableHeader,
  },
  props: {
    libVisible: {
      type: Boolean,
      required: true,
      default: false,
    },
    depList: {
      type: Array,
      required: true,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      department: "",
      searchVal: "",
      tableData: [
        {
          id: 1,
          department: "县公安局",
          name: "机动车登记证、行使证核发",
          name2: "机动车登记证、行驶证审查、办理、核发",
          count: 50,
          top: 1,
          time: "2022-12-12 12:00:00",
        },
        {
          id: 2,
          department: "县公安局",
          name: "机动车登记证、行使证核发",
          name2: "机动车登记证、行驶证审查、办理、核发",
          count: 50,
          top: 0,
          time: "2022-12-12 12:00:00",
        },
      ],
      pageSizes: [10, 20, 30, 40, 50, 100, 200],
      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>