var infixRuleMap = {
    '1': '日期(yyyyMMdd)',
    '2': '日期时间(yyyyMMddHHmmss)',
    '3': '十位时间戳',
    '4': '十三位时间戳',
    '5': '无',
    '6': '年月(yyMM)',
    '7': '年(yy)',
    '8': '年(yyyy)',
}
$(function () {
    loadGrid();
    var cbxDa = [];
    $.each(infixRuleMap, function (idx, val) {
        cbxDa.push({id: idx, text: val})
    })
    $("#infixRule").combobox("loadData", cbxDa)
});


function loadGrid() {
    $('#tb').datagrid({
        iconCls: 'icon-list',
        title: '',
        method: "GET",
        height: gridheight + 20,
        width: gridwidth,
        url: g.ctx + 'pc/sys/sequence/list',
        singleSelect: true,
        pagination: true,
        idField: 'id',
        autoHeight: true,
        loadMsg: "数据加载中......",
        rownumbers: true,
        fitColumns: false,
        remoteSort: true,
        page: 1,
        pageSize: 10,
        queryParams: {
            page: 1,
            rows: 10,
            name: "",
            desc: ""
        },
        onLoadSuccess: function () {
        },
        columns: [[
            {
                field: 'ck',
                checkbox: true
            },
            {
                field: 'code',
                title: '单据号规则编码',
                width: '15%',
                align: 'center'

            },
            {
                field: 'name',
                title: '单据号规则名称',
                width: '15%',
                align: 'center'

            },
            {
                field: 'prefix',
                title: '前缀',
                width: '15%',
                align: 'center'

            },
            {
                field: 'infixRule',
                title: '中缀类型',
                width: '15%',
                align: 'center',
                formatter: function (value) {
                    return infixRuleMap[value];
                }
            },
            {
                field: 'suffixLength',
                title: '后缀长度',
                width: '15%',
                align: 'center'

            },
            {
                field: 'zeroingFlag',
                title: '每日归零',
                width: '15%',
                align: 'center',
                formatter: function (value) {
                    return value == '1' ? "是" : "否";
                }
            },
            {
                field: 'value',
                title: '单据号值',
                width: '15%',
                align: 'center'
            }
        ]],
        toolbar: [{
            text: '编辑',
            iconCls: 'icon-edit',
            handler: function () {
                editOrderRule();
            }
        }
        ]
    });
}


function editOrderRule() {
    var cbox = $('#tb').datagrid('getSelected');
    if (cbox === null || cbox === undefined) {
        layer.msg("请选中一条记录");
        return;
    }
    var sequencEditDialog = openDialog('sequencEditDialog', g.ctx + 'pc/sys/sequence/edit?id=' + cbox.id, {
            title: "编辑",
            width: '370px',
            height: '360px',
            cache: false,
            modal: true,
            border: false,
            draggable: false,
            shadow: false,
            onClose: function () {
                sequencEditDialog.dialog('destroy');
            },
            buttons: [
                {
                    text: itablei8n.save,
                    handler: function () {
                        topWin.frames['sequencEditDialog'].save(function () {
                            sequencEditDialog.dialog('close');
                            $('#tb').datagrid('reload');
                        });
                    }
                },
                {
                    text: itablei8n.close,
                    handler: function () {
                        sequencEditDialog.dialog('close');
                    }
                }
            ]
        }
    );
}




