tel.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. $(function(){
  2. tel={
  3. //总入口
  4. init:function(){
  5. var that=this;
  6. that.validate('#hack',that.msg.no_tel,that.btnname.just_white);
  7. //that.validate('#bind',that.msg.no_tel,that.btnname.just_white);
  8. that.time('#hack');
  9. //that.close('#close');
  10. that.close('#go');
  11. that.active();
  12. that.blurValidatetel('keyup');
  13. that.blurValidatetel('blur');
  14. that.message('#message');
  15. },
  16. //弹出信息
  17. msg:{
  18. no_tel:'请认真填写你的手机号',
  19. no_yanz:'请填写验证码',
  20. yanz_err:'验证码错误',
  21. lg:'该手机已经领取过红包',
  22. no_lq:'该手机不能领取红包',
  23. remove:'获取验证码哦',
  24. over:'该手机已经领取过红包',
  25. no_pass:'该手机号不能领取红包'
  26. },
  27. //按钮信息
  28. btnname:{
  29. just_white:'这就写',
  30. rewrite:'重新填写',
  31. check:'知道了'
  32. },
  33. //判断验证顺序
  34. b:false,
  35. //插入验证结构
  36. validate:function(id,msg,btnmsg,sj){
  37. var that=this;
  38. $(id).on('touchstart',function(e){
  39. e.preventDefault();//阻止浏览器默认事件
  40. var telVal=$('#tel_number').val(),
  41. tel=new RegExp("^[1][3-8]+\\d{9}");
  42. //console.log(tel.test(telVal));
  43. //验证输入手机规则
  44. if(telVal==''||(!tel.test(telVal))){
  45. that.appendDom(msg,btnmsg);//插入HTML弹窗结构
  46. that.b=false;
  47. }
  48. else{
  49. that.b=true;
  50. return;
  51. }
  52. })
  53. },
  54. blurValidatetel:function(eve){
  55. var that=this;
  56. $("#tel_number").on(eve,function(){
  57. var thisVal=$(this).val(),
  58. tel=new RegExp("^[1][3-8]+\\d{9}");
  59. if(thisVal==''||(!tel.test(thisVal))){
  60. that.b=false;
  61. return false;
  62. }
  63. else {
  64. that.b=true;
  65. }
  66. })
  67. },
  68. //dom结构
  69. appendDom:function(msg,btnmsg){
  70. var dom='<div class="layer_box center" id="bomb">'+
  71. '<div class="layer">'+
  72. '<div class="top_msg">'+
  73. '<p>'+msg+'</p>'+
  74. '</div>'+
  75. '<div class="bottom_btn">'+
  76. '<p id="go">'+btnmsg+'</p>'+
  77. '</div>'+
  78. '</div>'+
  79. '</div>';
  80. $('body').append(dom);
  81. },
  82. //留言
  83. input_msg:function(){
  84. var dom='<div class="layer_box" id="bomb">'+
  85. '<div class="layer" style="padding-bottom: 2px">'+
  86. '<div class="top_msg" style="padding: 0 20px;line-height: 126px">'+
  87. '<div><textarea id="pass_msg" placeholder="写下你想说的话" style="width:98%;height:50px;font-size: 1.2rem"></textarea></div>'+
  88. '</div>'+
  89. '<div class="bottom_btn center" style="background: #fff;">'+
  90. '<p id="go" class="post_btn" style="float: left;width: 50%;border-top: 1px solid #bfbfbf;color: #000;">取消</p>'+
  91. '<p id="post" style="float:left; color: #ff4e4e;width: 49.5%;border-top: 1px solid #bfbfbf;border-left: 1px solid #bfbfbf;">发送</p>'+
  92. '</div>'+
  93. '</div>'+
  94. '</div>';
  95. $('body').append(dom);
  96. },
  97. //关闭弹出
  98. close:function(id){
  99. $(id).live('touchstart',function(e){
  100. e.preventDefault();
  101. $('#bomb').remove();
  102. });
  103. },
  104. //倒计时
  105. time:function(id,msg,btnmsg){
  106. var that=this,
  107. times=function(){
  108. if(that.b==false){
  109. return;
  110. }
  111. tel = $("#tel_number").val();
  112. var url_host=window.location.hostname;
  113. $.post("http://" + url_host + "/mobile/index.php?act=login&op=getcode&type=getbonus&client_type=ajax", {
  114. mobile: tel
  115. }), function (data, status) {
  116. return;
  117. };
  118. var yzVal = $('#yanz').val(),
  119. time = 60,
  120. a = setInterval(function () {
  121. time = time - 1;
  122. $(id).text(time);
  123. if (time == 0) {
  124. clearInterval(a);
  125. $(id).text('重新发送');
  126. }
  127. }, 1000);
  128. };
  129. $(id).on('touchstart', function () {
  130. //判断倒计时是否开始了
  131. var text = $(this).text();
  132. if (text == '重新发送' || text == '获取验证码') {
  133. times();
  134. }
  135. else {
  136. return;
  137. }
  138. })
  139. },
  140. //验证码验证
  141. active: function () {
  142. var that = this;
  143. $('#bind').on('touchstart', function () {
  144. var b = that.b;
  145. //yanzVal = $('#yanz').val();
  146. if (b == false) {
  147. that.appendDom(that.msg.no_tel, that.btnname.just_white);
  148. }
  149. else {
  150. if (yanzVal == '') {
  151. that.appendDom(that.msg.no_yanz, that.btnname.just_white);
  152. }
  153. else {
  154. var yanzVal = $("#yanz").val();
  155. var tel = $("#tel_number").val();
  156. var alink = $("#url").val();
  157. var bonus_sn = $("#mine_bonus").val();
  158. var url_host=window.location.hostname;
  159. $.ajax({
  160. type:'post',
  161. dataType:'json',
  162. url:'http://'+url_host + '/mobile/index.php?act=bonusex&op=bind&client_type=ios',
  163. data:{
  164. mobile: tel,
  165. code: yanzVal,
  166. bonus_sn:bonus_sn
  167. },
  168. success:function(data) {
  169. if (data.code==200) {
  170. var tel = $("#tel_number").val();
  171. var alink = $("#url").val();
  172. var other_html='';
  173. var html='';
  174. var ser = function binded_info(){
  175. function formatDate(now) {
  176. //var year=now.getYear()+1900;
  177. var month=now.getMonth()+1;
  178. var date=now.getDate();
  179. var hour=now.getHours();
  180. var minute=now.getMinutes();
  181. var second=now.getSeconds();
  182. return month+"-"+date+" "+hour+":"+minute;
  183. }
  184. //其他用户的结构
  185. var other_ser=data.datas.binded_info;
  186. var king=data.datas.type_info.max_amount;
  187. var mine_bonus_sn=data.datas.mine_bonus.bonus_sn;
  188. var mine_bonus_value = data.datas.mine_bonus.bonus_value;
  189. var comment=data.datas.binded_info;
  190. //红包金额
  191. $('.price span').text(mine_bonus_value);
  192. for(var i=0;i<other_ser.length;i++){
  193. var king_icon='',
  194. mine ='',
  195. user_comment='';
  196. if(other_ser[i].bonus_sn==mine_bonus_sn){
  197. mine = '<a href="javascript:void(0)" id="message" style="color: #1927D1">留言</a>'
  198. }
  199. else {
  200. mine=formatDate(new Date(parseInt(other_ser[i].get_time)*1000));
  201. }
  202. if(other_ser[i].binded_over == 1 && other_ser[i].bonus_value==king) {
  203. king_icon = '<s class="king"></s>手气最佳';
  204. }
  205. if(comment[i].user_comment==''){
  206. user_comment='';
  207. }
  208. else {
  209. user_comment=comment[i].user_comment;
  210. }
  211. other_html+='<div class="li">'+
  212. '<div class="li_left">'+
  213. '<p class="p">'+other_ser[i].user_name+'</p>'+
  214. '<p class="prompt" id="my_prompt">'+mine+'</p>'+
  215. '<p style="color:#9b9b9b">'+user_comment+'</p>'+
  216. '</div>'+
  217. '<div class="li_right">'+
  218. '<p class="p">'+other_ser[i].bonus_value+'</p>'+
  219. '<p class="king_box">'+king_icon+'</p>'+
  220. '</div>'+
  221. '</div>';
  222. }
  223. var binded_num=data.datas.type_info.binded_num,
  224. total_num=data.datas.type_info.total_num,
  225. //抢购数量
  226. shtml='<div class="prompt text_left">'+
  227. '<p class="prompt pro">领取'+binded_num+'/'+total_num+'个</p>'+
  228. '</div>';
  229. html+=shtml+other_html;
  230. return html;
  231. };
  232. $('.list').html(ser());
  233. $('#bind_link').hide();
  234. $('#link').css('display','block').addClass('link_but');
  235. } else {
  236. that.appendDom(that.msg.yanz_err, that.btnname.rewrite);
  237. }
  238. }
  239. });
  240. }
  241. }
  242. })
  243. },
  244. //留言框
  245. message:function(id){
  246. var that=this;
  247. $(id).live('touchstart',function(){
  248. if($(this).text()!=='留言'){
  249. return false;
  250. }
  251. else{
  252. that.input_msg(that.msg.no_yanz, that.btnname.just_white);
  253. $('#pass_msg').focus();
  254. }
  255. });
  256. $('#post').live('touchstart',function(){
  257. var msg=$('#pass_msg').val();
  258. if(msg==''){return false;}
  259. else {
  260. var url_host=window.location.hostname;
  261. var my_bonus_sn=$('#mine_bonus').val();
  262. $.post("http://" + url_host + "/mobile/index.php?act=bonusex&op=comment&client_type=ajax", {
  263. comment: msg,
  264. bonus_sn:my_bonus_sn
  265. }),function (data, status) {
  266. return false;
  267. };
  268. $('#message').text(msg).css('color','9b9b9b');
  269. $('#bomb').remove();
  270. }
  271. });
  272. $('#pass_msg').live('textInput',function(){
  273. var msg_length=$(this).val().length;
  274. if(msg_length>20){
  275. $(this).val($(this).val().substr(0,20));
  276. }
  277. })
  278. }
  279. };
  280. tel.init();
  281. });