YE1070720405 2019-04-29 10:18 采纳率: 0%
浏览 312

如何整合弹窗中自己输入的值和复选框为数组用于传参

现有四个弹窗,要把弹窗中我输入的值和复选框勾选的东西整合成数组该怎么写
弹窗一:

var selactive = {};
     var list=[]
  function showActiveDialog(thisObj,goodsid)
    {
        getLsActive(thisObj, 1, 0,goodsid);
        bootbox.dialog({
          title: "选择活动",
          message: '<table class="table table-bordered table-striped" id="active_select">' +
          '<thead class="thin-border-bottom">' +
          '<tr>'+
          '<th></th>'+
          // '<th class="center"><label class="pos-rel"><input type="checkbox" id="chk" class="ace chk" /><span class="lbl"></span></label></td></th>' +
          '<th>ID</th>' +
          '<th>缩略图</th>' +
          '<th>活动名</th>' +
          '<th>开始时间</th>' +
          '<th>结束时间</th>' +
           '<th>选择规则</th>' +
          '</tr></thead><tbody></tbody><table>' +
          '<script>$(\'#active_select input[id="chk"]\').on(\'click\',function(){if($(this).is(\':checked\')){$(\'.chkItems\').each(function(){this.checked = true;});}else{$(\'.chkItems\').each(function (){this.checked = false;});}});</script>'+
          '<ul id="pagination-active" class="pagination-sm"></ul>',
          buttons: {
            success: {
              label: "确定",
              className: "btn-sm btn-success",
              callback  : function (){
                var arr = []
                for(var g=0;g<list.length;g++){
                       //if(list[g].selected=="selected"){
                            selactive["key_"+list[g]['al_id']]=[]
                            if(list[g].selected=="selected" && list[g].rule.length){

                                 for(var gs=0;gs<list[g].rule.length;gs++){
                                     if(list[g]['rule'][gs].selectd=="selectd"){
                                      selactive["key_"+list[g]['al_id']].push(list[g]['rule'][gs].id)
                                     }
                                 }
                            }
                       //}
                }
        //console.log(selactive)
        selactives=JSON.stringify(selactive);
        //console.log(selactives)
            $.ajax({
            url: '/goods/addactive',
            type: 'POST',
            data: {activeids:selactives,id:goodsid},
            dataType: 'json',
            error: function(e){
                alert('没有权限或服务器连接失败!');
            },
            success: function(msgObj) {
             if (msgObj.ret== 1) {
                alert(msgObj.msg);
             }else if (msgObj.ret== 2){
                alert(msgObj.msg);
             }else if (msgObj.ret== 3){
                alert(msgObj.msg);
             }

            }

                        })
              }
            }
          }
        });
    }

弹窗2

