¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container scheduling-container"> |
| | | <!-- çéåºå --> |
| | | <div class="filter-section"> |
| | | <el-form :inline="true" :model="filterForm" class="filter-form"> |
| | | <el-form-item label="åå·¥å§åï¼"> |
| | | <el-input |
| | | v-model="filterForm.employeeName" |
| | | placeholder="请è¾å
¥åå·¥å§å" |
| | | clearable |
| | | style="width: 150px" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="çæ¬¡ç±»åï¼"> |
| | | <el-select v-model="filterForm.shiftType" placeholder="è¯·éæ©çæ¬¡" clearable style="width: 120px"> |
| | | <el-option label="æ©ç" value="æ©ç" /> |
| | | <el-option label="ä¸ç" value="ä¸ç" /> |
| | | <el-option label="æç" value="æç" /> |
| | | <el-option label="å¤ç" value="å¤ç" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="æ¥æèå´ï¼"> |
| | | <el-date-picker |
| | | v-model="filterForm.dateRange" |
| | | type="daterange" |
| | | range-separator="è³" |
| | | start-placeholder="å¼å§æ¥æ" |
| | | end-placeholder="ç»ææ¥æ" |
| | | format="YYYY-MM-DD" |
| | | value-format="YYYY-MM-DD" |
| | | style="width: 250px" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" @click="handleFilter"> |
| | | <el-icon><Search /></el-icon> |
| | | çé |
| | | </el-button> |
| | | <el-button @click="resetFilter"> |
| | | <el-icon><Refresh /></el-icon> |
| | | éç½® |
| | | </el-button> |
| | | <el-button type="primary" @click="openScheduleDialog('add')"> |
| | | <el-icon><Plus /></el-icon> |
| | | æ°å¢æç |
| | | </el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </div> |
| | | |
| | | <!-- æçè¡¨æ ¼ --> |
| | | <div class="table-section"> |
| | | <el-table |
| | | :data="filteredScheduleList" |
| | | border |
| | | stripe |
| | | style="width: 100%" |
| | | height="calc(100vh - 18.5em)" |
| | | @selection-change="handleSelectionChange" |
| | | > |
| | | <el-table-column type="selection" width="55" /> |
| | | <el-table-column prop="employeeName" label="åå·¥å§å" width="120" /> |
| | | <el-table-column prop="employeeId" label="å工工å·" width="100" /> |
| | | <el-table-column prop="department" label="é¨é¨" width="120" /> |
| | | <el-table-column prop="shiftType" label="çæ¬¡ç±»å" width="100"> |
| | | <template #default="scope"> |
| | | <el-tag :type="getShiftTagType(scope.row.shiftType)"> |
| | | {{ scope.row.shiftType }} |
| | | </el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="workDate" label="工使¥æ" width="120" /> |
| | | <el-table-column prop="startTime" label="å¼å§æ¶é´" width="100" /> |
| | | <el-table-column prop="endTime" label="ç»ææ¶é´" width="100" /> |
| | | <el-table-column prop="workHours" label="工使¶é¿" width="100"> |
| | | <template #default="scope"> |
| | | {{ scope.row.workHours }}å°æ¶ |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="status" label="ç¶æ" width="100"> |
| | | <template #default="scope"> |
| | | <el-tag :type="getStatusTagType(scope.row.status)"> |
| | | {{ scope.row.status }} |
| | | </el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="remark" label="夿³¨" min-width="150" /> |
| | | <el-table-column label="æä½" width="200" fixed="right"> |
| | | <template #default="scope"> |
| | | <el-button |
| | | type="primary" |
| | | size="small" |
| | | @click="openScheduleDialog('edit', scope.row)" |
| | | > |
| | | ç¼è¾ |
| | | </el-button> |
| | | <el-button |
| | | type="danger" |
| | | size="small" |
| | | @click="handleDelete(scope.row)" |
| | | > |
| | | å é¤ |
| | | </el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </div> |
| | | |
| | | <!-- æ¹éæä½ --> |
| | | <div class="batch-actions" v-if="selectedRows.length > 0"> |
| | | <el-button |
| | | type="danger" |
| | | @click="handleBatchDelete" |
| | | :disabled="selectedRows.length === 0" |
| | | > |
| | | æ¹éå é¤ ({{ selectedRows.length }}) |
| | | </el-button> |
| | | </div> |
| | | |
| | | <!-- æçæ°å¢/ç¼è¾å¯¹è¯æ¡ --> |
| | | <el-dialog |
| | | v-model="scheduleDialog" |
| | | :title="dialogType === 'add' ? 'æ°å¢æç' : 'ç¼è¾æç'" |
| | | width="700px" |
| | | @close="closeScheduleDialog" |
| | | > |
| | | <el-form |
| | | :model="scheduleForm" |
| | | :rules="scheduleRules" |
| | | ref="scheduleFormRef" |
| | | label-width="120px" |
| | | > |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="åå·¥å§åï¼" prop="employeeName"> |
| | | <el-input v-model="scheduleForm.employeeName" placeholder="请è¾å
¥åå·¥å§å" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å工工å·ï¼" prop="employeeId"> |
| | | <el-input v-model="scheduleForm.employeeId" placeholder="请è¾å
¥å工工å·" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="é¨é¨ï¼" prop="department"> |
| | | <el-select v-model="scheduleForm.department" placeholder="è¯·éæ©é¨é¨" style="width: 100%"> |
| | | <el-option label="ææ¯é¨" value="ææ¯é¨" /> |
| | | <el-option label="éå®é¨" value="éå®é¨" /> |
| | | <el-option label="人äºé¨" value="人äºé¨" /> |
| | | <el-option label="è´¢å¡é¨" value="è´¢å¡é¨" /> |
| | | <el-option label="ç产é¨" value="ç产é¨" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="çæ¬¡ç±»åï¼" prop="shiftType"> |
| | | <el-select v-model="scheduleForm.shiftType" placeholder="è¯·éæ©çæ¬¡" style="width: 100%"> |
| | | <el-option label="æ©ç" value="æ©ç" /> |
| | | <el-option label="ä¸ç" value="ä¸ç" /> |
| | | <el-option label="æç" value="æç" /> |
| | | <el-option label="å¤ç" value="å¤ç" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="工使¥æï¼" prop="workDate"> |
| | | <el-date-picker |
| | | v-model="scheduleForm.workDate" |
| | | type="date" |
| | | placeholder="鿩工使¥æ" |
| | | style="width: 100%" |
| | | format="YYYY-MM-DD" |
| | | value-format="YYYY-MM-DD" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ç¶æï¼" prop="status"> |
| | | <el-select v-model="scheduleForm.status" placeholder="è¯·éæ©ç¶æ" style="width: 100%"> |
| | | <el-option label="已宿" value="已宿" /> |
| | | <el-option label="已确认" value="已确认" /> |
| | | <el-option label="已宿" value="已宿" /> |
| | | <el-option label="已忶" value="已忶" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å¼å§æ¶é´ï¼" prop="startTime"> |
| | | <el-time-picker |
| | | v-model="scheduleForm.startTime" |
| | | placeholder="éæ©å¼å§æ¶é´" |
| | | style="width: 100%" |
| | | format="HH:mm" |
| | | value-format="HH:mm" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ç»ææ¶é´ï¼" prop="endTime"> |
| | | <el-time-picker |
| | | v-model="scheduleForm.endTime" |
| | | placeholder="éæ©ç»ææ¶é´" |
| | | style="width: 100%" |
| | | format="HH:mm" |
| | | value-format="HH:mm" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <el-row :gutter="20"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="夿³¨ï¼" prop="remark"> |
| | | <el-input |
| | | v-model="scheduleForm.remark" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请è¾å
¥å¤æ³¨ä¿¡æ¯" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" @click="submitScheduleForm">确认</el-button> |
| | | <el-button @click="closeScheduleDialog">åæ¶</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, computed, onMounted } from 'vue' |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { Plus, Download, Search, Refresh } from '@element-plus/icons-vue' |
| | | |
| | | // ååºå¼æ°æ® |
| | | const scheduleDialog = ref(false) |
| | | const dialogType = ref('add') |
| | | const selectedRows = ref([]) |
| | | const scheduleFormRef = ref() |
| | | |
| | | // çé表å |
| | | const filterForm = reactive({ |
| | | employeeName: '', |
| | | shiftType: '', |
| | | dateRange: [] |
| | | }) |
| | | |
| | | // æç表å |
| | | const scheduleForm = reactive({ |
| | | id: '', |
| | | employeeName: '', |
| | | employeeId: '', |
| | | department: '', |
| | | shiftType: '', |
| | | workDate: '', |
| | | startTime: '', |
| | | endTime: '', |
| | | workHours: 0, |
| | | status: '已宿', |
| | | remark: '' |
| | | }) |
| | | |
| | | // 表åéªè¯è§å |
| | | const scheduleRules = reactive({ |
| | | employeeName: [{ required: true, message: '请è¾å
¥åå·¥å§å', trigger: 'blur' }], |
| | | employeeId: [{ required: true, message: '请è¾å
¥å工工å·', trigger: 'blur' }], |
| | | department: [{ required: true, message: 'è¯·éæ©é¨é¨', trigger: 'change' }], |
| | | shiftType: [{ required: true, message: 'è¯·éæ©çæ¬¡ç±»å', trigger: 'change' }], |
| | | workDate: [{ required: true, message: 'è¯·éæ©å·¥ä½æ¥æ', trigger: 'change' }], |
| | | startTime: [{ required: true, message: 'è¯·éæ©å¼å§æ¶é´', trigger: 'change' }], |
| | | endTime: [{ required: true, message: 'è¯·éæ©ç»ææ¶é´', trigger: 'change' }], |
| | | status: [{ required: true, message: 'è¯·éæ©ç¶æ', trigger: 'change' }] |
| | | }) |
| | | |
| | | // 模ææçæ°æ® |
| | | const scheduleList = ref([ |
| | | { |
| | | id: 1, |
| | | employeeName: 'å¼ æµ·æ´', |
| | | employeeId: 'EMP001', |
| | | department: 'ææ¯é¨', |
| | | shiftType: 'æ©ç', |
| | | workDate: '2024-01-15', |
| | | startTime: '08:00', |
| | | endTime: '17:00', |
| | | workHours: 9, |
| | | status: '已宿', |
| | | remark: 'æ£å¸¸æç' |
| | | }, |
| | | { |
| | | id: 2, |
| | | employeeName: 'æè¶
', |
| | | employeeId: 'EMP002', |
| | | department: 'éå®é¨', |
| | | shiftType: 'ä¸ç', |
| | | workDate: '2024-01-15', |
| | | startTime: '14:00', |
| | | endTime: '22:00', |
| | | workHours: 8, |
| | | status: '已确认', |
| | | remark: '客æ·ä¼è®®' |
| | | }, |
| | | { |
| | | id: 3, |
| | | employeeName: 'çæ°', |
| | | employeeId: 'EMP003', |
| | | department: 'ç产é¨', |
| | | shiftType: 'æç', |
| | | workDate: '2024-01-15', |
| | | startTime: '22:00', |
| | | endTime: '06:00', |
| | | workHours: 8, |
| | | status: '已宿', |
| | | remark: 'å¤çç产' |
| | | } |
| | | ]) |
| | | |
| | | // 计ç®å±æ§ï¼çéåçæçå表 |
| | | const filteredScheduleList = computed(() => { |
| | | let result = scheduleList.value |
| | | |
| | | if (filterForm.employeeName) { |
| | | result = result.filter(item => |
| | | item.employeeName.includes(filterForm.employeeName) |
| | | ) |
| | | } |
| | | |
| | | if (filterForm.shiftType) { |
| | | result = result.filter(item => item.shiftType === filterForm.shiftType) |
| | | } |
| | | |
| | | if (filterForm.dateRange && filterForm.dateRange.length === 2) { |
| | | result = result.filter(item => { |
| | | const workDate = new Date(item.workDate) |
| | | const startDate = new Date(filterForm.dateRange[0]) |
| | | const endDate = new Date(filterForm.dateRange[1]) |
| | | return workDate >= startDate && workDate <= endDate |
| | | }) |
| | | } |
| | | |
| | | return result |
| | | }) |
| | | |
| | | // è·åçæ¬¡æ ç¾ç±»å |
| | | const getShiftTagType = (shiftType) => { |
| | | const typeMap = { |
| | | 'æ©ç': 'success', |
| | | 'ä¸ç': 'warning', |
| | | 'æç': 'info', |
| | | 'å¤ç': 'danger' |
| | | } |
| | | return typeMap[shiftType] || 'info' |
| | | } |
| | | |
| | | // è·åç¶ææ ç¾ç±»å |
| | | const getStatusTagType = (status) => { |
| | | const typeMap = { |
| | | '已宿': 'info', |
| | | '已确认': 'warning', |
| | | '已宿': 'success', |
| | | '已忶': 'danger' |
| | | } |
| | | return typeMap[status] || 'info' |
| | | } |
| | | |
| | | // çé |
| | | const handleFilter = () => { |
| | | // çéé»è¾å·²å¨è®¡ç®å±æ§ä¸å®ç° |
| | | } |
| | | |
| | | // éç½®çé |
| | | const resetFilter = () => { |
| | | filterForm.employeeName = '' |
| | | filterForm.shiftType = '' |
| | | filterForm.dateRange = [] |
| | | } |
| | | |
| | | // æå¼æçå¯¹è¯æ¡ |
| | | const openScheduleDialog = (type, data) => { |
| | | dialogType.value = type |
| | | scheduleDialog.value = true |
| | | |
| | | if (type === 'edit' && data) { |
| | | // ç¼è¾æ¨¡å¼ï¼å¤å¶æ°æ® |
| | | Object.assign(scheduleForm, { ...data }) |
| | | } else { |
| | | // æ°å¢æ¨¡å¼ï¼é置表å |
| | | Object.keys(scheduleForm).forEach(key => { |
| | | scheduleForm[key] = '' |
| | | }) |
| | | scheduleForm.status = '已宿' |
| | | scheduleForm.workDate = new Date().toISOString().split('T')[0] |
| | | } |
| | | } |
| | | |
| | | // å
³éæçå¯¹è¯æ¡ |
| | | const closeScheduleDialog = () => { |
| | | scheduleFormRef.value?.resetFields() |
| | | scheduleDialog.value = false |
| | | } |
| | | |
| | | // 计ç®å·¥ä½æ¶é¿ |
| | | const calculateWorkHours = () => { |
| | | if (scheduleForm.startTime && scheduleForm.endTime) { |
| | | const start = new Date(`2000-01-01 ${scheduleForm.startTime}`) |
| | | const end = new Date(`2000-01-01 ${scheduleForm.endTime}`) |
| | | |
| | | if (end < start) { |
| | | // 跨天çæ
åµ |
| | | end.setDate(end.getDate() + 1) |
| | | } |
| | | |
| | | const diffMs = end - start |
| | | const diffHours = diffMs / (1000 * 60 * 60) |
| | | scheduleForm.workHours = Math.round(diffHours * 100) / 100 |
| | | } |
| | | } |
| | | |
| | | // æäº¤æç表å |
| | | const submitScheduleForm = () => { |
| | | scheduleFormRef.value.validate((valid) => { |
| | | if (valid) { |
| | | // 计ç®å·¥ä½æ¶é¿ |
| | | calculateWorkHours() |
| | | |
| | | if (dialogType.value === 'add') { |
| | | // æ°å¢ |
| | | const newSchedule = { |
| | | ...scheduleForm, |
| | | id: Date.now() // ä½¿ç¨æ¶é´æ³ä½ä¸ºä¸´æ¶ID |
| | | } |
| | | scheduleList.value.push(newSchedule) |
| | | ElMessage.success('æ°å¢æçæå') |
| | | } else { |
| | | // ç¼è¾ |
| | | const index = scheduleList.value.findIndex(item => item.id === scheduleForm.id) |
| | | if (index !== -1) { |
| | | scheduleList.value[index] = { ...scheduleForm } |
| | | ElMessage.success('ç¼è¾æçæå') |
| | | } |
| | | } |
| | | |
| | | closeScheduleDialog() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // å 餿ç |
| | | const handleDelete = (row) => { |
| | | ElMessageBox.confirm( |
| | | `ç¡®å®è¦å é¤ ${row.employeeName} çæçè®°å½åï¼`, |
| | | 'å é¤æç¤º', |
| | | { |
| | | confirmButtonText: '确认', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning' |
| | | } |
| | | ).then(() => { |
| | | const index = scheduleList.value.findIndex(item => item.id === row.id) |
| | | if (index !== -1) { |
| | | scheduleList.value.splice(index, 1) |
| | | ElMessage.success('å 餿å') |
| | | } |
| | | }).catch(() => { |
| | | ElMessage.info('已忶å é¤') |
| | | }) |
| | | } |
| | | |
| | | // æ¹éå é¤ |
| | | const handleBatchDelete = () => { |
| | | if (selectedRows.value.length === 0) { |
| | | ElMessage.warning('è¯·éæ©è¦å é¤çè®°å½') |
| | | return |
| | | } |
| | | |
| | | ElMessageBox.confirm( |
| | | `ç¡®å®è¦å é¤éä¸ç ${selectedRows.value.length} æ¡æçè®°å½åï¼`, |
| | | 'æ¹éå é¤æç¤º', |
| | | { |
| | | confirmButtonText: '确认', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning' |
| | | } |
| | | ).then(() => { |
| | | const selectedIds = selectedRows.value.map(row => row.id) |
| | | scheduleList.value = scheduleList.value.filter(item => !selectedIds.includes(item.id)) |
| | | selectedRows.value = [] |
| | | ElMessage.success('æ¹éå 餿å') |
| | | }).catch(() => { |
| | | ElMessage.info('已忶å é¤') |
| | | }) |
| | | } |
| | | |
| | | // éæ©ååäºä»¶ |
| | | const handleSelectionChange = (selection) => { |
| | | selectedRows.value = selection |
| | | } |
| | | |
| | | // ç嬿¶é´ååï¼èªå¨è®¡ç®å·¥ä½æ¶é¿ |
| | | const watchTimeChange = () => { |
| | | if (scheduleForm.startTime && scheduleForm.endTime) { |
| | | calculateWorkHours() |
| | | } |
| | | } |
| | | |
| | | // çå½å¨æ |
| | | onMounted(() => { |
| | | // 页é¢åå§å |
| | | }) |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .scheduling-container { |
| | | padding: 20px; |
| | | background-color: #f5f7fa; |
| | | min-height: 100vh; |
| | | } |
| | | |
| | | .page-header { |
| | | text-align: center; |
| | | margin-bottom: 30px; |
| | | padding: 20px; |
| | | background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
| | | border-radius: 12px; |
| | | color: white; |
| | | } |
| | | |
| | | .page-header h2 { |
| | | color: white; |
| | | margin-bottom: 10px; |
| | | font-size: 28px; |
| | | font-weight: 600; |
| | | } |
| | | |
| | | .page-header p { |
| | | color: rgba(255, 255, 255, 0.9); |
| | | font-size: 14px; |
| | | margin: 0 0 15px 0; |
| | | } |
| | | |
| | | .header-controls { |
| | | display: flex; |
| | | justify-content: center; |
| | | gap: 15px; |
| | | } |
| | | |
| | | .filter-section { |
| | | background: white; |
| | | padding: 20px; |
| | | border-radius: 8px; |
| | | margin-bottom: 20px; |
| | | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| | | } |
| | | |
| | | .filter-form { |
| | | margin: 0; |
| | | } |
| | | |
| | | .table-section { |
| | | background: white; |
| | | border-radius: 8px; |
| | | overflow: hidden; |
| | | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| | | margin-bottom: 20px; |
| | | } |
| | | |
| | | .batch-actions { |
| | | background: white; |
| | | padding: 15px 20px; |
| | | border-radius: 8px; |
| | | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| | | } |
| | | |
| | | .dialog-footer { |
| | | text-align: right; |
| | | } |
| | | |
| | | :deep(.el-form-item__label) { |
| | | font-weight: 500; |
| | | color: #303133; |
| | | } |
| | | |
| | | :deep(.el-input__wrapper) { |
| | | box-shadow: 0 0 0 1px #dcdfe6 inset; |
| | | } |
| | | |
| | | :deep(.el-input__wrapper:hover) { |
| | | box-shadow: 0 0 0 1px #c0c4cc inset; |
| | | } |
| | | |
| | | :deep(.el-input__wrapper.is-focus) { |
| | | box-shadow: 0 0 0 1px #409eff inset; |
| | | } |
| | | |
| | | /* ååºå¼è®¾è®¡ */ |
| | | @media (max-width: 768px) { |
| | | .scheduling-container { |
| | | padding: 10px; |
| | | } |
| | | |
| | | .page-header { |
| | | padding: 15px; |
| | | } |
| | | |
| | | .page-header h2 { |
| | | font-size: 24px; |
| | | } |
| | | |
| | | .header-controls { |
| | | flex-direction: column; |
| | | gap: 10px; |
| | | } |
| | | } |
| | | |
| | | @media (max-width: 768px) { |
| | | .filter-form .el-form-item { |
| | | margin-bottom: 10px; |
| | | } |
| | | } |
| | | </style> |