/**
 * 对账模块-对账单新增页面JS
 *
 * Created by li.kui on 2020/8/1.
 */
'use strict';
var el = {
    dataPanel: '#dataPanel',
    dataDiv: '#dataDiv',
    id: '#id',
    orderType: '#orderType',
    isSupplier: '#isSupplier',
    supplierCode: '#supplierCode',
    supplierName: '#supplierName',
    companyCode: '#companyCode',
    companyName: '#companyName',
    factoryCode: '#factoryCode',
    factoryName: '#factoryName',
    deductionAmount: '#deductionAmount',
    rebateAmount: '#rebateAmount',
    inStockStartDate: '#inStockStartDate',
    inStockEndDate: '#inStockEndDate',
    bpPayableBalance: '#bpPayableBalance',
    bpEstimateBalance: '#bpEstimateBalance',
    etPayableBalance: '#etPayableBalance',
    etEstimateBalance: '#etEstimateBalance',
    beginPeriodTotal: '#beginPeriodTotal',
    endPeriodTotal: '#endPeriodTotal',
    currPaymentAmount: '#currPaymentAmount',
    notTaxAmount: '#notTaxAmount',
    taxAmount: '#taxAmount',
    currencyCode: '#currencyCode',
    remark: '#remark',
    dataTabs: '#dataTabs',
    tbDetails: '#tbDetails',
    tbDeduction: '#tbDeduction',
    tbRebate: '#tbRebate',
    localCurrency : '#localCurrency',
    originalCurrency: '#originalCurrency',
    advanceLocalCurrency: '#advanceLocalCurrency',
    advanceOriginalCurrency: '#advanceOriginalCurrency',
    invoiceFileInput: '#invoiceFileInput',
    fileId: '#fileId',
    taxCode: '#taxCode',
    paymentTermDesc: '#paymentTermDesc',
    paymentTermCode: '#paymentTermCode',
    purchaseGroup: '#purchaseGroup',
    poType: '#poType',
    choseSupplierDialog: null,
    choseRebateDataDialog: null,
    userTableColumn: [],
    bodyHeight: document.documentElement.clientHeight
};


/**
 * 文档就绪
 */
$(function () {
    $(el.dataPanel).panel({
        collapsible: true,
        onCollapse: function () {
            $(el.dataTabs).tabs('select', 0);

            $(el.tbDetails).datagrid('resize', {height: el.bodyHeight - 80});
            // $(el.tbRebate).datagrid('resize', {height: el.bodyHeight - 80});
            // $(el.tbDeduction).datagrid('resize', {height: el.bodyHeight - 80});
        },
        onExpand: function () {
            $(el.dataTabs).tabs('select', 0);

            var dataDiv = $(el.dataDiv).outerHeight() + 90;
            $(el.tbDetails).datagrid('resize', {height: el.bodyHeight - dataDiv});
            // $(el.tbRebate).datagrid('resize', {height: el.bodyHeight - dataDiv});
            // $(el.tbDeduction).datagrid('resize', {height: el.bodyHeight - dataDiv});
        }
    });

    // 获取当前用户在本页面中表格列配置
    // findUserTableColumn();

    // 加载页面输入或下拉框数据
    initPageInput();

    initTbDetails();
    initTbDeduction();
    // initTbRebate();
});


/**
 * 初始化页面输入框
 */
function initPageInput() {
    var isSupplier = $(el.isSupplier).val();
    var companyDataUrl = g.ctx + 'pc/sys/company/rest/listAll?isAuthority=0';

    // 初始化工厂代码下拉框
    $(el.factoryCode).combobox({
        panelHeight: 300,
        panelWidth: 260,
        prompt: '--- 请先选择采购公司 ---',
        disabled: true,
        required: false
    });
    //采购组
    // $('#purchaseGroup').combobox({
    //     onChange: function (data) {
    //         $(el.tbDetails).datagrid('loadData', { total: 0, rows: [] });
    //         var rows = $(el.tbDetails).datagrid('getSelections');
    //         calculationAmount(rows);
    //     }
    // });

    // 初始化公司代码下拉框
    $(el.companyCode).combobox({
        required: true,
        url: companyDataUrl,
        panelHeight: 'auto',
        panelWidth: 340,
        valueField: 'companyCode',
        textField: 'companyCodeName',
        prompt: '--- 请选择 ---',
        onSelect: function (data) {
            var oriCc = $(el.companyCode).combobox('getValue');
            if(oriCc !== data.companyCode){
                clearPageTableData();
            }

            $(el.companyName).val(data.companyName);
            findFactoryDataByCompanyCode(data.companyCode, isSupplier);
        },
        onLoadSuccess: function () { //加载完成后,设置选中第一项
            $(this).combobox("select", $('#deptCode').val());
        }
    });

    // 初始化币种下拉框
    $(el.currencyCode).combobox({
        panelHeight: 'auto',
        panelWidth: 200,
        valueField: 'dicId',
        textField: 'dicTxt',
        url: '/dic/getDicByType',
        queryParams: {
            type: 'TENDER_currency'
        },
        onSelect: function (data) {
            getExchangeRate(data.dicId);
            clearPageTableData();
        },
        onLoadSuccess: function () { //加载完成后,设置选中第一项
            var val = $(this).combobox("getData");
            for (var item in val[0]) {
                if (item == "dicId") {
                    $(this).combobox("select", val[0][item]);
                    getExchangeRate(val[0][item]);
                }
            }
        }
    });

    if(Number(isSupplier) === 0){
        $(el.supplierCode).textbox({
            prompt: '请选择供应商',
            required: true,
            icons: [
                {
                    iconCls: 'icon-search',
                    handler: function () {
                        choseSupplier();
                    }
                }
            ]
        });
        $(el.supplierCode).textbox('textbox').css('cursor', 'pointer');
        $(el.supplierCode).textbox('textbox').bind('click', function () {
            choseSupplier();
        });
    }


    // 初始化入库凭证开始日期
    $(el.inStockStartDate).datebox({
        value: moment(new Date()).subtract(1, 'months').startOf('month').format("YYYY-MM-DD"),
        onSelect: function(date){
            var curr = $(this).datebox('getValue'), update = moment(date).format("YYYY-MM-DD");
            if(curr !== update){
                clearPageTableData();
            }
        }
    });

    // 初始化入库凭证结束日期
    $(el.inStockEndDate).datebox({
        value: moment(new Date()).subtract(1, 'months').endOf('month').format("YYYY-MM-DD"),
        onSelect: function(date){
            var curr = $(this).datebox('getValue'), update = moment(date).format("YYYY-MM-DD");
            if(curr !== update){
                clearPageTableData();
            }
        }
    });

    // 税率
    $(el.taxCode).combobox({
        panelHeight: 'auto',
        panelWidth: 200,
        limitToList: 'true',
        valueField: 'dicCode',
        textField: 'newItemCodeAndName',
        prompt: '--- 请选择 ---',
        url: '/dic/getDicByType?type=tax',
        onChange: function (data) {
            $(el.tbDetails).datagrid('loadData', { total: 0, rows: [] });
            var rows = $(el.tbDetails).datagrid('getSelections');
            calculationAmount(rows);
        }
    });

    // 采购组
    $(el.purchaseGroup).combobox({
        panelHeight: '200px',
        // panelWidth: 200,
        valueField: 'purchaseGroupCode',
        textField: 'purchaseGroupName',
        limitToList: 'true',
        prompt: '--- 请选择 ---',
        url: '/fin/account/statement/getUserPgList'
    });

    // 付款条件
    $(el.paymentTermCode).combobox({
        panelHeight: 'auto',
        // panelWidth: 200,
        valueField: 'dicCode',
        limitToList: 'true',
        textField: 'dicTxt',
        prompt: '--- 请选择 ---',
        url: '/dic/getDicByType?type=supplier_fktj'
    });
    // 订单类型
    $(el.poType).combobox({
        panelHeight: 'auto',
        panelWidth: 200,
        valueField: 'dicCode',
        multiple: true,
        textField: 'dicTxt',
        prompt: '--- 请选择 ---',
        url: '/dic/getDicByType?type=po_type',
        icons: [{
            iconCls: 'icon-delete',
            handler: function (e) {
                $(el.poType).combobox('clear');
                $(el.tbDetails).datagrid('loadData', { total: 0, rows: [] });
                var rows = $(el.tbDetails).datagrid('getSelections');
                calculationAmount(rows);
            }
        }],
        onChange: function (data) {
            $(el.tbDetails).datagrid('loadData', { total: 0, rows: [] });
            var rows = $(el.tbDetails).datagrid('getSelections');
            calculationAmount(rows);
        },
        onLoadSuccess: function (record) {
            //全选
            var valueField = $(el.poType).combobox("options").valueField;
            var data = $(el.poType).combobox("getData");
            var selectVaues = [];
            data.reduce(function(prev, current, index, array){
                selectVaues.push(current[valueField]);
            },selectVaues);
            $(el.poType).combobox('setValues', selectVaues);
        }
    });
}

