yaowanxin
20 小时以前 85ef9a437fe32c569b55f6e8391fdefb76780840
src/views/personnelManagement/selfService/index.vue
@@ -26,7 +26,7 @@
            <el-button type="primary" @click="addAttendanceRecord">新增记录</el-button>
          </div>
        </template>
        <el-table :data="attendanceData" style="width: 100%">
        <el-table :data="attendanceData" style="width: 100%" :loading="tableLoading">
          <el-table-column prop="date" label="日期"  />
          <el-table-column prop="checkIn" label="签到时间"  />
          <el-table-column prop="checkOut" label="签退时间"  />
@@ -41,7 +41,7 @@
          <el-table-column label="操作" width="150">
            <template #default="scope">
              <el-button size="small" @click="editAttendanceRecord(scope.row)">编辑</el-button>
              <el-button size="small" type="danger" @click="deleteAttendanceRecord(scope.$index)">删除</el-button>
              <el-button size="small" type="danger" @click="deleteAttendanceRecord(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
@@ -52,15 +52,15 @@
        <template #header>
          <div class="card-header">
            <span>薪资单查询</span>
            <el-date-picker v-model="salaryMonth" type="month" placeholder="选择月份" />
            <el-date-picker v-model="payDateStr" type="month" placeholder="选择月份" value-format="YYYY-MM" format="YYYY-MM" @change="changMonth"/>
          </div>
        </template>
        <el-table :data="salaryData" style="width: 100%">
          <el-table-column prop="month" label="月份"  />
          <el-table-column prop="payDate" label="月份"  />
          <el-table-column prop="basicSalary" label="基本工资"  />
          <el-table-column prop="bonus" label="奖金"  />
          <el-table-column prop="deduction" label="扣款"  />
          <el-table-column prop="total" label="实发工资"  />
          <el-table-column prop="actualWages" label="实发工资"  />
          <el-table-column prop="status" label="状态" >
            <template #default="scope">
              <el-tag :type="scope.row.status === '已发放' ? 'success' : 'warning'">
@@ -76,7 +76,7 @@
        <template #header>
          <div class="card-header">
            <span>假期申请管理</span>
            <el-button type="primary" @click="showLeaveDialog = true">申请假期</el-button>
            <el-button type="primary" @click="openLeaveForm">申请假期</el-button>
          </div>
        </template>
        <el-table :data="leaveData" style="width: 100%">
@@ -95,7 +95,7 @@
          <el-table-column label="操作" width="150">
            <template #default="scope">
              <el-button size="small" @click="editLeaveRecord(scope.row)">编辑</el-button>
              <el-button size="small" type="danger" @click="deleteLeaveRecord(scope.$index)">删除</el-button>
              <el-button size="small" type="danger" @click="deleteLeaveRecord(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
@@ -106,7 +106,7 @@
        <template #header>
          <div class="card-header">
            <span>个人信息维护</span>
            <el-button type="primary" @click="editProfile = true">编辑信息</el-button>
            <el-button type="primary" @click="editProfileForm">编辑信息</el-button>
          </div>
        </template>
        <el-descriptions :column="2" border>
@@ -117,13 +117,13 @@
          <el-descriptions-item label="入职日期">{{ profile.hireDate }}</el-descriptions-item>
          <el-descriptions-item label="联系电话">{{ profile.phone }}</el-descriptions-item>
          <el-descriptions-item label="邮箱">{{ profile.email }}</el-descriptions-item>
          <el-descriptions-item label="地址">{{ profile.address }}</el-descriptions-item>
          <el-descriptions-item label="地址">{{ profile.adress }}</el-descriptions-item>
        </el-descriptions>
      </el-card>
    </div>
    <!-- 假期申请弹窗 -->
    <el-dialog v-model="showLeaveDialog" title="申请假期" width="500px">
    <el-dialog v-model="showLeaveDialog" :title="leaveOperationType === 'add' ? '申请假期' : '编辑假期'" width="500px">
      <el-form :model="leaveForm" label-width="100px">
        <el-form-item label="假期类型">
          <el-select v-model="leaveForm.type" placeholder="请选择假期类型">
