/**
 * 对账模块-预付款申请首页JS
 *
 */
'use strict';
var el = {
    searchForm: '#searchForm',
    companyCode: '#companyCode',
    supCodeOrName: '#supCodeOrName',
    paymentChangeNo: '#paymentChangeNo',
    createTimeStart: '#createTimeStart',
    createTimeEnd: '#createTimeEnd',
    status: '#status',
    dataType:'#dataType',
    syncState: '#syncState',
    oaProcessNo: '#oaProcessNo',
    pushOaUserName: '#pushOaUserName',
    poCode: '#poCode',
    btn_look: '#btn_look',
    btn_confirm:'#btn_confirm',
    btn_add: '#btn_add',
    btn_edit: '#btn_edit',
    btn_remove: '#btn_remove',
    btn_push_oa: '#btn_push_oa',
    tb: '#tb',
    tipsIndex: null,
    addOrEditDialog: null,
    lookDialog: null,
    bodyHeight: document.documentElement.clientHeight
};


/**
 * 文档就绪
 */
$(function () {
    initPageComBoBox();

    initPageDataGrid();

    // initFileBox();
});


/**
 * 初始化页面下拉框
 */
function initPageComBoBox() {
    // 初始化数据状态下拉框
    $(el.status).combobox({
        valueField: 'value',
        textField: 'label',
        value: -1,
        data: [
            {label: '全部', value: -1},
            {label: '暂存', value: 0},
            {label: '待财务确认', value: 1},
            {label: '财务驳回', value: 2},
            {label: '已发布', value: 3}
        ],
        editable: false,
        panelHeight: 'auto'
    });
    //数据类型
    $(el.dataType).combobox({
        valueField: 'value',
        textField: 'label',
        value: -1,
        data: [
            {label: '全部', value: -1},
            {label: '转单', value: 0},
            {label: '退款', value: 1}
        ],
        editable: false,
        panelHeight: 'auto'
    });


    initNecessaryDatas("pc/sys/company/rest/listAll");
    // 初始化公司代码下拉框
    $(el.companyCode).combobox({
        data:getNecessaryDataList("pc/sys/company/rest/listAll"),
        panelHeight: 300,
        panelWidth: 340,
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---'
    });
    initDict("sync_state");
    $(el.syncState).combobox({
        data:getDictList("sync_state"),
        panelHeight: 300,
        panelWidth: 340,
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---'
    });
}


/**
 * 初始化页面表格数据
 */
function initPageDataGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight, 37, 40);

    $(el.tb).datagrid({
        loadMsg: '数据加载中......',
        url: '/pc/finance/paymentAdvanceRefundTransferApply/apply/rest/list',
        height: el.bodyHeight - searchHeight,
        singleSelect: true,
        rownumbers: true,
        // 定义从服务器对数据进行排序
        remoteSort: true,
/*
        title:"<span style='color: red'>*合同上约定了需要预付款的并且没有取得发票，此情况走预付款申请</span>",
*/
        // 定义是否允许多列排序
        // multiSort: true,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        queryParams: {},
        frozenColumns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'status',
                    title: '数据状态',
                    width: 90,
                    sortable: true,
                    formatter: function (value) {
                        switch (value) {
                            case 0:
                                return '暂存';
                            case 1:
                                return '<span style="color: orange;">待财务确认</span>';
                            case 2:
                                return '财务驳回';
                            case 3:
                                return '已发布';
                            default:
                                return '';
                        }
                    }
                },
                {
                    field: 'paymentChangeNo',
                    title: '预付款变更单',
                    width: 120,
                    sortable: true
                },
            ]
        ],
        columns: [
            [
                {
                field: 'supplierCode',
                title: '供应商编码',
                width: 90
                },
                {
                    field: 'supplierName',
                    title: '供应商名称',
                    width: 140
                },
                {
                    field: 'currencyCode',
                    title: '币种',
                    width: 70,
                    sortable: true
                },
                {
                    field: 'companyCode',
                    title: '付款公司',
                    width: 260,
                    sortable: true,
                    formatter: function (value, row) {
                        return getNecessaryDataName('pc/sys/company/rest/listAll',value);
                    }
                },
                // {
                //     field: 'companyCode',
                //     title: '付款公司代码',
                //     width: 160,
                //     sortable: true
                // },
                {
                    field: 'dataType', //转单0、退款1
                    title: '数据类型',
                    width: 70,
                    sortable: true,
                    formatter: function (value) {
                        switch (value) {
                            case 0:
                                return '转单';
                            case 1:
                                return '退款';
                            default:
                                return '';
                        }
                    }
                },
                {
                    field: 'recordedAmount',
                    title: '金额',
                    width: 50,
                    sortable: true
                },

                {
                    field: 'reversedAmount',
                    title: '冲账金额',
                    width: 90,
                    sortable: true
                },
                {
                    field: 'remark',
                    title: '备注',
                    width: 130
                },{
                field: 'createUserName',
                title: '创建用户',
                width: 80

            },
                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 130,
                    sortable: true,
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return moment(value).format('YYYY-MM-DD HH:mm');
                    }
                }
                ,{
                field: 'updateUserName',
                title: '更新用户',
                width: 90

            },{
                    field: 'updateTime',
                    title: '最后更新时间',
                    width: 130,
                    sortable: true,
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return moment(value).format('YYYY-MM-DD HH:mm');
                    }
                }
            ]
        ],
        toolbar: [
            {
                text: '查看',
                iconCls: 'icon-find',
                id: 'btn_look',
                handler: function () {
                    detail(2)
                    setOperationLog("查看按钮", "预付款退款/转单");

                }
            },
            '-',
            {
                text: '新增',
                iconCls: 'icon-add',
                id: 'btn_add',
                handler: function () {
                    detail(0)
                }
            },
            '-',
            {
                text: '编辑',
                iconCls: 'icon-edit',
                id: 'btn_edit',
                handler: function () {
                    detail(1)
                    setOperationLog("编辑按钮", "预付款退款/转单");
                }
            },
            '-',
            {
                text: '删除',
                iconCls: 'icon-remove',
                id: 'btn_remove',
                handler: function () {
                    delPaaOrder();
                }
            },
            '-',
            {
                text: '提交',
                iconCls: 'icon-ok',
                id: 'btn_push_oa',
                handler: function () {
                    dataSubmit();
                }
            },
           "-",
            {
                text: '财务确认',
                iconCls: 'icon-find',
                id: 'btn_confirm',
                handler: function () {
                    detail(3)
                }
            }

        ],
        onLoadSuccess: function () {
            displayButtonByUserRole("fin.payment.advance.refund.transfer.apply.index");

            $(el.tb).datagrid('clearSelections');
        },
        onCheck: function (rowIndex) {
            var rows = $(el.tb).datagrid('getRows');
            var status = rows[rowIndex].status;
            //数据状态 1:暂存待提交 2:待推送OA审批 3:OA审批中 4:OA审批拒绝 5:付款完成(OA审批通过)
            // switch (Number(status)) {
            //     case 1:
            //         $(el.btn_look).linkbutton('enable');
            //         $(el.btn_add).linkbutton('enable');
            //         $(el.btn_edit).linkbutton('enable');
            //         $(el.btn_remove).linkbutton('enable');
            //         $(el.btn_push_oa).linkbutton('enable');
            //         $(el.approval).linkbutton('enable');
            //         $(el.btn_confirm).linkbutton('enable');
            //
            //         break;
            //     case 2:
            //         $(el.btn_look).linkbutton('enable');
            //         $(el.btn_add).linkbutton('enable');
            //         $(el.btn_edit).linkbutton('disable');
            //         $(el.btn_remove).linkbutton('enable');
            //         $(el.btn_push_oa).linkbutton('enable');
            //         $(el.approval).linkbutton('enable');
            //         $(el.btn_confirm).linkbutton('enable');
            //         break;
            //     case 3:
            //         $(el.btn_look).linkbutton('enable');
            //         $(el.btn_add).linkbutton('enable');
            //         $(el.btn_edit).linkbutton('disable');
            //         $(el.btn_remove).linkbutton('disable');
            //         $(el.btn_push_oa).linkbutton('disable');
            //         $(el.approval).linkbutton('enable');
            //         $(el.btn_confirm).linkbutton('enable');
            //         break;
            //     case 4:
            //         $(el.btn_look).linkbutton('enable');
            //         $(el.btn_add).linkbutton('enable');
            //         $(el.btn_edit).linkbutton('enable');
            //         $(el.btn_remove).linkbutton('disable');
            //         $(el.btn_push_oa).linkbutton('enable');
            //         $(el.approval).linkbutton('enable');
            //         $(el.btn_confirm).linkbutton('enable');
            //         break;
            //     case 5:
            //         $(el.btn_look).linkbutton('enable');
            //         $(el.btn_add).linkbutton('enable');
            //         $(el.btn_edit).linkbutton('disable');
            //         $(el.btn_remove).linkbutton('disable');
            //         $(el.btn_push_oa).linkbutton('disable');
            //         $(el.approval).linkbutton('disable');
            //         $(el.btn_confirm).linkbutton('enable');
            //         break;
            //     case 6:
            //         $(el.btn_look).linkbutton('enable');
            //         $(el.btn_add).linkbutton('enable');
            //         $(el.btn_edit).linkbutton('disable');
            //         $(el.btn_remove).linkbutton('enable');
            //         $(el.btn_push_oa).linkbutton('disable');
            //         $(el.approval).linkbutton('disable');
            //         $(el.btn_confirm).linkbutton('enable');
            //         break;
            //     default:
            //         break;
            // }
        }
    });
}
function syncSap(){
    let rows = $(el.tb).datagrid('getSelections');
    if(rows.length!=1){
        layer.msg("请选中一条记录"); return;
    }
    if(parseFloat(rows[0].oaBorrowMoney)<=0){
        layer.msg("付款金额小于等于0不能同步SAP");
        return false;
    }
    if ((rows[0].syncState != 1 && rows[0].syncState != 3) || rows[0].status!=5) {
        layer.alert("未同步或新建同步失败，且审批通过状态才可操作");
        return;
    }
    layer.confirm('确认同步SAP?', function(index) {
        let load = topWin.layer.load(0);
        $.ajax({
            url:"/fin/payment/advance/apply/rest/syncSap",
            data: {id : rows[0].id},
            success:function(data){
                if (data && data.state) {
                    $(el.tb).datagrid('load');
                    layer.close(index);
                    layer.alert(data.msg);
                }else {
                    layer.alert(data.msg);
                }
                topWin.layer.close(load);
            },
            error:function(){
                topWin.layer.close(load);
                layer.close(index);
                layer.alert("执行出错！");
            }
        })
    })
}