function initPaymentTermCode(supplierCode) {
    $(el.paymentTermCode).combobox('clear');
    $(el.paymentTermCode).combobox({
        panelHeight: 'auto',
        // panelWidth: 200,
        valueField: 'dicCode',
        textField: 'dicTxt',
        prompt: '--- 请选择 ---',
        url: '/fin/common/rest/getSupplierProductTypeBySupplierCode?supplierCode='+supplierCode
    });
}
function payableOutstanding() {

    var companyCode = $(el.companyCode).combobox('getValue');
    var  supplierCode = $(el.supplierCode).textbox('getValue');
    var  currencyCode = $(el.currencyCode).combobox('getValue');
    var  inStockEndDate = $(el.inStockEndDate).datebox('getValue');

    if(companyCode==''||supplierCode==''||currencyCode==''){
        topWin.layer.alert('请检查“公司”、“供应商”、“本币”是否已选', {icon: 0});
        return false;
    }
    $.ajax({
        type: 'POST',
        url: g.ctx + 'fin/account/statement/rest/payableOutstanding',
        async: false,
        data: {
            companyCode: companyCode,
            supplierCode: supplierCode,
            inStockEndDate: inStockEndDate,
            currency:currencyCode
        },
        success: function (data) {

            $(el.localCurrency).textbox('setValue',new BigNumber(data.apDmbtr).toFormat(2));
            $(el.originalCurrency).textbox('setValue',new BigNumber(data.apWrbtr).toFormat(2));
            $(el.advanceLocalCurrency).textbox('setValue',new BigNumber(data.ppDmbtr).toFormat(2));
            $(el.advanceOriginalCurrency).textbox('setValue',new BigNumber(data.ppWrbtr).toFormat(2));


        }
    });


}

/**
 * 初始化入库明细表格
 */
function initTbDetails() {
    var dataDiv = $(el.dataDiv).outerHeight() + 90, orderType = $(el.orderType).val();
    // var columns = dynamicColumns(orderType);

    $(el.tbDetails).datagrid({
        loadMsg: '数据加载中, 请耐心等待......',
        height: el.bodyHeight - dataDiv,
        singleSelect: false,
        rownumbers: true,
        // 定义从服务器对数据进行排序
        remoteSort: false,
        // 定义是否允许多列排序
        // multiSort: true,
        pagination: false,
        showFooter: true,
        queryParams: {},
        frozenColumns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                }
            ]
        ],
        columns: [
            tableColumns
        ],
        toolbar: [
            {
                text: '获取凭证信息',
                iconCls: 'icon-add',
                handler: function () {
                    var companyCode = $(el.companyCode).combobox('getValue'), factoryCode = $(el.factoryCode).combobox('getValue'), taxCode = $(el.taxCode).combobox('getValue'),
                        inStockStartDate = $(el.inStockStartDate).datebox('getValue'), inStockEndDate = $(el.inStockEndDate).datebox('getValue'),
                        currencyCode = $(el.currencyCode).combobox('getValue'), supplierCode = $(el.supplierCode).textbox('getValue'),
                        poType = getTextByJs($(el.poType).combobox('getValues')),
                        purchaseGroup = $('#purchaseGroup').combobox('getValue');
                    getVoucherData(companyCode, factoryCode, supplierCode, currencyCode, inStockStartDate, inStockEndDate,purchaseGroup,poType,taxCode);
                }
            },
            '-',
            {
                text: '全选',
                iconCls: 'icon-ok',
                handler: function () {
                    detailSelectAll();
                }
            },
            '-',
            {
                text: '取消全选',
                iconCls: 'icon-remove',
                handler: function () {
                    cancelSelectAll();
                }
            },
            '-',
            {
                text: '导出',
                iconCls: 'icon-download',
                handler: function () {
                    detailExport();
                }
            },
            '-',
            {
                text: '填充应付未清金额',
                iconCls: 'icon-ok',
                handler: function () {
                    payableOutstanding();
                }
            }
        ],
        onLoadSuccess: function (data) {
            // 默认全部选中
            $(el.tbDetails).datagrid('selectAll');
            var dataRows = data.rows;

            calculationAmount(dataRows);
        },
        onClickRow: function (index, row) {
            // if (row.voucherFlag === 'H') {
            $(el.tbDetails).datagrid('selectRow', index);
            // }
            var rows = $(el.tbDetails).datagrid('getSelections');
            calculationAmount(rows);
        },
        onCheck: function(){
            var rows = $(el.tbDetails).datagrid('getSelections');
            calculationAmount(rows);
        },
        onUncheck: function () {
            var rows = $(el.tbDetails).datagrid('getSelections');
            calculationAmount(rows);
        }
    });
}
/**
 * 初始化扣款信息表格
 */