@@ -142,6 +142,13 @@
        <el-form-item label="申请原因">
          <el-input v-model="leaveForm.reason" type="textarea" rows="3" />
        </el-form-item>
        <!-- <el-form-item label="审批状态">
          <el-select v-model="leaveForm.status" placeholder="请选择审批状态">
            <el-option label="审批中" value="审批中" />
            <el-option label="已通过" value="已通过" />
            <el-option label="已拒绝" value="已拒绝" />
          </el-select>
        </el-form-item> -->
      </el-form>
      <template #footer>
        <el-button @click="showLeaveDialog = false">取消</el-button>
@@ -149,11 +156,11 @@
      </template>
    </el-dialog>
    <!-- 新增考勤记录弹窗 -->
    <el-dialog v-model="showAttendanceDialog" title="新增考勤记录" width="500px">
    <!-- 新增-编辑考勤记录弹窗 -->
    <el-dialog v-model="showAttendanceDialog" :title="operationType === 'add' ? '新增考勤记录' : '编辑考勤记录'" width="500px">
      <el-form :model="attendanceForm" :rules="attendanceRules" ref="attendanceFormRef" label-width="100px">
        <el-form-item label="日期" prop="date">
          <el-date-picker v-model="attendanceForm.date" type="date" placeholder="选择日期" />
          <el-date-picker v-model="attendanceForm.date" type="date" value-format="YYYY-MM-DD" format="YYYY-MM-DD" placeholder="选择日期" />
        </el-form-item>
        <el-form-item label="签到时间" prop="checkIn">
          <el-time-picker v-model="attendanceForm.checkIn" placeholder="选择签到时间" format="HH:mm" value-format="HH:mm" />
@@ -189,7 +196,7 @@
          <el-input v-model="profileForm.email" />
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="profileForm.address" type="textarea" rows="2" />
          <el-input v-model="profileForm.adress" type="textarea" rows="2" />
        </el-form-item>
      </el-form>
      <template #footer>
@@ -201,14 +208,29 @@
</template>
<script setup>
import { ref, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { ref, reactive, watch, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { 
  Calendar, 
  Money, 
  Clock, 
  User
} from '@element-plus/icons-vue'
import { personalAttendanceRecordsListPage, personalAttendanceRecordsAdd, personalAttendanceRecordsUpdate, personalAttendanceRecordsDelete, holidayApplicationListPage, holidayApplicationAdd, holidayApplicationUpdate, holidayApplicationDelete } from '@/api/personnelManagement/selfService'
import { compensationListPage, compensationAdd, compensationUpdate, compensationDelete } from '@/api/personnelManagement/payrollManagement'
const { proxy } = getCurrentInstance()
import { getUserProfile } from '@/api/system/user.js'
import {staffJoinUpdate, staffJoinListPage} from "@/api/personnelManagement/onboarding.js";
import { fa, id } from 'element-plus/es/locales.mjs'
const tableLoading = ref(false)
// 分页参数
const page = reactive({
  current: 1,
  size: 10,
  total: 0
})
// 当前视图
const currentView = ref('attendance')
@@ -222,63 +244,84 @@
]
// 考勤数据
const attendanceData = ref([
  { date: '2024-01-15', checkIn: '09:00', checkOut: '18:00', workHours: '9小时', status: '正常' },
  { date: '2024-01-16', checkIn: '08:55', checkOut: '18:05', workHours: '9小时10分', status: '正常' },
  { date: '2024-01-17', checkIn: '09:15', checkOut: '18:00', workHours: '8小时45分', status: '迟到' }
])
const attendanceData = ref([])
// 薪资数据
const salaryData = ref([
  { month: '2024-01', basicSalary: 8000, bonus: 1000, deduction: 200, total: 8800, status: '已发放' },
  { month: '2023-12', basicSalary: 8000, bonus: 800, deduction: 150, total: 8650, status: '已发放' }
])
const salaryData = ref([])
// 假期数据
const leaveData = ref([
  { type: '年假', startDate: '2024-02-01', endDate: '2024-02-03', days: 3, reason: '春节回家', status: '已通过' },
  { type: '病假', startDate: '2024-01-20', endDate: '2024-01-21', days: 2, reason: '感冒发烧', status: '审批中' }
])
const leaveData = ref([])
const currentUser = ref()
const user= ref()
// 个人信息
const profile = ref({
  name: '张海洋',
  employeeId: 'EMP001',
  department: '技术部',
  position: '软件工程师',
  hireDate: '2023-03-01',
  phone: '13800138000',
  email: 'zhangsan@company.com',
  address: '北京市朝阳区xxx街道xxx号'
})
  id: '',
  name: '',
  employeeId: '',
  department: '',
  position: '',
  hireDate: '',
  phone: '',
  email: '',
  adress: ''
  })
