<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" prop="tenantId">
        <el-input
          v-model="queryParams.tenantId"
          placeholder="请输入租户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登录用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入登录用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工所属部门" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          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="age">
        <el-input
          v-model="queryParams.age"
          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="idcard">
        <el-input
          v-model="queryParams.idcard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCardNumber">
        <el-input
          v-model="queryParams.bankCardNumber"
          placeholder="请输入银行卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户行" prop="openingBank">
        <el-input
          v-model="queryParams.openingBank"
          placeholder="请输入开户行"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基本工资" prop="basicSalary">
        <el-input
          v-model="queryParams.basicSalary"
          placeholder="请输入基本工资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日薪" prop="daySalary">
        <el-input
          v-model="queryParams.daySalary"
          placeholder="请输入日薪"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时薪" prop="hourSalary">
        <el-input
          v-model="queryParams.hourSalary"
          placeholder="请输入时薪"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="每日应出勤小时数" prop="hoursPerDay">
        <el-input
          v-model="queryParams.hoursPerDay"
          placeholder="请输入每日应出勤小时数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-input
          v-model="queryParams.education"
          placeholder="请输入学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家庭住址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入家庭住址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急联系人" prop="contact">
        <el-input
          v-model="queryParams.contact"
          placeholder="请输入紧急联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急联系人电话" prop="contactPhone">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入紧急联系人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质检(1-是 0-否)" prop="zhijian">
        <el-input
          v-model="queryParams.zhijian"
          placeholder="请输入质检(1-是 0-否)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员(1-是 0-否)" prop="yewu">
        <el-input
          v-model="queryParams.yewu"
          placeholder="请输入业务员(1-是 0-否)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同补助开始时间" prop="htstime">
        <el-date-picker clearable
          v-model="queryParams.htstime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择合同补助开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同补助结束时间" prop="htetime">
        <el-date-picker clearable
          v-model="queryParams.htetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择合同补助结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="删除标志" prop="deleted">
        <el-input
          v-model="queryParams.deleted"
          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="['pay:employeeInfo: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="['pay:employeeInfo: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="['pay:employeeInfo: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="['pay:employeeInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeeInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" v-if="true"/>
      <el-table-column label="租户id" align="center" prop="tenantId" />
      <el-table-column label="登录用户id" align="center" prop="userId" />
      <el-table-column label="员工所属部门" align="center" prop="deptId" />
      <el-table-column label="员工姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="身份证号" align="center" prop="idcard" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber" />
      <el-table-column label="开户行" align="center" prop="openingBank" />
      <el-table-column label="基本工资" align="center" prop="basicSalary" />
      <el-table-column label="日薪" align="center" prop="daySalary" />
      <el-table-column label="时薪" align="center" prop="hourSalary" />
      <el-table-column label="休息类型(0 :周休 1:非周休 2：天休 3：小时 4：包月 5：周二天)" align="center" prop="restType" />
      <el-table-column label="每日应出勤小时数" align="center" prop="hoursPerDay" />
      <el-table-column label="工资计算类型(
0:日薪(日工+包活)
1:月薪(日工+包活)
2:喷涂按小时数(16/17、17/18)
3.外贸按小时数(17/21)
4.包月工资)
" align="center" prop="payCalcType" />
      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="家庭住址" align="center" prop="address" />
      <el-table-column label="紧急联系人" align="center" prop="contact" />
      <el-table-column label="紧急联系人电话" align="center" prop="contactPhone" />
      <el-table-column label="质检(1-是 0-否)" align="center" prop="zhijian" />
      <el-table-column label="业务员(1-是 0-否)" align="center" prop="yewu" />
      <el-table-column label="合同补助开始时间" align="center" prop="htstime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.htstime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同补助结束时间" align="center" prop="htetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.htetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="删除标志" align="center" prop="deleted" />
      <el-table-column label="备注" align="center" prop="remark" />
      <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="['pay:employeeInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pay:employeeInfo: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" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租户id" />
        </el-form-item>
        <el-form-item label="登录用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入登录用户id" />
        </el-form-item>
        <el-form-item label="员工所属部门" prop="deptId">
          <el-input v-model="form.deptId" 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="age">
          <el-input v-model="form.age" 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="idcard">
          <el-input v-model="form.idcard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="开户行" prop="openingBank">
          <el-input v-model="form.openingBank" placeholder="请输入开户行" />
        </el-form-item>
        <el-form-item label="基本工资" prop="basicSalary">
          <el-input v-model="form.basicSalary" placeholder="请输入基本工资" />
        </el-form-item>
        <el-form-item label="日薪" prop="daySalary">
          <el-input v-model="form.daySalary" placeholder="请输入日薪" />
        </el-form-item>
        <el-form-item label="时薪" prop="hourSalary">
          <el-input v-model="form.hourSalary" placeholder="请输入时薪" />
        </el-form-item>
        <el-form-item label="每日应出勤小时数" prop="hoursPerDay">
          <el-input v-model="form.hoursPerDay" placeholder="请输入每日应出勤小时数" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="家庭住址" prop="address">
          <el-input v-model="form.address" placeholder="请输入家庭住址" />
        </el-form-item>
        <el-form-item label="紧急联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item label="紧急联系人电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入紧急联系人电话" />
        </el-form-item>
        <el-form-item label="质检(1-是 0-否)" prop="zhijian">
          <el-input v-model="form.zhijian" placeholder="请输入质检(1-是 0-否)" />
        </el-form-item>
        <el-form-item label="业务员(1-是 0-否)" prop="yewu">
          <el-input v-model="form.yewu" placeholder="请输入业务员(1-是 0-否)" />
        </el-form-item>
        <el-form-item label="合同补助开始时间" prop="htstime">
          <el-date-picker clearable
            v-model="form.htstime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择合同补助开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同补助结束时间" prop="htetime">
          <el-date-picker clearable
            v-model="form.htetime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择合同补助结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标志" prop="deleted">
          <el-input v-model="form.deleted" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmployeeInfo, getEmployeeInfo, delEmployeeInfo, addEmployeeInfo, updateEmployeeInfo } from "@/api/pay/employeeInfo";

