<template>
  <div class="department-manage">
    <el-card>
      <div class="filter-container">
        <el-form :model="queryParams" label-width="100px" class="demo-form-inline">
          <el-row>
            <el-col :span="6">
              <el-form-item label="部门类型">
                <el-select v-model="queryParams.deptType" placeholder="全部规则" clearable style="width: 100%" size="small">
                  <el-option label="总部" value="headquarters" />
                  <el-option label="分部" value="branch" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="部门名称">
                <el-input v-model="queryParams.name" placeholder="请输入部门名称" clearable size="small" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="创建时间">
                <el-date-picker
                  v-model="queryParams.dateRange"
                  type="daterange"
                  range-separator="-"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  style="width: 100%"
                  size="small"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>
                <el-button type="primary" size="medium" @click="handleQuery">查询</el-button>
                <el-button type="primary" plain size="medium" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <el-table v-loading="loading" :data="departmentList" row-key="id" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
        <el-table-column prop="name" label="部门名称" />
        <el-table-column prop="leader" label="负责人" />
        <el-table-column prop="phone" label="联系电话" />
        <el-table-column prop="email" label="邮箱" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
              {{ scope.row.status === 1 ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="orderNum" label="排序" />
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'DepartmentManage',
  data() {
    return {
      loading: false,
      departmentList: [],
      queryParams: {
        deptType: '',
        name: '',
        dateRange: []
      }
    }
  },
  methods: {
    handleQuery() {
      // TODO: 实现查询逻辑
    },
    resetQuery() {
      this.queryParams.deptType = ''
      this.queryParams.name = ''
      this.queryParams.dateRange = []
      this.handleQuery()
    },
    handleEdit(row) {
      // TODO: 实现编辑逻辑
    }
  }
}
</script>

<style lang="scss" scoped>
.department-manage {
  padding: 20px;

  .filter-container {
    margin-bottom: 20px;

    .el-form-item {
      margin-bottom: 10px;
      margin-right: 10px;

      .el-form-item__label {
        padding-right: 8px;
      }
    }
  }
}
</style>
