刚使用requrie.js时的代码

2021-06-10 01:04

阅读:495

标签:ice   trim   focus   receiver   als   epo   addclass   数据   setw   

//短信服务
define([‘jquery‘,‘jsrender‘,‘base‘,‘text!../../html/sms.html‘,‘pagination‘,‘bootstrap‘, ‘datetimepicker‘, ‘datetimepicker.zh-CN‘], function($,jsrender,base,html){
    function init(){
            var blackIdArry = [],
                timesDate = ‘‘,
                sendTypeN = ‘‘;
            $(‘body>.wrapper>.content‘).html(html);
            //控制短信内容字数
            function controlWord(){
                var remainWd = 70-$(‘#status‘).val().length;
                $(‘.tipsWd‘).html(remainWd);
            }
            $(‘#mask‘).on(‘keydown‘,‘#status‘,function(){
                controlWord()
            })
            $(‘#mask‘).on(‘keyup‘,‘#status‘,function(){
                controlWord()
            })
            /*==========================选择分组====================================================*/
            $(‘#mask‘).on(‘click‘,‘.span-tab‘,function(){
                var i = $(this).index();
                $(this).addClass(‘select‘).siblings(‘.span-tab‘).removeClass(‘select‘);
                $(‘.show-con‘).eq(i).show().siblings(‘.show-con‘).hide();
            })
            /*
            * 下拉选择
            * 多选
            */
            //点击得到下拉区域
            $(‘#mask‘).on(‘click‘,‘.region-box‘,function(){
                $(".region-list").show();
                var queryData = {};
                    queryData.enterpriseId = sessionStorage.getItem("enterpriseId");
                    // queryData.name = ‘‘;
                base.ajax({"type":"GET","url":"/ecapi/cardgroup/query","data":queryData},function(res){
                    if(res.record == 1200){
                        //console.log(res);
                        //渲染表格数据
                        var liList = $(‘.region-list ul li‘);
                        var valData = res.data;
                        var valLen = valData.length;
                        var _Html = ‘‘;
                        if(liList.length ){
                            for(var i=1;i){
                                _Html += ‘
  • ‘+valData[i].name+‘
  • ; } $(‘.region-list ul‘).html(_Html); } //隐藏号码为空的Li var liListLen = $(‘.region-list ul li‘).length; for(var i = 0;i){ if($(‘.region-list ul li‘).eq(i).attr("data-amount") == "0"){ $(‘.region-list ul li‘).eq(i).hide(); } } } }); //阻止冒泡 return false; }) //隐藏下拉区域 $("#mask").on(‘click‘,function(){ $(this).find(".region-list").hide(); }) $(‘#mask‘).on(‘click‘,‘.region-list‘,function(){ //阻止冒泡 return false; }) //选择所在区域 checkbox $(‘#mask‘).on(‘click‘,‘.region-list ul .check‘,function(){ if( $(this).parent(‘li‘).hasClass(‘selected‘)){ $(this).parent(‘li‘).removeClass(‘selected‘); var val = $(this).parent().find(".text").html(); $(".region-com li").find(".text").each(function(){ if($(this).html() == val){ $(this).parent("li").remove(); } }) }else{ $(this).parent(‘li‘).addClass(‘selected‘); var val = $(this).parent().find(".text").html(); var text = ‘
  • ‘+val+‘
  • ; $(".region-com ul").append(text); } }) //全选 $(‘#mask‘).on(‘click‘,‘.region-list ul .allcheck‘,function(){ if($(this).parent(‘li‘).hasClass(‘selected‘)){ $(this).parent(‘li‘).removeClass(‘selected‘); $(this).parent(‘li‘).siblings(‘li‘).removeClass(‘selected‘); var lihtml = $(this).parent(‘li‘).siblings(‘li‘); $(".region-com ul").html(‘‘); }else{ $(this).parent(‘li‘).addClass(‘selected‘); $(this).parent(‘li‘).siblings(‘li‘).addClass(‘selected‘); var lihtml = $(this).parent(‘li‘).siblings(‘li‘); for(var i = 0;i){ var val = lihtml.eq(i).find(‘.text‘).html(); var text = ‘
  • ‘+val+‘
  • ; $(".region-com ul").append(text); } } }) /*==========================手动输入生成标签===========================================*/ /* * 手动添加 设备SN获取焦点 */ $("#mask").on("click",".plan-num-com",function(){ $(".sn-input").focus(); }); function checkSn(sn, err_info, err_box) { var checkNumberData = []; checkNumberData.push(sn); base.ajax({"type":"POST","url":"/ecapi/shortMessage/checkNumber","data":{‘number‘:checkNumberData}},function(res){ if(res.record == 1200){ err_info.removeClass("error"); err_box.html(‘‘); return true; }else{ err_info.addClass("error"); err_box.html(res.msg); return false; } }); } // 如果超过6行,出现滚动条 var sixHeiFun = function() { var sn_box = $(".plan-num-com"), sn_hei = sn_box.height(); if (sn_hei >= 125) { sn_box.css({ "overflow-y" : "auto", "height" : "125px" }); } else { sn_box.css({ "overflow-y" : "hidden", "height" : "auto" }); } } /* * 手动添加函数 * 判断是否重复 * 正则验证 * */ var equipSN = function(){ //SN00000001 var num = Number($(".sn-list").length); var _this = $("#J_inp_sn"); var check_val = /^[a-zA-Z0-9]{1,32}$/; var inp_val = ($.trim(_this.val())).split(" "), str_len = inp_val.length; for(var j=0;j){ if(j == 21 || num == 21){ break; } if(inp_val[j] != ""){ var text = ‘

    ‘+inp_val[j]+‘

    ; $(".sn-com").before(text); _this.val("").css({"width":"13px"}); var len = $(".sn-list").length- 1, err_box = $("#plan-num").next(), err_info = $(".sn-list").last(); sixHeiFun(); // for(var i=0;i// if($(".sn-list").eq(i).find("p").html() == inp_val[j]){ // err_info.addClass("error"); // err_box.html("设备SN重复."); // continue; // }//设备SN只允许输入英文大小写及数字 // else if(!check_val.test(inp_val[j])){ // err_info.addClass("error"); // err_box.html("请输入1-32位字母、数字组合的设备SN."); // continue; // } // } /** * 查询数据库里是否有重复 */ checkSn(inp_val[j], err_info, err_box); //return true; //如果大于超过50个设备时,则不能输入; if(num >= 19){ $("#J_inp_sn").attr("disabled","disabled"); }else{ $("#J_inp_sn").removeAttr("disabled"); } } } } /* * 自动延伸宽度 * */ var autoLength = function() { var input = document.getElementById(‘J_inp_sn‘); var hlp = document.getElementById(‘input_help‘); if (!hlp) { hlp = document.createElement(‘span‘); hlp.id = ‘input_help‘; hlp.style.visibility = ‘hidden‘; hlp.style.position = ‘absolute‘; hlp.style.left = 0; hlp.style.top = 0; hlp.style.wordWrap = ‘nowrap‘; hlp.style.overflowX = ‘visible‘; document.getElementById("J_sn_com").appendChild(hlp); } hlp.innerHTML = input.value; // 这里多加20个像素,使文本框右边内部有空白空间 input.style.width = (hlp.offsetWidth + 5) + ‘px‘; } /* * 手动添加 号码 */ $("#mask").on("keyup",".sn-input",function(e){ autoLength(); var keyCode = window.event ? e.keyCode : e.which; if(keyCode == 13){ equipSN(); } }); /* * 输入input失去焦点时 * 默认把input内容自动生成标签 * 右键粘贴 * */ $("#mask").on("paste","#J_inp_sn",function(){ setTimeout(function() { equipSN(); },100); }); $("#mask").on("blur","#J_inp_sn",function(){ equipSN(); }); /* * 手动添加 设备SN 删除标签 */ $("#mask").on("click", ".sn-close", function() { var num = Number($(".sn-list").length); $(this).parent().remove(); sixHeiFun(); // 如果大于20个号码时,则不能输入; if (num = 20) { $("#J_inp_sn").removeAttr("disabled"); } // 如果错误标签删除时,提示需要清除 if (!$(".sn-list").hasClass("error")) { $("#plan-num").next().html(""); return true; } }) /* * 得到前N天或后N天的日期 * */ function showdateAll(n){ var uom = new Date(new Date()-0+n*86400000), m_num = uom.getMonth()+ 1, d_num = uom.getDate(); if(m_num ){ m_num = "0"+m_num; } if(d_num ){ d_num = "0"+d_num; } uom = uom.getFullYear() + "-" + (m_num) + "-" + (d_num); return uom; } /* * 得到当前日期 * */ function nowdate(){ var d = new Date(), m_now = d.getMonth()+ 1, d_now = d.getDate(); if(m_now ){ m_now = "0"+m_now; } if(d_now ){ d_now = "0"+d_now; } var dateEnd = d.getFullYear()+‘-‘+ (m_now)+"-"+ d_now; return dateEnd; } /*==========================选择短信发送方式===========================================*/ $(‘#mask‘).on(‘click‘,‘.form_item .label‘,function(){ if($(‘#timingsend‘).is(":checked")){ $(‘#show-inputTime‘).show(); }else{ $(‘#show-inputTime‘).hide(); } //定时发送时间控件 var s_time = showdateAll(7), e_time = showdateAll(1); $(‘#sms_query_time‘).val(‘‘).datetimepicker({ format: ‘yyyy-mm-dd hh:ii‘, language: ‘zh-CN‘, startView: ‘year‘, minView: ‘hour‘, initialDate: e_time, startDate : e_time, endDate : s_time, //Date autoclose: true }); $(‘.datetimepicker‘).hide(); //选择定时发送 $(‘#mask #sms-month-pick‘).on(‘changeDate‘,function(){ sendTypeN = ‘2‘; timesDate = $(‘#sms_query_time‘).val(); //console.log(timesDate); }) }) //选择即时发送 $(‘#mask‘).on(‘click‘,‘#Immediatesed‘,function(){ sendTypeN = ‘1‘; var u_data = new Date(); m_num = u_data.getMonth()+ 1, d_num = u_data.getDate(); if(m_num ){ m_num = "0"+m_num; } if(d_num ){ d_num = "0"+d_num; } timesDate = u_data.getFullYear()+‘-‘+ (m_num)+"-"+ (d_num)+" "+ u_data.getHours()+":"+ u_data.getMinutes()+":"+ u_data.getSeconds(); }) //黑名单号码列表checkbox $(‘#mask‘).on(‘click‘,‘#blackNameTable .maincheck‘,function(){ if($(this).is(‘:checked‘)){ $(‘#blackNameTable‘).find(‘.subcheck‘).prop("checked",true); }else{ $(‘#blackNameTable‘).find(‘.subcheck‘).prop("checked",false); } }); $(‘#mask‘).on(‘click‘,‘#blackNameTable .subcheck‘,function(){ var checkLen = $(this).is(":checked").length; //获取当前td的id var blackId = Number($(this).parent(‘td‘).attr(‘id‘)); if($(this).is(":checked")){ blackIdArry.push(blackId); }else{ blackIdArry.pop(blackId); } console.log("n9999",blackIdArry); if(checkLen == 0){ $("#blackNameTable .maincheck").prop("checked",true); }else{ $("#blackNameTable .maincheck").prop("checked",false); } }) /*==========================短信发送记录===========================================*/ //短信查询时间控件 $(‘#J_query_time‘).val(‘‘).datetimepicker({ format: ‘yyyy-mm-dd‘, language: ‘zh-CN‘, startView: ‘year‘, minView: ‘month‘, initialDate: ‘‘, startDate: new Date(‘2017‘), //Date autoclose: true }); $(‘.datetimepicker‘).hide(); //短信发送记录查询 queryShortMessageFn({"shortTime":‘‘,"pageNum":1,"pageSize":10}); function queryShortMessageFn(queryMessageData){ base.ajax({"type":"GET","url":"/ecapi/shortMessage/queryShortMessage","data":queryMessageData},function(res){ if(res.record == 1200){ //渲染表格数据 var smsTableHtml = $("#smsTabel").render(res.data); $("#sms-table").html(smsTableHtml); //分页 queryMessageData.total = res.data.total; base.listPage(queryShortMessageFn,queryMessageData,‘#sms-tableForm-box‘,true); } }); } //导出 queryShortMessageFn.exportFile = function(queryMessageData){ window.location.href="/ecapi/shortMessage/downloadShortMessage?shortTime="; } //点击日历查询短信发送记录 $(‘#month-pick‘).on(‘changeDate‘,function(ev){ var update_time = $(‘#J_query_time‘).val(); queryShortMessageFn({"shortTime":update_time,"pageNum":1,"pageSize":10}); //导出 queryShortMessageFn.exportFile = function(queryMessageData){ window.location.href="/ecapi/shortMessage/downloadShortMessage?shortTime="+update_time; } }) /**********************************弹窗操作***********************************/ /*********************发送短信弹窗*********************** */ $(‘.serviceBtn .setBtn‘).on(‘click‘,function(){ $(‘#mask‘).removeClass(‘hidden‘); var setMessageHtml = $("#setMessage").render(); $("#mask").html(setMessageHtml); }) /*******焦点离开验证**********/ $(‘#mask‘).on(‘blur‘,‘#status‘,function(){ var messageCon_box = $(‘#status‘), messageCon = messageCon_box.val(), error_box = messageCon_box.parents(‘.form_item‘).next(); if(messageCon == ‘‘){ error_box.html(‘请输入短信内容‘); return false; }else{ error_box.html(‘‘); return true; } }) /*******点击发送验证**********/ //发送内容 function setMessage(){ var messageCon_box = $(‘#status‘), messageCon = messageCon_box.val(), error_box = messageCon_box.parents(‘.form_item‘).next(); if(messageCon == ‘‘){ error_box.html(‘请输入短信内容‘); return false; }else{ error_box.html(‘‘); return true; } } /* * 添加弹框点击确定按钮时 * 判断手动输入的号码是否通过 * */ function handList(){//1311234567913 if($("#plan-num").next().html() == "号码不在该集团客户下"){ return false; }else{ return true; } } function blackname(){ if($("#plan-num").next().html() ==‘号码已在黑名单,不能对其发送短信‘){ return false }else{ return true; } } //验证接收号码是否为空 function snList(){ if($(‘.span-tab.tab1‘).hasClass(‘select‘)){ // $(‘.region-com ul‘).html(‘‘); if($(‘.sn-list‘).length == 0){ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘请输入接受号码或选择分组‘); return false; }else{ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘‘); return true; } } if($(‘.span-tab.tab2‘).hasClass(‘select‘)){ $(‘.sn-list‘).html(‘‘); if($(‘.region-com ul li‘).length > 0){ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘‘); return true; }else{ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘请输入接受号码或选择分组‘); return false; } } } //验证发送方式是否为空 function typePost(){ if(timesDate == ‘‘){ $(‘.show-inputTime‘).parents(‘.form_item‘).next().html(‘请选择发送方式‘); return false; }else{ $(‘.show-inputTime‘).parents(‘.form_item‘).next().html(‘‘); return true; } } //点击发送按钮 $(‘#mask‘).on(‘click‘,‘#sendBtn‘,function(){ if(setMessage() && handList() &&blackname() && snList() && typePost()){ //接收号码发送格式 var receivertype = ‘‘; var numberArry = []; if($("#mask .span-tab.select").attr("data-type") == "1"){ $(".plan-num-com .sn-list").each(function(){ numberArry.push($(this).find(‘p‘).html()); }) receivertype = ‘1‘; }else{ // $("#J-region-com li").each(function(){ // numberArry.push($(this).find(".text").html()); // }) $(‘.region-list li.selected‘).each(function(){ numberArry.push($(this).find(‘span‘).attr(‘data-id‘)); }) receivertype = ‘2‘; } console.log(numberArry); console.log(‘发送~~‘,timesDate); console.log(‘发送类型‘,receivertype); var sendShortData = {}; sendShortData.sendMessage = $(‘#status‘).val(); sendShortData.receiverNumber = numberArry;//以数组格式上传号码 sendShortData.receiverType = receivertype; sendShortData.sendTime = timesDate; sendShortData.sendType = sendTypeN; //发送短信请求接口 base.ajax({"type":"POST","url":"/ecapi/shortMessage/sendShort","data":sendShortData},function(res){ if(res.record == 1200){ $("#mask").addClass("hidden").html(); base.popo(res.msg); //短信发送记录查询 queryShortMessageFn({"shortTime":‘‘,"pageNum":1,"pageSize":10}); } }); } }) /*********************黑名单管理*********************** */ //黑名单管理请求数据 function blacklistFn(blacklistData){ base.ajax({"type":"GET","url":"/ecapi/shortMessage/blacklist",‘data‘:blacklistData},function(res){ if(res.record == 1200){ var blackTableHtml = $("#blackName").render(res.data); $("#mask").html(blackTableHtml); //分页 blacklistData.total = res.data.total; base.listPage(blacklistFn,blacklistData,"#black-tableForm-box",false); } }); } //点击显示黑名单弹窗 $(‘.serviceBtn .blackBtn‘).on(‘click‘,function(){ $(‘#mask‘).removeClass(‘hidden‘); //显示数据 blacklistFn({"pageNum":1,"pageSize":10}); }) //勾选复选框点击移除按钮 $(‘#mask‘).on(‘click‘,‘#J_black_name_box #removeBtn‘,function(){ var trLine = $(‘#blackNameTable tr‘); for(var i = 0;i){ if(trLine.eq(i).find(‘.subcheck‘).is(‘:checked‘)){ popInfotrue(); } } }) //是否将所选号码移除黑名单 function popInfotrue(){ var tryebox = $(‘#J_info_true_box‘).clone(); $(‘#mask‘).append(tryebox); $(‘#J_info_true_box‘).show(); $(‘#mask‘).removeClass(‘hidden‘); } //点击确定移除黑名单 $(‘#mask‘).on(‘click‘,‘#J_info_true_box .true‘,function(){ removeName(); $(‘#J_info_true_box‘).hide(); //移除黑名单管理请求数据 base.ajax({"type":"POST","url":"/ecapi/shortMessage/delBlacklist",‘data‘:{‘blackId‘:blackIdArry}},function(res){ if(res.record == 1200){ blacklistFn({"pageNum":1,"pageSize":10}); } }); }) function removeName(){ var trLine = $(‘#blackNameTable tr‘); for(var i = 0;i){ if(trLine.eq(i).find(‘.subcheck‘).is(‘:checked‘)){ trLine.eq(i).remove(); } } } //点击取消 $(‘#mask‘).on(‘click‘,‘#J_info_true_box .del‘,function(){ $(‘#J_info_true_box‘).hide(); }) //添加黑名单 $(‘#mask‘).on(‘keyup‘,‘#J_balckname‘,function(e){ var keycode = event.which; if (keycode == 13) { addBlackname(); } }); function addBlackname(){ //添加黑名单请求数据 var addBlacklistData = {}; addBlacklistData.number = $(‘#J_balckname‘).val(); base.ajax({"type":"POST","url":"/ecapi/shortMessage/addBlacklist",‘data‘:addBlacklistData},function(res){ if(res.record == 1200){ //base.alerts({"title":"提示","tip":"添加黑名单成功"},function(){}) base.popo(res.msg); blacklistFn({"pageNum":1,"pageSize":10}); }else if(res.record == 1500){ base.popo(res.msg); } }); } /* * 所有弹层关闭/取消 * 公用class="window-close/cancel" */ $("#mask").on(‘click‘,‘.window-close,.cancel‘,function(){ $(‘#mask‘).addClass(‘hidden‘).html(); }) /*==========================短信网关配置====================================================*/ base.ajax({"type":"GET","url":"/ecapi/shortMessage/checkGateway"},function(res){ if(res.record == 1200){ $(‘.congifSms-box‘).hide(); $(‘.smsService-box‘).show(); }else{ $(‘.smsService-box‘).hide(); $(‘.congifSms-box‘).show(); } }); function congifSmsFn(){ var param1Val = $(‘#param1‘).val(), param2Val = $(‘#param2‘).val(), param3Val = $(‘#param3‘).val(); if(param1Val == ‘‘ || param2Val == ‘‘ || param3Val == ‘‘){ $(‘.congifSms-box .btnWrapper .btn‘).addClass(‘greyBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).removeClass(‘blueBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).css(‘cursor‘,‘default‘); $(‘.congifSms-box .btnWrapper .btn‘).attr(‘disabled‘); }else{ $(‘.congifSms-box .btnWrapper .btn‘).removeClass(‘greyBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).addClass(‘blueBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).css(‘cursor‘,‘pointer‘); $(‘.congifSms-box .btnWrapper .btn‘).removeAttr(‘disabled‘); } } $(‘#param1,#param2,#param3‘).keydown(function(){ congifSmsFn(); }) $(‘#param1,#param2,#param3‘).keyup(function(){ congifSmsFn(); }) //点击确定保存 $(‘.congifSms-box‘).on(‘click‘,‘#sureBtn‘,function(){ var shortGateWayData = {}; shortGateWayData.param1 = $(‘#param1‘).val(); shortGateWayData.param2 = $(‘#param2‘).val(); shortGateWayData.param3 = $(‘#param3‘).val(); base.ajax({"type":"POST","url":"/ecapi/shortMessage/shortGateWay",‘data‘:shortGateWayData},function(res){ if(res.record == 1200){ $(‘.congifSms-box‘).hide(); $(‘.smsService-box‘).show(); base.popo(res.msg); }else{ $(‘.smsService-box‘).hide(); $(‘.congifSms-box‘).show(); base.popo(res.msg); } }); }) } return { init:init }; })

     

    刚使用requrie.js时的代码

    标签:ice   trim   focus   receiver   als   epo   addclass   数据   setw   

    原文地址:http://www.cnblogs.com/fayer/p/7296621.html


    评论


    亲,登录后才可以留言!