function initTbDeduction() {
    var dataDiv = $(el.dataDiv).outerHeight() + 90;

    $(el.tbDeduction).datagrid({
        loadMsg: '数据加载中, 请耐心等待......',
        height: el.bodyHeight - dataDiv,
        url: g.ctx + 'fin/account/statement/rest/find/statement/deduction/list',
        singleSelect: false,
        showFooter: true,
        rownumbers: true,
        // 定义从服务器对数据进行排序
        remoteSort: false,
        // 定义是否允许多列排序
        // multiSort: true,
        pagination: false,
        queryParams: {
            asId: $(el.id).val()
        },
        frozenColumns: [
            [
                {
                    field: 'deductionId',
                    title: '附件查看',
                    width: 80,
                    formatter: function (value) {
                        if(value){
                            return '<a href="javascript:void(0)" onclick="lookDrAttachment(this)" data-type="1" data-id="' + value + '">查看</a>';
                        }
                        return '';
                    }
                },
                {
                    field: 'deductionNo',
                    title: '扣款编号',
                    width: 140,
                    sortable: true
                },
                {
                    field: 'deductionTypeDesc',
                    title: '扣款类型',
                    width: 90,
                    sortable: true
                },
                {
                    field: 'deductionAmount',
                    title: '含税扣款金额(元)',
                    width: 110,
                    sortable: true,
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return formatNumber(value, 2, 1);
                    }
                },
                {
                    field: 'taxCodeDesc',
                    title: '税率',
                    width: 160,
                    sortable: true
                },
                {
                    field: 'deductionTime',
                    title: '扣款时间',
                    width: 90,
                    sortable: true,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD");
                        }
                        return '';
                    }
                }
            ]
        ],
        columns: [
            [
                {
                    field: 'deductionReason',
                    title: '扣款原因',
                    width: 300
                },
                {
                    field: 'companyCode',
                    title: '公司代码',
                    width: 80
                },
                {
                    field: 'companyName',
                    title: '公司名称',
                    width: 180
                },
                {
                    field: 'supplierCode',
                    title: '供应商编码',
                    width: 90
                },
                {
                    field: 'supplierName',
                    title: '供应商名称',
                    width: 270
                },
                {
                    field: 'associatedNo',
                    title: 'SRM业务单据',
                    width: 140,
                    formatter: function (value, row) {
                        if(!row.associatedRowNo){
                            return value;
                        }else {
                            return value + '|' + row.associatedRowNo;
                        }
                    }
                },
                {
                    field: 'associatedOaNo',
                    title: 'OA流程单号',
                    width: 120,
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 140,
                    sortable: true,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                }
            ]
        ]
    });
}


/**
 * 获取凭证数据
 */
function getVoucherData(companyCode, factoryCode, supplierCode, currencyCode, inStockStartDate, inStockEndDate,purchaseGroup,poType,taxCode) {
    if(!supplierCode){
        topWin.layer.alert('请选择供应商信息', {icon: 0});
        return false;
    }

    if(!currencyCode){
        topWin.layer.alert('请选择币种', {icon: 0});
        return false;
    }

    if(!companyCode){
        topWin.layer.alert('请选择采购公司', {icon: 0});
        return false;
    }

    if(!factoryCode){
        topWin.layer.alert('请选择工厂', {icon: 0});
        return false;
    }

    if(!inStockStartDate){
        topWin.layer.alert('请选择入库开始时间', {icon: 0});
        return false;
    }

    if(!inStockEndDate){
        topWin.layer.alert('请选择入库结束时间', {icon: 0});
        return false;
    }

    if(moment(inStockStartDate) > moment(inStockEndDate)){
        topWin.layer.alert('入库开始时间不能大于结束时间', {icon: 0});
        return false;
    }

    // if(!poType){
    //     topWin.layer.alert('请选择订单类型', {icon: 0});
    //     return false;
    // }
console.log(purchaseGroup)

    // 3.获取入库凭证数据
    findVoucherData(companyCode, factoryCode, supplierCode, currencyCode, inStockStartDate, inStockEndDate,purchaseGroup,poType,taxCode);
    // findDeductionData(companyCode, supplierCode, inStockStartDate, inStockEndDate);
}


/**
 * 创建对账单时进行数据校验
 *
 * @param companyCode 公司编码
 * @param supplierCode 供应商编码
 * @returns {object}
 */
function createStatementCheck(companyCode, supplierCode) {
    var rebateData = 0;
    $.ajax({
        type: 'POST',
        url: g.ctx + 'fin/account/statement/rest/create/check',
        async: false,
        data: {
            companyCode: companyCode,
            supplierCode: supplierCode
        },
        success: function (data) {
            rebateData = data;
        }
    });

    return rebateData;
}


/**
 * 获取入库明细数据
 *
 * @param companyCode 公司编码
 * @param factoryCode 工厂编码
 * @param supplierCode 供应商编码
 * @param currencyCode 货币代码
 * @param inStockStartDate 入库开始时间
 * @param inStockEndDate 入库结束时间
 */
