onlinereg.js 10.9 KB
define('admin/onlinereg', function(require, exports){
    var box = require('admin/box'); // 提示框
    var $ = require("jquery");
    var common = require("common");
    var upload = require('admin/upload');
    var form_html = $("#form_pan").html()+'';
    $("#form_pan").remove();
    exports.index = function() 
    {
    	//全选
    	$("#all_check").bind("click",function()
    	{
    		if($(this).attr("checked"))
    		{
    			$.each($("input[type=checkbox]"), function(i, obj)
    			{
    				$(obj).attr("checked", 1);
    			});
    		}
    		else
    		{
    			$.each($("input[type=checkbox]"), function(i, obj)
    			{
    				$(obj).attr("checked", false);
    			});
    		}
    	});
    	//批量导出
    	$(".batch_export").bind("click",function()
    	{
    		var ids = '';
    		$("input[type=checkbox]").each(function()
    		{
    			if($(this).attr("checked"))
    			{
    				ids += $(this).attr("seller_id")+',';
    			}
    		});
    		if(ids != '')
    		{
    			window.location.href = '/admin/onlinereg/export?id='+ids;
    		}
    		else
    		{
    			alert("没有选中");
    		}
    	});
    	//查看数据
    	$(".look").bind("click",function()
    	{
    		var type = $(".nav-tabs").attr("type");
    		var sellerId = $(this).attr("seller_id");
    		var seller;
    	    box.confirm(form_html,function() 
    	    {
    	    	var type = $(".nav-tabs").attr("type");
	    	    var params = {};
	    	    var sellerId = $("#box_confirm_ok").attr("seller_id");
	    	    var requires = [];
	    	    //参展商校验数据
	    	    var requireType0 = ['name','contact','telphone','relation','place'];
	    	    //赞助商校验数据
	    	    var requireType1 = ['name','product_type','contact','telphone'];
	    	    //媒体校验数据
	    	    var requireType2 = ['name','mobile'];
	    	    var val = '';
	    	    var keys = ['name','product_type','profession','company','contact','telphone','mobile','brand_reg_type',
	    	                'country', 'zipcode','city','introduction','email','place','website'];
	    	    var selectKeys = ['is_enter_yohobuy','is_3c','relation','brand_reg_type','sex'];
	    	    var i;
	    	    params.id = sellerId;
    			if(type == 0) 
    			{
    				requires = requireType0;
    			}
    			else if(type == 1)
    			{
    				requires = requireType1;
    			}
    			else if(type == 2)
    			{
    				requires = requireType2;
    			}
    			
	    	    for(i = 0;i< selectKeys.length; i++)
	    	    {
	    	    	if($("select[name="+selectKeys[i]+"]").size()> 0)
			        {
			    		params[""+selectKeys[i]+""] = $("select[name="+selectKeys[i]+"]").val();
			        }
	    	    }
		    	for(i = 0; i< keys.length; i++)
		    	{
		    		if($("input[name="+keys[i]+"]").size() > 0)
		    		{
		    			val = $.trim($("input[name="+keys[i]+"]").val());
		    			if($.inArray(keys[i], requires) !== -1 && val == '')
		    			{
		    				alert("带*内容不能为空");
		    				return false;
		    			}
		    			params[""+keys[i]+""] = val;
		    		}
		    	}
		    	$.ajax
		    	({
		    		type:"post",
		    		url:"/admin/onlinereg/setseller",
		    		data:params,
		    		success:function(data)
		    		{
		    			if(data.code == 200)
		    			{
		    				window.location.reload();
		    			}
		    			else
		    			{
		    				alert("保存失败");
		    			}
		    		}
		    	});
    	    },{title: '查看详情', width: '750px', autoClose: false});
    		$.ajax
    		({
    			type:"post",
    			url:"/admin/onlinereg/getseller",
    			data:{id:sellerId},
    			success:function(data)
    			{
    				seller = data.data;
    				if(data.code == 200)
    				{
    					var files = [], html = '', filePath;
    					$("input[name=name]").val(seller.name);
    					$("select[name=is_enter_yohobuy]").val(seller.is_enter_yohobuy);
    					$("input[name=product_type]").val(seller.product_type);
    					$("input[name=profession]").val(seller.profession);
    					$("select[name=sex]").val(seller.sex);
    					$("input[name=company]").val(seller.company);
    					$("input[name=contact]").val(seller.contact);
    					$("input[name=telphone]").val(seller.telphone);
    					$("input[name=mobile]").val(seller.mobile);
    					$("select[name=relation]").val(seller.relation);
    					$("input[name=country]").val(seller.country);
    					$("input[name=zipcode]").val(seller.zipcode);
    					$("input[name=city]").val(seller.city);
    					$("input[name=introduction]").val(seller.introduction);  					
    					$("input[name=email]").val(seller.email);
    					$("input[name=place]").val(seller.place);
    					$("select[name=is_3c]").val(seller.is_3c);
    					$("select[name=brand_reg_type]").val(seller.brand_reg_type);
    					$("input[name=website]").val(seller.website);
    					if(seller.files != "")
    					{
    						files = seller.files.split("|");
    						for(var i = 0; i <files.length; i++)
        					{
        						if(files[i] !='') 
        						{
        							filePath = common.getImages(files[i],'source', 'blogimg');
            						html+='<a href="' + filePath + '">'+files[i].split("/")[files[i].split("/").length - 1]+'</a><br/>';
        						}
        					}
    					}
    					
    					$("#download_list").html(html);
    					$("#box_confirm_ok").attr("seller_id", sellerId);
    				}
    			}
    		});
    		
    	});
    };
    
    function init_upload(id, callback, setting, post_params)
    {
    	var defaultSetting = {
                button_placeholder_id:id,
                button_width : "58",
                button_height : "30",
                post_params: {'key':$('#'+id).attr('key'), 'format':'json'},
                file_queue_limit:50,
                custom_settings:
                {
                    saveCallback:callback 
                }
            };
    	if(setting)
    	{
    		$.extend(defaultSetting, setting);
    	}
    	if(post_params)
    	{
    		$.extend(defaultSetting.post_params, post_params);
    	}
        //绑定上传背景按钮
        upload.init(defaultSetting);
    }
    
    //设置下载信息
    exports.download = function()
    {
    	//设置下载信息
    	$(".modify, #create_download_info").bind("click", function()
    	{
    		var download_id = 0;
    		var type = $(".table").attr("type");
    		var title = type == 0 ? '设置参展商手册':'设置新闻稿';
    		//设置下载信息
    		box.confirm(form_html,function()
    		{
    			var id = parseInt($("#download_id").val());
    			var title = $("input[name=title]").val();
    			var type = $(".table").attr("type");
    			var file = $("#file").size() ? $("#file").attr("val") : '';
    			var cover = '';
    			var source = ''; 
    			var source_link = '';
    			if(title == '' ||  file == '')
    			{
					alert("带*内容不能为空");
					return false;
    			}
    			//封面
    			if(typeof($("#pic").attr("val")) !=="undefined")
    			{
    				cover = $("#pic").attr("val");
    				if(cover == '')
    				{
    					alert("带*内容不能为空");
    					return false;
    				}
    			}
    			//来源
    			if($("input[name=source]").size())
    			{
    				source = $("input[name=source]").val();
    				if(source == '')
    				{
    					alert("带*内容不能为空");
    					return false;
    				}
    			}
    			//来源链接
    			if($("input[name=source_link]").size())
    			{
    				source_link = $("input[name=source_link]").val();
    				if(source_link == '')
    				{
    					alert("带*内容不能为空");
    					return false;
    				}
    			}
    			
    			$.ajax
    			({
    				type:"post",
    				url:"/admin/onlinereg/setdownload",
    				data:{title:title,cover:cover, file:file, id: id, type:type, source:source, source_link:source_link},
    				success:function(data)
    				{
    					if(data.code == 200)
    					{
    						window.location.reload();
    					}
    					else
    					{
    						alert("设置失败");
    					}
    				}
    			})
    			
    		},{title: title, width: '750px', autoClose: false});
    		
    		if($("#upload_pic").size()) 
    		{
    			//上传图片
                init_upload('upload_pic', function(response, swf)
                {
                	var thumbPath = common.getImages(response.data.file.relaPath, "0100x0100", "blogimg", "primary");
                    var realPath = response.data.file.relaPath;
                    $("#picdiv").html("<img id='pic' class='thumb_but' val='"+realPath+"' src='"+thumbPath+"' width='100' height='100' /> ");
                }, {button_width:"100", button_height : "30"});
    		}
    		
    		if($("#upload_file").size())
    		{
    	        //上传文件
                init_upload('upload_file', function(response, swf)
                {
                	var filePath = response.data.file.absPath;
                    var realPath = response.data.file.relaPath;
                    var file = filePath.split("/")[filePath.split("/").length - 1];
                    //图片
                    $("#filediv").html('<a id="file" href="'+filePath+'" val="'+realPath+'">'+file+'</a>');
                    
                }, {button_width:"100", button_height : "30",file_types:"*.zip;*.xlsx;*.xls;*.docx;*.doc;*.pdf;*.ppt;*.pptx"}, {"fileType":"file"});
    		}
    		//下载ID
    		if(typeof($(this).attr("download_id")) !== 'undefined')
    		{
    			download_id = $(this).attr("download_id");
    			$("#download_id").val(download_id);
    		}
    		
            if(download_id > 0) 
            {
            	$.ajax
        		({
        			type:"get",
        			url:"/admin/onlinereg/getdownload",
        			data:{id:download_id},
        			success:function(data)
        			{
        				if(data.code == 200)
        				{
        					$("#title").val(data.data.title);    					
        					var thumbPath = common.getImages(data.data.cover, "0100x0100", "blogimg", "primary");
        					$("#picdiv").html("<img id='pic' class='thumb_but' val='"+data.data.cover+"' src='"+thumbPath+"' width='100' height='100' /> ");
        	                var filePath = common.getImages(data.data.file,'source','blogimg');
        	                var file = filePath.split("/")[filePath.split("/").length - 1];
        	                $("#filediv").html('<a id="file" href="'+filePath+'" val="'+data.data.file+'">'+file+'</a>');
        	                $("input[name=source]").val(data.data.source);
        	                $("input[name=source_link]").val(data.data.source_link);
        				}
        			}
        		});
            }
            
    	});
    	
    	//删除下载
    	$(".del").bind("click",function()
    	{
    		if(window.confirm("你确定要删除吗?"))
    		{
    			var download_id = $(this).attr("download_id");
    			$.ajax
    			({
    				type:"post",
    				url:"/admin/onlinereg/deldownload",
    				data:{id:download_id},
    				success:function(data)
    				{
    					if(data.code == 200)
    					{
    						window.location.reload();
    					}
    					else
    					{
    						alert("删除失败");
    					}
    				}
    			});
    		}
    	});
    	
    };
});