function getLsActive(thisObj, page, totalPages,goodsid)
    {
        // 获取当前选中ids
        var activeIds = [];
        $(document).find('.cate table:visible tbody tr').each(function() {
            //获取活动id,判断banner的tr类型为top,active的tr类型为active,通过 split方法得到id
            if($(this).attr('id').split('_')[0] == 'active' || $(this).attr('id').split('_')[0] == 'top')
            {
                var id = $(this).attr('id').split('_')[1];
                activeIds.push(parseInt(id));
            }

        });

        $.ajax({
            url: '/activity/lsajaxList',
            type: 'get',
            data: {p: page,id:goodsid},
            dataType: 'json',
            success: function(res) {
                var activeHtml = '';
                var rules=[];

                if (res.ret == 1) {
                     list = res.msg['list'];
                     //console.log(list);
                    for (var i in list) {
                        var isChk ="";
                        var rules=list[i].rule
                        if(rules.length){
                             for(var g in rules){
                                   if(rules[g].selectd=="selectd"){
                                        list[i].selected="selected"
                                        isChk="checked"
                                   }
                             }
                        }

                        activeHtml += '<tr>';
                        activeHtml += '<td class="center"><label class="pos-rel"><input name="chkitem" date-index="'+i+'" type="checkbox"'+isChk+' value="'+list[i].al_id+'" class="ace chkItems" /><span class="lbl"></span></label></td>';
                        activeHtml += '<td>'+list[i].al_id+'</td>';
                        activeHtml += '<td class="pic"><img src="'+list[i].pic+'" class="cateImg" /></td>';
                        activeHtml += '<td class="title">'+list[i].al_name+'</td>';
                        activeHtml += '<td class="starttime">'+list[i].starttime+'</td>';
                        activeHtml += '<td class="endtime">'+list[i].endtime+'</td>';
                        activeHtml += '<td class="setrule"><button type="button"  date-index="'+i+'" class="btn btn-minier btn-inverse setActiveRule" date-key="key_'+list[i].al_id+'" date-id="'+list[i].al_id+'" date-ruleid="'+i+'">设置规则</button></td>';
                        activeHtml += '</tr>';
                    }
                    $('#active_select tbody').html(activeHtml);


                        totalPages = res.msg['totalPages'];

                        $('#pagination-active').twbsPagination({
                            totalPages: totalPages,
                            visiblePages: 8,
                            first: '首页',
                            prev: '上一页',
                            next: '下一页',
                            last: '尾页',
                            onPageClick: function (event, page) {
                                if (page >= 1) {
                                    getLsActive(thisObj, page, totalPages,goodsid);
                                }
                            }
                        });


                   $('#active_select .setActiveRule').on('click', function() {
                         var ruids=$(this).attr("date-ruleid");
                         var actid=$(this).attr("date-id");
                         var actkey=$(this).attr("date-key");
                         var actindex=$(this).attr("date-index");
                         rules=list[ruids].rule || []
                         var htmls='<tr>';
                         for(var ru=0;ru<rules.length;ru++){

                          if(rules[ru].selected=="selected"){
                                 selActive.map((x,y)=>{
                                         if(x==actkey){
                                             if(selActive[x].length==0){
                                                selActive[x].push(y) 
                                             }else{
                                                 selActive[x].map((ys,yk)=>{
                                                     if(yk==rules[ru].id){
                                                        rules[ru].selected="selected" 
                                                     }

                                                 })
                                             }
                                         }
                                 })

                          }
                         var isSelchk=rules[ru].selectd=="selectd"?"checked":"";
                          htmls+='<tr>';
                          htmls+='<td class="center"><label class="pos-rel"><input name="chkruleitem"  onChange="clickChildItem(this,'+actindex+','+ru+')" date-cindex="'+ru+'"   data-index="'+actindex+'" data-keys="key_'+actid+'" type="checkbox"'+isSelchk+' value="'+rules[ru].id+'" class="ace chkruleitem" /><span class="lbl"></span></label></td>'
                           htmls+='<td>'+rules[ru].id+'</td>'
                            htmls+='<td>'+rules[ru].name+'</td>'
                             htmls+= '<td class="setrule"><button type="button" onClick="setAttra(this,'+rules[ru].id+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                             htmls+='<tr>';
                       }

            bootbox.dialog({
            title: "规则选择",
            message: '<table class="table table-bordered table-striped" id="active_select2">' +
           '<thead class="thin-border-bottom">' +
          '<tr>'+
          '<th></th>'+
          '<th>规则ID</th>' +
          '<th>规则名称</th>' +
          '<th>规则类型</th>' +
          '</tr></thead><tbody>'+htmls+'</tbody><table>',
          buttons: {
             success: {
              label: "确定",
              className: "btn-sm btn-success"

             }
          }
        });
                   })


                     $('#active_select input[name="chkruleitem"]').on('change', function() {

                        var nowrulval=$(this).val()
                        var dindex=$(this).attr("data-index")
                        var cindex=$(this).attr("data-cindex")

                        if($(this).is(':checked')){

                            list[dindex]['rule'][cindex].selectd='selectd';
                        }else{
                            list[dindex]['rule'][cindex].selectd='';
                        }


                    });

                    $('#active_select input[name="chkitem"]').on('change', function() {

                        var dindex=$(this).attr("date-index")
                        if($(this).is(':checked')){
                           list[dindex].selected="selected"
                        }else{
                           list[dindex].selected=""
                        }


                    });
                }else{
                    alert('响应超时,获取活动信息失败');
                }
            },
            error: function() {
                alert('响应超时,获取活动信息失败');
            }
        });
    }

