<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="86px">
      <el-form-item label="日期" prop="dateRange">
        <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="datetimerange" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item class="ml20">
        <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-button type="warning" icon="el-icon-upload" size="mini" @click="importRecord">导入</el-button> -->
        <el-button style="margin-left: 20px" type="success" icon="el-icon-download" size="mini" @click="handleExport">导出
        </el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="clockRecordList" stripe>
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="设备工号" align="center" prop="deviceNum" />
      <el-table-column label="员工工号" align="center" prop="teacherCode" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="部门" align="center" prop="orgname" />
      <el-table-column label="考勤日期" align="center" prop="clockDate" />
      <el-table-column label="打卡时间" align="center" min-width="200px" prop="clockTime" />
      <el-table-column label="备注" align="center" min-width="200px" 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="handleEdit(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-dialog title="编写备注" :visible.sync="dialogEditNote" width="1000px" append-to-body>
      <el-form ref="form" :model="form" label-width="110px" style="width: 100%; margin: auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备工号" prop="deviceNum">
              <el-input :value="form.deviceNum" placeholder="请输入设备工号" />
            </el-form-item>

            <el-form-item label="姓名" prop="userName">
              <el-input :value="form.userName" placeholder="请输入姓名" />
            </el-form-item>
            <el-form-item label="考勤日期" prop="clockDate">
              <el-date-picker v-model="form.clockDate" type="date" style="width: 100%" placeholder="请选择考勤日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工工号" prop="teacherCode">
              <el-input :value="form.teacherCode" placeholder="请输入员工工号" />
            </el-form-item>
            <el-form-item label="部门" prop="orgname">
              <el-input :value="form.orgname" placeholder="请输入部门" />
            </el-form-item>
            <el-form-item label="打卡时间" prop="times">
              <el-input :value="form.times" placeholder="请输入打卡时间" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" show-overflow-tooltip placeholder="请输入备注" />
          </el-form-item>
        </el-row>
      </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 { personalList, submitRemark } from "@/api/smartSchool/personWork/clockRecord.js"

export default {
  name: ' PersonWorkClockRecord',
  data() {
    return {
      dialogEditNote: false,
      form: {},
      // 日期范围
      dateRange: [],
      // 模糊搜索
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 加载遮罩
      loading: true,
      // 记录条数
      total: 0,
      // 记录列表
      clockRecordList: [],
    };
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true;
      personalList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.clockRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    // 模糊搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/schoolAtt/personalList/export', {
        ...this.queryParams
      }, `personal_${Date.now()}.xlsx`)
    },
    handleEdit(row) {
      this.form = row
      this.dialogEditNote = true
    },
    // 取消按钮
    cancel() {
      this.dialogEditNote = false;
      this.form = {}
      this.handleQuery();
    },
    //提交备注
    submitForm() {
      this.dialogEditNote = false;
      submitRemark(this.form).then((res) => {
        this.form = {}
        this.handleQuery();
      })


    }
  },
  created() {
    this.getList()
  },
};
</script>
<style scoped></style>
