/**
 *
 * @author BOGON
 * @version 1.0
 */

var page = {
    dataGrid: {},
    initData: function () {
        page.dataGrid = $('#tb').datagrid({
            iconCls: 'icon-list',
            width: '100%',
            method: "GET",
            height: $(window).height() - $('#searchForm').outerHeight() - 10,
            url: g.ctx + 'pc/tender/bid/rest/historyList',
            singleSelect: true,
            pagination: true,
            loadMsg: tenderTxt.dataLoad,
            rownumbers: true,
            nowrap: true,
            remoteSort: true,
            striped: true,
            page: 1,
            pageSize: 20,
            queryParams: {
                page: 1,
                rows: 10
            },
            columns: [[
                {
                    field: 'ck',
                    checkbox: true
                }, {
                    field: 'id',
                    hidden: true
                },
                {
                    field: 'status',
                    title: "状态",
                    width: 90,
                    align: 'left',
                    formatter: function (value, row, index) {
                        if(row.bstatus===TENDER_STATUS_CONST[9].val){
                            return BID_STATUS_CONST[value].color
                        }else{
                            return TENDER_STATUS_CONST[3].color
                        }
                    }

                },
                {
                    field: 'tenderCode',
                    title: tenderTitles.tenderCodeNum,
                    width: 180,
                    align: 'left'

                },
                {
                    field: 'tenderTitle',
                    title: tenderTitles.tenderTit,
                    width: 250,
                    align: 'left'

                },
                {
                    field: 'tenderRemark',
                    title: tenderTitles.remarks,
                    width: 300,
                    align: 'left'

                },
                {
                    field: 'submitDepositFileName',
                    title: '保证金附件',
                    width: 160,
                    align: 'left',
                    formatter: function (val, row) {
                        var statusTitle = '无需保证金';
                        if (row.submitDepositFileId != '') {
                            return '<a href="#" onclick="previewFileForm(undefined,\'' + row.submitDepositFileName + '\',\'' + row.submitDepositFileId + '\')">预览</a>'
                        } else {
                            return statusTitle;
                        }
                    }

                }, {
                    field: 'marginStatus',
                    title: '保证金是否退回',
                    width: 150,
                    align: 'left',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return '<span style="color: darkgreen;">已退回</span>'
                        } else {
                            return '<span style="color: red;">未退回</span>'
                        }
                    }

                }
            ]],
            toolbar: [
                {
                    text: tenderBtns.check,
                    iconCls: 'icon-accept',
                    id: "info",
                    handler: function () {
                        var selectedRow = page.dataGrid.datagrid('getSelected');
                        if (!selectedRow) {
                            layer.msg(tenderTxt.txt1);
                            return;
                        }
                        bidComm.openDetailDialog(3, selectedRow.id, selectedRow.tenderId);
                    }
                }, "-",
                {
                    text: tenderBtns.tenderAQ,
                    iconCls: 'icon-help',
                    handler: function () {
                        var row = page.dataGrid.datagrid('getSelected');
                        if (row == null) {
                            topWin.layer.msg(tenderTxt.txt4);
                            return;
                        }
                        tenderComm.answerQuestions(row.tenderId, 1)
                    }
                }
            ]
        });
    },
    tableReload: function () {
        page.dataGrid.datagrid("reload");

    }
}
$(function () {
    page.initData()
})