releaseGoods.js 8.21 KB
/**
 * founder : zzf
 * Creation time :  2015/3/26
 */
define(function( require, exports, module ) {
    require( 'regionbox' );
    var _Jselect = require( 'jselect'),
       // _SalesData = require( 'SalesData' );
        _SalesData = require( '../sell/salesdata.js' );


    var methods = {
        unit : "",
        updateUnit : function(){
            $(".t-unit").html(this.unit);
        },
        specifications : function(view){
            $(view).html("按商品规格报价");
            $(view).prev("span").html("商品规格不同,分别报价");
            $(view).next(".tips").find("img").attr("src", "../images/tip-1.png");
            $(view).next(".tips").find("p").text("若您需要分商品规格分别报价,请点击“按商品规格报价”");
            $("#purchases-2").show();
            $("#interval-3").hide();
        },
        ladder : function(view){
            $(view).html("按销售量阶梯报价");
            $(view).prev("span").html("销售量不同,可进行");
            $(view).next(".tips").find("img").attr("src", "../images/tip-2.png");
            $(view).next(".tips").find("p").text("您可以针对销售量不同,给您的商品多个价格,买得越多,越便宜");
            $("#purchases-2").hide();
            $("#interval-3").show();
        },
        showMyImage : function(){
            $("#my-img").show();
            $("#local-img").hide();
            $(".img-list").hide();
        }
    };

    //商品产地
    region.start();
    //下拉框样式
    $( '.sea-select' ).each( function(){
        new _Jselect(  this , {
            searchBar:true
        });
    });
    //设置单位
    $(".sea-select").change(function(){
        methods.unit = $(this).val();
        methods.updateUnit();
    });

    /*报价栏*/
    $(".addbtn").click(function(){//添加
        var leng = $("#purchases-2 tbody tr").length;
        var view = '<tr><td>起批量:<input type="text"><span ng-bind="name" class="t-unit">公斤</span>以上</td>'+
                   '<td><input type="text">元/<span ng-bind="name" class="t-unit">公斤</span><span class="delete a-link">'+
                   '删除</span></td></tr>';
        if(leng <= 2){
            $("#purchases-2").append($(view));
        }
        if(leng >= 2){
            $("#purchases-2 tfoot").hide();
        }
    });
    $(".delete").live("click", function(){
       $(this).parent().parent().remove();
        $("#purchases-2 tfoot").show();
    });

    //报价库存
    var sales = new _SalesData({
        rootView:'#transaction-set-2',
        showView:'#interval-2',
        radioNmae:'#unit-view-2',
        res : [
            {"class" : "price", "dilipattern" : "/^[0-9]+$/,可售量有误!", "value" : 0}
        ]
    });



    //图片选择切换
    var isshowimg = true;
    $(".s-ntab a").click(function(){
        $(".s-ntab a").removeClass("current");
        $(this).addClass("current");
        if(isshowimg){
            methods.showMyImage();
            isshowimg = false;
        }else{
            $("#local-img").show();
            $(".img-list").show();
            $("#my-img").hide();
            isshowimg = true;
        };
        return false;
    });

    //报价切换
    var iscat = false;
    $(".title-right a").click(function(){
        if(iscat){
            methods.specifications(this);
            iscat = false;
        }else{
            methods.ladder(this);
            iscat = true;
        };

        return false;
    });

    //图片库选择
    $(".switch-img").click(function(){
        $(".s-ntab a").removeClass("current");
        $(".s-ntab a").eq(1).addClass("current");
        methods.showMyImage();
        isshowimg = false;
        return false;
    });

    //我的图库选择
    $(".my-imgs input").change(function(){
        var imagesPage = 0;
        var muns = 0;
        $(".my-imgs input").each(function(){
            if($(this).attr("checked")){
                imagesPage += 1;
            }
        });
        $(".img-list li").each(function(){
            if($(this).find("img").attr("src")){
                muns += 1;
            }
        });
        if(imagesPage > (6 - muns)){
            $(this).attr("checked", false);
            return false;
        }
        $(".mun-max").html(muns);
        $(".iamges-val .sell-num").html(6-muns-imagesPage);
    });

    //图片编辑
    $(".set-home-img").click(function(){
        var view1 = $(".img-list li").eq(0).find("img");
        var view2 = $(this).parent().parent().find("img");
        var p1 = view1.attr("src");
        var p2 = view2.attr("src");
        if(p1 && p2){
            view1.attr("src", p2);
            view2.attr("src", p1);
        }
    });
    //删除图片
    $(".img-del").click(function(){
        var view = $(this).parent().parent().find("img");
        view.attr("src", "");
    });
    $(".img-list li").hover(function(){
        var view = $(this).find("img");
        if(! view.attr("src")){
            $(this).find(".head").hide();
        }else{
            $(this).find(".head").show();
        }
        if(! $(this).index()){
            $(this).find(".set-home-img").hide();
        };
    }, function(){
        $(this).find(".head").hide();
    });
    //我的图库切换
    $(".time-nav li").click(function(){
        $(".time-nav li").removeClass("on");
        $(this).addClass("on");
    });
    //审核后指定时间上架
    $(".set-time").change(function(){
        var view = $(this).attr("cdata");
        if(view){
            $("#z-date").show();
        }else{
            $("#z-date").hide();
        }
    });

    $(".selected a").fancybox({
        padding : 30
    });


    $("#p-myimages .cat-tab a").click(function(){
        $("#p-myimages .cat-tab a").removeClass("on");
        $(this).addClass("on");
        if($(this).text() == "本地上传"){
            $(".user-upload").show();
            $(".user-image").hide();
        }else{
            $(".user-upload").hide();
            $(".user-image").show();
        }
        return false;
    });

    $(".upload-btns .submitBtn").click(function(){
        $(".photo-album").hide();
        $(".upload-btns").hide();
        $(".msg-remind-common").hide();
        $(".loading").show();

        setTimeout(function(){
            $(".loading").hide();
            $(".tailoring").show();
			setTimeout(function(){
				$("#target").attr("src", "../images/_DSC6871.jpg");
				$(".jcrop-preview").attr("src", "../images/_DSC6871.jpg");
				jcrop();
			}, 2000);
        }, 3000);
        return false;
    });

    $(".photo-album .ea7").click(function(){
        $(".cat-view").show();
        return false;
    });
    $(".cat-view .submitBtn").click(function(){
        $(".cat-view").hide();
        return false;
    });

    $("#p-myimages .iamges li").hover(function(){
        $(this).find("b").show();
    }, function(){
        $(this).find("b").hide();
    });
    var jcrop_api,
        boundx,
        boundy,
        $preview = $('#preview-pane'),
        $pcnt = $('#preview-pane .preview-container'),
        $pimg = $('#preview-pane .preview-container img'),
        xsize = $pcnt.width(),
        ysize = $pcnt.height();
	function jcrop(){
		$('#target').Jcrop({
			 onSelect: select,
            onChange: updatePreview,
            allowResize: true,
            dragEdges: true,
            cornerHandles: true,
            sideHandles: true,
            handleSize: 9,
            aspectRatio: 1,
			boxWidth: 300,
            minSize: [200, 200],
            setSelect: [0, 0, 200, 200]
		},function(){
			var bounds = this.getBounds();
			boundx = bounds[0];
			boundy = bounds[1];
			jcrop_api = this;
		});
		function select(c) {
            updatePreview(c);
            $(".jcrop-holder").css("top", ((300 - $(".jcrop-holder").height()) / 2));
        }
		function updatePreview(c){
			if (parseInt(c.w) > 0) {
				var rx = xsize / c.w;
				var ry = ysize / c.h;

				$pimg.css({
					width: Math.round(rx * boundx) + 'px',
					height: Math.round(ry * boundy) + 'px',
					marginLeft: '-' + Math.round(rx * c.x) + 'px',
					marginTop: '-' + Math.round(ry * c.y) + 'px'
				});
			}
		};
	}
    

    $(".img-list ul").dragsort({ dragSelector: "li", dragEnd: function() { }, placeHolderTemplate:'<li class="selected"></li>'});
});