| | |
| | | import { Message, toRound } from '@12333/utils'; |
| | | import * as taskCheckReceiveServices from '@12333/services/apiV2/taskCheckReceive'; |
| | | import dayjs from 'dayjs'; |
| | | import { EnumTaskUserSubmitCheckReceiveStatus } from '@12333/constants'; |
| | | import { MaybeRef } from 'vue'; |
| | | |
| | | type UseSettlementAmountOptions = { |
| | | id: MaybeRef<string>; |
| | | date: string; |
| | | onSuccess?: () => void; |
| | | taskInfoUserId: MaybeRef<string>; |
| | | timeoutServiceFee: MaybeRef<number>; |
| | | }; |
| | | |
| | | export function useSettlementAmount({ |
| | | id, |
| | | date, |
| | | taskInfoUserId, |
| | | onSuccess, |
| | | timeoutServiceFee, |
| | | }: UseSettlementAmountOptions) { |
| | | const dialogVisible = ref(false); |
| | | |
| | | const form = reactive({ |
| | | serviceFee: 0, |
| | | timeoutHours: 0, |
| | | timeoutFee: 0, |
| | | otherFee: 0, |
| | | remark: '', |
| | | timeoutServiceFee: 0, |
| | | }); |
| | | |
| | | const settlementAmount = computed(() => sumSettlementAmount()); |
| | | |
| | | function sumSettlementAmount() { |
| | | return toRound( |
| | | getFeeValue(Number(form.timeoutFee ?? 0)) + |
| | | getFeeValue(Number(form.serviceFee ?? 0)) + |
| | | getFeeValue(Number(form.otherFee ?? 0)) |
| | | ); |
| | | } |
| | | |
| | | function getFeeValue(val: number) { |
| | | return val || 0; |
| | | } |
| | | |
| | | async function openDialog(checkInTime: string) { |
| | | let res = await calcTaskCheckReceive(checkInTime); |
| | | if (res) { |
| | | dialogVisible.value = true; |
| | | form.serviceFee = res.serviceFee ?? 0; |
| | | form.timeoutHours = res.timeoutHours ?? 0; |
| | | form.otherFee = 0; |
| | | form.timeoutFee = 0; |
| | | form.remark = ''; |
| | | form.timeoutServiceFee = unref(timeoutServiceFee) ?? 0; |
| | | } |
| | | } |
| | | |
| | | async function calcTaskCheckReceive(checkInTime: string) { |
| | | try { |
| | | let params: API.CalcTaskCheckReceiveCommand = { |
| | | taskInfoId: unref(id), |
| | | checkInTime: dayjs(checkInTime).format('YYYY-MM-DD HH:mm:ss'), |
| | | checkOutTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), |
| | | }; |
| | | return await taskCheckReceiveServices.calcTaskCheckReceive(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | function handleCancel() { |
| | | dialogVisible.value = false; |
| | | } |
| | | |
| | | async function handleConfirm() { |
| | | try { |
| | | let params: API.CheckReceiveTaskCommand = { |
| | | taskInfoUserId: unref(taskInfoUserId), |
| | | date: dayjs(date).format('YYYY-MM-DD'), |
| | | checkReceiveStatus: EnumTaskUserSubmitCheckReceiveStatus.Success, |
| | | serviceFee: form.serviceFee, |
| | | timeoutHours: form.timeoutHours, |
| | | timeoutFee: form.timeoutFee, |
| | | otherFee: form.otherFee, |
| | | remark: form.remark, |
| | | settlementAmount: settlementAmount.value, |
| | | }; |
| | | let res = await taskCheckReceiveServices.checkReceiveTask(params); |
| | | if (res) { |
| | | Message.success('提交成功'); |
| | | dialogVisible.value = false; |
| | | // infiniteLoadingProps.value?.refetch?.(); |
| | | onSuccess?.(); |
| | | } |
| | | } catch (error) {} |
| | | } |
| | | |
| | | function onTimeoutHoursChange(event: any) { |
| | | form.timeoutFee = Number(form.timeoutServiceFee) |
| | | ? form.timeoutServiceFee * event.detail.value |
| | | : 0; |
| | | } |
| | | |
| | | return { |
| | | dialogVisible, |
| | | form, |
| | | settlementAmount, |
| | | handleCancel, |
| | | openDialog, |
| | | handleConfirm, |
| | | onTimeoutHoursChange, |
| | | }; |
| | | } |