/**
 * 查看预付款申请
 */
function detail(optType) {//optType === 3时，财务审核页面，需要在详情页面上加上两个按钮和一个审批意见
    var id = '';
    if (optType===otpTypeEnum.EDIT||optType===otpTypeEnum.COPY || optType=== 3){
        var row = $(el.tb).datagrid('getSelected'), userId = $(el.userId).val();
        if (!row) {
            topWin.layer.alert('请选中一条记录', {icon: 0});
            return false;
        }
        id = row.id;
    }
    var url = g.ctx + 'pc/finance/paymentAdvanceRefundTransferApply/apply/detail?id=' + id + '&optType='+optType;
    var buttons = [];
    if (optType===otpTypeEnum.COPY){
        buttons.push(
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.addOrEditDialog.dialog('close');
                }
            }
        );
    }else if(optType=== 3){
        buttons.push(
            {
                text: '审核通过',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['addOrEditPaa'].confirm(function () {
                        topWin.layer.msg('审核通过，操作成功', {icon: 1});
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '审核驳回',
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['addOrEditPaa'].refuse(function (data) {
                        topWin.layer.msg('审核拒绝成功', {icon: 1});
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $(el.tb).datagrid('reload');
                    el.addOrEditDialog.dialog('close');
                }
            }
        );
    }else{
        buttons.push(
            {
                text: '暂存',
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['addOrEditPaa'].dataSave(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $(el.tb).datagrid('reload');
                    el.addOrEditDialog.dialog('close');
                }
            }
        );
    }
    el.addOrEditDialog = openDialog('addOrEditPaa', url, {
        title: (optType === otpTypeEnum.ADD ? "新增" :optType===otpTypeEnum.EDIT?"编辑":"查看"),
        width: '99%',
        height: '100%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.addOrEditDialog.dialog('destroy');
        },
        buttons: buttons
    });
}

/**
 * 查看预付款申请
 */
function lookPaaOrder() {
    var rows = $(el.tb).datagrid('getSelections');
    if (rows.length !== 1) {
        topWin.layer.alert('请选择一条预付款申请单进行操作', {icon: 0});
        return false;
    }

    var url = g.ctx + 'pc/finance/paymentAdvance/apply/look?id=' + rows[0].id+'&companyType='+companyType;
    el.lookDialog = openDialog('lookPaaOrder', url, {
        title: '查看预付款申请',
        width: '99%',
        height: '100%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.lookDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.lookDialog.dialog('close');
                }
            }
        ]
    });
}


