lyg
2025-03-04 72bbec1590f85974d369ce7aeaa05be8905672a0
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
layui.define(['tool'], function (exports) {
    const tool = layui.tool,layer = layui.layer,form = layui.form,laydate = layui.laydate;
    const obj = {
        loading:false,
        load: function (tid) {
            let callback = function (res) {
                if (res.code == 0 && res.data.length > 0) {
                    let itemSchedule = '';
                    $.each(res.data, function (index, item) {
                        itemSchedule += `
                            <div class="pt-2">
                                <p class="gray">${item.start_time}~${item.end_time},${item.labor_time}工时</p>
                                <p><span class="blue">${item.name}:</span>${item.title}</p>
                            </div>
                        `;
                    });
                    $("#schedule_" + tid).html(itemSchedule);
                    layer.closeAll();
                }
            }
            tool.get("/project/api/task_schedule", { tid: tid }, callback);
        },
        //保存
        save: function (postData) {
            let callback = function (e) {
                if (e.code == 0) {
                    layer.closeAll();
                    layer.msg(e.msg);
                    if(layui.scheduleTable){
                        layui.scheduleTable.reload();
                    }
                    else{
                        setTimeout(function(){
                            location.reload();
                        },1000);    
                    }                    
                } else {
                    layer.msg(e.msg);
                }
            }
            tool.post("/oa/schedule/add", postData, callback);
        },
        //查看
        view: function (detail) {
            let project = '';
            if(detail.tid>0){
                project = `<table class="layui-table" style="margin:12px 12px 0;">
                                <tr>
                                <td class="layui-td-gray">关联项目</td>
                                <td>${detail.project}</td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">关联任务</td>
                                    <td>${detail.task}</td>
                                </tr>
                            </table>`;
            }
            let content = `<div style="width:696px">
                            <table class="layui-table" style="margin:12px 12px 0;">
                                <tr>
                                    <td class="layui-td-gray">执行员工</td>
                                    <td>${detail.name}</td>                                    
                                    <td class="layui-td-gray">所在部门</td>
                                    <td>${detail.department}</td>
                                    <td class="layui-td-gray">工作类别</td>
                                    <td>${detail.work_cate}</td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">时间范围</td>
                                    <td colspan="3">${detail.start_time} 至 ${detail.end_time},共${detail.labor_time}工时</td>
                                    <td class="layui-td-gray">工作类型</td>
                                    <td>${detail.labor_type_string}</td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">工作内容</td>
                                    <td colspan="5">${detail.title}</td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">补充描述</td>
                                    <td colspan="5">${detail.remark}</td>
                                </tr>
                            </table>
                            ${project}
                        </div>`;
            $(parent.$('.express-close')).addClass('parent-colse');            
            layer.open({
                type: 1,
                title: '工作记录详情',
                area: ['720px', '420px'],
                content: content,
                end: function(){
                    $(parent.$('.express-close')).removeClass('parent-colse');
                },
                success: function () {
 
                },
                btn: ['关闭'],
                btnAlign: 'c',
                yes: function (idx) {
                    layer.close(idx);
                }
            })
        },
        add: function (tid, schedule) {
            let that = this, detail = {}, title = '添加工作记录';
            if(that.loading == true){
                return false;
            }
            that.loading = true;
            let html_time = '';
            if (schedule['id'] > 0) {
                if(schedule['admin_id'] != login_admin){
                    layer.msg('不能编辑他人的工作记录');
                    return false;
                }
                title = '编辑工作记录';
                detail['id'] = schedule['id'];
                detail['cid'] = schedule['cid'];
                detail['tid'] = schedule['tid'];
                detail['title'] = schedule['title'];
                detail['labor_type'] = schedule['labor_type'];
                detail['start_time_a'] = schedule['start_time_a'];
                detail['start_time_b'] = schedule['start_time_b'];
                detail['end_time_a'] = schedule['end_time_a'];
                detail['end_time_b'] = schedule['end_time_b'];
                detail['remark'] = schedule['remark'];
                
                html_time = detail.start_time_a+' '+detail.start_time_b+' 至 '+detail.end_time_b+',共'+schedule.labor_time+'工时';
            } else {
                detail['id'] = schedule['id'];
                detail['tid'] = tid;
                detail['cid'] = 1;
                detail['title'] = '';
                detail['labor_type'] = 0;
                detail['start_time_a'] = schedule['start_time_a']?schedule['start_time_a']:'';
                detail['start_time_b'] = '09:00';
                detail['end_time_a'] = schedule['end_time_a']?schedule['end_time_a']:'';
                detail['end_time_b'] = '09:30';
                detail['remark'] = '';
                
                html_time = `<input id="start_time_a" name="start_time_a" style="width:90px; display:inline-block;" autocomplete="off" class="layui-input" value="${detail.start_time_a}" readonly lay-verify="required" lay-reqText="请选择"><div style="display: inline-block; margin-left:3px; width: 80px;"><select lay-filter="start_time_b" id="start_time_b"></select></div> 至 <input id="end_time_a" name="end_time_a" style="width:90px; display:inline-block;" autocomplete="off" class="layui-input" value="${detail.end_time_a}" readonly lay-verify="required" lay-reqText="请选择"><div style="display: inline-block; margin-left:3px; width: 80px;"><select lay-filter="end_time_b" id="end_time_b"></select></div>`;
            }            
            let callback = function(e){
                that.loading = false;
                if(e.code==0){
                    let cate = e.data;    
                    let content = `<form class="layui-form" style="width:696px">
                            <table class="layui-table" style="margin:12px 12px 0;">
                                <tr>
                                    <td class="layui-td-gray">时间范围 <span style="color: red">*</span></td>
                                    <td>${html_time}</td>
                                    <td class="layui-td-gray">工作类别<font>*</font></td>
                                    <td style="width: 120px;"><select name="cid" lay-filter="work_cate" id="work_cate"></select></td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">工作类型<font>*</font></td>
                                    <td colspan="3"><input type="radio" name="labor_type" lay-filter="labor_type" value="1" title="案头工作"><input type="radio" name="labor_type" value="2" lay-filter="labor_type" title="外勤工作"></td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">工作内容 <span style="color: red">*</span></td>
                                    <td colspan="3"><input name="title" class="layui-input" value="${detail.title}" lay-verify="required" lay-reqText="请完成工作内容"></td>
                                </tr>
                                <tr>
                                    <td class="layui-td-gray">补充描述</td>
                                    <td colspan="3">
                                        <textarea name="remark" form-input="remark" class="layui-textarea" style="min-height:120px;">${detail.remark}</textarea>
                                        <input name="tid" type="hidden" value="${detail.tid}">
                                    </td>
                                </tr>
                            </table>
                        </form>`;
                    $(parent.$('.express-close')).addClass('parent-colse');        
                    layer.open({
                        type: 1,
                        title: title,
                        area: ['720px', '420px'],
                        content: content,
                        end: function(){
                            $(parent.$('.express-close')).removeClass('parent-colse');
                        },
                        success: function () {
                            if (detail['id'] == 0) {
                                //日期时间范围
                                laydate.render({
                                    elem: '#start_time_a',
                                    type: 'date',
                                    min: -7,
                                    max: 0,
                                    format: 'yyyy-MM-dd',
                                    showBottom: false,
                                    done: function (a, b, c) {
                                        $('#end_time_a').val(a);
                                        detail.start_time_a = a;
                                        detail.end_time_a = a;
                                    }
                                });
 
                                //日期时间范围
                                laydate.render({
                                    elem: '#end_time_a',
                                    type: 'date',
                                    min: -7,
                                    max: 0,
                                    format: 'yyyy-MM-dd',
                                    showBottom: false,
                                    done: function (a, b, c) {
                                        $('#start_time_a').val(a);
                                        detail.start_time_a = a;
                                        detail.end_time_a = a;
                                    }
                                });
                                $('#start_time_b,#end_time_b').empty();
 
                                var hourArray = [];
                                for (var h = 0; h < 24; h++) {
                                    var t = h < 10 ? '0' + h : h
                                    var t_1 = t + ':00', t_2 = t + ':15', t_3 = t + ':30', t_4 = t + ':45';
                                    hourArray.push(t_1, t_2, t_3, t_4);
                                }
 
                                var html_1 = '', html_2 = '', def_h1 = detail['start_time_b'], def_h2 = detail['end_time_b'];
                                for (var s = 0; s < hourArray.length; s++) {
                                    var check_1 = '', check_2 = '';
                                    if (hourArray[s] == def_h1) {
                                        check_1 = 'selected';
                                    }
                                    if (hourArray[s] == def_h2) {
                                        check_2 = 'selected';
                                    }
                                    html_1 += '<option value="' + hourArray[s] + '" ' + check_1 + '>' + hourArray[s] + '</option>';
                                    html_2 += '<option value="' + hourArray[s] + '" ' + check_2 + '>' + hourArray[s] + '</option>';
                                }
 
                                $('#start_time_b').append(html_1);
                                $('#end_time_b').append(html_2);
                            }
                            $("input[name=labor_type][value="+detail.labor_type+"]").prop("checked","true");    
                            
                            var html_c='';
                            for (var c = 0; c < cate.length; c++) {
                                var check_c = '';
                                if (cate[c].id == detail['cid']) {
                                    check_c = 'selected';
                                }
                                html_c += '<option value="' + cate[c].id + '" ' + check_c + '>' + cate[c].title + '</option>';
                            }
 
                            $('#work_cate').append(html_c);
                            
                            form.render();
 
                            form.on('select(start_time_b)', function (data) {
                                detail.start_time_b = data.value;
                            });
                            form.on('select(end_time_b)', function (data) {
                                detail.end_time_b = data.value;
                            });
                            $('[name="title"]').on('input', function () {
                                var _val = $(this).val();
                                detail.title = _val;
                            });
                            form.on('radio(labor_type)', function(data){
                               detail.labor_type=data.value;
                            })
                            form.on('select(work_cate)', function(data){
                               detail.cid=data.value;
                            })
                            $('[form-input="remark"]').on('input', function () {
                                var _val = $(this).val();
                                detail.remark = _val;
                            });
                        },
                        btn: ['确定提交'],
                        btnAlign: 'c',
                        yes: function (idx) {
                            if (detail.start_time_a == '' || detail.end_time_a == '') {
                                layer.msg('请选择工作时间范围');
                                return;
                            }
                            if(detail.labor_type==0){
                                layer.msg('请选择工作类型');
                                return;
                            }
                            if (detail.title == '') {
                                layer.msg('请填写工作内容');
                                return;
                            }
                            that.save(detail);
                        }
                    })
                }
            }
            tool.get("/api/index/get_work_cate", {}, callback);
        }
    };
    exports('oaSchedule', obj);
});