// 弹窗控制
const showLeaveDialog = ref(false)
const editProfile = ref(false)
const salaryMonth = ref('')
const payDateStr = ref('')
// 表单数据
const leaveForm = reactive({
  id: '',
  type: '',
  startDate: '',
  endDate: '',
  reason: ''
  days: 0,
  reason: '',
  status: ''
})
const profileForm = reactive({
  name: '',
  phone: '',
  email: '',
  address: ''
  name: "",
  email: "",
  adress: "",
  phone: "",
})
const joinForm = reactive({
  id: "",
  staffNo: "",
  staffName: "",
  email: "",
  adress: "",
  sex: "",
  nativePlace: "",
  postJob: "",
  firstStudy: "",
  profession: "",
  identityCard: "",
  age: 0,
  phone: "",
  emergencyContact: "",
  emergencyContactPhone: "",
  contractTerm: 0,
  contractStartTime: "",
  contractEndTime: "",
  staffState: 1,
})
// 新增考勤记录:弹窗与表单
const operationType = ref('add')
const leaveOperationType = ref('add')
const showAttendanceDialog = ref(false)
const attendanceFormRef = ref(null)
const attendanceForm = reactive({
  id: '',
  date: '',
  checkIn: '',
  checkOut: '',
  workHours: '',
  status: '正常'
})
const attendanceRules = {
@@ -305,6 +348,7 @@
// 新增考勤记录(打开弹窗并预填默认值)
const addAttendanceRecord = () => {
  operationType.value = 'add'
  attendanceForm.date = new Date().toISOString().split('T')[0]
  attendanceForm.checkIn = '09:00'
  attendanceForm.checkOut = '18:00'
@@ -324,11 +368,15 @@
  return m === 0 ? `${h}小时` : `${h}小时${m}分`
}
// 提交新增考勤记录
// 编辑考勤记录
const editAttendanceRecord = (row) => {
  operationType.value = 'edit'
  Object.assign(attendanceForm, row)
  showAttendanceDialog.value = true
}
// 提交新增-编辑考勤记录
const submitAttendance = () => {
  if (!attendanceFormRef.value) return
  attendanceFormRef.value.validate((valid) => {
    if (!valid) return
  // if (!attendanceFormRef.value) return
    const workHours = computeWorkHours(attendanceForm.checkIn, attendanceForm.checkOut)
    const newRecord = {
      date: attendanceForm.date,
@@ -337,88 +385,320 @@
      workHours,
      status: attendanceForm.status
    }
    attendanceData.value.unshift(newRecord)
    showAttendanceDialog.value = false
    // 重置表单
    attendanceForm.date = ''
    attendanceForm.checkIn = ''
    attendanceForm.checkOut = ''
    attendanceForm.status = '正常'
    ElMessage.success('考勤记录添加成功')
  if (operationType.value === 'add') {
    personalAttendanceRecordsAdd(newRecord)
    .then(res => {
      if (res.code === 200) {
        ElMessage.success('考勤记录添加成功')
        getPersonalAttendanceRecordsList()
        showAttendanceDialog.value = false
        // 重置表单
        attendanceForm.date = ''
        attendanceForm.checkIn = ''
        attendanceForm.checkOut = ''
        attendanceForm.status = '正常'
      }
    }).catch(err => {
      ElMessage.error('考勤记录添加失败')
    })
  }else{
    attendanceForm.workHours = computeWorkHours(attendanceForm.checkIn, attendanceForm.checkOut)
    personalAttendanceRecordsUpdate(attendanceForm)
    .then(res => {
      if (res.code === 200) {
        ElMessage.success('考勤记录更新成功')
        getPersonalAttendanceRecordsList()
        showAttendanceDialog.value = false
        // 重置表单
        attendanceForm.date = ''
        attendanceForm.checkIn = ''
        attendanceForm.checkOut = ''
        attendanceForm.status = '正常'
      }
    }).catch(err => {
      ElMessage.error('考勤记录更新失败')
    })
  }
  // attendanceFormRef.value.validate((valid) => {
  //   if (!valid) return
  // })
}
// 删除考勤记录
const deleteAttendanceRecord = (row) => {
  ElMessageBox.confirm('确定删除该考勤记录吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    personalAttendanceRecordsDelete(row.id)
    .then(res => {
      if (res.code === 200) {
        ElMessage.success('考勤记录删除成功')
        getPersonalAttendanceRecordsList()
      }
    }).catch(err => {
      ElMessage.error('考勤记录删除失败')
    })
  }).catch(() => {
    ElMessage({
      type: 'info',
      message: '已取消删除'
    })
  })
}
// 编辑考勤记录
const editAttendanceRecord = (row) => {
  ElMessage.info('编辑功能开发中...')
// 申请假期
const openLeaveForm = () => {
  leaveOperationType.value = 'add'
  showLeaveDialog.value = true
  // leaveForm.type = ''
  // leaveForm.startDate = ''
  // leaveForm.endDate = ''
  // leaveForm.days = 0
  // leaveForm.reason = ''
  // leaveForm.status = 'warning'
}
// 删除考勤记录
const deleteAttendanceRecord = (index) => {
  attendanceData.value.splice(index, 1)
  ElMessage.success('考勤记录删除成功')
}
// 编辑假期记录
const editLeaveRecord = (row) => {
  ElMessage.info('编辑功能开发中...')
  leaveOperationType.value = 'edit'
  showLeaveDialog.value = true
  Object.assign(leaveForm, row)
  // ElMessage.info('编辑功能开发中...')
}
// 删除假期记录
const deleteLeaveRecord = (index) => {
  leaveData.value.splice(index, 1)
  ElMessage.success('假期记录删除成功')
const deleteLeaveRecord = (row) => {
  ElMessageBox.confirm('确定删除该假期记录吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    holidayApplicationDelete(row.id)
    .then(res => {
      if (res.code === 200) {
        ElMessage.success('假期记录删除成功')
        getHolidayApplicationList()
      }
    }).catch(err => {
      ElMessage.error('假期记录删除失败')
    })
  }).catch(() => {
    ElMessage({
      type: 'info',
      message: '已取消删除'
    })
  })
}
//计算假期天数
const calculateDays = () => {
  try {
    if (leaveForm.startDate && leaveForm.endDate) {
      const start = new Date(leaveForm.startDate)
      const end = new Date(leaveForm.endDate)
      leaveForm.startDate = start.toISOString().split('T')[0]
      leaveForm.endDate = end.toISOString().split('T')[0]
      if (isNaN(start.getTime()) || isNaN(end.getTime())) {
        console.warn('无效的日期格式')
        return
      }
      const diffTime = Math.abs(end - start)
      const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1
      leaveForm.days = diffDays
    }
  } catch (error) {
    console.error('计算天数失败:', error)
  }
}
// 提交假期申请
const submitLeaveApplication = () => {
  if (!leaveForm.type || !leaveForm.startDate || !leaveForm.endDate || !leaveForm.reason) {
    ElMessage.warning('请填写完整信息')
    return
  }
  const newLeave = {
  if (leaveOperationType.value === 'add') {
    if (!leaveForm.type || !leaveForm.startDate || !leaveForm.endDate || !leaveForm.reason) {
      ElMessage.warning('请填写完整信息')
      return
    }
    calculateDays()
    const newLeave = {
    type: leaveForm.type,
    startDate: leaveForm.startDate,
    endDate: leaveForm.endDate,
    days: 3, // 简单计算
    days: leaveForm.days, // 简单计算
    reason: leaveForm.reason,
    status: '审批中'
    }
    holidayApplicationAdd(newLeave)
    .then(res => {
      if (res.code === 200) {
        ElMessage.success('假期申请提交成功')
        getHolidayApplicationList()
        showLeaveDialog.value = false
        // 重置表单
        Object.keys(leaveForm).forEach(key => {
          leaveForm[key] = ''
        })
      }
    }).catch(err => {
      ElMessage.error('假期申请提交失败')
    })
  }else{
    calculateDays()
    holidayApplicationUpdate(leaveForm)
    .then(res => {
      if (res.code === 200) {
        ElMessage.success('假期申请更新成功')
        getHolidayApplicationList()
        showLeaveDialog.value = false
        // 重置表单
        Object.keys(leaveForm).forEach(key => {
          leaveForm[key] = ''
        })
      }
    }).catch(err => {
      ElMessage.error('假期申请更新失败')
    })
  }
  leaveData.value.unshift(newLeave)
  showLeaveDialog.value = false
  // 重置表单
  Object.keys(leaveForm).forEach(key => {
    leaveForm[key] = ''
}
// 获取个人信息
const getProfile = () => {
  tableLoading.value = true;
  getUserProfile().then(res => {
    if (res.code === 200) {
      currentUser.value = res.data
      // console.log("----",currentUser.value)
        //得到人员列表
        staffJoinListPage({staffState: 1}).then(res => {
          //筛选出和currentUser同名的人员
          // let tableData = res.data.records
          user.value = res.data.records.find(item => item.staffName === currentUser.value.userName)
          // console.log("++++",user.value)
          if(user.value){
            profile.value.id=user.value.id
            profile.value.name=user.value.staffName
            profile.value.employeeId=user.value.staffNo
            profile.value.phone=user.value.phone
            profile.value.email=currentUser.value.email
            profile.value.adress=user.value.adress
            profile.value.position=user.value.postJob
            profile.value.hireDate=user.value.createTime
            profile.value.department=currentUser.value.deptNames
          }
          // console.log(profile.value)
          // tableLoading.value = false;
        }).catch(err => {})
    }
  }).catch(err => {
    tableLoading.value = false;
    ElMessage.error('获取个人信息失败')
  })
  ElMessage.success('假期申请提交成功')
}
// 保存个人信息
const saveProfile = () => {
  Object.assign(profile.value, profileForm)
  editProfile.value = false
  ElMessage.success('个人信息保存成功')
}
const saveProfile = async () => {
  tableLoading.value = true;
  try {
    const userRes = await getUserProfile();
    if (userRes.code === 200) {
      currentUser.value = userRes.data;
      const staffListRes = await staffJoinListPage({ staffState: 1 });
      user.value = staffListRes.data.records.find(item => item.staffName === currentUser.value.userName);
      // console.log("++++", user.value);
// 初始化个人信息表单
const initProfileForm = () => {
      Object.assign(joinForm, user.value);
      joinForm.staffName = profileForm.name;
      joinForm.phone = profileForm.phone;
      joinForm.email = profileForm.email;
      joinForm.adress = profileForm.adress;
      console.log(joinForm)
      // 调用更新个人信息的接口
      staffJoinUpdate(joinForm).then(res => {
        if (res.code === 200) {
          ElMessage.success('个人信息保存成功');
          getProfile();
          editProfile.value = false;
        }
      }).catch(err => {
        ElMessage.error('个人信息保存失败');
      })
    }
  } catch (err) {
    ElMessage.error('获取个人信息失败');
  } finally {
    tableLoading.value = false;
  }
};
// 编辑个人信息
const editProfileForm = () => {
  editProfile.value = true;
  Object.assign(profileForm, {
    name: profile.value.name,
    phone: profile.value.phone,
    email: profile.value.email,
    address: profile.value.address
    adress: profile.value.adress,
  });
};
//月份改变
const changMonth = () => {
  getCompensationList()
}
//获取考勤记录列表
const getPersonalAttendanceRecordsList = async () => {
  tableLoading.value = true
  personalAttendanceRecordsListPage(page)
  .then(res => {
    attendanceData.value = res.data.records
    page.value.total = res.data.total;
    tableLoading.value = false;
  }).catch(err => {
    tableLoading.value = false;
  })
}
//薪资单查询
const getCompensationList = async () => {
  tableLoading.value = true
  compensationListPage({...page,payDateStr:payDateStr.value})
  .then(res => {
    salaryData.value = res.data.records
    //过滤出当前月份的扣款合计
    salaryData.value.forEach(item => {
      item.deduction =0 + item.deductionAbsenteeism+item.sickLeaveDeductions+item.deductionPersonalLeave+item.forgetClockDeduct,
      item.bonus=0,
      item.status='已发放'
    })
// 监听编辑个人信息弹窗
watch(editProfile, (val) => {
  if (val) {
    initProfileForm()
  }
    page.value.total = res.data.total;
    tableLoading.value = false;
  }).catch(err => {
    tableLoading.value = false;
  })
}
//获取假期申请列表
const getHolidayApplicationList = async () => {
  tableLoading.value = true
  holidayApplicationListPage(page)
  .then(res => {
    leaveData.value = res.data.records
    page.value.total = res.data.total;
    tableLoading.value = false;
  }).catch(err => {
    tableLoading.value = false;
  })
}
onMounted(() => {
  // 初始化
  getPersonalAttendanceRecordsList()
  getCompensationList()
  getHolidayApplicationList()
  getProfile()
})
</script>