haoxuan
2024-04-24 5d36d46434a7f4d23844dc94c34e7716eae172a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<template>
  <el-dialog :close-on-click-modal="false" :visible.sync="islook" width="40rem" class="add-event-dialog"
    @close="cancelMethod">
    <div slot="title" class="tac drawerHeader">详情</div>
    <div class="dialog-content-box">
      <el-form class="form-box" ref="form" :rules="rules" :model="form" label-width="140px" label-position="right">
        <el-form-item label="员工姓名:" prop="workerName">
          {{ form.workerName ||'--'}}
        </el-form-item>
        <el-form-item label="员工ID:" prop="workerId">
          {{ form.workerId||'--' }}
        </el-form-item>
        <el-form-item label="工种:" prop="workType">
          {{ form.workType||'--' }}
        </el-form-item>
        <el-form-item label="考勤日期:" prop="month">
          {{ form.month||'--' }}
        </el-form-item>
        <el-form-item label="状态:" prop="status">
          <template v-if="!isEditOne">
            <i  v-if='form.status==1' class="el-icon-circle-check cursor_pointer font_size_20 color_67c23a"></i>
           <span :class="getClassName(form.status)">
            {{ getAttendanceStatus(form.status) }}
            </span>
           <i @click="editOneClick" class="el-icon-edit-outline cursor_pointer font_size_20"></i>
          </template>
          <template v-else>
            <el-select v-model="form.status" filterable placeholder="请选择"  class="margin_right_15px" style="width: calc(100% - 120px)">
            <el-option v-for="item in attendanceStatusList" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
              <el-button type="text" :loading="isAddloadingOne"  @click="submitEditOneClick('form')">确定</el-button>
              <el-button type="text" @click="cancelEditClick('isEditOne')">取消</el-button>
          </template>
        </el-form-item>
        <el-form-item label="上班打卡时间:" prop="startWorkTime">
          {{ form.startWorkTime||'--' }}
        </el-form-item>
        <el-form-item label="下班打卡时间:" prop="endWorkTime">
          {{ form.endWorkTime||'--' }}
        </el-form-item>
        <el-form-item label="班次:" prop="classes">
          {{ form.classes ||'--'}}
        </el-form-item>
        <el-form-item label="班次开始时间:" prop="classesStartTime">
          {{ form.classesStartTime ||'--'}}
        </el-form-item>
        <el-form-item label="班次结束时间:" prop="classesEndTime">
          {{ form.classesEndTime||'--' }}
        </el-form-item>
        <el-form-item label="工作日加班时长:" prop="weekdayOverTime">
          <template v-if="!isEditTwo">
           {{ form.weekdayOverTime }}
           <i @click="editTwoClick" class="el-icon-edit-outline cursor_pointer font_size_20"></i>
          </template>
          <template v-else>
            <el-input
                v-model.number="form.weekdayOverTime"
                maxlength="20"
                style="width: calc(100% - 120px)"
                clearable
                placeholder="请输入"
                class="margin_right_15px"
              ></el-input>
              <el-button type="text" :loading="isAddloadingTwo" @click="submitEditTwoClick('form')">确定</el-button>
              <el-button type="text" @click="cancelEditClick('isEditTwo')">取消</el-button>
          </template>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer tac">
      <el-button type="cancel" @click="cancelMethod()">关闭</el-button>
      <!-- <el-button type="primary" @click="submitForm('form')">确定</el-button> -->
    </div>
  </el-dialog>
</template>
 
<script>
import { updateAttendance } from "@/api/employeeSalary/attendanceManage.js"
import { getDataByType } from "@/api/data"
export default {
  props: {
    editRow: {
      type: Object,
    }
  },
  data() {
    return {
      islook: false,
      form: {
        id: '',
        isCore: '',
        phoneNum: '',
      },
      isEditOne:false,
      isEditTwo:false,
      attendanceStatusList: getDataByType("attendanceStatus"),
      rules: {
        weekdayOverTime: [
          {
            required: false,
            message: "请输入",
            trigger: "blur",
          },
          {
            validator: this.validatorNum,
            trigger: "blur",
          },
        ],
      },
      isAddloadingOne:false,
      isAddloadingTwo:false,
    };
  },
  created() {
  },
  watch: {
    islook(newVal) {
      if (newVal) {
        this.formInfo()
      }
    },
    editRow() {
      this.formInfo()
    },
  },
  methods: {
    getAttendanceStatus(val){
      let string = "";
      if (val) {
        for (let i in this.attendanceStatusList) {
          if (this.attendanceStatusList[i].id == val) {
            string = this.attendanceStatusList[i].value;
          }
        }
      }
      return string;
    },
    getClassName(val){
      let classname=''
       // 1==正常 2===加班 3==休假 4===异常
      if(val==1){
        classname = "color_67c23a";
      }else if(val==2){
        classname = "color_FF9900 ";
      }else if(val==3){
        classname = "color_333";
      }else if(val==4){
        classname = "color_red";
      }
      return classname
    },
    editOneClick(){
      this.isEditOne=true
    },
    submitEditOneClick(){
      this.submitForm('form','isEditOne','isAddloadingOne')
    },
    editTwoClick(){
      this.isEditTwo=true
    },
    submitEditTwoClick(){
      this.submitForm('form','isEditTwo','isAddloadingTwo')
    },
    formInfo() {
      if (this.islook) {
        this.form = {};
        this.isEditOne=false
        this.isEditTwo=false
        this.$nextTick(()=>{
          this.$refs["form"].resetFields();
          if (this.editRow.workerId) {
            this.form = JSON.parse(JSON.stringify(this.editRow));
          }
        })
      }
    },
    cancelEditClick(name){
      this[name]=false
      this.formInfo()
    },
    validatorNum(rule, value, callback) {
      if (value&&this.isEditTwo) {
        if (value == undefined || value == null) {
          callback(new Error("请输入有效数字"));
        } else {
          var reg = /^\+?[1-9]\d*$/;
          if (!reg.test(value)) {
            callback(new Error("请填写不小于0的数字"));
          } else {
            callback();
          }
        }
      } else {
        callback();
      }
    },
    cancelMethod() {
      this.$refs["form"].resetFields();
      this.islook = false;
      this.$emit('shutdown')
    },
    submitForm(formName,name,loading) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let form = JSON.parse(JSON.stringify(this.form));
          let day=(Number(form.dateDay)<10)?'0'+form.dateDay:form.dateDay
          let params={
            date:form.month+'-'+day,
            overTimeDuration:Number(form.weekdayOverTime),
            status:form.status,
            workerId:form.workerId,
            classes:form.classes,
            classesEndTime:form.classesEndTime,
            classesStartTime:form.classesStartTime,
            endWorkTime:form.endWorkTime,
            startWorkTime:form.startWorkTime,
            workTypeId:form.workTypeId,
            workerName:form.workerName,
          }
            this[loading]=true
            updateAttendance(params).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "操作成功!",
                  type: "success",
                });
                this[name]=false
                this.cancelMethod();
              }
              this[loading]=false
            }).catch(() => {
             setTimeout(() => {
              this[loading]=false
                }, 2000);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
};
</script>
 
<style lang="scss" scoped>
.dialog-content-box {
  height: 28rem;
 
  .form-box {
    width: 90%;
    padding: 0 5%;
    height: 100%;
    overflow-y: auto;
 
  }
}
</style>