<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="配置项ID,可以获取项目ID和总包ID" prop="cfgid">
        <el-input v-model="queryParams.cfgid" placeholder="请输入配置项ID,可以获取项目ID和总包ID" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="厂商编号参考字典attendance_vendors" prop="vendorsCode">
        <el-input v-model="queryParams.vendorsCode" placeholder="请输入厂商编号参考字典attendance_vendors" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工人id" prop="workerId">
        <el-input v-model="queryParams.workerId" placeholder="请输入工人id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目工人履历id对于旧劳务，这个字段相当于工人的projectWorkerId，管理人员的registerManagerId" prop="laborWorkerId">
        <el-input v-model="queryParams.laborWorkerId"
          placeholder="请输入项目工人履历id对于旧劳务，这个字段相当于工人的projectWorkerId，管理人员的registerManagerId" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="人员类别0：工人，1：管理人员" prop="workerCategory">
        <el-input v-model="queryParams.workerCategory" placeholder="请输入人员类别0：工人，1：管理人员" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工号" prop="qrCode">
        <el-input v-model="queryParams.qrCode" placeholder="请输入工号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="民族" prop="ethnic">
        <el-input v-model="queryParams.ethnic" placeholder="请输入民族" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="籍贯" prop="nativePlace">
        <el-input v-model="queryParams.nativePlace" placeholder="请输入籍贯" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别0:男 1:女" prop="gender">
        <el-input v-model="queryParams.gender" placeholder="请输入性别0:男 1:女" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="出生日期时间戳" prop="birthDate">
        <el-input v-model="queryParams.birthDate" placeholder="请输入出生日期时间戳" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学历" prop="degreeName">
        <el-input v-model="queryParams.degreeName" placeholder="请输入学历" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证照" prop="photo">
        <el-input v-model="queryParams.photo" placeholder="请输入身份证照" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="近照" prop="recentPhoto">
        <el-input v-model="queryParams.recentPhoto" placeholder="请输入近照" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属班组ID" prop="groupId">
        <el-input v-model="queryParams.groupId" placeholder="请输入所属班组ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属班组" prop="groupName">
        <el-input v-model="queryParams.groupName" placeholder="请输入所属班组" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否班组长" prop="leader">
        <el-input v-model="queryParams.leader" placeholder="请输入是否班组长" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工种编码" prop="workTypeCode">
        <el-input v-model="queryParams.workTypeCode" placeholder="请输入工种编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工种" prop="workTypeName">
        <el-input v-model="queryParams.workTypeName" placeholder="请输入工种" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="安全帽编号" prop="hatCode">
        <el-input v-model="queryParams.hatCode" placeholder="请输入安全帽编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="进退场状态0:进场，1:退场" prop="state">
        <el-input v-model="queryParams.state" placeholder="请输入进退场状态0:进场，1:退场" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="进场日期" prop="enterDate">
        <el-input v-model="queryParams.enterDate" placeholder="请输入进场日期" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="退场日期" prop="exitDate">
        <el-input v-model="queryParams.exitDate" placeholder="请输入退场日期" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="分包商id" prop="companyId">
        <el-input v-model="queryParams.companyId" placeholder="请输入分包商id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="分包商名称" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入分包商名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="平台对应分包商ID" prop="vendorId">
        <el-input v-model="queryParams.vendorId" placeholder="请输入平台对应分包商ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="队伍id" prop="teamId">
        <el-input v-model="queryParams.teamId" placeholder="请输入队伍id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="队伍名称" prop="teamName">
        <el-input v-model="queryParams.teamName" placeholder="请输入队伍名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="" prop="isDel">
        <el-input v-model="queryParams.isDel" 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="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['project:attendanceWorker:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['project:attendanceWorker:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['project:attendanceWorker:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['project:attendanceWorker:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="attendanceWorkerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="配置项ID,可以获取项目ID和总包ID" align="center" prop="cfgid" />
      <el-table-column label="厂商编号参考字典attendance_vendors" align="center" prop="vendorsCode" />
      <el-table-column label="工人id" align="center" prop="workerId" />
      <el-table-column label="项目工人履历id对于旧劳务，这个字段相当于工人的projectWorkerId，管理人员的registerManagerId" align="center"
        prop="laborWorkerId" />
      <el-table-column label="人员类别0：工人，1：管理人员" align="center" prop="workerCategory" />
      <el-table-column label="工号" align="center" prop="qrCode" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="民族" align="center" prop="ethnic" />
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="性别0:男 1:女" align="center" prop="gender" />
      <el-table-column label="出生日期时间戳" align="center" prop="birthDate" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="学历" align="center" prop="degreeName" />
      <el-table-column label="身份证照" align="center" prop="photo" />
      <el-table-column label="近照" align="center" prop="recentPhoto" />
      <el-table-column label="所属班组ID" align="center" prop="groupId" />
      <el-table-column label="所属班组" align="center" prop="groupName" />
      <el-table-column label="是否班组长" align="center" prop="leader" />
      <el-table-column label="工种编码" align="center" prop="workTypeCode" />
      <el-table-column label="工种" align="center" prop="workTypeName" />
      <el-table-column label="是否特殊工种" align="center" prop="specWorkType" />
      <el-table-column label="安全帽编号" align="center" prop="hatCode" />
      <el-table-column label="进退场状态0:进场，1:退场" align="center" prop="state" />
      <el-table-column label="进场日期" align="center" prop="enterDate" />
      <el-table-column label="退场日期" align="center" prop="exitDate" />
      <el-table-column label="分包商id" align="center" prop="companyId" />
      <el-table-column label="分包商名称" align="center" prop="companyName" />
      <el-table-column label="平台对应分包商ID" align="center" prop="vendorId" />
      <el-table-column label="队伍id" align="center" prop="teamId" />
      <el-table-column label="队伍名称" align="center" prop="teamName" />
      <el-table-column label="进场方式0:自动,1:手动2:拍照" align="center" prop="enterType" />
      <el-table-column label="服务返回的JSON" align="center" prop="other" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="" align="center" prop="isDel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['project:attendanceWorker:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['project:attendanceWorker:remove']">删除</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-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="配置项ID,可以获取项目ID和总包ID" prop="cfgid">
          <el-input v-model="form.cfgid" placeholder="请输入配置项ID,可以获取项目ID和总包ID" />
        </el-form-item>
        <el-form-item label="厂商编号参考字典attendance_vendors" prop="vendorsCode">
          <el-input v-model="form.vendorsCode" placeholder="请输入厂商编号参考字典attendance_vendors" />
        </el-form-item>
        <el-form-item label="工人id" prop="workerId">
          <el-input v-model="form.workerId" placeholder="请输入工人id" />
        </el-form-item>
        <el-form-item label="项目工人履历id对于旧劳务，这个字段相当于工人的projectWorkerId，管理人员的registerManagerId" prop="laborWorkerId">
          <el-input v-model="form.laborWorkerId"
            placeholder="请输入项目工人履历id对于旧劳务，这个字段相当于工人的projectWorkerId，管理人员的registerManagerId" />
        </el-form-item>
        <el-form-item label="人员类别0：工人，1：管理人员" prop="workerCategory">
          <el-input v-model="form.workerCategory" placeholder="请输入人员类别0：工人，1：管理人员" />
        </el-form-item>
        <el-form-item label="工号" prop="qrCode">
          <el-input v-model="form.qrCode" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="民族" prop="ethnic">
          <el-input v-model="form.ethnic" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
        </el-form-item>
        <el-form-item label="性别0:男 1:女" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别0:男 1:女" />
        </el-form-item>
        <el-form-item label="出生日期时间戳" prop="birthDate">
          <el-input v-model="form.birthDate" placeholder="请输入出生日期时间戳" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="学历" prop="degreeName">
          <el-input v-model="form.degreeName" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="身份证照" prop="photo">
          <el-input v-model="form.photo" placeholder="请输入身份证照" />
        </el-form-item>
        <el-form-item label="近照" prop="recentPhoto">
          <el-input v-model="form.recentPhoto" placeholder="请输入近照" />
        </el-form-item>
        <el-form-item label="所属班组ID" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入所属班组ID" />
        </el-form-item>
        <el-form-item label="所属班组" prop="groupName">
          <el-input v-model="form.groupName" placeholder="请输入所属班组" />
        </el-form-item>
        <el-form-item label="是否班组长" prop="leader">
          <el-input v-model="form.leader" placeholder="请输入是否班组长" />
        </el-form-item>
        <el-form-item label="工种编码" prop="workTypeCode">
          <el-input v-model="form.workTypeCode" placeholder="请输入工种编码" />
        </el-form-item>
        <el-form-item label="工种" prop="workTypeName">
          <el-input v-model="form.workTypeName" placeholder="请输入工种" />
        </el-form-item>
        <el-form-item label="安全帽编号" prop="hatCode">
          <el-input v-model="form.hatCode" placeholder="请输入安全帽编号" />
        </el-form-item>
        <el-form-item label="进退场状态0:进场，1:退场" prop="state">
          <el-input v-model="form.state" placeholder="请输入进退场状态0:进场，1:退场" />
        </el-form-item>
        <el-form-item label="进场日期" prop="enterDate">
          <el-input v-model="form.enterDate" placeholder="请输入进场日期" />
        </el-form-item>
        <el-form-item label="退场日期" prop="exitDate">
          <el-input v-model="form.exitDate" placeholder="请输入退场日期" />
        </el-form-item>
        <el-form-item label="分包商id" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入分包商id" />
        </el-form-item>
        <el-form-item label="分包商名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入分包商名称" />
        </el-form-item>
        <el-form-item label="平台对应分包商ID" prop="vendorId">
          <el-input v-model="form.vendorId" placeholder="请输入平台对应分包商ID" />
        </el-form-item>
        <el-form-item label="队伍id" prop="teamId">
          <el-input v-model="form.teamId" placeholder="请输入队伍id" />
        </el-form-item>
        <el-form-item label="队伍名称" prop="teamName">
          <el-input v-model="form.teamName" placeholder="请输入队伍名称" />
        </el-form-item>
        <el-form-item label="服务返回的JSON" prop="other">
          <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAttendanceWorker, getAttendanceWorker, delAttendanceWorker, addAttendanceWorker, updateAttendanceWorker,queryAttendanceData } from "@/api/project/attendanceWorker";

