// JScript 文件
//定单管理
//1定单管理

//000000定单管理列表开始
var OrderInfoStore;
var ordereidtorderid;
OrderInfoManage = function(node) {//分页每页显示数量	 
    var pageSize = 12;
    //指定列参数

    var OrderInfoFields = ["ID", "OrderNum", "UserId", "OrderTime", "State", "Price", "Point", "Paytype", "RecName", "RecAddress", "RecZip", "RecTel", "RecMobile", "RecArieid", "Intro", "EmsType", "EmsState", "EmsNo", "EmsIntro"];
    OrderInfoStore = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy(
           {
               url: "/MCScriptManageServices/AllOrderInfo.aspx",
               method: "POST"
           }),
        reader: new Ext.data.JsonReader(
           {
               fields: OrderInfoFields,
               root: "data",
               id: "ID",
               totalProperty: "totalCount"

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




    //--------------------------------------------------列选择模式
    var sm = new Ext.grid.CheckboxSelectionModel({
    //dataIndex:"id"
});
//--------------------------------------------------列头
var cm = new Ext.grid.ColumnModel([
		sm,
{
    header: "定单号码",
    dataIndex: "OrderNum",
    tooltip: "定单号码",
    sortable: true
}, {
    header: "下单时间",
    tooltip: "下单时间",
    dataIndex: "OrderTime",
    sortable: true
}, {
    header: "价格",
    tooltip: "价格",
    dataIndex: "Price",
    sortable: true
} ,{
						    xtype: 'panel',
						    plain: true,
                            height:100,
						    html: "<iframe src='/MCScriptManageServices/upfilesAD.aspx'scrolling='no' frameborder=0 width=100% height=100%></iframe>"

						}]);


    var OrderInfoGrid = new Ext.grid.GridPanel({
        id: "OrderInfoGrid",
        store: OrderInfoStore,
        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: OrderInfoStore,
            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() {
			        OrderInfoStore.reload();
			    }
			}, "", "-"
		, "", "-", "", {
		    text: "编辑",
		    tooltip: "编辑定单信息",
		    iconCls: "editicon",
		    handler: EditOrderInfoFN
		}, "", "-", "", {
		    text: "删除",
		    tooltip: "删除定单信息",
		    iconCls: "deleteicon",
		    handler: DelOrderInfoFN

		}, "-"], listeners: {
		    'contextmenu': function(e) {
		        e.stopEvent();
		    },
		    'rowcontextmenu': function(grid, rowIndex, e) {
		        e.stopEvent();
		    }
		}
    });



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

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

            }
        })
    }
}

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

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

        EditOrderInfos(row[0]); //传行一行记录直接加载
                    ordereidtorderid=row[0].data.ID;
    }
}

//000000定单管理管理结束
//000000定单管理添加开始


