<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="日期" prop="attMon">
        <el-date-picker v-model="queryParams.attMon" value-format="yyyy-MM" type="month" placeholder="请选择日期">
        </el-date-picker>
      </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-button type="warning" style="margin-left: 50px" icon="el-icon-upload" size="mini" @click="handleInitData">
          按月初始化数据
        </el-button>
        <el-button type="success" icon="el-icon-download" size="mini" @click="handleSubmit">按月批量提交</el-button>
        <el-button type="success" icon="el-icon-download" size="mini" @click="exportRecord">导出</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="userName"/>
      <el-table-column label="部门/级部" align="center" prop="orgname"/>
      <el-table-column label="日期" align="center" prop="attMon"/>
      <el-table-column label="请假时长" align="center" prop="attEa">
        <template slot-scope="scope">
          {{ scope.row.attEa }}天
        </template>
      </el-table-column>
      <el-table-column label="加班时长" align="center" prop="attOt">
        <template slot-scope="scope">
          {{ scope.row.attOt }}时
        </template>
      </el-table-column>
      <!-- <el-table-column label="打卡时间" align="center" prop="reasonForLeave"/> -->
      <el-table-column label="操作" align="center" min-width="60px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" v-if="scope.row.state==0" type="text" icon="el-icon-edit"
                     @click="handleEdit(scope.row,1)"
                     v-hasPermi="['grade:monthRecord:edit']">修改
          </el-button>
          <el-button size="mini" v-if="scope.row.state==0" type="text" icon="el-icon-position"
                     @click="handleSubmitById(scope.row)"
                     v-hasPermi="['grade:monthRecord:submit']">提交
          </el-button>
          <el-button size="mini" type="text" @click="handleEdit(scope.row,0)" icon="el-icon-view"
                     v-hasPermi="['grade:monthRecord:view']">查看
          </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"
    />
  </div>
</template>

<script>
import {
  personalMonList, initDataByMon,
  submitDataByMon, submitDataByMonById, checkRow
} from "@/api/smartSchool/officialWork/monthRecord.js"

export default {
  name: '',
  components: {},
  props: {},
  data() {
    return {
      // 模糊搜索
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        attMon: undefined,
        userName: undefined,
      },
      // 加载遮罩
      loading: true,
      // 总条数
      total: 0,
      // 记录列表
      clockRecordList: [],
      // 查看请假加班时长信息对话框
      openForCheck: false,
      // 查看表单
      checkForm: {},
    };
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true;
      console.log(this.queryParams, 98)
      personalMonList(this.queryParams).then(response => {
        this.clockRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    // 模糊搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 按月初始化数据
    handleInitData() {
      const obj = {attMon: this.queryParams.attMon};
      initDataByMon(obj).then(() => {
        this.$modal.msgSuccess("初始化成功");
        this.getList();
      }).catch(() => {
      })
    },
    // 按月批量提交
    handleSubmit() {
      const obj = {attMon: this.queryParams.attMon};
      submitDataByMon(obj).then(() => {
        this.$modal.msgSuccess("按月提交成功");
        this.getList();
      }).catch(() => {
      })
    },
    // 单个提交
    handleSubmitById(row) {
      const id = row.id;
      submitDataByMonById(id).then(() => {
        this.$modal.msgSuccess("提交成功");
        this.getList();
      }).catch(() => {
      })
    },
    // 导出
    exportRecord() {
      this.download('/schoolAttMon/deptList/export', {
        ...this.queryParams
      }, `schoolAttMon_${Date.now()}.xlsx`)
    },
    //查看请假加班时长信息对话框
    handleView() {
      this.openForCheck = true;
    },
    // 跳转修改月度考勤
    handleEdit(row, isEdit) {
      const attMon = row.attMon;
      const userName = row.userName;
      const orgname = row.orgname;
      const attEa = row.attEa;
      const attOt = row.attOt;
      const attMonId = row.id;
      const userId = row.userId;
      const userType = row.userType;
      this.$router.push({
        path: "/officialWork/clockmanage/edit",
        query: {
          isEdit,
          attMon,
          userName,
          orgname,
          attEa,
          attOt,
          attMonId,
          userId,
          userType,
        },
      });
    },
  },
  created() {
    this.getList()
  },
};
</script>
<style scoped>
</style>
