<template>
  <div class="library-manage">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="clearfix">
        <span>公共库管理</span>
      </div>
      <TableHeader>
        <div slot="left">
          <el-button size="small" type="primary" @click="handleAddMaterials"
            >加入材料</el-button
          >
          <el-button size="small" type="danger" @click="handleDelAll"
            >批量移除</el-button
          >
        </div>
        <div slot="right" class="flex">
          <el-select v-model="department" size="small" placeholder="选择部门">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input
            size="small"
            v-model="searchVal"
            class="ml10 mr10"
            placeholder="请输入事项名称搜索"
          ></el-input>
          <el-button size="small" type="primary" @click="handleSearch"
            >搜索</el-button
          >
          <el-button size="small" @click="handleReset">重置</el-button>
        </div>
      </TableHeader>
      <!-- 表格 -->
      <div class="table-content">
        <el-table
          ref="multipleTable"
          size="small"
          :data="tableData"
          border
          tooltip-effect="dark"
          style="width: 100%"
          max-height="550px"
          :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="150"
          >
          </el-table-column>
          <el-table-column label="操作" align="center" width="100">
            <template slot-scope="scope">
              <div class="flex jca">
                <span class="primary pointer" @click="handlePreview(scope.row)"
                  >预览</span
                >
                <span class="delete pointer" @click="handleDel(scope.row.id)"
                  >移除</span
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <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>
    </el-card>
    <!-- 添加材料 -->
    <AddMaterals
      ref="AddMaterals"
      :depList="depList"
      :libVisible.sync="libVisible"
    ></AddMaterals>
    <!-- 材料预览 -->
    <PreviewMaterals
      :materalsInfo="materalsInfo"
      :previewVisible.sync="previewVisible"
    ></PreviewMaterals>
  </div>
</template>

<script>
import TableHeader from "@/components/TableHeader.vue";
import AddMaterals from "./modal/AddMaterals.vue";
import PreviewMaterals from "./modal/PreviewMaterals.vue";
export default {
  components: {
    TableHeader,
    AddMaterals,
    PreviewMaterals,
  },
  data() {
    return {
      department: "",
      options: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
        {
          value: "选项3",
          label: "蚵仔煎",
        },
        {
          value: "选项4",
          label: "龙须面",
        },
        {
          value: "选项5",
          label: "北京烤鸭",
        },
      ],
      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",
        },
      ],
      current: 1,
      size: 10,
      total: 10,
      pageSizes: [10, 20, 30, 40, 50, 100, 200],
      selectKeys: [],
      depList: [],
      libVisible: false,
      materalsInfo: {},
      previewVisible: false,
    };
  },
  methods: {
    // 加入材料
    handleAddMaterials() {
      this.libVisible = true;
    },
    // 批量移除
    handleDelAll() {
      if (!this.selectKeys.length) {
        this.$message.warning("请先勾选数据");
        return;
      }
    },
    // 搜索
    handleSearch() {
      console.log(11);
    },
    // 重置
    handleReset() {
      this.department = "";
      this.searchVal = "";
    },
    // 选中
    handleSelectionChange(select) {
      this.selectKeys = select;
    },
    // 翻页
    changePagination(cur) {
      this.current = cur;
    },
    // 改变没有显示数量
    changeSize(size) {
      this.size = size;
    },
    // 预览
    handlePreview(row) {
      this.materalsInfo = row;
      this.previewVisible = true;
    },
    // 移除
    handleDel(id) {
      this.$confirm(
        "此操作将从公共库中移除该材料信息，是否继续？",
        "系统提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          cancelButtonClass: "btn-custom-cancel",
          type: "warning",
        }
      )
        .then(async () => {
          console.log(id);
        })
        .catch(() => {
          console.log("取消成功！");
        });
    },
  },
};
</script>

<style lang="less" scoped>
.library-manage {
  width: 100%;
  height: 100%;
  .short {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .full-name {
    color: rgb(172, 170, 170);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .table-content {
    height: 550px;
  }
}
</style>