user-release-of-goods.js 7.03 KB
define(function( require, exports, module ) {

    require( 'region' );
    require( 'dragsort' );
    require( 'jqueryUI' );
    require( 'fancybox' );
	require( 'validate' );
	require( 'validate.extend' );
    var _SalesData = require( 'SalesData' ),
        _Jselect = require( 'jselect' );
		_Pophint = require( 'pophint' );


    $(function(){

        var methods = {
            updateunm : function(view){
                var mun = 0;
                $("#"+view+" .available").each(function(){
                    var value = $(this).val();
                    console.log(value);
                    if(value && !isNaN(value)){
                        mun += parseInt($(this).val());
                    };
                });
                return mun;
            },
            updateunit : function(){
                var unit = $("#unit").find("option:selected").length > 0 ? $("#unit").find("option:selected").text() : $("#unit").text();
                this.unit = unit;
                $(".t-unit").html(unit);
            },
            unit : "斤"
        };

        region.start();
        $(".certification .certification-img").fancybox({
            padding : 0
        });
        $("#add-certification .add-mbox").click(function(){
            $.fancybox.close();
        });
        $(".my-list p").click(function(){
            $(this).next().slideToggle();
        });
        $(".release-stairs").draggable();
        //初始化
        methods.updateunit();
        //业务逻辑区
            //添加报价区间
            var priceTable = $("#purchases tbody");
            $(".addbtn").click(function(){
                var pkey = '<tr><td>购买:<input type="text"><span class="jian">'+methods.unit+'</span>以上</td><td><input type="text">元/<span class="jian">'+methods.unit+'</span>'
                    +'<span class="delete a-link">删除</span></td></tr>';
                if($("#purchases tbody tr").length < 3){
                    priceTable.append(pkey);
                };
            });
            $("#purchases .delete").live("click", function(){
                if($("#purchases tbody tr").length > 1){
                    $(this).parent().parent().remove();
                };
            });
            //设置商品属性选择
            var sales1 = new _SalesData({
                'rootView':'#transaction-set',
                'showView':'#describe',
                'radioNmae':'#unit'
            })
            sales1.event("change", function(){
                methods.updateunit();
            });
            sales1.eachData();


            var sales2 = new _SalesData({
                'rootView':'#transaction-set',
                'showView':'#interval',
                'radioNmae':'#unit',
                res : [
                    {"class" : "price", "dilipattern" : "/^[0-9]+$/,可售量有误!", "value" : 0}
                ]
            });
            sales2.event("change", function(){
                methods.updateunit();
            });
            sales2.eachData();
            //报价方式
            $("input[name='pricetype']").change(function(){
                if($(this).val() == "false"){
                    $(".interval-view").show();
                    $(".specifications-view").hide();
                    sales2.changeData();
                }else{
                    $(".interval-view").hide();
                    $(".specifications-view").show();
                    sales1.changeData();
                };
            });
            //图片切换
            $(".s-ntab li").click(function(){
                $(".s-ntab li a").removeClass("current");
                $(this).find("a").addClass("current");
                $(".s-ntab-content").hide();
                $(".s-ntab-content").eq($(this).index()).show();
                return false;
            });
            //楼梯
            $(".icon-stairs-colse").click(function(){
                $(".release-stairs").hide();
            });
            //认证
            $(".img-remove").click(function(){
              $(this).parents('li').remove();

            });
            //拖动
            $("#user-list").dragsort({ dragSelector: "span", dragBetween: true, dragEnd: function(){
                
            }});
            //楼层跳转
            $(".release-stairs li").click(function(){
                var view = $(".form-box").eq($(this).index());
                var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
                var distance = view.offset().top;
                $body.stop().animate({scrollTop: distance}, 800);
            });
            $(".release-stairs .top").click(function(){
                var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
                $body.stop().animate({scrollTop: 0}, 800);
            });
            $(".certification-img").hover(function(){
                if($(this).find("img").attr("src") == ""){
                    $(this).next().hide();
                }else{
                    $(this).next().show();
                };
            });
            $(".available").live("change", function(){
                var getnum = 0;
                if($('input[name="pricetype"]:checked').val() == "true"){
                    getnum = methods.updateunm("describe");
                }else{
                    getnum = methods.updateunm("interval");
                };
                $(".sell-num").html(getnum+""+methods.unit);
            });

            require.async(['validate.extend'], function() {
                $( '.s-form' ).validate({

                });
            });
			
			//自动生成标题弹框
			$( "#auto-title" ).click(function(){
	
				new _Pophint( this,{
					operation: function( target ){
						//确定要执行的操作
						
					}, 
					content: "你确定取消吗?",
					showButton:	false
				});
				
			});


            /* 模拟下拉列表 */


            $( '.sea-select' ).each( function(){
                new _Jselect(  this , {
                    searchBar:true
                });
            });
            //新增子分类
            $( '#c-nav-add' ).click(function(){
                var _html = $('<div class="c-nav-box">\
                            <select class="sea-select categoryItem" data-pid="0">\
                                <option value="">请选择分类</option>\
                            </select>\
                            <span class="submitBtn grayBtn c-nav-rmove">删除</span>\
                        </div>');
                $( _html ).insertBefore( $( this ) );   

                new _Jselect(  $( _html ).find( '.sea-select' )[0] , {
                    searchBar:true
                });     
            });

            //自定义
            $( '.c-info' ).change(function(){
                if( $( this ).is( ':checked' ) ){
                    $( '#'+$( this ).attr('cdata') ).show();
                }else{
                    $( '#'+$( this ).attr('cdata') ).hide();
                }
            });

    });

});