//支付管理
// JScript 文件
//支付管理


//000000支付管理列表开始
var PayInfoStore;
PayInfoManage = function(node) {//分页每页显示数量	 
    var pageSize = 12;
    //指定列参数

    var PayInfoFields = ["ID", "Name", "PayUserName", "PayPass", "PayKey", "PayKeyMore", "Intro", "Flag"];
    PayInfoStore = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy(
           {
               url: "/MCScriptManageServices/AllPay.aspx",
               method: "POST"
           }),
        reader: new Ext.data.JsonReader(
           {
               fields: PayInfoFields,
               root: "data",
               id: "ID",
               totalProperty: "totalCount"

           }),
        //groupField:'id', 
        sortInfo: { field: 'ID', direction: "DESC" }
    });
    PayInfoStore.load({ params: { start: 0, limit: pageSize} });




    //--------------------------------------------------列选择模式
    var sm = new Ext.grid.CheckboxSelectionModel({
    //dataIndex:"id"
});
//--------------------------------------------------列头
var cm = new Ext.grid.ColumnModel([
		sm,
{
    header: "名称",
    dataIndex: "Name",
    tooltip: "名称",
    sortable: true
}]);


    var PayInfoGrid = new Ext.grid.GridPanel({
        id: "PayInfoGrid",
        store: PayInfoStore,
        sm: sm,
        cm: cm,
        loadMask: true,
        stripeRows: true,
        //autoExpandColumn:7,
        //超过长度带自动滚动条
        autoScroll: true,
        border: false,
        view: new Ext.grid.GroupingView({
            //自动填充
            forceFit: true,
            sortAscText: '正序排列',
            sortDescText: '倒序排列',
            columnsText: '列显示/隐藏',
            groupByText: '根据本列分组',
            showGroupsText: '是否采用分组显示',
            groupTextTpl: '{text} (<font color=red><b>{[values.rs.length]}</b></font> {[values.rs.length > 0 ? "条器件信息" : "暂无器件信息"]})'
        }),
        //分页
        bbar: new Ext.PagingToolbar({
            store: PayInfoStore,
            pageSize: pageSize,
            //显示右下角信息
            displayInfo: true,
            displayMsg: '当前记录 {0} -- {1} 条 共 {2} 条记录',
            emptyMsg: "No results to display",
            prevText: "上一页",
            nextText: "下一页",
            refreshText: "刷新",
            lastText: "最后页",
            firstText: "第一页",
            beforePageText: "当前页",
            afterPageText: "共{0}页"

        }),
        tbar: [
		new Ext.Toolbar.Fill()
		, "", "-", "",
			{
			    text: "刷新信息",
			    //默认样式为按下
			    //pressed:true,
			    tooltip: "刷新当前页面信息",
			    iconCls: "refreshicon",
			    handler: function() {
			        PayInfoStore.reload();
			    }
			}, "", "-"
		, "", "-", "", {
		    text: "编辑",
		    tooltip: "编辑支付信息",
		    iconCls: "editicon",
		    handler: EditPayInfoFn
		}, "-"], listeners: {
		    'contextmenu': function(e) {
		        e.stopEvent();
		    },
		    'rowcontextmenu': function(grid, rowIndex, e) {
		        e.stopEvent();
		    }
		}
    });



    GridMain(node, PayInfoGrid, "usericon");
}

function DelPayInfoFn() {
    var row = Ext.getCmp("PayInfoGrid").getSelectionModel().getSelections();
    if (row.length == 0) {
        Ext.Msg.alert("提示信息", "请您至少选择一个!");
    }
    else {
        Ext.Msg.confirm("提示!", "您确定要删除该支付信息吗?", function(btn) {
            if (btn == "yes") {
                DelPayInfoFn(row);
            }
            else {

            }
        })
    }
}

function EditPayInfoFn() {
    var row = Ext.getCmp("PayInfoGrid").getSelectionModel().getSelections();
    if (row.length == 0) {
        Ext.Msg.alert("提示信息", "您没有选中任何行!");
    }
    else if (row.length > 1) {

        Ext.Msg.alert("提示信息", "对不起只能选择一个!");
    } else if (row.length == 1) {

        EditPayInfos(row[0]); //传行一行记录直接加载
    }
}

//000000支付管理管理结束
//000000支付管理添加开始


