fastflowbase.js 20.3 KB
define(['fastflow-fixed-columns'], function (undefined) {
    var fastflowBase = {
        api: {
            renderbadge: function () {
                $.ajax({
                    type: "POST",
                    url: "fastflow/flow/bill/getBadge",
                    data: {},
                    dataType: "json",
                    success: function (data) {
                        if (data['code'] == 1) {
                            let parentWindow = window.parent.document;
                            $('.fastflow-badge', parentWindow).remove();
                            data['data'].forEach(function (item) {
                                if (item['count'] > 0) {
                                    $('a[addtabs=' + item['id'] + ']', parentWindow).append('<span class="pull-right-container fastflow-badge" style="margin-right: 20px"> <small class="' + item['shape'] + ' pull-right ' + item['color'] + '">' + item['show'] + '</small></span>');
                                }
                            });
                            if($('#bill-page',parentWindow).length === 1){
                                let topWindow = top.window.document;
                                $('.fastflow-badge', topWindow).remove();
                                data['data'].forEach(function (item) {
                                    if (item['count'] > 0) {
                                        $('a[addtabs=' + item['id'] + ']', topWindow).append('<span class="pull-right-container fastflow-badge" style="margin-right: 20px"> <small class="' + item['shape'] + ' pull-right ' + item['color'] + '">' + item['show'] + '</small></span>');
                                    }
                                });
                            }
                        }
                    }
                });
            },
            formatter: {
                id: function (value, row, index) {
                    return '<span class="label label-success" style="font-size: 94%;margin-right: 4px;"><i class="fa fa-check-circle" style="margin-right: 4px;"></i>' + value + '</span>';
                },
                progress: function (value, row, index) {
                    return '<div class="progress active" style="background: #d0d0d0;">'
                        + '<div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" style="width: '
                        + Math.round(value * 100)
                        + '%"> '
                        + '<b>'
                        + Math.round(value * 100)
                        + '%</b> '
                        + '</div></div>';
                },
                flowinfo: function (value, row, index) {
                    let html = '';
                    console.log('config',Config.initiator_id)
                    let backin =  '';
                    if(row.initiator_id == Config.initiator_id && row.flow_auth.code!=4){
                        backin =  '<a href="#" class="btn btn-xs btn-success btn-cx"  data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa fa-reply" style="margin-right: 4px;"></i>撤销</a>';
                    }
                    
                    if (row['flow_auth']['code'] == -3 || row['flow_auth']['code'] == -1 || row['flow_auth']['code'] == 3) {
                        let labelcolor = {
                            '-3': 'label-danger',
                            '-1': 'label-warning',
                            '3': 'label-warning',
                        };
                        html = '<span class="label ' + labelcolor[row['flow_auth']['code']] + '" style="font-size: 94%;margin-right: 4px;"><i class="fa fa-info-circle" style="margin-right: 4px;"></i>' + row['flow_auth']['msg'] + '</span>'
                            +backin
                            + '<a href="fastflow/flow/flow/detail?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog btn-detail" title="查看" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-list" style="margin-right: 4px;"></i>查看</a>'
                            + '<a href="fastflow/flow/flow/flowdiagram?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog" title="流程图" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-sitemap" style="margin-right: 4px;"></i>流程图</a>';
                    } else if (row['flow_auth']['code'] == 2) {
                        if (row['fastflow_signature_status'] == -1) {
                            html = '<a href="fastflow/signature/initiate?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-info btn-dialog btn-signature" title="发起签章" data-area=["60%","80%"] style="margin-right: 4px;font-size: 90%;"><i class="fa fa-file-text-o" style="margin-right: 4px;"></i>发起签章</a>'
                        } else if (row['fastflow_signature_status'] == 0) {
                            html = '<a href="javascript:;" class="btn btn-xs btn-warning" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-file-text-o" style="margin-right: 4px;"></i>待签章</a>'
                        } else if (row['fastflow_signature_status'] == 1) {
                            html = '<a href="javascript:;" class="btn btn-xs btn-info-light" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-file-text-o" style="margin-right: 4px;"></i>已签章</a>'
                        } else {
                            html = '<span class="label label-success" style="font-size: 94%;margin-right: 4px;"><i class="fa fa-info-circle" style="margin-right: 4px;"></i>' + row['flow_auth']['msg'] + '</span>'
                        }
                        html +=
                            backin + 
                            '<a href="fastflow/flow/flow/detail?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog btn-detail" title="查看" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-list" style="margin-right: 4px;"></i>查看</a>'
                            + '<a href="fastflow/flow/flow/flowdiagram?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog" title="流程图" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-sitemap" style="margin-right: 4px;"></i>流程图</a>';

                    } else if (row['flow_auth']['code'] == -2) {
                        html = '<span class="label label-warning" style="font-size: 94%;margin-right: 4px;"><i class="fa fa-info-circle" style="margin-right: 4px;"></i>' + row['flow_auth']['msg'] + '</span>';
                    } else if (row['flow_auth']['code'] == 0) {
                        html = '<a href="fastflow/flow/run/start?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-info btn-dialog btn-start" title="' + row['flow_auth']['msg'] + '" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-calendar-plus-o" style="margin-right: 4px;"></i>' + row['flow_auth']['msg'] + '</a>';
                    } else if (row['flow_auth']['code'] == 1) {
                        needCheckCount = 0;
                        row['runthread_info'] = Array.from(row['runthread_info']);
                        row['runthread_info'].forEach(function (item) {
                            if (item['auth_info'] !== false) {
                                needCheckCount += 1;
                            }
                        });
                        html = '<a href="javascript:;" class="btn btn-xs btn-success btn-cancheck" style="position:relative;font-size: 90%;margin-right: 4px;"><i class="fa fa-info-circle" style="margin-right: 4px;"></i><span class="label label-danger" style="position:absolute;text-align:center;font-size:12px;padding:3px 3px;right: -2px;top:-6px;border-radius:1em;width: 18px;height: 18px">'
                            + needCheckCount + '</span>'
                            + row['flow_auth']['msg'] + '</a>'
                            +backin
                            + '<a href="fastflow/flow/flow/detail?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog btn-detail" title="查看" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-list" style="margin-right: 4px;"></i>查看</a>'
                            + '<a href="fastflow/flow/flow/flowdiagram?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog" title="流程图" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-sitemap" style="margin-right: 4px;"></i>流程图</a>';
                    } else if (row['flow_auth']['code'] == 4) {
                        html = '<a href="fastflow/flow/run/start?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-info btn-dialog btn-start" title="' + row['flow_auth']['msg'] + '" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-calendar-plus-o" style="margin-right: 4px;"></i>' + row['flow_auth']['msg'] + '</a>'
                            +backin
                            + '<a href="fastflow/flow/flow/detail?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog btn-detail" title="查看" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-list" style="margin-right: 4px;"></i>查看</a>';
                    }else if (row['flow_auth']['code'] == 5) {
                        html = '<span class="label label-warning" style="font-size: 94%;margin-right: 4px;"><i class="fa fa-info-circle" style="margin-right: 4px;"></i>' + row['flow_auth']['msg'] + '</span>'
                        +backin
                        + '<a href="fastflow/flow/flow/detail?bill=' + row['bill'] + '&bill_id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog btn-detail" title="查看" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-list" style="margin-right: 4px;"></i>查看</a>';
                    }
                    
                    
                    return html;
                },
                detail: function (index, row, e) {
                    if (row['runthread_info'] == -1 || row['runthread_info'] == 2) {
                        $(e).parent().prev().find('.detail-icon').trigger('click').addClass('hidden');
                        return '';
                    }
                    detailtable = '<table style="width: 100%;margin-left: 15px" class="table table-hover detailtable"><tbody data-listidx="1"><tr style="background-color: #e9f4fd;"><th style="width: 60px;text-align: center">步骤编号</th><th style="text-align: center;">步骤名称</th><th style="text-align: center;">审批人</th><th style="text-align: center;">会签</th><th style="text-align: center;">回退</th><th style="text-align: center;">上一步骤</th><th style="text-align: center;">下一步骤</th><th style="text-align: center;">被代理人(组)</th><th style="text-align: center;">代理人(组)</th><th style="text-align: center;width:250px;">审批</th></tr>';
                    row['runthread_info'] = Array.from(row['runthread_info']);
                    row['runthread_info'].forEach(function (item) {


                    	var zrin =  '<a href="fastflow/flow/run/change?thread_id='+item["id"]+ '" class="btn btn-xs btn-warning-light btn-dialog"  title="转审" data-area=["25%","45%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa fa-reply-all" style="margin-right: 4px;"></i>转审</a>';
                        checkButton = '';
                        if (item['auth_info'] !== false) {
                            checkButton = (item['auth_info']['agency'] == true ? '<span class="label label-info" style="font-size: 94%;width:42px;margin-right: 9px;">代理</span>' : '')
                                + '<a href="fastflow/flow/run/agree?thread_id=' + item["id"] + '" class="btn btn-xs btn-success-light btn-dialog" title="同意" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-check-square" style="margin-right: 4px;"></i>同意</a>'
                                +zrin
                                + (item['can_back'] == 1 ? '<a href="fastflow/flow/run/back?thread_id=' + item["id"] + '" class="btn btn-xs btn-danger-light btn-dialog" title="驳回" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-reply" style="margin-right: 4px;"></i>驳回</a>' : '')
                                + (item['can_sign'] == 1 ? '<a href="fastflow/flow/run/sign?thread_id=' + item["id"] + '" class="btn btn-xs btn-info-light btn-dialog" title="会签" data-area=["95%","95%"] data-table-id="table" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-pencil" style="margin-right: 4px;"></i>会签</a>' : '');
                        } else {
                            checkButton = '<a href="javascript:;" class="btn btn-xs btn-warning-light" style="font-size: 94%;margin-right: 4px;"><i class="fa fa-info-circle" style="margin-right: 4px;"></i>无审批权限</a>';
                        }
                        checkButton = '<div style="width: 220px;">' + checkButton + '</div>';
                        checkUser = '';
                        item['check_worker_list'].forEach(function (worker) {
                            checked = false;
                            for (i = 0; i < item['checked_worker_list'].length; i++) {
                                if (worker == item['checked_worker_list'][i]) {
                                    checked = true;
                                    break;
                                }
                            }
                            if (checked) {
                                checkUser += '<span class="text-success">' + worker + '</span>,';
                            } else {
                                checkUser += worker + ',';
                            }
                        });
                        detailtable += '<tr style="text-align: center;"><td>' + item['id'] + '</td><td>' + item['name'] + '</td><td>'
                            + (checkUser == '' ? '<a class="btn btn-xs btn-danger">【错误】未设置审批人</a>' : (item['checkmode'] == 1 ? '<span class="text-info">联合审批:</span>' : '<span class="text-info">任一审批:</span>') + checkUser.slice(0, checkUser.length - 1))
                            + '</td><td>'
                            + (item['is_sign'] == 1 ? '<span class="text-warning">是</span>' : '否')
                            + '</td><td>'
                            + (item['is_back'] == 1 ? '<span class="text-warning">是</span>' : '否')
                            + '</td><td>'
                            + item['pre_step']
                            + '</td><td>'
                            + (item['next_step'] == '' ? '<a class="btn btn-xs btn-danger">【错误】请完善流程设计,条件转出步骤必须设置</a>' : item['next_step'])
                            + '</td><td>'
                            + (item['agency_info'] !== null ? item['agency_info']['principal_name'] : '')
                            + '</td><td>'
                            + (item['agency_info'] !== null ? item['agency_info']['agent_name'] : '')
                            + '</td><td>'
                            + checkButton
                            + '</td></tr>';
                    });
                    detailtable += '</tbody></table>';
                    return detailtable;
                },
            },
            events: {
                flowinfo: {
                    'click .btn-cancheck': function (e, value, row, index) {
                        e.stopPropagation();
                        $('tr[data-index="' + index + '"]').find('.detail-icon').trigger('click');
                    },
                    'click .btn-cx': function (e, value, row, index) {
                        e.stopPropagation();
                        console.log('rowrow',row.runthread_info[0].id)
                        // row['bill']  row['id']
                        Layer.confirm("是否确定撤销?", {icon: 3}, function (index) {
                            if(row.runthread_info[0].id==''){
                                Toastr.success("撤销失败1");
                                return false;
                            }
                            Fast.api.ajax({
                               url:'fastflow/flow/flow/revoke',
                               data:{bill:row['bill'],bill_id:row['id'],tid:row.runthread_info[0].id}
                            }, function(data, ret){
                               //成功的回调
                               layer.close(index);

                               $('#table').bootstrapTable('refresh');
                               Toastr.success("提交撤销成功");
                               return false;
                            }, function(data, ret){
                               //失败的回调
                               layer.close(index);
                               Toastr.success("提交撤销失败");
                               return false;
                            });


                            
                            Toastr.success("提交成功");
                        });
                    }
                    
                }
            },
            bindevent: function (table) {
                $('.btn-expandall').click(function (e) {
                    $('#table').bootstrapTable('expandAllRows');
                });
                
                
                $('.btn-collapseall').click(function (e) {
                    $('#table').bootstrapTable('collapseAllRows');
                });
                let indexUrl = $.fn.bootstrapTable.defaults.extend.index_url.replace(location.search,'');
                $(document).on("click", ".btn-mine", function () {
                    table.bootstrapTable('refresh', {url: indexUrl + '?show=mine'});
                    $(this).addClass('disabled');
                    $(".btn-showcancheck").removeClass('disabled');
                    $(".btn-showall").removeClass('disabled');
                    return false;
                });
                $(document).on("click", ".btn-showcancheck", function () {
                    table.bootstrapTable('refresh', {url: indexUrl + '?show=cancheck'});
                    $(this).addClass('disabled');
                    $(".btn-mine").removeClass('disabled');
                    $(".btn-showall").removeClass('disabled');
                    return false;
                });
                $(document).on("click", ".btn-showall", function () {
                    table.bootstrapTable('refresh', {url: indexUrl});
                    $(this).addClass('disabled');
                    $(".btn-mine").removeClass('disabled');
                    $(".btn-showcancheck").removeClass('disabled');
                    return false;
                });
                $('th.detail').css({
                    "text-align": "center",
                    "vertical-align": "middle",
                    "width": "36px",
                    "color": "#4397fd"
                });
                $('th.detail').html('<div class="th-inner"><a href="javascript:;" class="detail-toggle" data-expand="false"><i class="glyphicon glyphicon-plus icon-plus"></i></a></div><div class="fht-cell"></div>');
                $('th.detail .detail-toggle').click(function (e) {
                    if ($(this).data('expand') == false) {
                        $('#table').bootstrapTable('expandAllRows');
                        $(this).data('expand', true);
                        $('i', this).removeClass('glyphicon-plus icon-plus').addClass('glyphicon-minus icon-minus');
                    } else {
                        $('#table').bootstrapTable('collapseAllRows');
                        $(this).data('expand', false);
                        $('i', this).removeClass('glyphicon-minus icon-minus').addClass('glyphicon-plus icon-plus');
                    }

                });

            }
        }
    }
    return fastflowBase;
})