import { assignCarConfig } from '@/views/main/workOrderManagement/workOrderList/config/assignCar.config' //车辆转办
import { assignCommonConfig } from '@/views/main/workOrderManagement/workOrderList/config/assignCommon.config' //转办

import { evaluateCarConfig } from '@/views/main/workOrderManagement/workOrderList/config/evaluateCar.config'


export const orderBtnData = {
    1000: {
        1000: [ //工单状态-待交办
            {
                text: '交办',
                eventName: 'assignCommonBtn',
                popoutType: 'model',
            },
            {
                text: '完结',
                eventName: 'endCommonBtn',
                popoutType: 'newTab',
            },
            {
                text: '编辑',
                eventName: 'editCommonBtn',
            }
        ], //工单状态-待接单
        2000: {
            1: [],
            2: [],
            3: [{
                text: '接单',
                eventName: 'takeCommonBtn',
                popoutType: 'confirm',
            }, ]
        },
        3000: { //工单状态-待处理
            1: [{
                    text: '退回',
                    eventName: 'backCommonBtn',
                    popoutType: 'prompt',
                },
                {
                    text: '处理',
                    eventName: 'dealCommonBtn',
                    popoutType: 'newTab',
                }
            ],
            2: [],
            3: []
        }, //工单状态-待审核
        4000: {
            1: [],
            2: [{
                    text: '同意',
                    eventName: 'withdrawCommonBtn',
                    popoutType: 'confirm',
                },
                {
                    text: '拒绝',
                    eventName: 'refuseCommonBtn',
                    popoutType: 'prompt',
                }
            ],
            3: []
        }, //工单状态-待回访
        5000: {
            1: [{
                    text: '退回',
                    eventName: 'visitBackCommonBtn',
                    popoutType: 'prompt',
                    excludeListType: ['11'],
                },
                {
                    text: '移除',
                    eventName: 'removeWaringCommonBtn',
                    popoutType: 'confirm',
                    includeListType: ['11'],
                },
                {
                    text: '回访',
                    eventName: 'visitCommonBtn',
                    popoutType: 'newTab',
                }
            ],
            2: [],
            3: []
        },
        5100: [{}], //工单状态-待评价
        6000: [ //工单状态-已完结text:'重启'
            {
                text: '移除',
                eventName: 'removeWaringCommonBtn',
                popoutType: 'confirm',
                includeListType: ['11'],
            },
        ]
    },
    4000: {
        1000: [ //工单状态-待交办
            {
                text: '交办',
                eventName: 'assignCarBtn',
                popoutType: 'model',
            },
            {
                text: '编辑',
                eventName: 'editCommonBtn',
            }
        ],
        3100: { //工单状态-待发车  
            1: [{
                    text: '发车',
                    eventName: 'departCarBtn',
                    popoutType: 'confirm',
                },
                {
                    text: '退回',
                    eventName: 'backCarBtn',
                    popoutType: 'prompt',
                }
            ],
            2: [{
                text: '撤回',
                eventName: 'withdrawCarBtn',
                popoutType: 'confirm',
            }, ]
        },

        3200: { //工单状态-已发车
            1: [{
                text: '到达',
                eventName: 'arriveCarBtn',
                popoutType: 'confirm'
            }],
            2: []
        },
        5100: { //工单状态-待回访
            1: [{
                text: '评价',
                eventName: 'evaluateCarBtn',
                popoutType: 'model',
            }],
            2: []

        },
        6000: [{}]
    },
}
export const orderBtnFilter = (item, listType) => {
    // .listType listType 0 综合查询列表 1（处理人）我的待处理；2 待交办;3 已办待审核；4 已办待回访；5 我的回复列表；6 组内工单7 超期列表 8 延期审核 11 高危管理
    let getData = [],
        resultData = [],
        number, firstIndex
    if (listType.toString() === '0' || listType.toString() === '3') {
        number = 2
    } else if (listType.toString() === '6') {
        number = 3
    } else {
        number = 1
    }
    firstIndex = Number(item.firsttype)
    if (Number(item.firsttype) === 2000 || Number(item.firsttype) === 3000) {
        firstIndex = 1000
    }
    if (!firstIndex) {
        return
    }
    getData = orderBtnData[firstIndex][item.workorderstate]



    if (getData.constructor === Array) {
        resultData = getData
    } else {
        resultData = getData[number]
    }

    if (resultData) {
        resultData = resultData.filter((o) => {
            if (o.excludeListType) {
                return !o.excludeListType.includes(listType.toString())
            } else if (o.includeListType) {
                return o.includeListType.includes(listType.toString())
            } else {
                return true;
            }
        });
    }

    // if (listType.toString() === '11') {
    //     console.log(resultData, 'resultData')
    //     resultData = resultData.filter((o) => {
    //         return !['退回'].includes(o.text)
    //     });
    // }
    return resultData
}
export const getModalData = (btnObj) => {
    let resultData = {}
        // 车辆工单
    if (btnObj.eventName === 'assignCarBtn') { // 交办
        resultData.config = assignCarConfig
        resultData.pageNameUrl = '/order/carworkorder/assign'
    } else if (btnObj.eventName === 'evaluateCarBtn') { // 评价
        resultData.config = evaluateCarConfig
        resultData.pageNameUrl = '/order/carworkorder/evaluate'
    } else if (btnObj.eventName === 'departCarBtn') { // 发车
        resultData.pageNameUrl = '/order/carworkorder/go'
    } else if (btnObj.eventName === 'arriveCarBtn') { // 到达
        resultData.pageNameUrl = '/order/carworkorder/arrive'
    } else if (btnObj.eventName === 'withdrawCarBtn') { // 撤回
        resultData.pageNameUrl = '/order/carworkorder/withdraw'
    } else if (btnObj.eventName === 'backCarBtn') { // 退回
        resultData.pageNameUrl = '/order/carworkorder/back'
    }
    // 普通工单
    if (btnObj.eventName === 'assignCommonBtn') { // 交办
        resultData.config = assignCommonConfig
        resultData.pageNameUrl = '/order/workorder/transfer'
    } else if (btnObj.eventName === 'endCommonBtn') { // 完结
        resultData.pageNameUrl = '/order/workorder/end'
    } else if (btnObj.eventName === 'takeCommonBtn') { // 接单
        resultData.pageNameUrl = '/order/workorder/receive'
    } else if (btnObj.eventName === 'backCommonBtn') { // 退回
        resultData.pageNameUrl = '/order/workorder/back'
    } else if (btnObj.eventName === 'withdrawCommonBtn') { // 同意
        resultData.pageNameUrl = '/order/workorder/audit'
    } else if (btnObj.eventName === 'refuseCommonBtn') { // 拒绝
        resultData.pageNameUrl = '/order/workorder/audit'
    } else if (btnObj.eventName === 'visitBackCommonBtn') { // 退回
        resultData.pageNameUrl = '/order/workorder/backtoaudit'
    } else if (btnObj.eventName === 'removeWaringCommonBtn') { // 退回
        resultData.pageNameUrl = '/order/workorder/remove'
    }

    return resultData
}