export default {
  name: "AttendanceWorker",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考勤人员基本属性表格数据
      attendanceWorkerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cfgid: null,
        vendorsCode: null,
        workerId: null,
        laborWorkerId: null,
        workerCategory: null,
        qrCode: null,
        name: null,
        ethnic: null,
        nativePlace: null,
        gender: null,
        birthDate: null,
        phone: null,
        degreeName: null,
        photo: null,
        recentPhoto: null,
        groupId: null,
        groupName: null,
        leader: null,
        workTypeCode: null,
        workTypeName: null,
        specWorkType: null,
        hatCode: null,
        state: null,
        enterDate: null,
        exitDate: null,
        companyId: null,
        companyName: null,
        vendorId: null,
        teamId: null,
        teamName: null,
        enterType: null,
        other: null,
        isDel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        phone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        other: [
          { required: true, message: "服务返回的JSON不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    debugger
    queryAttendanceData('2023-09-25').then(d=>{
      debugger
    })
  },
  methods: {
    /** 查询考勤人员基本属性列表 */
    getList() {
      this.loading = true;
      listAttendanceWorker(this.queryParams).then(response => {
        this.attendanceWorkerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cfgid: null,
        vendorsCode: null,
        workerId: null,
        laborWorkerId: null,
        workerCategory: null,
        qrCode: null,
        name: null,
        ethnic: null,
        nativePlace: null,
        gender: null,
        birthDate: null,
        phone: null,
        degreeName: null,
        photo: null,
        recentPhoto: null,
        groupId: null,
        groupName: null,
        leader: null,
        workTypeCode: null,
        workTypeName: null,
        specWorkType: null,
        hatCode: null,
        state: null,
        enterDate: null,
        exitDate: null,
        companyId: null,
        companyName: null,
        vendorId: null,
        teamId: null,
        teamName: null,
        enterType: null,
        other: null,
        remark: null,
        isDel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考勤人员基本属性";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAttendanceWorker(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改考勤人员基本属性";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAttendanceWorker(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAttendanceWorker(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除考勤人员基本属性编号为"' + ids + '"的数据项？').then(function () {
        return delAttendanceWorker(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/attendanceWorker/export', {
        ...this.queryParams
      }, `attendanceWorker_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
