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

    require( 'region' );
    require( 'dragsort' );
    require( 'jqueryUI' );
    require( 'fancybox' );
    var _SalesData = require( 'SalesData' ),
        _Jselect = require( 'jselect'),
        _Controller = require('categorySelect');


    $(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" '
                    + 'min="1" maxlength="6" '
                    + 'dilimethod="checkQuotationStockNum" '
                    + 'name="qujianNum'+ $("#purchases tbody tr").length+'" required="true" '
                    + 'digits="true" class="count">'
                    + '<span ng-bind="name">' + methods.unit + '</span>以上</td> '
                    + '<td> '
                    + '<input type="text" '
                    + 'range="0.01,999999.99" '
                    + 'maxlength="9" '
                    + 'dilimethod="checkQuotationPrice" '
                    + 'name="qujianPrice'+ $("#purchases tbody tr").length+'" money="true" '
                    + 'required="true" class="price">元/'
                    + '<span ng-bind="name">' + methods.unit + '</span>'
                    + '<span class="delete a-link">删除</span> '
                    +'</td>'+'</tr>' ;
                if($("#purchases tbody tr").length < 3){
                    priceTable.append(pkey);
                }
                if ($("#purchases tbody tr").length ==3) {
                    $(".addbtn").parent().parent().hide();
                }
            });
            $("#purchases .delete").live("click", function(){
                if($("#purchases tbody tr").length > 1){
                    $(".addbtn").parent().parent().show();
                    $(this).parent().parent().remove();
                }
            });
            //设置商品属性选择
            var sales1 = new _SalesData({
                'rootView':'#saleAttr',
                'showView':'#describe',
                'radioNmae':'#unit'
            }) ;
            sales1.event("change", function(){
                methods.updateunit();
            });
            sales1.eachData();


            var sales2 = new _SalesData({
                'rootView':'#saleAttr',
                'showView':'#interval',
                'radioNmae':'#unit',
                res : [
                    {"class": "stockNum", "digits": "true", "maxlength": "6", "required": "true", "dilipattern": "/^[0-9]+$/,可售量有误!", "value": "", "name": ""}
                ]
            });
            sales2.event("change", function(){
                methods.updateunit();
            });
            sales2.eachData();

        //修改页区间设置
        var sales3 = new _SalesData({
            'rootView': '#saleAttr',
            'showView': '#interval1',
            'radioNmae': '#unit',
            res: [
                {"class": "stockNum", "digits": "true", "maxlength": "6", "required": "true", "dilipattern": "/^[0-9]+$/,可售量有误!", "value": "", "name": ""}
            ]
        });
        sales3.event("change", function () {
            methods.updateunit();
        });
        sales3.eachData();

            if($('input[name="quotationType"]:checked').val()==1){
                $(".interval-view").hide();
                $(".specifications-view").show();
                //sales1.changeData();
            }else{
                $(".interval-view").show();
                $(".specifications-view").hide();
                //sales2.changeData();
            }
            //报价方式
            $("input[name='quotationType']").change(function(){
                if($(this).val() == "2"){
                    $(".interval-view").show();
                    $(".specifications-view").hide();
                    if($(this.hasClass("update"))) {
                        sales3.changeData();
                    }else {
                        sales2.changeData();
                    }
                }else{
                    $(".interval-view").hide();
                    $(".specifications-view").show();
                    sales1.changeData();
                }
            });

            //楼梯
            $(".icon-stairs-colse").click(function(){
                $(".release-stairs").hide();
            });

            ////拖动
            //$("#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="quotationType"]:checked').val() == "1"){
                    getnum = methods.updateunm("describe");
                }else{
                    getnum = methods.updateunm("interval");
                }
                $(".sell-num").html(getnum+""+methods.unit);
            });

			//自动生成标题
			$( "#auto-title" ).click(function(){
                var countycity2= $("select[name='producingId2']").val();
                var countycity2Value= $("select[name='producingId2']").find("option:selected").text();//选中文本值
                var countycity3Value= $("select[name='producingId3']").find("option:selected").text();//选中文本值
                var  producingValue=$("input[name='producingId']").val();
                if (producingValue == "") {
                    alert("请选择产地!");
                    return false;
                }
                if (parseInt(producingValue) == -10) {
                    alert("产地还需选择下一级!");
                    return false;
                }
                if(producingValue>-20){
                    if(countycity2Value=='北京'||countycity2Value=='天津'||countycity2Value=='重庆'||countycity2Value=='上海'||countycity2Value=='澳门'||countycity2Value=='香港'){
                        productArea=countycity2Value;
                    }else{
                        if(countycity3Value=='请选择'){
                            productArea=countycity2Value;
                        }else{
                            productArea=countycity2Value+countycity3Value;
                        }
                    }
                }else{
                    productArea= $("input[name='producingId']").attr("data-cate-txt");
                }

                var cateName = $("#autoCname").val();

                //var pickUpId=[];
                //var pickUpNames=[];
                //$("input[name='deliId']:checked").each(function(){
                //    pickUpId.push($(this).val()) ;
                //    var text = $(this).attr("attr");
                //    //text=text.replaceAll(" ","");
                //    pickUpNames.push(text);
                //});
                //if(pickUpId.length==0){
                //    alert("需填写完成分类、产地时才能自动生成标题!");
                //    return false;
                //}

                //var pickUpName = pickUpNames[0]
                //if(pickUpNames.length>1){
                //    pickUpName+="等";
                //}
                //苹果 产地四川省成都市 提货点成都聚合等
                var pName = cateName+" 产地"+productArea;

                $("#title").val(pName);
                $("#title").blur();
			});


            /* 模拟下拉列表 */
            var conf = {
                url: "/titan/category/nextSubCategroy?parentId={cid}", root: "#subCategory", name: "subCategory",sid:"-1"
            };
            new _Controller(conf);

            $( '.sea-select' ).each( function(){
                new _Jselect(  this , {
                    searchBar:true
                });
            });
            //新增子分类
            $( '#c-nav-add' ).click(function(){
                var scId = $(".subCategoryVal").val();
                if(scId=="" || scId==undefined){
                    alert("请选择最后一级分类!");
                    return false;
                }
                var mcId = $("#mainCid").val();
                if(scId==mcId){
                    alert("该分类已存在主分类上了!");
                    return false;
                }
                var areadyScIdObj = $("#scId-"+scId);
                if(undefined != areadyScIdObj && areadyScIdObj.length >= 1){
                    alert("该分类已经添加了!");
                    return false;
                }
                var htmlScId = "scId-"+scId;
                var textSubClase = $(".subCategoryVal").attr("val");
                var _html = $('<div class="c-nav-box subcid" id="'+htmlScId+'" scid="'+ scId+'"><div id="" class="pack_jselect " ><div style="background: #f5f5f5;border: 1px #ccc;"><span>'+textSubClase+'</span></div></div><span class="submitBtn grayBtn c-nav-rmove">删除</span></div>');
                $( _html ).insertBefore( $( "#subCates" ) );

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

            //删除子分类
            $(".c-nav-rmove").live("click", function () {
               $(this).parent().remove();
            }) ;

            //有效期,上架模式自定义
            $( '.c-info' ).click(function(){
                if( $(this).hasClass("defind")){
                    if($(this).attr("name")=="indate") {
                        $("#defindIndate").val($(this).val());
                    }
                    $( '#'+$( this ).attr('cdata')).show();
                }else{
                    $('#' + $(this).attr('cdata')).find("input").removeAttr("value","");
                    $( '#'+$( this ).attr('cdata') ).hide();
                }
            });
            //有效期自定义自动赋值
            $("#indateInput").live("keyup", function () {
               $("#defindIndate").val($(this).val());
            }) ;
            ////产地选择切换
            //$("#sameCity").click(function(){
            //    if($(this).find("input").first().attr("checked")){
            //        $("#localityId").attr("value",$("#producingId").val());
            //        $("#home").hide();
            //    }else{
            //        $("#localityId").attr("value","");
            //        $("#home").show();
            //    }
            //})
    });

});