function findVoucherData(companyCode, factoryCode, supplierCode, currencyCode, inStockStartDate, inStockEndDate,purchaseGroup,poType,taxCode) {
    var queryParams = $(el.tbDetails).datagrid('options').queryParams;
    queryParams.supplierCode = supplierCode;
    queryParams.companyCode = companyCode;
    queryParams.factoryCode = factoryCode;
    queryParams.currencyCode = currencyCode;
    queryParams.postTimeStart = inStockStartDate;
    queryParams.postTimeEnd = inStockEndDate;
    queryParams.purchaseGroup = purchaseGroup;
    queryParams.poTypes = poType;
    queryParams.receiveType = $(el.orderType).val();
    queryParams.taxCode = taxCode;
    queryParams.paymentTermCode = $(el.paymentTermCode).val();
    $(el.tbDetails).datagrid('options').url = g.ctx + 'fin/receipt/voucher/rest/provide/create/statement';
    $(el.tbDetails).datagrid('load');
}


/**
 * 获取对账期间扣款数据
 *
 * @param companyCode 公司编码
 * @param supplierCode 供应商编码
 * @param inStockStartDate 入库开始时间
 * @param inStockEndDate 入库结束时间
 */
function findDeductionData(companyCode, supplierCode, inStockStartDate, inStockEndDate) {
    var queryParams = $(el.tbDeduction).datagrid('options').queryParams;
    queryParams.page = 1;
    queryParams.rows = 1000;
    queryParams.whether = 0;
    queryParams.queryForm = 2;
    queryParams.companyCode = companyCode;
    queryParams.supplierCode = supplierCode;
    $(el.tbDeduction).datagrid('options').url = g.ctx + 'fin/deduction/manage/rest/list';
    $(el.tbDeduction).datagrid('load');
}


/**
 * 入库明细全选
 */
function detailSelectAll() {
    $(el.tbDetails).datagrid('selectAll');
    var dataRows = $(el.tbDetails).datagrid('getRows');
    calculationAmount(dataRows);
}


/**
 * 入库明细取消全选
 */
function cancelSelectAll() {
    $(el.tbDetails).datagrid('unselectAll');
    var rows = $(el.tbDetails).datagrid('getSelections');
    calculationAmount(rows);
}


/**
 * 入库明细导出
 */
function detailExport() {
    var rows = $(el.tbDetails).datagrid('getRows');
    $(el.tbDetails).datagrid('toExcel', {
        filename: '入库明细数据.xls',
        rows: rows,
        worksheet: '入库明细'
    });
}


/**
 * 数据保存
 *
 * @param type 0:暂存 1：提交
 * @param callback 回调函数
 */
