index.html 5.3 KB
<!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>