/**
 * 新增开票申请单
 * @param optType 0 人民币发票交接 1 编辑 2 查看 3 采购确认 4 财务确认 5 外币资料交接 7 购销合同补录复核 8 补票
 * @param openMenu 0 对账资料交接申请 1 采购到票确认 2 财务到票确认
 */
function detail(optType, openMenu) {
    debugger;
    var id = '';
    if (optType!==0&&optType!==5){
        var row = $(el.tb).datagrid('getSelected');
        if (!row) {
            topWin.layer.alert('请选中一条记录', {icon: 0});
            return false;
        }
        id = row.id;

        // if (optType===1 && (Number(row.status) !== 1 || Number(row.status) !== 3)) {
        //     topWin.layer.alert('当前状态不可编辑', {icon: 0});
        //     return false;
        // }
    }
    var buttons = [];
    if (optType===2){
        buttons.push(
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.addOrEditDialog.dialog('close');
                }
            }
        )
    }else if (optType===0 || optType===1 || optType===5){
        buttons.push(
            {
                text: '暂存',
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['addInvoicedApply'].dataSave(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            // {
            //     text: '提交',
            //     iconCls: 'icon-ok',
            //     handler: function () {
            //         topWin.frames['addInvoicedApply'].dataSave(function (applyId) {
            //             console.info('数据保存成功');
            //             console.info(applyId);
            //             topWin.layer.msg('数据保存成功', {icon: 1});
            //             $(el.tb).datagrid('load');
            //             el.addOrEditDialog.dialog('close');
            //
            //             dataSaveSubmit(applyId.id);
            //         });
            //     }
            // },
            {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    if (optType === 0 || optType === 5) {
                        topWin.frames['addInvoicedApply'].deleteUnsavedAttachment();
                    }
                    el.addOrEditDialog.dialog('close');
                }
            }
        )
    }else if (optType===3){
        buttons.push(
            {
                text: '通过',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['addInvoicedApply'].purchaseConfirm(1,function (dataParams) {
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '拒绝',
                iconCls: 'icon-cancel',
                handler: function () {
                    topWin.frames['addInvoicedApply'].purchaseConfirm(0,function (dataParams) {
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-clear',
                handler: function () {
                    el.addOrEditDialog.dialog('close');
                }
            }
        )
    }else if (optType===4){
        buttons.push(
            {
                text: '通过',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['addInvoicedApply'].financeConfirm(1,function (dataParams) {
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '拒绝',
                iconCls: 'icon-cancel',
                handler: function () {
                    topWin.frames['addInvoicedApply'].financeConfirm(0,function (dataParams) {
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-clear',
                handler: function () {
                    el.addOrEditDialog.dialog('close');
                }
            }
        )
    }else if (optType===7){
        buttons.push(
            {
                text: '复核通过',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['addInvoicedApply'].saleContractConfirm(1,function (dataParams) {
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '复核拒绝',
                iconCls: 'icon-cancel',
                handler: function () {
                    topWin.frames['addInvoicedApply'].saleContractConfirm(0,function (dataParams) {
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-clear',
                handler: function () {
                    el.addOrEditDialog.dialog('close');
                }
            }
        )
    }else if (optType===8){
        buttons.push(
            {
                text: '提交',
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['addInvoicedApply'].redReversalSave(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        $(el.tb).datagrid('load');
                        el.addOrEditDialog.dialog('close');
                    });
                }
            },
            {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.addOrEditDialog.dialog('close');
                }
            }
        )
    }
    var url = g.ctx + 'pc/finance/invoiced/apply/detail?orderType=' + $(el.orderType).val() + '&optType='+optType +'&id='+id +'&openMenu='+openMenu;
    el.addOrEditDialog = openDialog('addInvoicedApply', url, {
        title: optType===0?'人民币发票交接':optType===1?'编辑开票申请单':optType===2?'查看开票申请单':optType===3?'采购确认开票申请单':optType===5?'外币资料交接':optType===4?'财务确认开票申请单':optType===7?'采购复核购销合同':'补票',
        width: '99%',
        height: '100%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            if (optType === 0 || optType === 5) {
                topWin.frames['addInvoicedApply'].deleteUnsavedAttachment();
            }
            el.addOrEditDialog.dialog('destroy');
        },
        buttons: buttons
    });
}