$(function(){ //重置申请编号 $('#resetnumber').click(function(){ $('#pnum').val($(this).attr('data-num')); toastr.success('已重置申请编号'); }); //设置自动编号 $('.autonumber').click(function(){ var str1 = $('#pnum').val(); $('#numhtmlshow').html(''); if(str1.trim() !== ''){ var match1 = /(?!\d{3,6})(\D|\d)|\d{3,6}/g; var result = str1.match(match1); var arr = new Array(); var j = 0; var numhtml = ''; for(var i=0; i1){ arr.push(result[i]); j++; }else if(i>=1 && result[i-1].length ==1){ arr[j-1] = arr[j-1]+result[i]; } }else { arr.push(result[i]); j++; } } $.each(arr,function(k,v){ numhtml += ''+v+' '; }); $('#numhtmlshow').html(numhtml); } $('#autonumber').modal('show'); }); $('body').on('click','.delrule',function(){ $(this).parents('.label').remove(); }); //tools change $('#tools').change(function(){ if($(this).val() == 1){ $('.toolshow').hide(); $('#noteshow').show(); }else if($(this).val() == 2){ $('.toolshow').hide(); $('#yearshow').show(); }else if($(this).val() == 3){ $('.toolshow').hide(); $('.numbershow').show(); }else{ $('.toolshow').hide(); } }); //add tools $('#addtools').click(function(){ var numhtml = ''; if($('#tools').val() == 0){ toastr.error('请选择组件再添加'); return false; }else if($('#tools').val() == 1){ if($('#noteshow input').val().trim() != ''){ numhtml += ''+$('#noteshow input').val().trim()+' '; }else{ toastr.error('请输入你想添加的文本内容'); return false; } }else if($('#tools').val() == 2){ numhtml += ''+$('#yearshow input').val()+' '; }else if($('#tools').val() == 3){ numhtml += ''+$('#setnumber').val()+' '; } $('#numhtmlshow').append(numhtml); }); //位数number编号大小设置 $('#numsite').on("valuechange", function (e, previous) { if($(this).val() == '' || parseInt($(this).val()) > 6 || parseInt($(this).val()) <3){ toastr.error('请输入编号位数区间在3到6位'); return false; }else{ var num = parseInt($(this).val()); var str = makenum(num); $('#setnumber').val(str); } }); //生成编号 $('#setcnum').click(function(){ var cnum = ''; $('#numhtmlshow span').each(function(){ cnum += $(this).text().trim(); }); $('#pnum').val(cnum); $('#autonumber').modal('hide'); }); //根据位数生成编号,3位-》001 ,5位-》00001 function makenum(num){ var arr = new Array(num); for(var i=0;i< num;i++){ if(i != num-1){ arr[i] = 0; }else{ arr[i] = 1; } } return arr.join(''); } });