<template>
  <div>
    <div style="margin-bottom: 10px; display: flex; align-items: center">
      <el-input
        class="input_content"
        placeholder="请输入内容"
        v-model="sourceList.pagination.keyword"
        style="width: 90%"
        clearable
        size="small"
      ></el-input>
      <div style="text-align: center; width: 10%">
        <el-icon style="cursor: pointer" @click="getList"><Search /></el-icon>
      </div>
    </div>
    <el-row>
      <el-col :span="11" style="border-right: 1px solid #d7d7d7">
        <div class="mulu">
          <el-tree
            :data="treeListData"
            :props="{ label: 'name', children: 'netdiskList' }"
            ref="tree"
            node-key="id"
            @node-click="treeChange"
            default-expand-all
            :expand-on-click-node="false"
          ></el-tree>
        </div>
      </el-col>
      <el-col :span="13" style="padding: 0 5px">
        <el-table
          :data="sourceList.data"
          style="width: 100%"
          v-loading="loading"
          :height="tableHeight"
        >
          <el-table-column prop="name" label="文件名" />
          <el-table-column
            prop="createTime"
            label="上传时间"
            width="80"
            align="center"
          >
            <template #default="{ row }">
              <el-tooltip
                class="box-item"
                effect="dark"
                :content="row.createTime"
                placement="top"
              >
                <!-- <span
                  class="iconfont icon-iconx_kehd"
                  style="cursor: pointer; font-size: 18px"
                ></span> -->
                <el-icon :size="20" style="cursor: pointer"><Timer /></el-icon>
              </el-tooltip>
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="操作"
            width="60"
            fixed="right"
            align="center"
            v-if="isShowBtn"
          >
            <template #default="{ row }">
              <el-button type="primary" text @click="handleClickRow(row)"
                ><i class="iconfont icon-iconm_wofqd"></i
              ></el-button>
            </template>
          </el-table-column> -->
        </el-table>

        <el-pagination
          style="margin-top: 10px"
          v-model:current-page="sourceList.pagination.pageNum"
          :page-size="10"
          layout="total, prev, pager, next"
          :total="sourceList.pagination.total"
          prev-text="上一页"
          next-text="下一页"
          @current-change="handleCurrentChange"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import useMailStore from "@/store/modules/mail";
const mailStore = useMailStore();
const isShowBtn = ref(false);
mailStore.$subscribe((mutations, state) => {
  if (state.currentId.includes("write")) {
    isShowBtn.value = true;
  } else {
    isShowBtn.value = false;
  }
});
const loading = ref(false);
const sourceList = ref({
  data: [],
  pagination: {
    total: 300,
    pageNum: 1,
    pageSize: 10,
    keyword: "",
  },
});
const treeListData = ref([]);
const tableHeight = ref(0);
const getTableHeight = () => {
  tableHeight.value = window.innerHeight - 250;
};
getTableHeight();
window.addEventListener("resize", () => {
  getTableHeight();
});
const statusData = ref([
  {
    label: "草稿",
    value: 0,
  },
  {
    label: "审批中",
    value: 10,
  },
  {
    label: "驳回",
    value: 20,
  },
  {
    label: "通过",
    value: 30,
  },
  {
    label: "终止",
    value: 99,
  },
]);
const { proxy } = getCurrentInstance();
const getList = (req) => {
  loading.value = true;
  proxy.post("/netdisk/page", sourceList.value.pagination).then((res) => {
    sourceList.value.data = res.rows;
    sourceList.value.pagination.total = res.total;
    setTimeout(() => {
      loading.value = false;
    }, 200);
  });
};

const handleCurrentChange = (val) => {
  sourceList.value.pagination.pageNum = val;
  getList();
};

const treeChange = (e) => {
  sourceList.value.pagination.parentFolderId = e.id;
  sourceList.value.pagination.pageNum = 1;
  getList();
};

const getTreeList = () => {
  proxy.get("/netdisk/tree", {}).then((res) => {
    treeListData.value = res.data;
    console.log(treeListData.value, "ada");
  });
};
getTreeList();
getList();

const handleClickRow = (row) => {
  console.log(row, "ada");
};
</script>

<style lang="scss" scoped>
* {
  font-size: 12px;
}
.el-button {
  padding: 0px;
}
.btn {
  width: 100%;
  border-radius: 10px;
  padding: 6px 10px;
  height: 24px;
}
.el-pagination {
  padding-left: 30px;
}
:deep(.el-pagination button, .el-pager li) {
  font-size: 12px;
}
:deep(.el-table .el-table__cell) {
  padding: 2px 0px;
}
</style>
<style lang="scss">
.mulu {
  width: 100%;
  // padding: 0 5px;
  height: calc(100vh - 50px - 50px - 10px - 30px - 28px - 46px - 35px - 24px);
  overflow-y: auto;
  overflow-x: auto;
  .el-tree {
    .el-tree-node.is-expanded > .el-tree-node__children {
      overflow: visible;
    }
    .el-tree-node > .el-tree-node__children {
      overflow: visible;
    }

    .el-tree-node__content {
      height: 26px !important;
    }
  }
}
</style>