var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    status: '#status',
    bidFlag: '#bidFlag',
    bodyHeight: document.documentElement.clientHeight
};
$(function () {
    initNecessaryDatas('pc/sys/tax/rest/listAll')
    initDict('currency,payment_method')
    initCombo();
    loadGrid();
});
/**
 * 初始化下拉框
 */
function initCombo() {
    $(el.status).combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        data: [
            {value: '', label: '全部'},
            {value: 3, label: '截止'},
            {value: 5, label: '完成'}
        ],
    });
    $(el.bidFlag).combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        data: [
            {value: '', label: '全部'},
            {value: 0, label: '否'},
            {value: 1, label: '是'}
        ],
    });
}
function loadGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight, 37, 40);
    $(el.tb).datagrid({
        height: el.bodyHeight - searchHeight,
        url: g.ctx + 'pc/inquiry/fix/rest/material/supplier/list/page?taxPriceFlag=1',
        singleSelect: false,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        rownumbers: true,
        columns: [[
            {
                field: 'materialCode',
                title: '物料编码',
                width: 110,
                formatter: function (value) {
                    if (value) {
                        return '<span style="color:blue;">' + value + '</span>';
                    }
                    return '';
                }
            },
            {
                field: 'materialName',
                title: '物料名称',
                width: 160,
                formatter: function (value) {
                    if (value) {
                        return '<span style="color:blue;">' + value + '</span>';
                    }
                    return '';
                }
            },
            // {
            //     field: 'productName',
            //     title: '品名',
            //     width: 100
            // },
            // {
            //     field: 'materialSpec',
            //     title: '规格',
            //     width: 100
            // },
            // {
            //     field: 'brand',
            //     title: '品牌',
            //     width: 100
            // },
            {
                field: 'supplierCode',
                title: '供应商编码',
                width: 110
            },
            {
                field: 'supplierShortName',
                title: '供应商简称',
                width: 110
            },
            {
                field: 'taxCode',
                title: '税率',
                width: 80,
                exportEnum:getNecessaryDataList('pc/sys/tax/rest/listAll'),
                formatter: function (value) {
                    return getNecessaryDataName('pc/sys/tax/rest/listAll',value);
                }
            },
            {
                field: 'currencyCode',
                title: '币别',
                width: 80,
                exportEnum:getDictList('currency'),
                formatter: function (value) {
                    return getDicName('currency',value);
                }
            },
            {
                field: 'lastBidPrice',
                title: '原中标价格',
                width: 100
            },
            {
                field: 'noTaxPrice',
                title: '未税单价',
                width: 100
            },
            {
                field: 'taxPrice',
                title: '最终报价',
                width: 100
            },
            {
                field: 'firstTaxPrice',
                title: '最初报价',
                width: 100
            },
            {
                field: 'stagePriceFlag',
                title: '阶梯报价',
                width: 90,
                exportEnum:[
                    {code:1,codeWithDesc:'是'},
                    {code:0,codeWithDesc:'否'}
                ],
                formatter: function (value, row, index) {
                    if (value === 1) {
                        return '是';
                    } else {
                        return '否';
                    }
                }
            },
            {
                field: 'paymentMethod',
                title: '付款条件',
                width: 80,
                exportEnum:getDictList('payment_method'),
                formatter: function (value) {
                    return getDicName('payment_method',value);
                }
            },
            {
                field: 'bidFlag',
                title: '定价',
                width: 60,
                exportEnum:[
                    {code:1,codeWithDesc:'是'},
                    {code:0,codeWithDesc:'否'}
                ],
                formatter: function (value) {
                    if (value === 1) {
                        return '<span style="color: red">是</span>'
                    } else {
                        return '否';
                    }
                }
            },
            {
                field: 'minPriceFlag',
                title: '是否最低价',
                width: 90,
                exportEnum:[
                    {code:1,codeWithDesc:'是'},
                    {code:0,codeWithDesc:'否'}
                ],
                formatter: function (value, row, index) {
                    if(value===1){
                        return "<sapn>是</sapn>"
                    }else{
                        return "<sapn style='color: red'>否</sapn>"
                    }
                }
            },
            {
                field: 'purchaseNum',
                title: '采购数量',
                width: 80
            },
            {
                field: 'taxTotalPrice',
                title: '报价总金额',
                width: 125
            },
            {
                field: 'bidNumber',
                title: '定价数量',
                width: 80
            },
            {
                field: 'bidTotalPrice',
                title: '定价总金额',
                width: 125
            },
            {
                field: 'confirmQuota',
                title: '确认配额',
                width: 80
            },
            {
                field: 'quoteRemark',
                title: '报价说明',
                width: 80
            },
            {
                field: 'desirePrice',
                title: '期望价格',
                width: 80
            },
            {
                field: 'priceOpinion',
                title: '议价意见',
                width: 170
            },
            {
                field: 'quoteFromDate',
                title: '有效期起始日',
                exportDateFormatter: 'date',
                width: 120,
                formatter: function (value) {
                    if (value) {
                        return moment(value).format("YYYY-MM-DD");
                    }
                    return '';
                }
            },
            {
                field: 'quoteEndDate',
                title: '有效期结束日',
                exportDateFormatter: 'date',
                width: 120,
                formatter: function (value) {
                    if (value) {
                        return moment(value).format("YYYY-MM-DD");
                    }
                    return '';
                }
            },
            {
                field: 'stageNum1',
                title: '数量1',
                width: '120',
                align: 'left'
            },
            {
                field: 'stagePrice1',
                title: '阶梯报价1',
                width: '120',
                align: 'left'
            },
            {
                field: 'stageNum2',
                title: '数量2',
                width: '120',
                align: 'left'
            },
            {
                field: 'stagePrice2',
                title: '阶梯报价2',
                width: '120',
                align: 'left'
            }, {
                field: 'stageNum3',
                title: '数量3',
                width: '120',
                align: 'left'
            },
            {
                field: 'stagePrice3',
                title: '阶梯报价3',
                width: '120',
                align: 'left'
            },
            {
                field: 'stageNum4',
                title: '数量4',
                width: '120',
                align: 'left'
            },
            {
                field: 'stagePrice4',
                title: '阶梯报价4',
                width: '120',
                align: 'left'
            },
            {
                field: 'stageNum5',
                title: '数量5',
                width: '120',
                align: 'left'
            },
            {
                field: 'stagePrice5',
                title: '阶梯报价5',
                width: '120',
                align: 'left'
            }
        ]],
        toolbar: [
            {
                text: '导出',
                iconCls: 'icon-print',
                id: 'icon_print',
                handler: function () {
                    var params = searchParams();
                    params.taxPriceFlag = 1;
                    openExportDialog('pc/inquiry/fix/rest/material/supplier/report/export','tb',params);
                }
            }
        ],
    });
}