/**
 * 新增或编辑预付款申请单
 *
 * @param type 0:新增 1:编辑
 */
function addOrEditPaaOrder(type) {
    var title = '新增预付款申请', url = g.ctx + 'pc/finance/paymentAdvance/apply/add?companyType='+companyType;

    if (Number(type) === 1) {
        var rows = $(el.tb).datagrid('getSelections');
        if (rows.length !== 1) {
            topWin.layer.alert('请选择一条预付款申请单进行操作', {icon: 0});
            return false;
        }

        if (rows[0].status === 1 || rows[0].status === 4) {
            title = '编辑预付款申请';
            url = g.ctx + 'pc/finance/paymentAdvance/apply/edit?companyType='+companyType +'&id=' + rows[0].id;
        } else {
            topWin.layer.alert('预付款申请单的状态不支持编辑', {icon: 0});
            return false;
        }
    }
    el.addOrEditDialog = openDialog('addOrEditPaa', url, {
        title: title,
        width: '99%',
        height: '100%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.addOrEditDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '暂存',
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['addOrEditPaa'].dataSave(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            // {
            //     text: '提交审核',
            //     iconCls: 'icon-ok',
            //     handler: function () {
            //         topWin.frames['addOrEditPaa'].dataSaveAndPushOa(function (data) {
            //             if(data === ''){
            //                 topWin.layer.msg('数据保存并推送成功', {icon: 1});
            //             }else {
            //                 topWin.layer.alert(data, {icon: 1});
            //             }
            //
            //             $(el.tb).datagrid('load');
            //             el.addOrEditDialog.dialog('close');
            //         });
            //     }
            // },
            {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $(el.tb).datagrid('reload');
                    el.addOrEditDialog.dialog('close');
                }
            }
        ]
    });
}


/**
 * 删除付款申请
 */