function dataSave(type,callback) {
    var id = $(el.id).val(), orderType = $(el.orderType).val(), supplierCode = $(el.supplierCode).textbox('getValue'),
        supplierName = $(el.supplierName).textbox('getValue'), currencyCode = $(el.currencyCode).combobox('getValue'),
        companyCode = $(el.companyCode).combobox('getValue'), companyName = $(el.companyName).val(),
        factoryCode = $(el.factoryCode).combobox('getValue'), factoryName = $(el.factoryName).val(),
        taxAmount = $(el.taxAmount).textbox('getValue'), notTaxAmount = $(el.notTaxAmount).val(),
        purchaseGroup = $('#purchaseGroup').combobox('getValue'),
        paymentTermCode = $(el.paymentTermCode).combobox('getValue'),
        poType = getTextByJs($(el.poType).combobox('getValues')),
        deductionAmount = "", rebateAmount = "",
        bpPayableBalance ="", bpEstimateBalance = "",
        etPayableBalance = "", etEstimateBalance = "",
        fileId = $(el.fileId).val(),
        inStockStartDate = $(el.inStockStartDate).datebox('getValue'), inStockEndDate = $(el.inStockEndDate).datebox('getValue'),
        remark = $(el.remark).textbox('getValue'), currPaymentAmount = "",
        localCurrency = $(el.localCurrency).textbox('getValue'),
        originalCurrency = $(el.originalCurrency).textbox('getValue'),
        advanceLocalCurrency = $(el.advanceLocalCurrency).textbox('getValue'),
        advanceOriginalCurrency = $(el.advanceOriginalCurrency).textbox('getValue');

    if($.isEmptyObject(localCurrency)||$.isEmptyObject(originalCurrency)||$.isEmptyObject(advanceLocalCurrency)||$.isEmptyObject(advanceOriginalCurrency)){
        topWin.layer.alert('请获取“应清未付金额”', {icon: 0});
        return false;
    }
    localCurrency = Number(localCurrency.replace(/,/g,'')),
        originalCurrency = Number(originalCurrency.replace(/,/g,'')),
        advanceLocalCurrency = Number(advanceLocalCurrency.replace(/,/g,'')),
        advanceOriginalCurrency = Number(advanceOriginalCurrency.replace(/,/g,''));
    if (!companyCode) {
        topWin.layer.alert('请选择采购公司', {icon: 0});
        return false;
    }
    if (!inStockStartDate) {
        topWin.layer.alert('请选择入库开始日期', {icon: 0});
        return false;
    }
    if (!inStockEndDate) {
        topWin.layer.alert('请选择入库结束日期', {icon: 0});
        return false;
    }
    if (!currencyCode) {
        topWin.layer.alert('请选择币种', {icon: 0});
        return false;
    }
    if (!purchaseGroup) {
        topWin.layer.alert('请选择采购组', {icon: 0});
        return false;
    }
    if (!poType) {
        topWin.layer.alert('请选择订单类型', {icon: 0});
        return false;
    }
    if (!remark) {
        topWin.layer.alert('请填写备注', {icon: 0});
        return false;
    }

    var headData = {};
    headData.id = id;
    headData.orderType = orderType;
    headData.companyCode = companyCode;
    headData.companyName = companyName;
    headData.factoryCode = factoryCode;
    headData.factoryName = factoryName;
    headData.inStockStartDate = inStockStartDate;
    headData.inStockEndDate = inStockEndDate;
    headData.currencyCode = currencyCode;
    headData.supplierCode = supplierCode;
    headData.taxCode = $(el.taxCode).combobox('getValue');
    headData.supplierName = supplierName;
    headData.paymentTermCode = paymentTermCode;
    headData.poType = poType;
    headData.taxAmount = Number(taxAmount.replace(/,/g,''));
    headData.notTaxAmount = Number(notTaxAmount.replace(/,/g,''));
    headData.deductionAmount = deductionAmount;
    headData.rebateAmount = rebateAmount;
    headData.bpPayableBalance = Number(bpPayableBalance.replace(/,/g,''));
    headData.bpEstimateBalance = Number(bpEstimateBalance.replace(/,/g,''));
    headData.etPayableBalance = Number(etPayableBalance.replace(/,/g,''));
    headData.etEstimateBalance = Number(etEstimateBalance.replace(/,/g,''));
    headData.currPaymentAmount = Number(currPaymentAmount.replace(/,/g,''));
    headData.purchaseGroup = purchaseGroup;
    headData.remark = remark;
    headData.localCurrency = localCurrency;
    headData.originalCurrency = originalCurrency;
    headData.advanceLocalCurrency = advanceLocalCurrency;
    headData.advanceOriginalCurrency = advanceOriginalCurrency;
    headData.fileId = fileId;


    // 入库明细
    var detail = $(el.tbDetails).datagrid('getSelections'), statementItem = [];
    if (detail.length === 0) {
        topWin.layer.alert('请选择入库凭证明细', {icon: 0});
        return false;
    }
    //校验税码和付款条件
    let taxCode = "",payTermCode = "",pgCode = "";
    var itSumAmount = new BigNumber(0);
    for(var i = 0; i < detail.length; i++){
        if(i !== 0 && taxCode !== detail[i].taxCode){
            layer.msg("所选税率必须一致");
            return false;
        }
        if(i !== 0 && payTermCode !== detail[i].paymentTermCode){
            layer.msg("所选付款条件必须一致");
            return false;
        }
        // if(i !== 0 && pgCode !== detail[i].pgCode){
        //     layer.msg("所选采购组必须一致");
        //     return false;
        // }
        taxCode = detail[i].taxCode;
        payTermCode = detail[i].paymentTermCode;
        pgCode = detail[i].pgCode;
        // headData.purchaseGroup = pgCode;

        var row = detail[i], obj = {};
        obj.asId = id;
        obj.receiveId = row.receiveId;
        obj.receiveCode = row.receiveCode;
        obj.receiveRowNo = row.receiveRowNo;
        obj.receiveNum = row.receiveNum;
        obj.asQuantity = row.asQuantity;
        obj.taxCode = row.taxCode;
        obj.taxValue = row.taxValue;
        obj.notTaxPrice = row.notTaxPrice;
        obj.taxPrice = row.taxPrice;
        obj.notTaxAmount = row.notTaxAmount;
        obj.taxAmount = row.taxAmount;
        obj.diffTaxAmount = row.diffTaxAmount;
        obj.priceUnit = row.priceUnit;
        obj.editFlag = row.editFlag;
        obj.minStatementQuantity = row.minStatementQuantity;
        statementItem.push(obj);

        itSumAmount = itSumAmount.plus(row.taxAmount);
    }

    // 扣款数据
    // var deduction = $(el.tbDeduction).datagrid('getRows'), deductionIds = [];
    // for(var j = 0; j < deduction.length; j++){
    //     deductionIds.push(deduction[j].id);
    // }

    // 返利数据
    // var rebate = $(el.tbRebate).datagrid('getRows'), rebateIds = [];
    // for(var k = 0; k < rebate.length; k++){
    //     rebateIds.push(rebate[k].id);
    // }

    // 需要校验凭证汇总含税金额 - (扣款金额 + 返利金额) > 0
    // var diff = itSumAmount.plus(deductionAmount).plus(rebateAmount);
    // if(diff.lt(0)){
    //     topWin.layer.alert('选择入库凭证明细的含税金额汇总小于选择的扣款金额', {icon: 0});
    //     return false;
    // }

    let title;
    if(type === 0){
        title = "您确定要保存对账单?";
    }else{
        title ="您确定要保存对账单,并提交财务确认?"
    }
    topWin.layer.confirm(title, {icon: 3}, function (index) {
        topWin.layer.close(index);

        var loading = topWin.layer.msg('数据保存中, 请耐心等待......', {icon: 16, time: 0, shade: 0.1});
        $.ajax({
            url: g.ctx + 'fin/account/statement/rest/save',
            type: 'POST',
            data: {
                headData: JSON.stringify(headData),
                statementItem: JSON.stringify(statementItem)
                // deductionIds: deductionIds.length === 0 ? '' : JSON.stringify(deductionIds),
                // rebateIds: rebateIds.length === 0 ? '' : JSON.stringify(rebateIds)
            },
            success: function (data) {
                topWin.layer.close(loading);
                callback(data.id);
            },
            error: function (data) {
                topWin.layer.close(loading);
                topWin.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
            }
        });
    });
}


/**
 * 选择供应商
 */
function choseSupplier() {
    var supplierCode = $(el.supplierCode).textbox('getValue');
    var url = g.ctx + 'fin/common/chose/sup/dialog?supCodes=' + supplierCode + '&singleSelect=1&parentFrameName=addStatementOrder&restrictType=1';
    el.choseSupplierDialog = openDialog('choseSupplier', url, {
        title: '供应商选择',
        width: '700px',
        height: '560px',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.choseSupplierDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '确定',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['choseSupplier'].confirmChose(function (data) {
                        var oriSupCode = $(el.supplierCode).textbox('getValue');
                        if(oriSupCode !== data[0].supplierCode){
                            clearPageTableData();
                        }

                        $(el.supplierCode).textbox('setValue', data[0].supplierCode);
                        $(el.supplierName).textbox('setValue', data[0].supplierName);
                        el.choseSupplierDialog.dialog('close');
                        initPaymentTermCode(data[0].supplierCode)
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.choseSupplierDialog.dialog('close');
                }
            }
        ]
    });
}


/**
 * 选择供应商弹框主动关闭弹框
 *
 * @param data 选中的结果
 */
function choseSupDialogConfirm(data) {
    var oriSupCode = $(el.supplierCode).textbox('getValue');
    if(oriSupCode !== data.supplierCode){
        clearPageTableData();
    }

    $(el.supplierCode).textbox('setValue', data.supplierCode);
    $(el.supplierName).textbox('setValue', data.supplierName);
    el.choseSupplierDialog.dialog('close');
}


/**
 * 根据公司编码获取工厂代码下拉框数据
 *
 * @param companyCode 公司编码
 * @param isSupplier 是否供应商账号 0:否 1是
 */