export default {
  name: "EmployeeInfo",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工信息表格数据
      employeeInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tenantId: undefined,
        userId: undefined,
        deptId: undefined,
        name: undefined,
        sex: undefined,
        age: undefined,
        phone: undefined,
        idcard: undefined,
        bankCardNumber: undefined,
        openingBank: undefined,
        basicSalary: undefined,
        daySalary: undefined,
        hourSalary: undefined,
        restType: undefined,
        hoursPerDay: undefined,
        payCalcType: undefined,
        education: undefined,
        address: undefined,
        contact: undefined,
        contactPhone: undefined,
        zhijian: undefined,
        yewu: undefined,
        htstime: undefined,
        htetime: undefined,
        deleted: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "主键不能为空", trigger: "blur" }
        ],
        tenantId: [
          { required: true, message: "租户id不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "登录用户id不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "员工所属部门不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "员工姓名不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        idcard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        bankCardNumber: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
        openingBank: [
          { required: true, message: "开户行不能为空", trigger: "blur" }
        ],
        basicSalary: [
          { required: true, message: "基本工资不能为空", trigger: "blur" }
        ],
        daySalary: [
          { required: true, message: "日薪不能为空", trigger: "blur" }
        ],
        hourSalary: [
          { required: true, message: "时薪不能为空", trigger: "blur" }
        ],
        restType: [
          { required: true, message: "休息类型(0 :周休 1:非周休 2：天休 3：小时 4：包月 5：周二天)不能为空", trigger: "change" }
        ],
        hoursPerDay: [
          { required: true, message: "每日应出勤小时数不能为空", trigger: "blur" }
        ],
        payCalcType: [
          { required: true, message: "工资计算类型", trigger: "change" }
        ],
        education: [
          { required: true, message: "学历不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "家庭住址不能为空", trigger: "blur" }
        ],
        contact: [
          { required: true, message: "紧急联系人不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "紧急联系人电话不能为空", trigger: "blur" }
        ],
        zhijian: [
          { required: true, message: "质检(1-是 0-否)不能为空", trigger: "blur" }
        ],
        yewu: [
          { required: true, message: "业务员(1-是 0-否)不能为空", trigger: "blur" }
        ],
        htstime: [
          { required: true, message: "合同补助开始时间不能为空", trigger: "blur" }
        ],
        htetime: [
          { required: true, message: "合同补助结束时间不能为空", trigger: "blur" }
        ],
        deleted: [
          { required: true, message: "删除标志不能为空", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "备注不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询员工信息列表 */
    getList() {
      this.loading = true;
      listEmployeeInfo(this.queryParams).then(response => {
        this.employeeInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        tenantId: undefined,
        userId: undefined,
        deptId: undefined,
        name: undefined,
        sex: undefined,
        age: undefined,
        phone: undefined,
        idcard: undefined,
        bankCardNumber: undefined,
        openingBank: undefined,
        basicSalary: undefined,
        daySalary: undefined,
        hourSalary: undefined,
        restType: undefined,
        hoursPerDay: undefined,
        payCalcType: undefined,
        education: undefined,
        address: undefined,
        contact: undefined,
        contactPhone: undefined,
        zhijian: undefined,
        yewu: undefined,
        htstime: undefined,
        htetime: undefined,
        deleted: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined
      };
      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.loading = true;
      this.reset();
      const id = row.id || this.ids
      getEmployeeInfo(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改员工信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateEmployeeInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addEmployeeInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除员工信息编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delEmployeeInfo(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pay/employeeInfo/export', {
        ...this.queryParams
      }, `employeeInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
