ttjlAdd.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. $(function () {
  2. /**
  3. * 初始化滚动条
  4. * */
  5. var iscroll;
  6. iscroll = new IScroll(".xzttIscroll",{
  7. scrollbars: true,
  8. fadeScrollbars:true,
  9. scrollbars: 'custom',
  10. shrinkScrollbars:'clip',
  11. click:true
  12. });
  13. setTimeout(function(){
  14. $("body").height(document.body.scrollHeight);
  15. iscroll.refresh();
  16. }, 600);
  17. /**
  18. * 滚动input以外失去焦点
  19. * */
  20. iscroll.on('scrollStart',function(e){
  21. var el = document.activeElement;
  22. if (el.nodeName.toLowerCase() == 'input') {
  23. el.blur();
  24. this.disable();
  25. this.enable();
  26. };
  27. return;
  28. });
  29. /**
  30. * 点击input以外失去焦点
  31. * */
  32. var beforeIpt=null;
  33. $("input").on("focus", function (e) {
  34. beforeIpt=this;
  35. });
  36. $(document).on("tap", function (e) {
  37. if(e.target.nodeName.toLowerCase()!="input") {
  38. if(beforeIpt) {
  39. beforeIpt.blur();
  40. beforeIpt=null;
  41. }
  42. }
  43. });
  44. /**
  45. * 自动初始化弹出框滑动模式
  46. * */
  47. (function($, window, document, undefined) {
  48. if ($.fn) {
  49. //自动初始化
  50. $.ready(function() {
  51. $('.mui-picker').picker();
  52. });
  53. }
  54. })(window.mui || window, window, document, undefined);
  55. $("#eph").bind("click", function() {
  56. var id = $("#id").val();
  57. if (id == "") {
  58. haifm.loadMobilePage("haifm", "getHaifmvZzttSearchDweb.htm?mcid=" + $("#mcid").val() +"&date=" + $("#date").val());
  59. }
  60. });
  61. //日期不能修改
  62. if ($("#id").val() != "" && $("#id").val() != "0"){
  63. $("#date" ).prop("disabled" , true);
  64. $("#eph" ).prop("disabled" , true);
  65. }
  66. /**
  67. * 淘汰类型
  68. * */
  69. $("#ttlx,.ttlx").on("tap",function(e){
  70. if(event.preventDefault){
  71. event.preventDefault();
  72. }else{
  73. event.returnValue = false;
  74. }
  75. $(".ttlxk").show(showOverlay());
  76. $(".ttlxk").css({height:"auto",overflow: "initial"});
  77. });
  78. $("#overlay,.sjok").on("tap",function(){
  79. var checked = $('.ttlxlist').find('.highlight').html();
  80. $("#ttlx").val(checked);
  81. var ttlxData = $('.ttlxlist').find('.highlight').data("for");
  82. $("#ttlx").attr("data-for", ttlxData);
  83. $(".ttlxk").hide(hideOverlay());
  84. setTimeout(function(){
  85. iscroll.refresh();
  86. }, 100);
  87. });
  88. /**
  89. * 转入舍栏
  90. * */
  91. $("#zrsl,.zrsl").on("tap",function(e){
  92. if(event.preventDefault){
  93. event.preventDefault();
  94. }else{
  95. event.returnValue = false;
  96. }
  97. $(".zrslk").show(showOverlay());
  98. $(".zrslk").css({height:"auto",overflow: "initial"});
  99. });
  100. $("#overlay,.sjok").on("tap",function(){
  101. var checked = $('.zrsllist').find('.highlight').html();
  102. $("#zrsl").val(checked);
  103. var zrslData = $('.zrsllist').find('.highlight').data("for");
  104. $("#zrsl").attr("data-for", zrslData);
  105. $(".zrslk").hide(hideOverlay());
  106. setTimeout(function(){
  107. iscroll.refresh();
  108. }, 100);
  109. });
  110. /**
  111. * 时间事件
  112. * */
  113. shijian();
  114. });
  115. /**
  116. * 时间事件
  117. * */
  118. function shijian() {
  119. mui.init();
  120. mui.ready(function() {
  121. var rqbtns = $('.showRq');
  122. rqbtns.each(function(i, showRq) {
  123. showRq.addEventListener('tap', function() {
  124. var that = this.value;
  125. dateP(showRq,that);
  126. }, false);
  127. });
  128. });
  129. }
  130. function dateP(inputClass,that) {
  131. var picker = new mui.DtPicker({
  132. type: "date",//设置日历初始视图模式
  133. value: that
  134. });
  135. picker.show(function(rs) {
  136. inputClass.value = rs.text;
  137. picker.dispose();
  138. });
  139. }
  140. /**
  141. * 显示遮罩层
  142. * */
  143. function showOverlay(){
  144. $("#overlay").height(pageHeight());
  145. $("#overlay").width(pageWidth());
  146. // fadeTo第一个参数为速度,第二个为透明度
  147. // 多重方式控制透明度,保证兼容性,但也带来修改麻烦的问题
  148. $("#overlay").fadeTo(200, 0.5);
  149. };
  150. /**
  151. * 隐藏覆盖层
  152. * */
  153. function hideOverlay(){
  154. $("#overlay").fadeOut(200);
  155. };
  156. /**
  157. * 当前页面高度
  158. */
  159. function pageHeight(){
  160. return document.body.scrollHeight;
  161. };
  162. /**
  163. * 当前页面宽度
  164. * */
  165. function pageWidth(){
  166. return document.body.scrollWidth;
  167. };
  168. /**
  169. * 返回
  170. */
  171. function backUrl() {
  172. haifm.loadMobilePage("haifm", "hvSjlrZzttIndex.htm?mcid=" + $("#mcid").val() + "&ksrq=" + $("#kssj").val() + "&jssj=" + $("#jsrq").val());
  173. }
  174. /**
  175. * 保存
  176. * @param type
  177. */
  178. function saveZztt(type) {
  179. //选择的日期不能大于当前日期
  180. var tof = EventUtil.dateLimit($("#date").val());
  181. if (!tof) {
  182. mui.alert('大于当前日期', '提示', function() {});
  183. return false;
  184. }
  185. var dweb = $("#dweb").val();
  186. var eph = $("#eph").val();
  187. if (eph == "") {
  188. mui.alert('请输入正确的耳牌号!', '提示', function() {});
  189. return false;
  190. } else {
  191. jQuery('#zzttForm').ajaxSubmit({
  192. dataType : 'json',
  193. data : {"mcid" : $("#mcid").val(),
  194. "dweb" : dweb,
  195. "eph" : eph,
  196. "ttlx" : $("#ttlx").attr("data-for"),
  197. "zrsl" : $("#zrsl").attr("data-for"),
  198. "ttsj" : $("#date").val()
  199. },
  200. beforeSend:function() {//触发ajax请求开始时执行
  201. $('.save').attr('onclick','javascript:void(0)');//改变提交按钮上的文字并将按钮设置为不可点击
  202. },
  203. success : function(msg, data) {
  204. // 保存成功
  205. if (msg.result=1) {
  206. mui.toast('保存成功');
  207. haifm.loadMobilePage("haifm", "hvSjlrZzttIndex.htm?mcid=" + $("#mcid").val());
  208. }else if (msg.count ==2) {
  209. mui.alert('淘汰时间小于种猪入栏日期', '提示', function() {});
  210. $('.save').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  211. }
  212. },
  213. error : function(data) {
  214. mui.alert('网络繁忙,请稍后再试...', '提示', function() {});
  215. $('.save').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  216. },
  217. complete: function(msg, data){
  218. //ajax请求完成时执行
  219. if(msg.result==1){
  220. $('.save').attr('onclick','javascript:void(0)');//改变提交按钮上的文字并将按钮设置为不可点击
  221. }
  222. }
  223. });
  224. }
  225. }