function findFactoryDataByCompanyCode(companyCode, isSupplier) {
    var factoryDataUrl = g.ctx + 'fin/common/rest/find/factory/select/data?isAuthority=0&companyCode=';
    // if(Number(isSupplier) === 1){
    //     factoryDataUrl = g.ctx + 'fin/common/rest/find/factory/select/data?isAuthority=0&companyCode=';
    // }

    $(el.factoryCode).combobox({
        url: factoryDataUrl,
        valueField: 'factoryCode',
        textField: 'factoryCodeName',
        prompt: '--- 请选择 ---',
        panelHeight: 300,
        panelWidth: 260,
        disabled: false,
        required: true,
        onLoadSuccess: function(data){
            for (var i = 0; i < data.length; i++) {
                if(data[i].companyCode === companyCode){
                    $(el.factoryCode).combobox('setValue', data[i].factoryCode);
                    $(el.factoryName).val(data[i].factoryName);
                }
            }
        },
        onSelect: function (data) {
            var oriFc = $(el.factoryCode).combobox('getValue');
            if(oriFc !== data.factoryCode){
                clearPageTableData();
            }

            $(el.factoryName).val(data.factoryName);
        }
    });
}



/**
 * 计算页面相关金额
 */
function calculationAmount(rows) {
    var taxAmount = new BigNumber(0), notTaxAmount = new BigNumber(0), invoicedAmount = new BigNumber(0),
        surplusAmount = new BigNumber(0), storageQuantity = new BigNumber(0), statementQuantity = new BigNumber(0);
    for (var j = 0; j < rows.length; j++) {
        var item = rows[j];
        taxAmount = taxAmount.plus(item.taxAmount);
        notTaxAmount = notTaxAmount.plus(item.notTaxAmount);
        invoicedAmount = invoicedAmount.plus(item.invoicedAmount);
        surplusAmount = surplusAmount.plus(item.surplusAmount);
        storageQuantity = storageQuantity.plus(item.receiveNum);
        statementQuantity = statementQuantity.plus(item.asQuantity);
    }

    $(el.taxAmount).textbox('setValue', taxAmount.toFormat(2));
    $(el.notTaxAmount).textbox('setValue',notTaxAmount.toFormat(2));

    if(0 !== rows.length){
        // 更新页脚行的值并刷新
        var footers = $(el.tbDetails).datagrid('getFooterRows');
        footers[0]['taxAmount'] = taxAmount.toFormat(2);
        footers[0]['notTaxAmount'] = notTaxAmount.toFormat(2);
        footers[0]['diffTaxAmount'] = taxAmount.minus(notTaxAmount).toFormat(2);
        footers[0]['invoicedAmount'] = invoicedAmount.toFormat(2);
        footers[0]['surplusAmount'] = surplusAmount.toFormat(2);
        footers[0]['receiveNum'] = storageQuantity.toFixed(3);
        footers[0]['asQuantity'] = statementQuantity.toFixed(3);
        $(el.tbDetails).datagrid('reloadFooter');
    }else {
        // 更新页脚行并载入新数据
        $(el.tbDetails).datagrid('reloadFooter', [
            {
                taxAmount: 0,
                notTaxAmount: 0,
                diffTaxAmount: 0,
                invoicedAmount: 0,
                surplusAmount: 0,
                receiveNum: 0,
                asQuantity: 0
            }
        ]);
    }
}


/**
 * 查看扣款或返利附件
 *
 * @param ele 当前操作DOM节点
 */
function lookDrAttachment(ele) {
    var drId = $(ele).data('id'), attType = $(ele).data('type');
    var url = g.ctx + 'fin/common/look/dr/attachment?drId=' + drId + '&attType=' + attType;
    var lookDrAttDialog = openDialog('lookDrAtt', url, {
        title: '附件查看',
        width: '35%',
        height: '45%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            lookDrAttDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    lookDrAttDialog.dialog('close');
                }
            }
        ]
    });
}


/**
 * 清空页面表格数据
 */
function clearPageTableData() {
    $(el.tbDetails).datagrid('loadData', {total: 0, rows: []});

    // 顺便清空页面输入的值
    $(el.bpPayableBalance).textbox('setValue', '');
    $(el.bpEstimateBalance).textbox('setValue', '');
    $(el.etPayableBalance).textbox('setValue', '');
    $(el.etEstimateBalance).textbox('setValue', '');
    $(el.beginPeriodTotal).textbox('setValue', '');
    $(el.endPeriodTotal).textbox('setValue', '');
}


// /**
//  * 获取当前用户表格列布局
//  */
// function findUserTableColumn() {
//     $.ajax({
//         type: 'POST',
//         url: g.ctx + 'fin/table/column/rest/user/setting?pageTable=2&isAuthority=0',
//         async: false,
//         success: function (data) {
//             for(var i = 0; i < data.length; i++){
//                 el.userTableColumn.push(data[i].columnField);
//             }
//         }
//     });
// }

function uploadFile() {
    var filebox = $("#invoiceFileInput").filebox("files");
    if (filebox.length == 1) {
        var formData = new FormData();
        formData.append("file", filebox[0]);
        var index = layer.load(1, {
            shade: [0.1, '#eee'] //0.1透明度的白色背景
        });
        var index_wait;
        $.ajax({
            url: '/files/invoiceUploadFile', //单文件上传
            type: 'POST',
            processData: false,
            contentType: false,
            data: formData,
            beforeSend: function(){
                index_wait = layer.load(0, {  //发送请求前调用load方法
                    shade: [0.5, '#fff'],  //0.5透明度的白色背景
                });
            },
            complete: function () {
                layer.close(index_wait);
            },
            success: function (result) {
                $("#invoiceFileInput").filebox('setText','');
                // $(el.fileId).val(result);

                let fjId = [], fileMessages = '';
                if($(el.fileId).val()){
                    fjId = $(el.fileId).val().split(',')
                }
                fjId.push(result);
                $(el.fileId).val(fjId.join(','));
                $('#fileDisplay').append('<span class="fileSpan">\n' +
                    '                            <a  href="javascript:" style="margin-left: 10px;color: black">' + getFileName($("#invoiceFileInput").filebox('getValue'))+
                    '                            </a>\n' +
                    '                            <a id="'+result+'" class="deleteFile" onclick="deleteFile1()">\n' +
                    '                                <img src="/static/img/89-Minus.png" style="width: 20px;height: 20px;">\n' +
                    '                            </a> &nbsp;&nbsp;\n' +
                    '                            </span>')
                layer.msg('上传成功', {icon: 1, title: '温馨提示'});
            },
            error: function (xhr, status, error) {
                $(this).filebox('setText','');
                layer.alert('文件上传失败', {icon: 2, title: '温馨提示'})
            }
        });
    }
}
function getFileName(o){
    var pos=o.lastIndexOf("\\");
    return o.substring(pos+1);
}
function deleteFile1() {
    $('#fileDisplay').on('click','.deleteFile',function () {
        let $this = $(this);
        let fileId = $this.attr('id');
        var fjId = [];
        if ($(el.fileId).val()) {
            fjId = $(el.fileId).val().split(',')
        }
        fjId.remove(fileId + "");

        $(el.fileId).val(fjId.join(','));

        $this.closest('span').remove();
        layer.msg('删除成功');
    });
}
/**
 * 动态表格列
 */