AddPayInfoFn = function() {
    //------支付类型

    //    var AddUserRoleFields = Ext.data.Record.create([
    //        { name: 'roleid', mapping: 'roleid' }, { name: 'rolename', mapping: 'rolename' }, { name: 'roledesc', mapping: 'roledesc' }
    //    ]);

    //    var AddUserRoleStore = new Ext.data.Store({
    //        proxy: new Ext.data.HttpProxy({
    //            url: 'services/system/RoleInfo/GetRoleInfo.aspx'
    //        }),
    //        reader: new Ext.data.JsonReader({
    //            root: 'data',
    //            id: 'roleid'
    //        },
    //        AddUserRoleFields
    //        )
    //    });
    //    AddUserRoleStore.load();


    var AddPayInfoForm = new Ext.form.FormPanel({
        width: 315,
        plain: true,
        layout: "form",
        defaultType: "textfield",
        labelWidth: 60,
        baseCls: "x-plain",
        defaults: { anchor: "95%", msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [//"ID", "Name", "PayUserName", "PayPass", "PayKey", "PayKeyMore", "Intro", "Flag"
			{
			    name: "Name",
			    fieldLabel: "支付名称",
			    allowBlank: false,
			    blankText: "支付名称",
			    readOnly: true
			}, {
			name: "PayUserName",
			    fieldLabel: "支付用户名",
			    allowBlank: false,
			    blankText: "支付用户名"
			},			{
			name: "PayPass",
			    fieldLabel: "支付密码",
			    allowBlank: false,
			    blankText: "支付密码"
			},			{
			name: "PayKey",
			    fieldLabel: "支付密钥",
			    allowBlank: false,
			    blankText: "支付密钥"
			}, {
			name: "PayKeyMore",
			    fieldLabel: "附加支付密钥",
			    allowBlank: false,
			    blankText: "附加支付密钥"
			}, {
			    name: "Intro",
			    fieldLabel: "简介",
			    allowBlank: false,
			    blankText: "简介"
			}
			]
    });


    var AddPayInfoWin = new Ext.Window({
        title: "添加新支付",
        width: 350,
        plain: true,
        layout: "form",
        iconCls: "addicon",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        labelWidth: 100,
        collapsible: true, //允许缩放条
        closeAction: 'hide',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [AddPayInfoForm],
        listeners: {
            "show": function() {
                AddPayInfoForm.getForm().reset();
            }
        },
        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                if (AddPayInfoForm.getForm().isValid()) {
                    //弹出效果
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    AddPayInfoForm.form.submit({
                        url: "/MCScriptManageServices/AddClassInfo.aspx",
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                            var flag = action.result.success;
                            if (flag == "true") {
                                Ext.MessageBox.alert("恭喜", "添加新支付成功!");
                                PayInfoStore.reload();
                                AddPayInfoWin.hide();
                            } else if (flag == "false") {

                                var reson = action.result.reson;
                                //Ext.MessageBox.alert("提示",""+reson+"!");
                                if (reson != "undefined")
                                    Ext.MessageBox.alert("提示", "系统已存在此支付名!");
                            }
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert("提示!", "添加新支付失败!");
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function() {
                AddPayInfoForm.getForm().reset();
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                AddPayInfoWin.hide();
            }
}]

        });
        AddPayInfoWin.show();
    }

    //000000支付管理添加结束
    //000000支付管理编辑开始
    EditPayInfos = function(row) {
        //------支付类型

        //        var EditUserRoleFields = Ext.data.Record.create([
        //        { name: 'roleid', mapping: 'roleid' }, { name: 'rolename', mapping: 'rolename' }, { name: 'roledesc', mapping: 'roledesc' }
        //    ]);

        //        var EditUserRoleStore = new Ext.data.Store({
        //            proxy: new Ext.data.HttpProxy({
        //            url: '/MCScriptManageServices/GetRoleInfoByid'
        //            }),
        //            reader: new Ext.data.JsonReader({
        //                root: 'data',
        //                id: 'roleid'
        //            },
        //        EditUserRoleFields
        //        )
        //        });
        //        EditUserRoleStore.load();

        var EditPayInfoForm = new Ext.form.FormPanel({
            width: 415,
            plain: true,
            layout: "form",
            defaultType: "textfield",
            labelWidth: 90,
            baseCls: "x-plain",
            defaults: { anchor: "95%", msgTarget: "side" },
            buttonAlign: "center",
            bodyStyle: "padding:0 0 0 0",
            items: [
						{
						    xtype: 'hidden',
						    name: "ID",
						    fieldLabel: "登录帐号",
						    allowBlank: false,
						    blankText: "帐号不允许为空",
						    readOnly: true
						}, {
			    name: "Name",
			    fieldLabel: "支付名称",
			    allowBlank: false,
			    blankText: "支付名称",
			    readOnly: true
			}, {
			name: "PayUserName",
			    fieldLabel: "支付用户名",
			    allowBlank: false,
			    blankText: "支付用户名"
			},			{
			name: "PayPass",
			    fieldLabel: "支付密码",
			    allowBlank: false,
			    blankText: "支付密码"
			},			{
			name: "PayKey",
			    fieldLabel: "支付密钥",
			    allowBlank: false,
			    blankText: "支付密钥"
			}, {
			name: "PayKeyMore",
			    fieldLabel: "附加支付密钥",
			    allowBlank: false,
			    blankText: "附加支付密钥"
			},{

			name: "Flag",
						    xtype: "combo",
						    fieldLabel: "状态",
						    editable: false,
						    typeAhead: true,
						    //传入后台真实值value field /value
						    hiddenName: "Flag",
						    mode: "local",
						    displayField: "show",
						    valueField: "value",
						    triggerAction: "all",
						    value: "0",
						    store: new Ext.data.SimpleStore({
						        fields: ["show", "value"],
						        data: [["正常", "0"], ["禁用", "1"]]
						    })
						}, {
			    name: "Intro",
			    fieldLabel: "简介",
			    allowBlank: false,
			    blankText: "简介"
			}
			]
        });


        var EditPayInfoWin = new Ext.Window({
            title: "编辑支付信息",
            width: 450,
            plain: true,
            //layout:"form",
            iconCls: "addicon",
            //不可以随意改变大小
            resizable: false,
            //是否可以拖动
            //draggable:false,
            defaultType: "textfield",
            labelWidth: 150,
            collapsible: true, //允许缩放条
            closeAction: 'hide',
            closable: true,
            //弹出模态窗体
            modal: 'true',
            buttonAlign: "center",
            bodyStyle: "padding:10px 0 0 15px",
            items: [EditPayInfoForm],
            listeners: {
                "show": function() {

                    EditPayInfoForm.getForm().reset();
                    var classid_input = row.data.ID;
                    EditPayInfoForm.form.load(
                                {
                                    url: "/MCScriptManageServices/GetPayByid.aspx?id=" + classid_input,
                                    method: "get",
                                    success: function(form, action) {

                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            },
            buttons: [{
                text: "保存信息",
                minWidth: 70,
                handler: function() {
                    if (EditPayInfoForm.getForm().isValid()) {
                        //弹出效果
                        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                        setTimeout(function() { }, 1000);
                        EditPayInfoForm.form.submit({
                        url: "/MCScriptManageServices/UpdatePay.aspx",
                            method: "POST",
                            success: function(form, action) {
                                //成功后
                                var flag = action.result.success;
                                if (flag == "true") {
                                    Ext.MessageBox.alert("恭喜", "保存支付信息成功!");
                                    PayInfoStore.reload();
                                    EditPayInfoWin.hide();
                                } else if (flag == "false") {

                                    Ext.MessageBox.alert("提示", "您的支付名可能系统中已经存在，请换一个支付名试下!");
                                    PayInfoStore.reload();
                                    EditPayInfoWin.hide();
                                }
                            },
                            failure: function(form, action) {
                                Ext.MessageBox.alert("提示!", "保存支付信息失败!");
                            }
                        });
                    }
                }
            }, {
                text: "重置",
                minWidth: 70,
                qtip: "重置数据",
                handler: function() {
                    var classid_input = row.data.id;
                    EditPayInfoForm.form.load(
                                {
                                    url: "/MCScriptManageServices/LoadClassInfo.aspx?loginid=" + classid_input,
                                    method: "get",
                                    success: function(form, action) {

                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }, {
                text: "取 消",
                minWidth: 70,
                handler: function() {
                    EditPayInfoWin.hide();
                }
}]

            });
            EditPayInfoWin.show();
        }

        //000000支付管理编辑结束
        //000000支付管理删除开始

        DelPayInfoFn = function(row) {
            var deletesplit = "";
            for (var i = 0; i < row.length; i++) {
                if (row.length == 1) {
                    deletesplit = row[i].data.id;
                }
                else {

                    if (i < (row.length - 1)) {
                        deletesplit = row[i].data.id + "," + deletesplit;
                    }
                    if (i == (row.length - 1)) {
                        deletesplit = deletesplit + row[i].data.id;
                    }
                }
            }
            Ext.Ajax.request({
                url: "/MCScriptManageServices/DeleteClassInfo.aspx",
                method: "POST",
                params: {
                    id: deletesplit
                },
                success: function() {
                    PayInfoStore.reload();
                },
                failure: function() {
                    Ext.Msg.alert("提 示", "删除失败了!");
                }
            });
        }

        //000000支付管理删除结束