cjjlAdd.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. $(function () {
  2. /**
  3. * 初始化滚动条
  4. * */
  5. var iscroll;
  6. iscroll = new IScroll(".xzIscroll",{
  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. $("#dweb").bind("click", function() {
  45. var id = $("#id").val();
  46. if (id == "") {
  47. haifm.loadMobilePage("haifm", "getHaifmvCjjlSearchDweb.htm?mcid=" + $("#mcid").val() +"&date=" + $("#date").val());
  48. }
  49. });
  50. /**
  51. * 初始化输入框颜色等
  52. */
  53. if ($("#id").val() != "" && $("#id").val() != "0"){
  54. $("#date" ).prop("disabled" , true);
  55. $("#dweb" ).prop("disabled" , true);
  56. }
  57. /**
  58. * 自动初始化弹出框滑动模式
  59. * */
  60. (function($, window, document, undefined) {
  61. if ($.fn) {
  62. //自动初始化
  63. $.ready(function() {
  64. $('.mui-picker').picker();
  65. });
  66. }
  67. })(window.mui || window, window, document, undefined);
  68. /**
  69. * select舍栏框
  70. * */
  71. $("#sl,.sl").on("tap",function(e){
  72. if(event.preventDefault){
  73. event.preventDefault();
  74. }else{
  75. event.returnValue = false;
  76. }
  77. $(".slk").show(showOverlay());
  78. $(".slk").css({height:"auto",overflow: "initial"});
  79. });
  80. $("#overlay,.sjok").on("tap",function(){
  81. var checked = $('.sllist').find('.highlight').html();
  82. $("#sl").val(checked);
  83. var slData = $('.sllist').find('.highlight').data("for");
  84. $("#sl").attr("data-for", slData);
  85. $(".slk").hide(hideOverlay());
  86. setTimeout(function(){
  87. iscroll.refresh();
  88. }, 100);
  89. });
  90. /**
  91. * 气味
  92. * */
  93. $("#qw,.qw").on("tap",function(e){
  94. if(event.preventDefault){
  95. event.preventDefault();
  96. }else{
  97. event.returnValue = false;
  98. }
  99. $(".qwk").show(showOverlay());
  100. $(".qwk").css({height:"auto",overflow: "initial"});
  101. });
  102. $("#overlay,.sjok").on("tap",function(){
  103. var checked = $('.qwlist').find('.highlight').html();
  104. $("#qw").val(checked);
  105. var qwData = $('.qwlist').find('.highlight').data("for");
  106. $("#qw").attr("data-for", qwData);
  107. $(".qwk").hide(hideOverlay());
  108. setTimeout(function(){
  109. iscroll.refresh();
  110. }, 100);
  111. });
  112. /**
  113. * 颜色
  114. * */
  115. $("#ys,.ys").on("tap",function(e){
  116. if(event.preventDefault){
  117. event.preventDefault();
  118. }else{
  119. event.returnValue = false;
  120. }
  121. $(".ysk").show(showOverlay());
  122. $(".ysk").css({height:"auto",overflow: "initial"});
  123. });
  124. $("#overlay,.sjok").on("tap",function(){
  125. var checked = $('.yslist').find('.highlight').html();
  126. $("#ys").val(checked);
  127. var ysData = $('.yslist').find('.highlight').data("for");
  128. $("#ys").attr("data-for", ysData);
  129. $(".ysk").hide(hideOverlay());
  130. setTimeout(function(){
  131. iscroll.refresh();
  132. }, 100);
  133. });
  134. /**
  135. * 是否合格
  136. * */
  137. $("#sfhg,.sfhg").on("tap",function(e){
  138. if(event.preventDefault){
  139. event.preventDefault();
  140. }else{
  141. event.returnValue = false;
  142. }
  143. $(".tfk").show(showOverlay());
  144. $(".tfk").css({height:"auto",overflow: "initial"});
  145. });
  146. $("#overlay,.sjok").on("tap",function(){
  147. var checked = $('.tflist').find('.highlight').html();
  148. $("#sfhg").val(checked);
  149. var sfhgData = $('.tflist').find('.highlight').data("for");
  150. $("#sfhg").attr("data-for", sfhgData);
  151. $(".tfk").hide(hideOverlay());
  152. setTimeout(function(){
  153. iscroll.refresh();
  154. }, 100);
  155. });
  156. /**
  157. * 时间事件
  158. * */
  159. shijian();
  160. });
  161. /**
  162. * 时间事件
  163. * */
  164. function shijian() {
  165. mui.init();
  166. mui.ready(function() {
  167. var rqbtns = $('.showRq');
  168. rqbtns.each(function(i, showRq) {
  169. showRq.addEventListener('tap', function() {
  170. var that = this.value;
  171. dateP(showRq,that);
  172. }, false);
  173. });
  174. });
  175. }
  176. function dateP(inputClass,that) {
  177. var picker = new mui.DtPicker({
  178. type: "date",//设置日历初始视图模式
  179. value: that
  180. });
  181. picker.show(function(rs) {
  182. inputClass.value = rs.text;
  183. picker.dispose();
  184. });
  185. }
  186. /**
  187. * 显示遮罩层
  188. * */
  189. function showOverlay(){
  190. $("#overlay").height(pageHeight());
  191. $("#overlay").width(pageWidth());
  192. // fadeTo第一个参数为速度,第二个为透明度
  193. // 多重方式控制透明度,保证兼容性,但也带来修改麻烦的问题
  194. $("#overlay").fadeTo(200, 0.5);
  195. };
  196. /**
  197. * 隐藏覆盖层
  198. * */
  199. function hideOverlay(){
  200. $("#overlay").fadeOut(200);
  201. };
  202. /**
  203. * 当前页面高度
  204. */
  205. function pageHeight(){
  206. return document.body.scrollHeight;
  207. };
  208. /**
  209. * 当前页面宽度
  210. * */
  211. function pageWidth(){
  212. return document.body.scrollWidth;
  213. };
  214. /**
  215. * 保存
  216. * @param type
  217. */
  218. function saveCjjl(type) {
  219. //选择的日期不能大于当前日期
  220. var tof = EventUtil.dateLimit($("#date").val());
  221. if (!tof) {
  222. mui.alert('大于当前日期', '提示', function() {});
  223. return false;
  224. }
  225. var dweb = $("#cjdweb").val();
  226. var eph = $("#dweb").val();
  227. var date = $("#date").val();
  228. if (eph == "") {
  229. mui.alert('请输入正确的耳牌号!', '提示', function() {});
  230. return false;
  231. } else {
  232. jQuery('#cjjlForm').ajaxSubmit({
  233. dataType : 'json',
  234. data : {"mcid" : $("#mcid").val(),
  235. "id" :$("#id").val(),
  236. "dweb" :dweb,
  237. "date" :date,
  238. "sl" : $("#sl").attr("data-for"),
  239. "qw" : $("#qw").attr("data-for"),
  240. "ys" : $("#ys").attr("data-for"),
  241. "sfhg" : $("#sfhg").attr("data-for")
  242. },
  243. beforeSend:function() {//触发ajax请求开始时执行
  244. $('.save').attr('disabled',true);//改变提交按钮上的文字并将按钮设置为不可点击
  245. },
  246. success : function(msg) {
  247. // 保存成功
  248. if (msg.count == 1) {
  249. mui.toast('保存成功');
  250. haifm.loadMobilePage("haifm", "hvSjlrCjIndex.htm?mcid=" + $("#mcid").val());
  251. } else if (msg.count == 2) {
  252. mui.alert('采精时间不能大于入栏时间', '提示', function() {});
  253. $('.save').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  254. }
  255. },
  256. error : function(msg) {
  257. mui.alert('网络繁忙,请稍后再试...', '提示', function() {});
  258. $('.save').removeAttr("disabled");//改变提交按钮上的文字并将按钮设置为可点击
  259. },
  260. complete: function(msg) {
  261. //ajax请求完成时执行
  262. if (msg.count == 1) {
  263. $('.save').attr('disabled',true);//改变提交按钮上的文字并将按钮设置为不可点击
  264. }
  265. }
  266. });
  267. }
  268. }
  269. /**
  270. * 返回
  271. */
  272. function backUrl() {
  273. haifm.loadMobilePage("haifm", "hvSjlrCjIndex.htm?mcid=" + $("#mcid").val() + "&ksrq=" + $("#kssj").val() + "&jssj=" + $("#jsrq").val());
  274. }