// function dynamicColumns(orderType) {
//     var result = [];
//     // for(var i = 0; i < el.userTableColumn.length; i++){
//         var columnField = el.userTableColumn[i];
//
//         for(var j = 0; j < tableColumns.length; j++){
//             var column =  tableColumns[j];
//             if(column.field === columnField){
//
//                 if(column.field === 'materialSupplierCode' || column.field === 'materialSupplierName' || column.field === 'freightType'){
//                     column.hidden = Number(orderType) === 1;
//                 }
//
//                 result.push(column);
//                 break;
//             }
//         }
//     // }
//
//     return result;
// }


// 报表所有列
// var tableColumns = [
//     {
//         field: 'receiveCode',
//         title: '入库凭证',
//         width: 90,
//         sortable: true
//     },
//     {
//         field: 'receiveRowNo',
//         title: '行号',
//         width: 60,
//         sortable: true
//     },
//     {
//         field: 'receiveDate',
//         title: '入库日期',
//         width: 100,
//         sortable: true
//     },
//     {
//         field: 'inOutFlag',
//         title: '出入库标识',
//         width: 85,
//         sortable: true
//     },
//     {
//         field: 'receiveNum',
//         title: '入库数量',
//         width: 70,
//         sortable: true,
//         formatter: function (value, row) {
//             if (row.voucherFlag === 'H') {
//                 return '<span style="color: red;">' + value + '</span>';
//             }else {
//                 return value;
//             }
//         }
//     },
//     {
//         field: 'asQuantity',
//         title: '剩余可对账数量',
//         width: 100,
//         sortable: true,
//         formatter: function (value, row) {
//             if (row.voucherFlag === 'H') {
//                 return '<span style="color: red;">' + value + '</span>';
//             }else {
//                 return value;
//             }
//         }
//     },
//     {
//         field: 'notTaxPrice',
//         title: '未税单价',
//         width: 70,
//         sortable: true
//     },
//     {
//         field: 'taxPrice',
//         title: '含税单价',
//         width: 70,
//         sortable: true
//     },
//     {
//         field: 'taxCodeDesc',
//         title: '税率',
//         width: 160,
//         sortable: true
//     },
//     {
//         field: 'notTaxAmount',
//         title: '不含税金额',
//         width: 100,
//         sortable: true,
//         formatter: function (value, row) {
//             if (row.voucherFlag === 'H') {
//                 return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
//             }else {
//                 return formatNumber(value, 2, 1);
//             }
//         }
//     },
//     {
//         field: 'taxAmount',
//         title: '含税金额',
//         width: 100,
//         sortable: true,
//         formatter: function (value, row) {
//             if (row.voucherFlag === 'H') {
//                 return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
//             }else {
//                 return formatNumber(value, 2, 1);
//             }
//         }
//     },
//     {
//         field: 'diffTaxAmount',
//         title: '税额',
//         width: 100,
//         sortable: true,
//         formatter: function (value) {
//             return formatNumber(value, 2, 1);
//         }
//     },
//     // {
//     //     // 累计开票金额 = 申请开票金额 + 采购确认金额 + 财务过账金额
//     //     field: 'invoicedAmount',
//     //     title: '累计开票金额',
//     //     width: 110,
//     //     sortable: true,
//     //     formatter: function (value) {
//     //         if(!value){
//     //             return '0.00'
//     //         }
//     //         return formatNumber(value, 2, 1);
//     //     }
//     // },
//     // {
//     //     // 剩余可开票金额 = (入库数量-对账数量) * 订单含税单价
//     //     field: 'surplusAmount',
//     //     title: '剩余可开票金额',
//     //     width: 120,
//     //     sortable: true,
//     //     formatter: function (value) {
//     //         if(!value){
//     //             return '0.00'
//     //         }
//     //         return formatNumber(value, 2, 1);
//     //     }
//     // },
//     {
//         field: 'zlsdh',
//         title: 'SC订单号',
//         width: 90,
//         sortable: true
//     },
//     {
//         field: 'poCode',
//         title: 'SAP订单号',
//         width: 90,
//         sortable: true
//     },
//     {
//         field: 'poItemNo',
//         title: '订单行号',
//         width: 70,
//         sortable: true
//     },
//     {
//         field: 'pgCode',
//         title: '采购组编码',
//         width: 70,
//         sortable: true
//     },
//     {
//         field: 'pgName',
//         title: '采购组名称',
//         width: 70,
//         sortable: true
//     },
//     {
//         field: 'materialCode',
//         title: '物料编码',
//         width: 90,
//         sortable: true
//     },
//     {
//         field: 'materialName',
//         title: '物料名称',
//         width: 180,
//         sortable: true
//     },
//     {
//         field: 'specs',
//         title: '规格',
//         width: 120
//     },
//     {
//         field: 'materialUnit',
//         title: '单位',
//         width: 60,
//         sortable: true
//     },
//     {
//         field: 'paymentTermCodeName',
//         title: '付款条件',
//         width: 200,
//         sortable: true
//     },
//     {
//         field: 'contractNo',
//         title: '合同号',
//         width: 120
//     },
//     {
//         field: 'purchaseUser',
//         title: '采购员',
//         width: 120
//     }
// ];

