<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="年月份" prop="timeMonth">
      <el-input v-model="dataForm.timeMonth" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="姓名" prop="ecnname">
      <el-input v-model="dataForm.ecnname" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="当月加班" prop="monthOvertimeAdd">
      <el-input v-model="dataForm.monthOvertimeAdd" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="当月调休" prop="monthOvertimeDecrease">
      <el-input v-model="dataForm.monthOvertimeDecrease" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="加班累计" prop="monthOvertimeSurplus">
      <el-input v-model="dataForm.monthOvertimeSurplus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="年假使用" prop="annualLeaveDecrease">
      <el-input v-model="dataForm.annualLeaveDecrease" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="剩余年假" prop="annualLeaveSurplus">
      <el-input v-model="dataForm.annualLeaveSurplus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="当月病假" prop="silkLeaveAdd">
      <el-input v-model="dataForm.silkLeaveAdd" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="病假累计" prop="silkLeaveAll">
      <el-input v-model="dataForm.silkLeaveAll" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="当月事假" prop="leaveAbsenceAdd">
      <el-input v-model="dataForm.leaveAbsenceAdd" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="事假累计" prop="leaveAbsenceAll">
      <el-input v-model="dataForm.leaveAbsenceAll" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="5分钟内迟到" prop="lateLess5">
      <el-input v-model="dataForm.lateLess5" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="6分钟以上迟到" prop="lateGreate6">
      <el-input v-model="dataForm.lateGreate6" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="迟到总计" prop="lateAll">
      <el-input v-model="dataForm.lateAll" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/inventory/sgtimesheet'

    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          timeMonth: '',
          eId: '',
          eCnname: '',
          monthOvertimeAdd: '',
          monthOvertimeDecrease: '',
          monthOvertimeSurplus: '',
          annualLeaveDecrease: '',
          annualLeaveSurplus: '',
          silkLeaveAdd: '',
          silkLeaveAll: '',
          leaveAbsenceAdd: '',
          leaveAbsenceAll: '',
          lateLess5: '',
          lateGreate6: '',
          lateAll: ''
        },
        dataRule: {
          timeMonth: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          eId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          eCnname: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          monthOvertimeAdd: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          monthOvertimeDecrease: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          monthOvertimeSurplus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          annualLeaveDecrease: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          annualLeaveSurplus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          silkLeaveAdd: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          silkLeaveAll: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          leaveAbsenceAdd: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          leaveAbsenceAll: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          lateLess5: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          lateGreate6: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          lateAll: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getObj(this.dataForm.id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$message.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$message.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                })
            }
          }
        })
      }
    }
  }
</script>
