let api = [];
api.push({
    alias: 'FlowDefinitionApiController',
    order: '1',
    link: '流程定义部署接口类',
    desc: '流程定义部署接口类',
    list: []
})
api[0].list.push({
    order: '1',
    desc: '流程部署列表查询',
});
api[0].list.push({
    order: '2',
    desc: '激活或挂起流程定义(已经部署)',
});
api[0].list.push({
    order: '3',
    desc: '根据流程定义ID获取流程图返回BASE64图片',
});
api[0].list.push({
    order: '4',
    desc: '根据流程定义ID获取xml',
});
api.push({
    alias: 'FlowProcessApiController',
    order: '2',
    link: '工作流流程对外服务接口',
    desc: '工作流流程对外服务接口',
    list: []
})
api[1].list.push({
    order: '1',
    desc: '启动流程',
});
api[1].list.push({
    order: '2',
    desc: '获取el表达式',
});
api[1].list.push({
    order: '3',
    desc: '激活或挂起流程实例',
});
api[1].list.push({
    order: '4',
    desc: '终止流程',
});
api[1].list.push({
    order: '5',
    desc: '删除流程',
});
api[1].list.push({
    order: '6',
    desc: '获取流程执行过程',
});
api[1].list.push({
    order: '7',
    desc: '根据流程实例ID获取当前流程运行情况返回BASE64图片',
});
api.push({
    alias: 'FlowTaskApiController',
    order: '3',
    link: '工作流任务对外服务接口',
    desc: '工作流任务对外服务接口',
    list: []
})
api[2].list.push({
    order: '1',
    desc: '我发起的流程',
});
api[2].list.push({
    order: '2',
    desc: '获取待办列表获取的列表需要和业务系统数据合并',
});
api[2].list.push({
    order: '3',
    desc: '获取已办任务获取的列表需要和业务系统数据合并',
});
api[2].list.push({
    order: '4',
    desc: '流程历史流转记录',
});
api[2].list.push({
    order: '5',
    desc: '获取流程变量',
});
api[2].list.push({
    order: '6',
    desc: '设置流程变量',
});
api[2].list.push({
    order: '7',
    desc: '撤回流程',
});
api[2].list.push({
    order: '8',
    desc: '取消申请',
});
api[2].list.push({
    order: '9',
    desc: '审批任务',
});
api[2].list.push({
    order: '10',
    desc: '驳回任务',
});
api[2].list.push({
    order: '11',
    desc: '退回任务',
});
api[2].list.push({
    order: '12',
    desc: '删除任务',
});
api[2].list.push({
    order: '13',
    desc: '委派任务',
});
api[2].list.push({
    order: '14',
    desc: '转办任务',
});
api[2].list.push({
    order: '15',
    desc: '加签任务',
});
api[2].list.push({
    order: '16',
    desc: '获取所有可回退的节点',
});
api[2].list.push({
    order: '17',
    desc: '获取下一节点',
});
api.push({
    alias: 'error',
    order: '4',
    link: 'error_code_list',
    desc: '错误码列表',
    list: []
})
api.push({
    alias: 'dict',
    order: '5',
    link: 'dict_list',
    desc: '数据字典',
    list: []
})
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code == 13) {
        const search = document.getElementById('search');
        const searchValue = search.value;
        let searchArr = [];
        for (let i = 0; i < api.length; i++) {
            let apiData = api[i];
            const desc = apiData.desc;
            if (desc.indexOf(searchValue) > -1) {
                searchArr.push({
                    order: apiData.order,
                    desc: apiData.desc,
                    link: apiData.link,
                    list: apiData.list
                });
            } else {
                let methodList = apiData.list || [];
                let methodListTemp = [];
                for (let j = 0; j < methodList.length; j++) {
                    const methodData = methodList[j];
                    const methodDesc = methodData.desc;
                    if (methodDesc.indexOf(searchValue) > -1) {
                        methodListTemp.push(methodData);
                        break;
                    }
                }
                if (methodListTemp.length > 0) {
                    const data = {
                        order: apiData.order,
                        desc: apiData.desc,
                        link: apiData.link,
                        list: methodListTemp
                    };
                    searchArr.push(data);
                }
            }
        }
        let html;
        if (searchValue == '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchArr,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiData, liClass, display) {
    let html = "";
    let doc;
    if (apiData.length > 0) {
        for (let j = 0; j < apiData.length; j++) {
            html += '<li class="'+liClass+'">';
            html += '<a class="dd" href="#_' + apiData[j].link + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
            html += '<ul class="sectlevel2" style="'+display+'">';
            doc = apiData[j].list;
            for (let m = 0; m < doc.length; m++) {
                html += '<li><a href="#_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + doc[m].desc + '</a> </li>';
            }
            html += '</ul>';
            html += '</li>';
        }
    }
    return html;
}