var tableColumns = [
    {
        field: 'deleteFlag',
        title: '删除标记',
        width: 80,
        formatter: function (value) {
            if (value ===1) {
                return '<span style="color: red;">已删除</span>';
            }else {
                return "未删除";
            }
        }
    },
    {
        field: 'zlsdh',
        title: 'SC订单号',
        width: 90,
        sortable: true
    },
    {
        field: 'poCode',
        title: 'SAP订单号',
        width: 90,
        sortable: true
    },
    {
        field: 'receiveRowNo',
        title: '行号',
        width: 60,
        sortable: true
    },
    {
        field: 'receiveDate',
        title: '入库日期',
        width: 110,
        sortable: true
    },
    {
        field: 'materialCode',
        title: '物料编码',
        width: 90,
        sortable: true
    },
    {
        field: 'materialName',
        title: '物料名称',
        width: 180,
        sortable: true
    },
    {
        field: 'specs',
        title: '规格',
        width: 120
    },

    {
        field: 'receiveNum',
        title: '入库数量',
        width: 70,
        sortable: true,
        formatter: function (value) {
            if (value < 0) {
                return '<span style="color: red;">' + value + '</span>';
            }else {
                return value;
            }
        }
    },
    {
        field: 'materialUnit',
        title: '单位',
        width: 70,
        sortable: true
    },
    {
        field: 'orderTaxPrice',
        title: '订单含税单价',
        width: 90,
        sortable: true
    },

    // {
    //     field: 'asNtAmount',
    //     title: '订单未税金额',
    //     width: 100,
    //     sortable: true,
    //     formatter: function (value) {
    //         if (value < 0) {
    //             return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
    //         }else {
    //             return formatNumber(value, 2, 1);
    //         }
    //     }
    // },
    // {
    //     field: 'asItAmount',
    //     title: '订单含税金额',
    //     width: 100,
    //     sortable: true,
    //     formatter: function (value) {
    //         if (value < 0) {
    //             return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
    //         }else {
    //             return formatNumber(value, 2, 1);
    //         }
    //     }
    // },
    // {
    //     field: 'asDiffPrice',
    //     title: '对账差异单价',
    //     width: 90,
    //     sortable: true
    // },
    // {
    //     field: 'asDiffAmount',
    //     title: '对账差异含税金额',
    //     width: 130,
    //     sortable: true,
    //     formatter: function (value) {
    //         if (value < 0) {
    //             return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
    //         }else {
    //             return formatNumber(value, 2, 1);
    //         }
    //     }
    // },
    // {
    //     // 累计开票金额 = 申请开票金额 + 采购确认金额 + 财务过账金额
    //     field: 'invoicedAmount',
    //     title: '累计开票金额',
    //     width: 110,
    //     sortable: true,
    //     formatter: function (value) {
    //         if (!value) {
    //             return '0.00';
    //         }
    //         return formatNumber(value, 2, 1);
    //     }
    // },
    // {
    //     // 剩余可开票金额 = (入库数量-对账数量) * 订单含税单价
    //     field: 'surplusAmount',
    //     title: '剩余可开票金额',
    //     width: 120,
    //     sortable: true,
    //     formatter: function (value) {
    //         if (!value) {
    //             return '0.00';
    //         }
    //         return formatNumber(value, 2, 1);
    //     }
    // },

    {
        field: 'poItemNo',
        title: '订单行号',
        width: 70,
        sortable: true
    },

    // {
    //     field: 'seekPgCodeName',
    //     title: '询源采购组',
    //     width: 110,
    //     sortable: true
    // },





    {
        field: 'paymentTermCodeName',
        title: '付款条件',
        width: 200,
        sortable: true
    },
    // {
    //     field: 'contractNo',
    //     title: '合同号',
    //     width: 120
    // },
    {
        field: 'inOutFlag',
        title: '出入库标识',
        width: 85,
        sortable: true
    },
    {
        field: 'receiveCode',
        title: '入库凭证',
        width: 90,
        sortable: true
    },
    {
        field: 'itemNo',
        title: '对账单行号',
        width: 80,
        sortable: true
    },
    {
        field: 'asQuantity',
        title: '本次对账数量',
        width: 100,
        sortable: true,
        formatter: function (value) {
            if (value < 0) {
                return '<span style="color: red;">' + value + '</span>';
            }else {
                return value;
            }
        }
    },
    {
        field: 'notTaxPrice',
        title: '未税单价',
        width: 70,
        sortable: true
    },
    {
        field: 'orderNotTaxPrice',
        title: '订单未税单价',
        width: 90,
        sortable: true
    },
    {
        field: 'taxAmount',
        title: '对账含税金额',
        width: 100,
        sortable: true,
        formatter: function (value) {
            if (value < 0) {
                return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
            }else {
                return formatNumber(value, 2, 1);
            }
        }
    },
    {
        field: 'diffTaxAmount',
        title: '对账税额',
        width: 90,
        sortable: true,
        formatter: function (value) {
            if (!value) {
                return '';
            }
            return formatNumber(value, 2, 1);
        }
    },
    {
        field: 'notTaxAmount',
        title: '对账未税金额',
        width: 100,
        sortable: true,
        formatter: function (value) {
            if (value < 0) {
                return '<span style="color: red;">' + formatNumber(value, 2, 1) + '</span>';
            }else {
                return formatNumber(value, 2, 1);
            }
        }
    },
    {
        field: 'taxPrice',
        title: '对账含税单价',
        width: 90,
        sortable: true
    },
    {
        field: 'poTypeName',
        title: '订单类型名称',
        width: 100
    },
    {
        field: 'orderTaxCodeDesc',
        title: '订单税率',
        width: 160,
        sortable: true
    },
    {
        field: 'taxCodeDesc',
        title: '税率',
        width: 160,
        sortable: true
    },
    // {
    //     field: 'paymentWayCodeDesc',
    //     title: '付款方式',
    //     width: 200,
    //     sortable: true
    // },
    // 承运商对账
    // {
    //     field: 'materialSupplierCode',
    //     title: '材料商编码',
    //     width: 90,
    //     sortable: true
    // },
    // {
    //     field: 'materialSupplierName',
    //     title: '材料商名称',
    //     width: 180,
    //     sortable: true
    // },
    // {
    //     field: 'freightType',
    //     title: '运费类型',
    //     width: 80,
    //     sortable: true
    // },
    // 集采订单信息
    // {
    //     field: 'jcPoCode',
    //     title: '集采SAP订单号',
    //     width: 110,
    //     sortable: true
    // },
    // {
    //     field: 'jcPoItemNo',
    //     title: '行号',
    //     width: 70,
    //     sortable: true
    // },
    // {
    //     field: 'jcFactoryCode',
    //     title: '集采工厂',
    //     width: 80,
    //     sortable: true
    // }
];