var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    dataState: '#dataState',
    bidFlag: '#bidFlag',
    purchaseBillDetailIds: '#purchaseBillDetailIds',
    transferStatus: '#transferStatus',
    purchaseGroupCode: '#purchaseGroupCode',
    purchaseApplyTypeCode: '#purchaseApplyTypeCode',
    bodyHeight: document.documentElement.clientHeight
};
$(function () {
    $(el.bidFlag).combobox({
        valueField: 'code',
        textField: 'name',
        limitToList: 'true',
        data: [
            {'name': '否', 'code': '0'},
            {'name': '是', 'code': '1'},
        ],
        editable: false,
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
    });
    loadGrid();
});
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/supplier/quote/log/rest/list',
        singleSelect: false,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        rownumbers: true,
        columns: [
            [
                {
                    field: 'inquiryCode',
                    title: '询价单编码',
                    width: 150
                },
                {
                    field: 'inquiryTitle',
                    title: '询价单主题',
                    width: 200
                },
                {
                    field: 'supplierCode',
                    title: '供应商编码',
                    width: 100
                },
                {
                    field: 'supplierName',
                    title: '供应商名称',
                    width: 200
                },
                {
                    field: 'materialCode',
                    title: '物料编码',
                    width: 90
                },
                {
                    field: 'materialName',
                    title: '物料名称',
                    width: 200,
                    formatter: function (value, row) {
                        return '<span title="'+value+'">'+value+'</span>';
                    }
                },
                {
                    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: 'type',
                    title: '报价类型',
                    width: 80,
                    exportEnum:[
                        {code:1,codeWithDesc:'报价'},
                        {code:2,codeWithDesc:'议价'}
                    ],
                    formatter: function (value) {
                        if (value === 1) {
                            return '报价';
                        } else if (value === 2) {
                            return '议价';
                        }
                    }
                },
                {
                    field: 'taxPrice',
                    title: '含税报价',
                    width: 90,
                    formatter: function (value) {
                        return formatNumber(value, 4, 1);
                    }
                },
                {
                    field: 'noTaxPrice',
                    title: '未税报价',
                    width: 90
                },
                {
                    field: 'createTime',
                    title: '报价时间',
                    width: 140,
                    exportDateFormatter:'dateTime',
                    formatter: function (value) {
                        if (value) {
                            return new Date(value).format('yyyy-MM-dd hh:mm:ss');
                        }
                        return value;
                    }
                },
                {
                    field: 'supplierFormFiles',
                    title: '供应商表单报价附件',
                    width: 140,
                    exportHidden: true,
                    formatter: function (value, row,rec) {
                        if (value){
                            return '<a href="#" onclick="uploadFilesDialog(this)" data-index="' + rec + '" data-value="' + value + '">查看('+value.split(',').length+')个附件</a>';
                        }else {
                            return '无附件';
                        }
                    }
                }
            ]
        ],
        toolbar: [
            {
                text: '导出',
                iconCls: 'icon-print',
                id: 'icon_print',
                handler: function () {
                    openExportDialog('pc/inquiry/supplier/quote/log/rest/export','tb',searchParams());
                }
            }
        ],
    });
}

function uploadFilesDialog(target){
    let rowIndex = $(target).data('index'), value = $(target).data('value'),fieldName = $(target).attr('data-fieldName');
    openFileUploadDialog('uploadFilesDialog',{
        title:'查看',
        fileIds : value,
        height: '75%',
        lookFlag: 1,
        callBack : function (fileId) {

            console.log(fileId)
        },
    });
}
