src/views/personnelManagement/contractManagement/index.vue
@@ -66,6 +66,34 @@
      </template>
    </el-dialog>
    <files-dia ref="filesDia"></files-dia>
    <!-- 合同到期提醒弹窗 -->
    <el-dialog
      v-model="expireWarningVisible"
      title="合同到期提醒"
      width="720px"
      @close="expireWarningVisible = false"
    >
      <div style="margin-bottom: 12px; color: #e6a23c; font-size: 14px;">
        以下员工合同将在 {{ EXPIRE_WARNING_DAYS }} 天内到期,请及时处理:
      </div>
      <el-table :data="expireWarningList" border max-height="400">
        <el-table-column label="姓名" prop="staffName" align="center" />
        <el-table-column label="员工编号" prop="staffNo" align="center" />
        <el-table-column label="联系电话" prop="phone" align="center" />
        <el-table-column label="合同结束日期" prop="contractExpireTime" align="center" width="140" />
        <el-table-column label="剩余天数" align="center" width="120">
          <template #default="scope">
            <el-tag :type="scope.row.expireDays < 0 ? 'danger' : 'warning'">
              {{ formatExpireDays(scope.row.expireDays) }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <el-button type="primary" @click="expireWarningVisible = false">知道了</el-button>
      </template>
    </el-dialog>
  </div>
</template>
@@ -207,6 +235,12 @@
const formDia = ref()
const { proxy } = getCurrentInstance()
// 合同到期预警天数(固定 45 天)
const EXPIRE_WARNING_DAYS = 45
// 合同到期提醒弹窗
const expireWarningVisible = ref(false)
const expireWarningList = ref([])
const changeDaterange = (value) => {
  searchForm.value.entryDateStart = undefined;
  searchForm.value.entryDateEnd = undefined;
@@ -239,13 +273,41 @@
  const params = { ...searchForm.value, ...page };
  params.entryDate = undefined
  params.staffState = 1
  staffOnJobListPage(params).then(res => {
  return staffOnJobListPage(params).then(res => {
    tableLoading.value = false;
    tableData.value = res.data.records
    page.total = res.data.total;
  }).catch(err => {
    tableLoading.value = false;
  })
};
// 检查合同到期提醒(45 天内到期)
const checkContractExpireWarning = () => {
  const today = dayjs().startOf('day');
  const list = (tableData.value || [])
    .filter(item => {
      if (!item.contractExpireTime) return false;
      const expireDay = dayjs(item.contractExpireTime);
      if (!expireDay.isValid()) return false;
      const diffDays = expireDay.diff(today, 'day');
      return diffDays <= EXPIRE_WARNING_DAYS;
    })
    .map(item => ({
      ...item,
      expireDays: dayjs(item.contractExpireTime).diff(today, 'day'),
    }));
  if (list.length > 0) {
    expireWarningList.value = list;
    expireWarningVisible.value = true;
  }
};
// 剩余天数格式化
const formatExpireDays = (days) => {
  if (days < 0) return `已过期 ${Math.abs(days)} 天`;
  if (days === 0) return "今天到期";
  return `剩余 ${days} 天`;
};
// 表格选择数据
const handleSelectionChange = (selection) => {
@@ -308,7 +370,7 @@
  getList();
};
onMounted(() => {
  getList();
  getList().then(() => checkContractExpireWarning());
});
</script>