<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="nickname">
        <el-input
          clearable
          v-model="queryParams.nickname"
          placeholder="根据姓名查询"
        ></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别">
          <el-option label="男" value="0"></el-option>
          <el-option label="女" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学历" prop="highestDegree">
        <el-input
            v-model="queryParams.highestDegree"
            placeholder="请输入学历"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:onboarding:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="peopleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index"/>
      <el-table-column label="姓名" align="center" prop="nickName"/>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <span v-if="scope.row.sex === '0'">男</span>
          <span v-else>女</span>
        </template>
      </el-table-column>
     
      <el-table-column label="部门" align="center" prop="dept.deptName"/>
      <el-table-column label="入职日期" align="center" prop="joiningDate" width="180">
        <template slot-scope="scope">
          <span>{{scope.row.joiningDate!==null?scope.row.joiningDate:'未完成审批流程'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-add"
              @click="openAddFile(scope.row)"
          >添加文件</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-detail"
              @click="handleDetail(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <el-drawer
      title="人员详情"
      :visible.sync="open"
      size="600px"
      direction="rtl"
      append-to-body
    >
      <!-- 操作按钮组 -->
      <template #title>
        <div class="drawer-header" v-if="!readOnly">
          <span class="el-drawer__title">人员详情</span>
          <div class="action-buttons">
            <el-button type="primary" size="mini" @click="handleAdd">添加</el-button>
            <el-button type="danger" size="mini" @click="handleDelete">删除</el-button>
            <el-button size="mini" @click="handlePrint">打印</el-button>
          </div>
        </div>
      </template>

      <!-- 内容区域 -->
      <div class="drawer-content">
        <!-- 多选操作 -->
        <div class="selection-info" v-if="selectedItems.length">
          已选择 {{ selectedItems.length }} 项
        </div>

        <!-- 详细信息列表 -->
        <el-list :model="form" class="info-list">
          <el-checkbox-group v-model="selectedItems">
            <section class="info-section">
              <el-list-item v-for="item in fileList" :key="item.id">
                <template #default>
                  <div class="list-item-container">
                    <el-checkbox :label="item.label" class="list-checkbox"/>
                    <div class="info-label">{{ item.label }}：</div>
                    <div class="info-value">{{ item.value }}</div>
                  </div>
                </template>
              </el-list-item>
            </section>
          </el-checkbox-group>
        </el-list>
      </div>
    </el-drawer>

    <el-dialog :open="addFileDialog" title="添加文件">
      <el-form :model="fileForm" label-width="80px">
        
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listOnboarding, getOnboarding, delOnboarding, addOnboarding, updateOnboarding } from "@/api/oa/onboarding";
import {addUser, listUser, tempRole} from "@/api/system/user";

export default {
  name: "Onboarding",
  dicts: ['joining_status'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      selectedItems: [],
      readonly: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入职管理表格数据
      onboardingList: [],
      peopleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      addFileDialog: false,
      fileForm: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickname: '',
        sex: '',
        userId: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "系统账号不能为空", trigger: "blur" }
        ],
        nickName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
      },
      fileList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 新增入职员工界面 */
    // toAddOnboarding(){
    //   this.$router.push({
    //     path: '/people/addOnboarding',
    //   })
    // },
    /** 查询人员列表列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        console.log(response);
        this.peopleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        onboardingId: undefined,
        idPhoto: undefined,
        userId: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    openAddFile(row) {
      console.log(row);
      this.open = true;
      this.readOnly = false;
    },
    openDetail(row) {
      console.log(row);
      this.open = true;
      this.readOnly = true;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.onboardingId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    addFile() {

    },
    deleteFiles() {

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/onboarding/export', {
        ...this.queryParams
      }, `onboarding_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
