<template>
  <div class="project-list flex-row jcsb">
    <div class="left">
      <div style="margin-bottom: 20px">人员绩效表</div>
      <el-tree
        :data="deptOptions"
        :props="defaultProps"
        :expand-on-click-node="false"
        :filter-node-method="filterNode"
        ref="tree"
        node-key="id"
        default-expand-all
        highlight-current
        @node-click="handleNodeClick"
      />
    </div>
    <div class="right f1">
      <div class="search-bar">
        <el-form
          :inline="true"
          :model="searchForm"
          class="demo-form-inline"
          size="small"
        >
          <el-form-item label="统计任务" class="form-item"> </el-form-item>
        </el-form>
      </div>
      <div class="f1 df">
        <CustomTable
          :columns="columns"
          :tableData="tableData"
          :total="total"
          :show-selection="false"
          :show-index="true"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          tableHeight="495px"
        >
          <template slot="operation" slot-scope="{ row }">
            <div class="operation-buttons">
              <el-button
                type="text"
                size="mini"
                icon="el-icon-view"
                @click="handleEdit(row, 0)"
                >查看详情</el-button
              >
            </div>
          </template>
        </CustomTable>
      </div>
    </div>
  </div>
</template>

<script>
import CustomTable from "@/components/CustomTable.vue";
import SelectUser from "@/components/SelectUser.vue";
import { projectApi, systemApi } from "@/utils/api";
import { deptTreeSelect } from "@/api/system/user";

export default {
  components: {
    CustomTable,
    SelectUser,
  },
  data() {
    return {
      deptOptions: undefined,
      searchForm: {
        projectName: "",
      },
      columns: [
        { prop: "projectName", label: "考核人员" },
        { prop: "projectCode", label: "考核评分", sortable: true },
        {
          prop: "projectState",
          label: "状态",
          type: "status",
          callback: (value) => {
            if (value == 1) var color = "#333";
            else var color = "#1686d68";

            return `<span style="color: ${color}">${value}</span>`;
          },
        },
        {
          prop: "operation",
          label: "操作",
          width: "250",
          className: "operation-column",
        },
      ],
      tableData: [],
      total: 0,
      currentSelectedUser: [],
      pageNum: 1, // 当前页码
      pageSize: 10, // 每页条数
      statusList: [
        { label: "全部", value: "" },
        { label: "待评分", value: "0" },
        { label: "已完成", value: "1" },
      ],
    };
  },
  methods: {
    onSearch() {
      this.fetchProjectList();
    },
    onReset() {
      Object.keys(this.searchForm).forEach((key) => {
        this.searchForm[key] = "";
      });
      this.fetchProjectList();
    },
    handleEdit(row, edit) {
      this.$router.push({
        path: "/projectBank/userScoreDetail",
        query: { id: row.id, edit },
      });
    },
    fetchProjectList() {
      projectApi
        .listProject({
          ...this.searchForm,
          pageNum: this.pageNum,
          pageSize: this.pageSize,
        })
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
        });
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.pageNum = 1; // 重置为第一页
      this.fetchProjectList();
    },
    handleCurrentChange(page) {
      this.pageNum = page;
      this.fetchProjectList();
    },
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
  },
  mounted() {
    this.getDeptTree();

    this.fetchProjectList();
  },
};
</script>

<style lang="scss" scoped>
.project-list {
  padding: 20px;
  background-color: white;
  height: 88vh;
  box-sizing: border-box;
  overflow: hidden;
  align-items: flex-start;
  gap: 20px;
  .left {
    padding-top: 20px;
    width: 300px;
    height: 100%;
    box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5); /* 阴影效果 */
  }
  .right {
    padding-top: 20px;
  }
}

.search-bar {
  margin-bottom: 20px;
}

.demo-form-inline {
  // display: flex;
  // flex-wrap: nowrap;
  // align-items: flex-start;
}

.demo-form-inline .el-form-item {
  // margin-right: 50px; /* 将间距设置为 30px */
  margin-bottom: 0;
}

.demo-form-inline .el-form-item:last-child {
  margin-right: 0; /* 移除最后一个元素的右边距 */
}

.form-item {
  flex: 1;
}

.form-item ::v-deep .el-form-item__content {
  // width: 100%;
}

.form-item ::v-deep .el-input,
.form-item ::v-deep .el-select {
  // width: 100%;
}

.search-buttons {
  white-space: nowrap;
}

::v-deep .operation-buttons .el-button {
  padding: 4px 8px;
  margin: 0 2px;
}

::v-deep .operation-column {
  background-color: #ffffff;
  box-shadow: -2px 0 5px rgba(241, 112, 6, 0.1);
}

.el-button.is-text {
  min-width: 32px !important;
}

.dialog-footer {
  display: flex;
  justify-content: center;
  align-items: center;
}

.dialog-footer .el-button {
  margin: 0 10px;
}

.delete-content {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.warning-icon {
  font-size: 24px;
  color: #e6a23c;
  margin-right: 10px;
}

/* 添加以下样式来使对话框垂直居中 */
::v-deep .delete-dialog.el-dialog {
  margin-top: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
::v-deep .el-table th {
  text-align: center;
}

::v-deep .el-table .cell {
  text-align: center;
}
</style>
