hpSjlrRsjlAdd.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. $(function(){
  2. /* 滚轮 */
  3. var myScroll = new IScroll(".iscroll",{
  4. scrollbars: true,
  5. fadeScrollbars:true,
  6. scrollbars: 'custom',
  7. shrinkScrollbars:'clip',
  8. });
  9. setTimeout(function () {
  10. $("body").height(document.body.scrollHeight);
  11. myScroll.refresh();
  12. }, 250);
  13. /**
  14. * 滚动input以外失去焦点
  15. * */
  16. myScroll.on('scrollStart',function(e){
  17. var el = document.activeElement;
  18. if (el.nodeName.toLowerCase() == 'input') {
  19. el.blur();
  20. this.disable();
  21. this.enable();
  22. };
  23. return;
  24. });
  25. var theme="android-ics";
  26. $("#date").mobiscroll().date({
  27. lang: "zh",//显示中文
  28. theme: theme,//主题
  29. setText: '确定',//确认按钮名称
  30. cancelText: '取消',//取消按钮名称
  31. dateFormat: 'yy-mm-dd',// 日期格式
  32. dateOrder: 'yymmdd',//面板中日期排列格式
  33. display: 'bottom',//显示方式
  34. endYear:2050,//结束年份
  35. });
  36. if ($("#date").val() == "") {
  37. $("#date").val(new Date().getFullYear()+"-"+p(new Date().getMonth()+1)+"-"+p(new Date().getDate()));
  38. }
  39. if ($("#id").val() != "") {
  40. if ($("#dweb").val() != "") {
  41. $("#dweb" ).prop("disabled" , true);
  42. }
  43. }
  44. if ($("#id").val() != "" && $("#id").val() != "0"){
  45. $("#date" ).prop("disabled" , true);
  46. }
  47. $("#eph").bind("click", function() {
  48. haifmp.loadMobilePage("haifm", "getRsjlSearchDweb.htm?mcid=" + $("#mcid").val()+"&date=" + $("#date").val());
  49. });
  50. //点击input键盘弹出滚动区域translateY往上滚动;
  51. $(document).ready(function () {
  52. var clickQian = document.body.clientHeight;
  53. var switcha = true;
  54. var a = null;
  55. $("input[type='text']").on("tap",function(){
  56. a = $(".content")[0].style.transform.split(',')[1].split(' ')[1].match(/\d+(\.\d+)?/)[0];
  57. if($("input[type='text']") && switcha){
  58. setTimeout(function(){
  59. var clickHou = document.body.clientHeight;
  60. var zimujpHeight = clickQian - clickHou - a - 135 + "px";
  61. $(".content")[0].style.transform = "translateY(-"+zimujpHeight+")";
  62. myScroll.refresh();
  63. switcha = false;
  64. },250);
  65. }
  66. });
  67. });
  68. //元素失去焦点隐藏软键盘
  69. $("#rsjlForm").on("tap",function(e){
  70. if(e.target.nodeName != "INPUT"){
  71. $('input').blur();
  72. };
  73. });
  74. });
  75. /**
  76. * 保存
  77. * @param type
  78. */
  79. function saveRsjl(type) {
  80. //选择的日期不能大于当前日期
  81. var tof = EventUtil.dateLimit($("#date").val());
  82. if (!tof) {
  83. alert("大于当前日期");
  84. return false;
  85. }
  86. var dweb = $("#dweb").val();
  87. if (dweb == "") {
  88. alert("请输入正确的耳标号!");
  89. return false;
  90. } else {
  91. jQuery('#rsjlForm').ajaxSubmit({
  92. dataType : 'json',
  93. data : {"mcid" : $("#mcid").val(),
  94. "dweb" : dweb,
  95. "id" :$("#id").val()
  96. },
  97. beforeSend:function() {//触发ajax请求开始时执行
  98. if (type == 1){
  99. $(".sub").text("提交中……");
  100. $('.sub').attr('disabled',true);//改变提交按钮上的文字并将按钮设置为不可点击
  101. } else {
  102. $(".subAdd").text("提交中……");
  103. $('.subAdd').attr('disabled',true);//改变提交按钮上的文字并将按钮设置为不可点击
  104. }
  105. },
  106. success : function(msg) {
  107. // 保存成功
  108. if (msg.count == 1) {
  109. alert("保存成功!");
  110. if (type == "1") {
  111. haifmp.loadMobilePage("haifm", "hpSjlrRsIndex.htm?mcid=" + $("#mcid").val());
  112. } else {
  113. haifmp.loadMobilePage("haifm", "hpSjlrRsAdd.htm?mcid=" + $("#mcid").val());
  114. }
  115. }else if (msg.count == 2) {
  116. alert("已有该妊娠记录,请勿重复保存");
  117. if (type == "1") {
  118. $('.sub').text('保存');
  119. $('.sub').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  120. } else {
  121. $('.subAdd').text('保存并新增');
  122. $('.subAdd').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  123. }
  124. }else if (msg.count ==3) {
  125. alert("妊娠时间小于配种时间");
  126. if (type == "1") {
  127. $('.sub').text('保存');
  128. $('.sub').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  129. } else {
  130. $('.subAdd').text('保存并新增');
  131. $('.subAdd').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  132. }
  133. }
  134. },
  135. error : function(msg) {
  136. if (type == "1") {
  137. alert('网络繁忙,请稍后再试...');
  138. $('.sub').text('保存');
  139. $('.sub').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  140. } else {
  141. alert('网络繁忙,请稍后再试...');
  142. $('.subAdd').text('保存并新增');
  143. $('.subAdd').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  144. }
  145. },
  146. complete: function(msg) {
  147. //ajax请求完成时执行
  148. if (msg.count == 1) {
  149. if (type == 1){
  150. $(".sub").text("提交中……");
  151. $('.sub').attr('disabled',true);//改变提交按钮上的文字并将按钮设置为不可点击
  152. } else {
  153. $(".subAdd").text("提交中……");
  154. $('.subAdd').attr('disabled',true);//改变提交按钮上的文字并将按钮设置为不可点击
  155. }
  156. }
  157. }
  158. });
  159. }
  160. }
  161. /**
  162. * 返回
  163. */
  164. function backUrl() {
  165. haifmp.loadMobilePage("haifm", "hpSjlrRsIndex.htm?mcid=" + $("#mcid").val());
  166. }