function delPaaOrder() {
    var rows = $(el.tb).datagrid('getSelections');
    if (rows.length === 0) {
        topWin.layer.alert('请选择预付款变更单进行操作', {icon: 0});
        return false;
    }

    var delIds = [];
    var set = new Set();
    for (var i = 0; i < rows.length; i++) {
        var item = rows[i];
        debugger
        delIds.push(item.id);
        set.add(Number(item.status))
        if (Number(item.status) === 0 || Number(item.status) === 1  || Number(item.status) ===2) {
            delIds.push(item.id);
            set.add(Number(item.status))
        } else {
            topWin.layer.alert('预付款申请单号: ' + item.paymentChangeNo + '当前状态不允许删除', {icon: 0});
            return false;
        }
    }
    if(set.size>1){
        topWin.layer.alert('抱歉,请选择相同状态的单据删除', {icon: 0});
        return false;
    }
    let msg = '您确定要删除选中的记录吗?';
    if(set.has(1)){
        msg = '您确定要删除选中的记录吗?';
    }


    topWin.layer.confirm(msg, {icon: 3}, function (index) {
        topWin.layer.close(index);
        var loading = topWin.layer.msg('数据删除中, 请耐心等待......', {icon: 16, time: 0, shade: 0.1});
        $.ajax({
            type: 'POST',
            url: g.ctx + 'pc/finance/paymentAdvanceRefundTransferApply/apply/rest/refundTransferApply/del',
            data: {
                applyIds: JSON.stringify(delIds)
            },
            success: function () {
                topWin.layer.close(loading);
                topWin.layer.msg('数据删除成功', {icon: 1});
                $(el.tb).datagrid('reload');
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    });
}


/**
 * 推送OA
 */
function dataSubmit() {
    var rows = $(el.tb).datagrid('getSelections');
    if (rows.length !== 1) {
        topWin.layer.alert('请选一条预付款变更申请单进行操作', {icon: 0});
        return false;
    }

    var item = rows[0];
    //暂时注释
    /*if(parseFloat(item.oaBorrowMoney)<=0){
        layer.msg("付款金额小于等于0不能同步OA");
        return false;
    }*/
    let msg = '请确认是否提交财务审批！';
    // if(Number(item.status) === 4){
    //     msg = '请确认是否将OA上对应的借款删除，请删除后再进行该操作?';
    // }else {
    //     msg = '您确定要将选中的记录进行审批吗?';
    // }
    // 数据状态 1:暂存 0 待财务确认 1 财务驳回 2  已发布 3
    if (Number(item.status) === 0 || Number(item.status) === 2 ) {
        topWin.layer.confirm(msg, {icon: 3}, function (index) {
            topWin.layer.close(index);
            var loading = topWin.layer.msg('数据推送中, 请耐心等待......', {icon: 16, time: 0, shade: 0.1});
            $.ajax({
                type: 'POST',
                url: g.ctx + 'pc/finance/paymentAdvanceRefundTransferApply/apply/rest/refundTransferApply/submit',
                data: {
                    applyId: item.id,
                    companyType: companyType
                },
                success: function () {
                    topWin.layer.close(loading);
                    topWin.layer.msg('数据提交成功，待财务审核', {icon: 1});
                    $(el.tb).datagrid('reload');
                },
                error: function (data) {
                    parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
                }
            });
        });
    } else {
        topWin.layer.alert('预付款变更申请单号: ' + item.apApplyNo + '当前状态不允许提交', {icon: 0});
        return false;
    }
}


/**
 * 数据导出
 */
function dataExport() {
    var url = g.ctx + 'fin/payment/advance/apply/rest/data/export' +
        '?applyNo=' + $.trim($(el.applyNo).val()) +
        '&supCodeOrName=' + $.trim($(el.supCodeOrName).val()) +
        '&oaProcessCode=' + $.trim($(el.oaProcessNo).val()) +
        '&poCode=' + $.trim($(el.poCode).val()) +
        '&pushOaUserName=' + $.trim($(el.pushOaUserName).val()) +
        '&companyCode=' + $(el.companyCode).combobox('getValue') +
        '&status=' + $(el.status).combobox('getValue') +
        '&createTimeStart=' + $(el.createTimeStart).datebox('getValue') +
        '&createTimeEnd=' + $(el.createTimeEnd).datebox('getValue');
    window.open(url);
}


/**
 * 数据查询
 */
function searchPaaData() {
    debugger;
    var queryParams = $(el.tb).datagrid('options').queryParams;
    queryParams.paymentChangeNo = $.trim($(el.paymentChangeNo).val());
    queryParams.supCodeOrName = $.trim($(el.supCodeOrName).val());
    queryParams.createUserName = $.trim($('#createUserName').val());
    queryParams.poCode = $.trim($(el.poCode).val());
    queryParams.companyCode = $(el.companyCode).combobox('getValue');
    queryParams.status = $(el.status).combobox('getValue');
    queryParams.dataType = $(el.dataType).combobox('getValue');
    queryParams.createTimeStart = $(el.createTimeStart).datebox('getValue');
    queryParams.createTimeEnd = $(el.createTimeEnd).datebox('getValue');


    $(el.tb).datagrid('load');
}


/**
 * 重置查询
 */
function resetPaaSearch() {
    $(el.paymentChangeNo).val('');
    $(el.supCodeOrName).val('');
    $('#createUserName').val('');
    $(el.poCode).val('');
    $(el.companyCode).combobox('setValue', '');
    $(el.status).combobox('setValue', -1);
    $(el.dataType).combobox('setValue', -1);
    $(el.createTimeStart).datebox('setValue', '');
    $(el.createTimeEnd).datebox('setValue', '');
    $(el.tb).datagrid('reload');
    searchPaaData();
}

/**
 * 审批通过
 *
 */
function approvalPass() {
    var rows = $(el.tb).datagrid('getSelections'),  ids = [];

    if(rows.length === 0){
        layer.msg("请至少选择一行数据", {icon: 0});
        return false;
    }
    var rowsFilter=rows.filter(item=>item.isOa!=1)
    // if(rowsFilter.length!=0){
    //     layer.msg("只能手工审批通过“是否OA补录”为是的单据", {icon: 0});
    //     return false;
    // }

    ids=rows.map(item=>item.id).join(',')

    topWin.layer.confirm('您确定要通过吗?', {icon: 3}, function (index) {
        var load = topWin.layer.load(0);
        $.ajax({
            url: g.ctx + 'pc/finance/paymentAdvance/apply/rest/approval/pass',
            type: 'POST',
            data: {
                ids: ids,
            },
            success: function () {
                topWin.layer.close(load);
                topWin.layer.close(index);
                topWin.layer.msg('审批成功', {icon: 1});
                $(el.tb).datagrid('reload');
            },
            error: function (data) {
                topWin.layer.close(load);
                topWin.layer.close(index);
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    });
}

/**
 * 显示title
 *
 * @param ele 当前DOM节点
 */
function showFailInfo(ele) {
    el.tipsIndex = layer.tips($(ele).data('msg'), ele, {
        tips: [1, '#3595CC'],
        time: 0
    });
}


/**
 * 关闭tip
 */
function closeShowTip() {
    if(null !== el.tipsIndex){
        layer.close(el.tipsIndex);
    }
}

/**
 * 财务确认按钮功能
 */
function advanceImport(){
    var importDialog = openImportExcelDialog('static/excel/预付款导入模版.xlsx','预付款期初导入',function(file){
        let formData = new FormData();
        formData.append("file", file);
        var loading = topWin.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/finance/paymentAdvance/apply/rest/import',
            method: "POST",
            data: formData,
            contentType: false,
            processData: false,
            success: function (data) {

                if (data === 'ok') {
                    topWin.layer.alert("导入成功", {icon: 1}, function (idx) {
                        $(el.tb).datagrid('reload');
                        $(el.tb).datagrid('clearSelections');
                        topWin.layer.close(idx);
                        importDialog.dialog('close');
                    });
                } else {
                    topWin.layer.confirm('部分导入成功,是否下载未成功数据?', function (index) {
                        $(el.tb).datagrid('reload');
                        $(el.tb).datagrid('clearSelections');
                        topWin.layer.close(index);
                        window.location.href = g.ctx + 'pc/sys/file/rest/download/' + data
                    });
                }
            },
            complete: function(data) {
                topWin.layer.close(loading);
            },
            error: function (data) {
                topWin.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
            }
        });
    });
}