AddOrderInfoFN = 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 AddOrderInfoForm = 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: [
			{
			    name: "userid",
			    fieldLabel: "登陆帐号",
			    allowBlank: false,
			    blankText: "帐号不允许为空"
			}, {
			    name: "userpwd",
			    fieldLabel: "密码",
			    allowBlank: false,
			    blankText: "密码不能为空",
			    inputType: "password"
			}, {
			    name: "userpwd1",
			    fieldLabel: "确认",
			    inputType: "password",
			    allowBlank: false,
			    blankText: "确认密码不能为空",
			    invalidText: '两次密码不一致！',
			    validator: function() {
			        if (Ext.get('userpwd').dom.value == Ext.get('userpwd1').dom.value) {
			            return true;
			        } else {
			            return false;
			        }
			    }
			}, {
			    name: "username",
			    fieldLabel: "名称",
			    allowBlank: false,
			    blankText: "名称不能为空",
			    regex: /^[\s\S]{1,10}$/,
			    regexText: "名称请不要超过10个字符"
			}, {

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

        //			    xtype: "combo",
        //			    tpl: '<tpl for="."><div ext:qtip="{rolename}. {roledesc}" class="x-combo-list-item">{rolename}</div></tpl>',
        //			    store: AddUserRoleStore,
        //			    typeAhead: true,
        //			    fieldLabel: '角色',
        //			    hiddenName: 'roleid',
        //			    name: 'roleid',
        //			    forceSelection: true,
        //			    triggerAction: 'all',
        //			    emptyText: '选择角色类型',
        //			    selectOnFocus: true,
        //			    width: 130,
        //			    editable: false,
        //			    allowBlank: false,
        //			    blankText: '请选择角色类型',
        //			    displayField: 'rolename',
        //			    valueField: 'roleid',
        //			    mode: 'remote'
        //			}, 
			{
			name: "remarks",
			fieldLabel: "备注描述",
			allowBlank: false,
			blankText: "备注描述不能为空"

}
			]
    });


    var AddOrderInfoWin = 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: [AddOrderInfoForm],
        listeners: {
            "show": function() {
                AddOrderInfoForm.getForm().reset();
            }
        },
        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                if (AddOrderInfoForm.getForm().isValid()) {
                    //弹出效果
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    AddOrderInfoForm.form.submit({
                        url: "/MCScriptManageServices/AddClassInfo.aspx",
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                            var flag = action.result.success;
                            if (flag == "true") {
                                Ext.MessageBox.alert("恭喜", "添加新定单成功!");
                                OrderInfoStore.reload();
                                AddOrderInfoWin.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() {
                AddOrderInfoForm.getForm().reset();
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                AddOrderInfoWin.hide();
            }
}]

        });
        AddOrderInfoWin.show();
    }

    //000000定单管理添加结束
    //000000定单管理编辑开始
    EditOrderInfos = 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 OrderInfoFields = ["ID", "OrderNum", "UserId", "OrderTime",
    // "State", "Price", "Point", "Paytype", "RecName", "RecAddress", 
    //"RecZip", "RecTel", "RecMobile", "RecArieid", "Intro", "EmsType", 
    //"EmsState", "EmsNo", "EmsIntro"];

        var EditOrderInfoForm = new Ext.form.FormPanel({
            width: 500,
            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: [
						{
						    xtype: 'hidden',
						    name: "ID",
						    fieldLabel: "登录帐号",
						    allowBlank: false,
						    blankText: "帐号不允许为空",
						    readOnly: true
						}, {
						name: "OrderNum",
						    fieldLabel: "定单号",
					
						    blankText: "定单号",
						 
						}, {
						name: "OrderTime",
						    fieldLabel: "下单时间",
						 
						    blankText: "下单时间",
						 
						}, {
						name: "State",
						    fieldLabel: "状态",
					
						    blankText: "状态",
						
						}, {
						name: "Price",
						    fieldLabel: "价格",
						 
						    blankText: "价格",
						  
						}, {
						name: "Point",
						    fieldLabel: "积分",
						   
						    blankText: "积分",
						   
						}, {
						name: "Paytype",
						    fieldLabel: "支付方式",
						    blankText: "支付方式"
						}, {
						name: "RecName",
						    fieldLabel: "收货人",
						 
						    blankText: "收货人"
						}, {
						name: "RecAddress",
						    fieldLabel: "收货地址",
						 
						    blankText: "收货地址"
						}, {
						name: "RecZip",
						    fieldLabel: "邮编",
						    
						    blankText: "邮编"
						}, {
						name: "RecTel",
						    fieldLabel: "收货电话",
						   
						    blankText: "收货电话"
						}, {
						name: "RecMobile",
						    fieldLabel: "收货手机",
						  
						    blankText: "收货手机"
						}, {
						name: "Intro",
						    fieldLabel: "备注",
						    
						    blankText: "备注"
						},  {
						    name: "EmsType",
						    fieldLabel: "配送方式",
						   
						    blankText: "配送方式"
						}, {
						    name: "EmsState",
						    fieldLabel: "配送状态",
						
						    blankText: "配送状态",
						    readOnly: true
						}, {
						    name: "EmsNo",
						    fieldLabel: "快递单号",
						  
						    blankText: "快递单号"
						}, {
						    name: "EmsIntro",
						    fieldLabel: "快递备注",
						 
						    blankText: "快递备注"
						}, {
						    xtype: 'panel',
						    plain: true,
						    width: 500,
                            height:200,
                             autoScroll:true,
						    html: "<iframe src='/MCScriptManageServices/getordermoreinfo.aspx?id="+row.data.ID+"'scrolling='no' frameborder=0 width=490 height=100%></iframe>"

						}
			]
        });


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

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

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

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

            });
            EditOrderInfoWin.show();
        }

        //000000定单管理编辑结束
        //000000定单管理删除开始

        DelOrderInfoFNS = 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/DelOrderInfo.aspx",
                method: "POST",
                params: {
                    id: deletesplit
                },
                success: function() {
                    OrderInfoStore.reload();
                },
                failure: function() {
                    Ext.Msg.alert("提 示", "删除失败了!");
                }
            });
        }

        //000000定单管理删除结束