云
8 天以前 a241b66efcc41e973290a6722fb7a4d79b833ea1
src/views/hrm/leave/index.vue
@@ -1,15 +1,22 @@
<script lang="ts" setup>
import { automaticApproval } from '#/store/audit-policy';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { HrmLeaveApi } from '#/api/hrm/leave';
import { ref } from 'vue';
import { Page, useVbenModal } from '#/packages/effects/common-ui/src';
import { message } from 'ant-design-vue';
import { message, Modal, Select, Tag } from 'ant-design-vue';
import { DICT_TYPE } from '#/packages/constants/src';
import { getDictLabel } from '#/packages/effects/hooks/src';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  cancelLeave,
  deleteLeave,
  getLeaveApproveProcessDefinitionList,
  getLeavePage,
  submitLeave,
} from '#/api/hrm/leave';
@@ -58,11 +65,39 @@
  }
}
/** 提交请假申请 */
const submitModalVisible = ref(false);
const currentRow = ref<HrmLeaveApi.Leave>();
const processList = ref<HrmLeaveApi.ApproveProcess[]>([]);
const selectedProcessKey = ref<string>();
const submitLoading = ref(false);
/** 提交请假申请(先选择审批流程) */
async function handleSubmit(row: HrmLeaveApi.Leave) {
  await submitLeave(row.id!);
  message.success('提交成功');
  handleRefresh();
  processList.value = automaticApproval.value ? [] : await getLeaveApproveProcessDefinitionList();
  currentRow.value = row;
  selectedProcessKey.value = undefined;
  if (automaticApproval.value) {
    selectedProcessKey.value = 'hrm_leave';
    await confirmSubmit();
    return;
  }
  submitModalVisible.value = true;
}
async function confirmSubmit() {
  if (!selectedProcessKey.value) {
    message.warning('请选择请假审批流程');
    return;
  }
  submitLoading.value = true;
  try {
    await submitLeave(currentRow.value!.id!, selectedProcessKey.value);
    message.success('提交成功');
    submitModalVisible.value = false;
    handleRefresh();
  } finally {
    submitLoading.value = false;
  }
}
/** 撤销请假申请 */
@@ -70,6 +105,20 @@
  await cancelLeave(row.id!);
  message.success('撤销成功');
  handleRefresh();
}
/** 请假类型颜色 */
function getLeaveTypeColor(type: number): string {
  switch (type) {
    case 1: return 'green';      // 年假
    case 2: return 'orange';     // 事假
    case 3: return 'red';        // 病假
    case 4: return 'purple';     // 婚假
    case 5: return 'cyan';       // 产假
    case 6: return 'magenta';    // 丧假
    case 7: return 'geekblue';   // 调休
    default: return 'default';
  }
}
const [Grid, gridApi] = useVbenVxeGrid({
@@ -119,6 +168,11 @@
          ]"
        />
      </template>
      <template #leaveType="{ row }">
        <Tag :color="getLeaveTypeColor(row.leaveType)">
          {{ getDictLabel(DICT_TYPE.HRM_LEAVE_TYPE, row.leaveType) }}
        </Tag>
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
@@ -165,5 +219,19 @@
        />
      </template>
    </Grid>
    <Modal
      v-model:open="submitModalVisible"
      title="提交至协同办公"
      width="420px"
      :confirm-loading="submitLoading"
      @ok="confirmSubmit"
    >
      <Select
        v-model:value="selectedProcessKey"
        class="w-full"
        placeholder="请选择请假审批流程"
        :options="processList.map((item) => ({ label: item.name, value: item.key }))"
      />
    </Modal>
  </Page>
</template>