index.html
5.3 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>考勤</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
padding: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
color: #555;
}
.form-group input, .form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.form-group input[type="datetime-local"] {
max-width: 300px;
}
.form-group button {
width: 100%;
padding: 10px;
background-color: #28a745;
border: none;
border-radius: 4px;
color: white;
font-size: 16px;
cursor: pointer;
}
.form-group button:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="container">
<h2>考勤</h2>
<form id="workScheduleForm">
<div class="form-group">
<label for="employeeName">员工姓名:</label>
<input type="text" id="employeeName" name="employeeName" placeholder="请输入员工姓名" required autocomplete="off">
<ul id="employeeList" style="border: 1px solid #ddd; display: none; max-height: 150px; overflow-y: auto; margin-top: 5px; padding: 5px;">
<!-- 动态生成的员工列表 -->
</ul>
</div>
<div class="form-group">
<label for="startTime">上班时间:</label>
<input type="datetime-local" id="startTime" name="startTime" step="1" required>
</div>
<div class="form-group">
<label for="endTime">下班时间:</label>
<input type="datetime-local" id="endTime" name="endTime" step="1" required>
</div>
<div class="form-group">
<button type="submit">提交</button>
</div>
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const employeeInput = document.getElementById('employeeName');
const employeeList = document.getElementById('employeeList');
employeeInput.addEventListener('input', function() {
const query = employeeInput.value.trim();
if (query.length > 0) {
fetch(`https://crm.bosiny.com/addons/qingdong/staff/listStaff2?name=${query}`)
.then(response => response.json())
.then(data => {
employeeList.innerHTML = ''; // 清空列表
if (data.data.length > 0) {
data.data.forEach(employee => {
const li = document.createElement('li');
li.textContent = employee.name;
li.style.cursor = 'pointer';
li.addEventListener('click', function() {
employeeInput.value = employee.name;
employeeInput.setAttribute('data-id', employee.id); // 将员工ID存储在输入框的data属性中
employeeList.style.display = 'none'; // 选择后隐藏列表
});
employeeList.appendChild(li);
});
employeeList.style.display = 'block';
} else {
employeeList.style.display = 'none';
}
})
.catch(error => {
console.error('Error fetching employee data:', error);
employeeList.style.display = 'none';
});
} else {
employeeList.style.display = 'none';
}
});
document.getElementById('workScheduleForm').addEventListener('submit', function(event) {
event.preventDefault();
const employeeId = employeeInput.getAttribute('data-id');
const startTime = document.getElementById('startTime').value;
const endTime = document.getElementById('endTime').value;
if (employeeId && startTime && endTime) {
const formData = new FormData();
formData.append('employeeId', employeeId);
formData.append('startTime', startTime);
formData.append('endTime', endTime);
fetch('https://crm.bosiny.com/addons/qingdong/staff/addTime', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.log('data',data)
// return false;
if (data.code == 1) {
alert('修改成功');
} else {
alert('提交失败');
}
})
} else {
alert('请填写所有字段');
}
});
});
</script>
</body>
</html>