弹窗3

    function setAttra(Obj,attrid,goodsid){
        //var attrid=$(this).attr("data-id")
        //let thatone=Obj
        //console.log(thatone)
        $.ajax({
            url: '/activity/spajaxList',
            type: 'get',
            data: {aprid: attrid,id: goodsid},
            dataType: 'json',
            success: function(res) {
                var html1='';
                if(res.ret==1){
                    html1+='<tr>';
                    html1+='<td>'+'定价'+'</td>'
                    html1+='<td></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }else if(res.ret==2){
                    var name = 'zk_['+goodsid+']['+attrid+']'
                    var resdisc = $('input[type="hidden"][name="'+name+'"]').val() ? $('input[type="hidden"][name="'+name+'"]').val() : res.disc ;
                    html1+='<tr>';
                    html1+='<td>'+'折扣'+'</td>'
                    html1+='<td><input type="text" name="'+name+'" value="'+resdisc+'" /></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }else if(res.ret==3){
                    html1+='<tr>';
                    html1+='<td>'+'满减'+'</td>'
                    html1+='<td></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }else if(res.ret==4){
                    html1+='<tr>';
                    html1+='<td>'+'满赠'+'</td>'
                    html1+='<td></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }else if(res.ret==5){
                    html1+='<tr>';
                    html1+='<td>'+'买赠'+'</td>'
                    html1+='<td></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }else if(res.ret==6){
                    html1+='<tr>';
                    html1+='<td>'+'满包邮'+'</td>'
                    html1+='<td></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }else if(res.ret==7){
                    html1+='<tr>';
                    html1+='<td>'+'赠品领用'+'</td>'
                    html1+='<td></td>'
                    html1+='<td class="setrule"><button type="button" onClick="setAttr(this,'+res.ret+','+attrid+','+goodsid+')" class="btn btn-minier btn-inverse" >设置规格</button></td>';
                    html1+='<tr>';
                }
                bootbox.dialog({
                title: "规则类型",
                message: '<table class="table table-bordered table-striped attr_select3" id="active_select3">' +
                '<thead class="thin-border-bottom">' +
                '<tr>'+
                '<th>规则类型</th>' +
                '<th>折扣</th>' +
                '<th>设置规格</th>' +
                '</tr></thead><tbody>'+html1+'</tbody><table>',
                buttons: {
                  success: {
                    label: "确定",
                    className: "btn-sm btn-success",
                    callback: function() {
                        // 活动价
                        $('#active_select3 input[type="text"]:visible').each(function() {
                            var name = $(this).prop('name');
                            $('input[name="'+name+'"]').remove();
                            if ($(this).val() == '') return;
                            $('#goods_'+goodsid).prepend('<input type="hidden" name="'+name+'" value="'+$(this).val()+'" />');
                        });
                    }
                  }
                }
                });
            }
        })

    }

