prod.js 7.03 KB
/**
 * @fileOverview snap模块
 * @author:Hbomb(zhouqq@yoho.cn)
 * @date:2013-05-27
 */
define('admin/prod',function(require, exports)
{
    var box = require('admin/box'); // 提示框
    var $ = require("jquery");
    var common = require("common");
    var form_html = $("#form_pan").html()+'';
    $("#form_pan").remove();
    $("#add_prod").click(function()
    {
        box.confirm
        (
            form_html, submit,
            {
                title: '添加商品', 
                width: '750px', 
                autoClose: false
            }
        );
        $('#create_time').click(function()
        {
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});
        });

        
    });
    
    $(".del").click(function()
    {
        var id = $(this).attr('val');
        box.confirm("确定要删除这个商品吗?",function()
        {
            $.ajax
            ({
                type: "post",
                url: '/admin/prod/del',
                data: "id="+id,
                success: function(data)
                {
                    if (data.code == 200)
                    {
                        window.location.reload();
                    }
                    else
                    {
                        box.alert(data.message);
                    }
                }
            });
        });
    });
    
    //查看
    $(".look").click(function()
    {
        box.confirm
        (
            form_html, submit,
            {
                title: '查看商品', 
                width: '750px', 
                autoClose: false
            }
        );
        
        $('#create_time').click(function()
        {
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});
        });
        
        var obj = $(this).parents("tr");
        var name = obj.find("td:eq(1)").text();
        var brand_id = obj.find("td:eq(2)").text();
        var pic = obj.find("td:eq(5)").attr("pic");
        var text = obj.find("td:eq(7)").text();
        var id = obj.find("td:eq(0)").text();
        var price = obj.find("td:eq(6)").text();
        var url = obj.find("td:eq(4) a").attr("href");
        var sort = obj.find("td:eq(8)").text();
        var create_time = obj.find("td:eq(9)").text();
        var market_price = $("#prod_info").attr("market_price");
        var product_skn = $("#prod_info").attr("product_skn");
        var product_id = $("#prod_info").attr("product_id");
        $("#id").val(id);
        $("#name").val(name);
        $("#brand_id").val(brand_id);
        $("#text").val(text);
        $("#pic").val(pic);
        $("#price").val(price);
        $("#recom_status").val($(this).attr("recom_status"));
        $("#pic").after(obj.find("td:eq(5)").html());
        $("#sort").val(sort);
        $("#create_time").val(create_time);
        $("#product_skn").val(product_skn);
        $("#product_id").val(product_id);
        $("#market_price").val(market_price);
        $("#url").val(url);
    });
    
    //提交商品
    function submit()
    {
        var text = $("#text").val();
        var pic = $("#pic").val();
        var id =  $("#id").val();
        var brand_id =$("#brand_id").val();
        var name = $("#name").val();
        var url = $("#url").val();
        var create_time = $("#create_time").val();
        var recom_status = $("#recom_status").val();
        var price = $.trim($("#price").val());
        var market_price = $.trim($("#market_price").val());
        var product_skn = $.trim($("#product_skn").val());
        var product_id = $.trim($("#product_id").val());
        var sort = parseInt($("#sort").val());
        if(name == "")
        {
            alert("名称不能为空!");
            return;
        }
        if(url == "")
        {
            alert("链接不能为空!");
            return;
        }
        if(pic=="")
        {
            alert("图片不能为空!");
            return;
        }
        if(price == "")
        {
        	alert("价格不能为空");
        	return;
        }
        if(sort<0)
        {
        	alert("排序值有问题");
        	return;
        }
        $.ajax
        ({
            type: "post",
            url: '/admin/prod/submit',
            data: "id=" + id+
            "&text="+encodeURIComponent(text)+
            "&name="+encodeURIComponent(name)+
            "&url="+encodeURIComponent(url)+
            "&pic="+encodeURIComponent(pic)+
            "&brand_id="+encodeURIComponent(brand_id)+
            "&price="+price+
            "&market_price="+market_price+
            "&product_skn="+product_skn+
            "&product_id="+product_id+
            "&recom_status="+recom_status+
            "&create_time="+encodeURIComponent(create_time)+
            "&sort="+sort,
            success: function(data)
            {
                if (data.code == 200)
                {
                    window.location.reload();
                }
                else
                {
                    box.alert(data.message);
                }
            }
        });
    }
  
    $(".look_v").click(function()
    {
        $(this).next().toggle();
    });
    
    $("#get_prod").live("click",function()
    {
        $.ajax
        ({
            type: "post",
            url: '/admin/prod/getprod',
            data: "url=" + $("#url").val(),
            success: function(data)
            {
                if (data.code == 200)
                {
                    $("#name").val(data.data.product_name);
                    $("#price").val(data.data.price);
                    $("#product_skn").val(data.data.skn);
                    $("#product_id").val(data.data.product_id);
                    $("#market_price").val(data.data.market_price);
                    var pics = [];
                    var pic_html = '';
                    for(var i=0;i<data.data.skc_list.length;i++)
                    {
                        var skc_img = data.data.skc_list[i]['600x1000'].replace('http://img03','');
                        skc_img = skc_img.replace('http://img04','');
                        skc_img = skc_img.replace('http://img05','');
                        skc_img = skc_img.replace('http://img06','');
                        if(data.data.image['600x1000'].indexOf(skc_img)>-1)
                        {
                            for(var k=0;k<data.data.skc_list[i]['images'].length;k++)
                            {
                                pics.push(data.data.skc_list[i]['images'][k]['100x100'].replace('0100x0100','0420x0560'));
                                pic_html += '<img src="'+data.data.skc_list[i]['images'][k]['100x100'].replace('0100x0100','0420x0560')+'" style="width:100px;height:100px;">';
                            }
                        }
                    }
                    
                    $("#pic").val(pics.join('|'));
                    $("#pic").parent().find('img').remove();
                    $("#pic").after(pic_html);
                }
                else
                {
                    box.alert(data.message);
                }
            }
        });
    });
});