/*
 * @Author: micky 1254597151@qq.com
 * @Date: 2023-11-11 14:42:46
 * @LastEditors: micky 1254597151@qq.com
 * @LastEditTime: 2023-11-16 09:12:58
 * @FilePath: \housekeeping-admin\src\views\order\lists\hook.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import type { Component } from 'vue'
import { useCreateModal } from '@/hooks/useCreateModal'
import { apiOrderCancel } from '@/api/order/lists'
import feedback from '@/utils/feedback'

export function useCancelOrderAction(Component: Component) {
    const commandComponent = useCreateModal(Component)
    /**取消订单 */
    const handleCancelOrder = (orderInfo: any, refresh: (params?: any) => Promise<void>) => {
        commandComponent({
            title: '取消订单',
            width: 500,
            orderInfo,
            onConfirm: async payload => {
                try {
                    const { refundReason, value, orderId, intervalTime, practicalDeductionRatio } = payload
                    const data = {
                        orderId: orderId,
                        practicalDeductionRatio: value,
                        refundReason,
                        serviceTimeBeforeMinute: intervalTime,
                        deductionRatio: practicalDeductionRatio
                    }
                    await apiOrderCancel(data)
                    feedback.msgSuccess('取消订单成功')
                    refresh()
                } catch (error) {}
            }
        })
    }
    return { handleCancelOrder }
}