弹窗四

    function setAttr(obj,childType,attrid,goodsid){
            let that=obj
            if(!start){return}
            start=false
            //childType=$(this).attr("data-ret");
        $.ajax({
            url: '/goods/ajaxRuleAttrs',
            type: 'post',
            data: {ruleId: 2, goodsId: goodsid},
            dataType: 'json',
            success: function(res) {
                if (res.ret == 1) {
                    // 仅定价和折扣显示活动价
                   // var childType = $('input[name="apr_child_type"]:checked').val();
                    var disRulePrice = (childType != 1 && childType != 2) ? 'hide' : '';
                    var disNums=childType==7?'':'hide'
                    var attrHtml = '';
                    var list = res.msg;
                    for (var i in list) {
                        var item = list[i];
                        var name = 'id_['+goodsid+']['+attrid+']';
                        var numname = 'rule_['+goodsid+']['+attrid+']';
                        var limitnumname = 'rule[props_limit_num]['+goodsid+']['+attrid+']';
                        // 属性规格默认价格
                         var defaultVal = $('input[type="hidden"][name="'+name+'"]').val() ? $('input[type="hidden"][name="'+name+'"]').val() : '';
                         var defaultNumsVal = $('input[type="hidden"][name="'+numname+'"]').val() ? $('input[type="hidden"][name="'+numname+'"]').val() : '';
                          var defaultLimitNumsVal = $('input[type="hidden"][name="'+limitnumname+'"]').val() ? $('input[type="hidden"][name="'+limitnumname+'"]').val() : 0;

                        // 是否默认选中
                        var isChk = ($('input[name="rule[props_ids]['+goodsid+']['+attrid+']"][value="'+item.k_attr_ids+'"]').length > 0) ? 'checked="checked"' : '';
                        attrHtml += '<tr>';
                        attrHtml += '<td class="center"><label class="pos-rel"><input name="rule[props_ids]['+goodsid+']['+attrid+']" type="checkbox" '+isChk+' value="'+item.k_attr_ids+'" class="ace chk-item"><span class="lbl"></span></label></td>';
                        attrHtml += '<td>'+item.k_attr_name+'</td>';
                        attrHtml += '<td>'+item.k_attr_price+'</td>';
                        attrHtml += '<td class="'+disRulePrice+'"><input type="text" name="'+name+'" value="'+defaultVal+'" /></td>';
                         attrHtml += '<td class="'+disNums+'"><input type="text" name="'+numname+'" value="'+defaultNumsVal+'" /></td>';
                          attrHtml += '<td class="'+disNums+'"><input type="text" name="'+limitnumname+'" value="'+defaultLimitNumsVal+'" /><br/>(为0购买数量不限)</td>';
                        attrHtml += '</tr>';
                    }
                }

                bootbox.dialog({
                  title: "设置规格 (填写活动价则为该规格参加活动)",
                  message: '<table class="table table-bordered table-striped" id="props_select">' +
                  '<thead class="thin-border-bottom">' +
                  '<th></th>' +
                  '<th>属性名</th>' +
                  '<th>原价格</th>' +
                  '<th class="'+disRulePrice+'">活动价</th>' +
                  '<th class="'+disNums+'">发放数量</th>' +
                  '<th class="'+disNums+'">限制单用户购买数量</th>' +
                  '</tr></thead><tbody>'+attrHtml+'</tbody><table>',
                  buttons: {
                    success: {
                      label: "确定",
                      className: "btn-sm btn-success",
                      callback: function() {
                        // 复选框
                        $('#props_select input[type="checkbox"]').each(function() {
                            var name = $(this).prop('name');
                            $('input[type="hidden"][name="'+name+'"][value="'+$(this).val()+'"]').remove();
                            console.log(name + '|' + $(this).prop('value'));
                            if ($(this).val() == 'on') return;
                            if ($(this).is(':checked')) {
                                $('#goods_'+goodsid).prepend('<input type="hidden" name="'+name+'" value="'+$(this).val()+'" />');
                            }
                        });
                        // 活动价
                        $('#props_select input[type="text"]:visible').each(function() {
                            var name = $(this).prop('name');
                            $('input[name="'+name+'"]').remove();
                            if ($(this).val() == '') return;
                            $('#goods_'+goodsid).prepend('<input type="hidden" name="'+name+'" value="'+$(this).val()+'" />');
                        });
                         start=true
                      }

                    }
                  }
                });
                start=true

            },
            error: function() {
                alert('响应超时,获取规格信息失败');
                 start=true
            }
        });

    }
  • 写回答

1条回答

  • ChoneyLove 2019-04-29 15:54
    关注

    把各个输入框的值都放到数组里啊,具体怎么放,可以用push,concat,也可以直接写好

    result = array.concat(ary(this.value)).concat(ary(new1)).concat(ary(new2)).concat(ary(new3))
    
    评论

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复