/**
 *
 * @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/confirmJoinList',
            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: tenderTitles.tenderStatus,
                    width: 90,
                    align: 'left',
                    formatter: function (value, row, index) {
                        if (row)
                            return BID_STATUS_CONST[value].color
                    }
                },
                {
                    field: 'tenderCode',
                    title: tenderTitles.tenderCodeNum,
                    width: 180,
                    align: 'left'

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

                },
                {
                    field: 'startDay',
                    title: '开始时间',
                    width: 130,
                    align: 'left'
                },
                {
                    field: 'endDay',
                    title: '截止时间',
                    width: 130,
                    align: 'left'
                },
                {
                    field: 'tenderRemark',
                    title: tenderTitles.remarks,
                    width: 300,
                    align: 'left'

                }
            ]],
            toolbar: [
                {
                    text: tenderBtns.check,
                    iconCls: 'icon-accept',
                    id: "info",
                    handler: function () {
                        var selectedRow = page.dataGrid.datagrid('getSelected');
                        if (!selectedRow) {
                            topWin.layer.msg(tenderTxt.txt1);
                            return;
                        }
                        bidComm.openDetailDialog(0, selectedRow.id, selectedRow.tenderId);
                    }
                }, "-", {
                    text: tenderBtns.confirmJoin,
                    id: 'ok_join',
                    iconCls: 'icon-coins',
                    handler: function () {
                        var selectedRow = page.dataGrid.datagrid('getSelected');
                        if (!selectedRow) {
                            topWin.layer.msg(tenderTxt.txt2);
                            return;
                        }
                        if (selectedRow.status + "" == (BID_STATUS_CONST["0"].val + "") ||
                            selectedRow.status + "" == (BID_STATUS_CONST["6"].val + "")) {
                            page.openConfirmJoinDialog(selectedRow.id, selectedRow.tenderId);
                        } else {
                            topWin.layer.msg(tenderTxt.txt3);
                            return;
                        }

                    }
                }, "-",
                {
                    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)
                    }
                }
            ]
        });
    },
    openConfirmJoinDialog: function (id, tenderId) {
        page.confirmJoinDialogElement = openDialog("confirmJoinDialog", g.ctx + "pc/tender/page/agreement?tenderId=" + tenderId, {
            title: tenderTitles.tenderNotice,
            width: '700',
            height: '100%',
            cache: false,
            modal: true,
            border: false,
            draggable: false,
            shadow: false,
            onClose: function () {
                page.confirmJoinDialogElement.dialog('destroy');
            },
            buttons: [{
                text: tenderBtns.confirmJoin,
                handler: function () {
                    topWin.frames['confirmJoinDialog'].page.join(page.closeDialog, id);
                }
            }, {
                text: tenderBtns.noJoin,
                handler: function () {
                    topWin.frames['confirmJoinDialog'].page.noJoin(page.closeDialog, id);
                }
            }]
        });
    },
    closeDialog: function () {
        page.confirmJoinDialogElement.dialog('close');
        page.tableReload();
    },
    tableReload: function () {
        page.dataGrid.datagrid("reload");

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