/**
 *
 * @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/securityDepositList',
            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: 'securityDepositStatus',
                    title: tenderTitles.bzjStatus,
                    width: 160,
                    align: 'left',
                    formatter: function (val, row) {
                        var statusTitle = '';
                        if (val === '') {
                            statusTitle = "未缴纳";
                        } else if (val == 0){
                            statusTitle = APPROV_STATUS[0].color;
                        }else if(val == 1){
                            statusTitle = APPROV_STATUS[1].color;
                        }else{
                            statusTitle = APPROV_STATUS[2].color;
                        }
                        if (row.submitDepositFileId != '') {
                            return statusTitle + '(<a href="' + g.ctx + "pc/sys/file/rest/download/" + row.submitDepositFileId + '">' + row.submitDepositFileName + '</a>)'
                        } else {
                            return statusTitle;
                        }
                    }

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

                },
                {
                    field: 'reason',
                    title: "原因",
                    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: tenderTxt.DepositPayment,
                    id: 'bondUpload',
                    iconCls: 'icon-coins',
                    handler: function () {
                        var selectedRow = page.dataGrid.datagrid('getSelected');
                        if (!selectedRow) {
                            topWin.layer.msg(tenderTxt.txt6);
                            return;
                        }
                        if (selectedRow.agreeFlag != 1) {
                            topWin.layer.msg(tenderTxt.txt7);
                            return;
                        }
                        if (selectedRow.status == BID_STATUS_CONST[2].val ||
                            selectedRow.status == BID_STATUS_CONST[8].val) {
                            page.openPayDepositDialog(selectedRow.id);
                        } else {
                            return;
                        }

                    }
                }, "-",
                {
                    text: tenderTitles.tenderAQ,
                    iconCls: 'icon-help',
                    handler: function () {
                        var row = page.dataGrid.datagrid('getSelected');
                        if (row == null) {
                            layer.msg(tenderTxt.txt4);
                            return;
                        }
                        tenderComm.answerQuestions(row.tenderId, 1)
                    }
                }
            ]
        });
    },
    openPayDepositDialog: function (bidId) {
        page.payDepositDialogElement = openDialog("payDepositDialog", g.ctx + "pc/tender/bid/page/uploadSecurityDeposeit?bidId=" + bidId, {
            title: tenderTitles.deposit,
            width: 400,
            height: 415,
            cache: false,
            modal: true,
            border: false,
            draggable: false,
            shadow: false,
            onClose: function () {
                page.payDepositDialogElement.dialog('destroy');
            },
            buttons: [{
                text: tenderBtns.confirm,
                handler: function () {
                    topWin.frames['payDepositDialog'].page.fileUpload(bidId, function () {
                        page.payDepositDialogElement.dialog('close');
                        page.tableReload()
                    });
                }
            }, {
                text: tenderBtns.cancel,
                handler: function () {
                    page.payDepositDialogElement.dialog('close');
                }
            }]
        });
    },
    tableReload: function () {
        page.dataGrid.datagrid("reload");

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