zhangjiaqing
8 天以前 1cef3adee31c6934c0da4b4f0b8a6f5ac03b364f
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
/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            staffAttendanceManageInfo: {
                staffs: [],
                attendances: [],
                classesId: '',
                orgId: '',
                orgName: '',
                curDate: '',
                curYear: '',
                curMonth: '',
                curStaffId: '',
                maxDay: ''
            }
        },
        _initMethod: function () {
            $that._loadStaffs();
            $that.initStaffDate();
        },
        _initEvent: function () {
            vc.on('staffAttendanceManage', 'listMonthAttendance', function (_param) {
                $that._loadStaffAttendances(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._loadStaffAttendances(_currentPage, DEFAULT_ROWS);
            });
            vc.on('staffAttendanceManage', 'switchOrg', function (_org) {
                $that.staffAttendanceManageInfo.orgId = _org.orgId;
                $that.staffAttendanceManageInfo.orgName = _org.allOrgName;
                $that._loadStaffs();
            });
        },
        methods: {
            _loadStaffs: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        orgId: $that.staffAttendanceManageInfo.orgId,
                        staffName:$that.staffAttendanceManageInfo.staffNameLike
                    }
                }
                vc.http.apiGet('/query.staff.infos',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        // 员工列表 和 岗位列表匹配
                        let staffList = _json.staffs;
                        $that.staffAttendanceManageInfo.staffs = staffList;
                        if (staffList && staffList.length > 0) {
                            $that.staffAttendanceManageInfo.curStaffId = staffList[0].userId;
                            $that._loadStaffAttendances();
                        }
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            initStaffDate: function () {
                let _date = new Date(new Date());
                $that.staffAttendanceManageInfo.curMonth = _date.getMonth() + 1
                $that.staffAttendanceManageInfo.curYear = _date.getFullYear();
                $that.staffAttendanceManageInfo.curDate = _date.getFullYear() + "-" + (_date.getMonth() + 1);
                $that.staffAttendanceManageInfo.maxDay = new Date(_date.getFullYear(), _date.getMonth() + 1, 0).getDate();
                vc.initDateMonth('queryDate', function (_value) {
                    $that.staffAttendanceManageInfo.curDate = _value;
                    let _values = _value.split('-');
                    $that.staffAttendanceManageInfo.curYear = _values[0];
                    $that.staffAttendanceManageInfo.curMonth = _values[1];
                    $that._loadStaffAttendances();
                })
                //防止多次点击时间插件失去焦点
                document.getElementsByClassName(' form-control queryDate')[0].addEventListener('click', myfunc)
 
                function myfunc(e) {
                    e.currentTarget.blur();
                }
            },
            _getAttendanceState: function (_day) {
                let _attendance = $that._getDayAttendance(_day);
                if (!_attendance) {
                    return "<span style='color:rgb(220, 53, 69)'>未考勤</span>";
                }
                return "<span style='color:rgb(18, 150, 219)'>" + _attendance.stateName + "</span>";
            },
            _getAttendanceDetail: function (_day) {
                let _attendance = $that._getDayAttendance(_day);
                if (!_attendance) {
 
                    let _date = new Date();
                    let _taskYear = $that.staffAttendanceManageInfo.curYear
                    let _taskMonth = $that.staffAttendanceManageInfo.curMonth;
                    if(_taskYear == _date.getFullYear() && parseInt(_taskMonth) == (_date.getMonth()+1) && _day > _date.getDate()){
                        return [{
                            rest:'未到时间',
                        }];;
                    }
    
 
                    return [{
                        rest:'无需考勤',
                    }];
                }
                return _attendance.attendanceClassesTaskDetails;
            },
            _getDayAttendance: function (_day) {
                let _attendance = null;
                if (!$that.staffAttendanceManageInfo.attendances) {
                    return _attendance;
                }
                $that.staffAttendanceManageInfo.attendances.forEach(item => {
                    if (item.taskDay == _day) {
                        _attendance = item;
                    }
                });
                return _attendance;
            },
            _getBgColor: function (_curDay) {
                return "#fff"
            },
            _staffAttendanceChangeOrg: function () {
                vc.emit('chooseOrgTree', 'openOrgModal', {});
            },
            swatchStaff: function (_staff) {
                $that.staffAttendanceManageInfo.curStaffId = _staff.userId;
                $that._loadStaffAttendances();
            },
            _loadStaffAttendances: function () {
                if (!$that.staffAttendanceManageInfo.curStaffId) {
                    return;
                }
                if (!$that.staffAttendanceManageInfo.curDate) {
                    return;
                }
                let param = {
                    params: {
                        page: 1,
                        row: 1000,
                        date: $that.staffAttendanceManageInfo.curDate,
                        staffId: $that.staffAttendanceManageInfo.curStaffId
                    }
                };
                //发送get请求
                vc.http.apiGet('/attendanceClass/queryAttendanceClassesTask',
                    param,
                    function (json, res) {
                        var _todayAttendanceManageInfo = JSON.parse(json);
                        $that.staffAttendanceManageInfo.attendances = _todayAttendanceManageInfo.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _checkInLog: function (_day) {
                let _curMonth = $that.staffAttendanceManageInfo.curMonth;
                if (_curMonth < 10) {
                    _curMonth = "0" + _curMonth;
                }
                if (_day < 10) {
                    _day = "0" + _day;
                }
                vc.emit('staffAttendanceDetail', 'openModel', {
                    staffId: $that.staffAttendanceManageInfo.curStaffId,
                    date: $that.staffAttendanceManageInfo.curYear + "-" + _curMonth + '-' + _day
                });
            },
            _replenishCheckIn: function (_day) {
                let _details = $that._getAttendanceDetail(_day);
                if (!_details || _details.length < 1) {
                    vc.toast('不存在 补考勤任务');
                    return;
                }
                let _newDetails = [];
                _details.forEach(item => {
                    if (item.state == '10000') {
                        _newDetails.push(item)
                    }
                });
                if (_newDetails.length < 1) {
                    vc.toast('不存在 补考勤任务');
                    return;
                }
                vc.emit('staffAttendanceReplenishCheckIn', 'openModel', _newDetails);
            }
        }
    });
})(window.vc);