cjjl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. $(function () {
  2. var zsIscrollHeight = $(".cjjlIscroll");
  3. var cententHeight = $(".cjjlIscroll div:first-child");
  4. heightvs(zsIscrollHeight,cententHeight);
  5. //初始化page
  6. if(localStorage.hasOwnProperty("cjIndexPage")) {
  7. $("#page").val(localStorage.getItem("cjIndexPage"));
  8. }
  9. //输入框快速删除初始化
  10. mui(".mui-input-row input").input();
  11. //时间初始化
  12. var date = new Date();
  13. var year = date.getFullYear()+"";
  14. var month = date.getMonth()+1;
  15. var day = date.getDate();
  16. date.setDate(date.getDate()-7);
  17. var lYear = date.getFullYear()+"";
  18. var lMonth = date.getMonth()+1;
  19. var lwDay = date.getDate();
  20. if ($("#startT").data("for") == "") {
  21. $("#startT .nian").html(lYear);
  22. $("#startT .yue").html(lMonth);
  23. $("#startT .ri").html(lwDay);
  24. } else {
  25. var ksrq = $("#startT").data("for");
  26. var ksrqArr = ksrq.split("-");
  27. $("#startT .nian").html(ksrqArr[0]);
  28. $("#startT .yue").html(ksrqArr[1]);
  29. $("#startT .ri").html(ksrqArr[2]);
  30. }
  31. if ($("#endT").data("for") == "") {
  32. $("#endT .nian").html(year);
  33. $("#endT .yue").html(month);
  34. $("#endT .ri").html(day);
  35. } else {
  36. var jsrq = $("#endT").data("for");
  37. var jsrqArr = jsrq.split("-");
  38. $("#endT .nian").html(jsrqArr[0]);
  39. $("#endT .yue").html(jsrqArr[1]);
  40. $("#endT .ri").html(jsrqArr[2]);
  41. }
  42. /**
  43. * 初始化滚动条
  44. * */
  45. var iscroll;
  46. iscroll = new IScroll(".cjjlIscroll",{
  47. scrollbars: true,
  48. fadeScrollbars:true,
  49. scrollbars: 'custom',
  50. shrinkScrollbars:'clip',
  51. probeType: 2,
  52. click:true
  53. });
  54. setTimeout(function(){
  55. iscroll.refresh();
  56. }, 600);
  57. /**
  58. * 点击input获取焦点
  59. * */
  60. $(".mui-input-row.mui-search,.mui-input-row .mui-input-clear~.mui-icon-clear:before").on("touchstart", function (e) {
  61. $("input[type='search']").focus();
  62. });
  63. /**
  64. * 滚动input以外失去焦点
  65. * */
  66. iscroll.on('scrollStart',function(e){
  67. var el = document.activeElement;
  68. if (el.nodeName.toLowerCase() == 'input') {
  69. el.blur();
  70. this.disable();
  71. this.enable();
  72. };
  73. return;
  74. });
  75. /**
  76. * 点击input以外失去焦点
  77. * */
  78. var beforeIpt=null;
  79. $("input").on("focus", function (e) {
  80. beforeIpt=this;
  81. });
  82. $(document).on("tap", function (e) {
  83. if(e.target.nodeName.toLowerCase()!="input") {
  84. if(beforeIpt) {
  85. beforeIpt.blur();
  86. beforeIpt=null;
  87. }
  88. }
  89. });
  90. /**
  91. * 开关事件
  92. * */
  93. onOff(iscroll,zsIscrollHeight,cententHeight);
  94. /**
  95. * 时间事件
  96. * */
  97. sjchaxun();
  98. /**
  99. * 弹出修改框
  100. * */
  101. confirm();
  102. //模糊查询键盘enter键事件
  103. $("input[type='search']").on('keypress',function(e) {
  104. var keycode = e.keyCode;
  105. if(keycode=='13') {
  106. e.preventDefault();
  107. //请求搜索接口
  108. clear();
  109. haifm.loadMobilePage("haifm", "hvSjlrCjIndex.htm?mcid=" + $("#mcid").val() + "&cxeph=" + $("#dweb").val());
  110. }
  111. });
  112. /**
  113. * 下拉加载
  114. */
  115. var pullUp = $("#pullUp"),
  116. pullUpLabel = $(".pullUpLabel"),
  117. loadingStep = 0;//加载状态0默认,1显示加载状态,2执行加载数据,只有当为0时才能再次加载,这是防止过快拉动刷新
  118. //滚动时触发
  119. iscroll.on("scroll",function(){
  120. if(loadingStep == 0 && !pullUp.attr("class").match('refresh')){
  121. if(this.y < (this.maxScrollY - 14)){//上拉加载更多
  122. pullUp.addClass("refresh").show();
  123. pullUp.css({"background":"","background-size":""});
  124. pullUpLabel.text("松手开始加载...");
  125. loadingStep = 1;
  126. iscroll.refresh();
  127. }
  128. }
  129. });
  130. //滚动结束触发
  131. iscroll.on("scrollEnd",function(){
  132. if(loadingStep == 1){
  133. if( pullUp.attr("class").match("refresh") ){//上拉加载操作
  134. pullUp.removeClass("refresh").addClass("loading");
  135. pullUpLabel.text("");
  136. pullUp.css({"background":"#D7DFEA url(views/haifmv/img/pullUp.gif) no-repeat center","background-size":"12%"});
  137. loadingStep = 2;
  138. pullUpAction();
  139. iscroll.refresh();
  140. }
  141. }
  142. //滑动定位
  143. var thisy = parseInt(this.y);
  144. localStorage.setItem("cjIndexY",thisy);
  145. });
  146. /**
  147. * 上拉加载方法
  148. * */
  149. function pullUpAction(){
  150. var kssj = $("#startT .nian").html()+"-" + $("#startT .yue").html()+"-" + $("#startT .ri").html();
  151. var jssj = $("#endT .nian").html()+"-" + $("#endT .yue").html()+"-" + $("#endT .ri").html();
  152. var page = parseInt($("#page").val())+1;
  153. var maxPages = $("#maxPages").val();
  154. if (page <= maxPages) {
  155. jQuery.ajax({
  156. type : "get",
  157. url : "addSjlrCjjl.htm",
  158. data : {
  159. "mcid" : $("#mcid").val(),
  160. "cxeph": $("#dweb").val(),
  161. "ksrq" : kssj,
  162. "jsrq" : jssj,
  163. "page" : page
  164. },
  165. dataType : "json",
  166. async : true,
  167. success : function(data) {
  168. var hc = localStorage.getItem("cjIndex");
  169. setTimeout(function() {
  170. var something = "";
  171. for (var i = 0 ; i < data.length; i++) {
  172. var obj = data[i];
  173. something += "<li class='mui-table-view-cell'>"
  174. + "<span style='margin-right: 0.2rem;'>"+obj.cjrq+"</span><span>(共"+obj.count+"头)</span>"
  175. + "<div class='mui-switch mui-active'>"
  176. + "<div class='mui-switch-handle'></div>"
  177. + "</div>"
  178. +"</li>"
  179. +"<li class='hiddenli xx"+i+"'></li>";
  180. for (var j = 0 ; j < obj.cjjlList.length ; j++) {
  181. var o = obj.cjjlList[j];
  182. something += "<div class='rowBox container-fluid' id='confirmBtn' data-id=" + o.id + " data-for=" + o.eph + ">"
  183. + "<div class='row'>"
  184. + "<div class='col-xs-7 col-sm-7 col-md-7 discenter'>耳牌号:<span id ='eph'>" + o.eph + "</span></div>"
  185. + "<div class='col-xs-5 col-sm-5 col-md-5 discenter'>状态:<span class='iofo'>" + o.sfhgStr+ "</span></div>"
  186. +"</div>"
  187. + "<div class='row'>"
  188. + "<div class='col-xs-7 col-sm-7 col-md-7 discenter'>采精量:<span>" + o.cjl + "ml</span></div>"
  189. + "<div class='col-xs-5 col-sm-5 col-md-5 discenter'>制备份数:<span>" + o.zbfs + "</span></div>"
  190. + "</div>"
  191. + "<div class='row'>"
  192. + "<div class='col-xs-7 col-sm-7 col-md-7 discenter'>精子活力:<span>" + o.jzhl + "</span></div>"
  193. + "<div class='col-xs-5 col-sm-5 col-md-5 discenter'></div>"
  194. + "</div>"
  195. + "</div>";
  196. };
  197. }
  198. $(".cjjlIscroll ul").append($(something));
  199. pullUp.attr("class","");
  200. pullUpLabel.text("上拉加载更多");
  201. pullUp.css({"background":""});
  202. iscroll.refresh();
  203. loadingStep = 0;
  204. localStorage.setItem("cjIndex",hc + something);
  205. onOff(iscroll,zsIscrollHeight,cententHeight);
  206. confirm();
  207. },1000);
  208. $("#page").val(page);
  209. localStorage.setItem("cjIndexPage",page);
  210. }
  211. });
  212. }else {
  213. pullUp.css({"background":"","background-size":""});
  214. pullUpLabel.text("没有数据了");
  215. iscroll.refresh();
  216. }
  217. }
  218. //加载缓存中的内容
  219. if (localStorage.hasOwnProperty("cjIndex")) {
  220. var sth = localStorage.getItem("cjIndex");
  221. $(".cjjlIscroll ul").append(sth.substring(4,sth.length));
  222. };
  223. //定位到上次离开的位置
  224. if (localStorage.hasOwnProperty("cjIndexY")) {
  225. var tall = localStorage.getItem("cjIndexY");
  226. iscroll.scrollTo(0,tall,1000, IScroll.utils.ease.elastic);
  227. iscroll.refresh();
  228. };
  229. });
  230. /**
  231. * 时间方法
  232. * */
  233. function sjchaxun(){
  234. mui.init();
  235. mui.ready(function() {
  236. //开始时间
  237. var startN = $('.nian')[0];
  238. var startnY = $('.yue')[0];
  239. var startR = $('.ri')[0];
  240. var startTbtns = $('#startT');
  241. startTbtns.each(function(i, startTbtn) {
  242. startTbtn.addEventListener('tap', function() {
  243. var dataFor = this.getAttribute('data-for');
  244. var that = this;
  245. dateP(startN,startnY,startR,dataFor,that);
  246. }, false);
  247. });
  248. //结束时间
  249. var endN = $('.nian')[1];
  250. var endY = $('.yue')[1];
  251. var endR = $('.ri')[1];
  252. var endTbtns = $('#endT');
  253. endTbtns.each(function(i, endTbtn) {
  254. endTbtn.addEventListener('tap', function() {
  255. var dataFor = this.getAttribute('data-for');
  256. var that = this;
  257. dateP(endN,endY,endR,dataFor,that);
  258. }, false);
  259. });
  260. });
  261. function dateP(nian,yue,ri,dataFor,that) {
  262. var picker = new mui.DtPicker({
  263. type: "date",//设置日历初始视图模式
  264. value: dataFor
  265. });
  266. picker.show(function(rs) {
  267. nian.innerHTML = rs.y.text;
  268. yue.innerHTML = rs.m.text;
  269. ri.innerHTML = rs.d.text;
  270. that.setAttribute('data-for',rs.value);
  271. picker.dispose();
  272. });
  273. }
  274. }
  275. /**
  276. * 返回
  277. * */
  278. function backUrl() {
  279. //清除定位和缓存
  280. clear();
  281. haifm.loadMobilePage("haifm", "haifmvMain.htm?uuid=" + $("#uuid").val() + "&mcid=" + $("#mcid").val() + "&qyid=" + $("#qyid").val() +"&toList=2");
  282. }
  283. /**
  284. * 新增
  285. * */
  286. function addUrl() {
  287. haifm.loadMobilePage("haifm", "hvSjlrCjAdd.htm?mcid=" + $("#mcid").val());
  288. };
  289. /**
  290. * 查询是否是24小时之内的数据
  291. * @param val
  292. */
  293. function checkDataIsIn24H(val1,val2) {
  294. var kssj = $("#startT .nian").html()+"-" + $("#startT .yue").html()+"-" + $("#startT .ri").html();
  295. var jssj = $("#endT .nian").html()+"-" + $("#endT .yue").html()+"-" + $("#endT .ri").html();
  296. jQuery.ajax({
  297. url : 'hvSjlrCjCheckDataIsIn24H.htm',
  298. dataType : 'json',
  299. type : 'post',
  300. cache : false,
  301. data : {
  302. "id" : val1,
  303. },
  304. success : function(data) {
  305. if (data.count > 0) {
  306. haifm.loadMobilePage("haifm", "hvSjlrCjAdd.htm?mcid=" + $("#mcid").val() + "&id=" + val1 + "&eph=" + val2 + "&kssj=" + kssj + "&jssj=" + jssj);
  307. } else {
  308. mui.alert('此数据非24小时之内的数据,不可修改', '提示', function() {});
  309. }
  310. },
  311. error : function(data) {
  312. mui.alert('网络异常!查询失败!', '提示', function() {});
  313. }
  314. });
  315. }
  316. function timeSearch() {
  317. var ksrq = $("#startT .nian").html() + "-" + $("#startT .yue").html() + "-" + $("#startT .ri").html();
  318. var jsrq = $("#endT .nian").html() + "-" + $("#endT .yue").html() + "-" + $("#endT .ri").html();
  319. haifm.loadMobilePage("haifm", "hvSjlrCjIndex.htm?mcid=" + $("#mcid").val() + "&ksrq=" + ksrq + "&jsrq=" + jsrq + "&searchFlag=" + "1");
  320. }
  321. //开关事件
  322. function onOff(iscroll,zsIscrollHeight,cententHeight){
  323. mui('.mui-content .mui-switch').each(function() { //循环所有toggle
  324. mui(this)['switch']();
  325. //toggle 事件监听
  326. this.addEventListener('toggle', function(event) {
  327. //event.detail.isActive 可直接获取当前状态
  328. var isActive = this.classList.contains("mui-active"); //判断打开ON或者关闭OFF
  329. if(isActive){ //打开状态
  330. $(this).parent().next().slideDown(500,function(){
  331. heightvs(zsIscrollHeight,cententHeight);
  332. iscroll.refresh();
  333. }).siblings('.hiddenli').stop().slideUp(500);
  334. $(".mui-switch").removeClass("mui-active").children().css({'transition-duration': '0.2s', 'transform': 'translate(0, 0px)'});
  335. $(this).toggleClass("mui-active");
  336. }else{ //关闭状态
  337. $(this).parent().next().slideUp(500,function(){
  338. heightvs(zsIscrollHeight,cententHeight);
  339. iscroll.refresh();
  340. });
  341. }
  342. });
  343. });
  344. }
  345. //修改事件
  346. function confirm(){
  347. (function($) {
  348. var confirmBtns = $("div[id*='confirmBtn']");
  349. confirmBtns.each(function(i, confirmBtns) {
  350. confirmBtns.addEventListener('tap', function() {
  351. var id = this.getAttribute("data-id");
  352. var btnArray = ['否', '是'];
  353. var ep = this.getAttribute("data-for");
  354. mui.confirm('是否对'+ep+'进行修改?','提示!', btnArray, function(e) {
  355. if (e.index == 1) {
  356. checkDataIsIn24H(id,ep);
  357. }
  358. });
  359. }, false);
  360. });
  361. })(mui);
  362. }
  363. //滑动高度和内容高度对比
  364. function heightvs(zsIscrollHeight,cententHeight){
  365. if(zsIscrollHeight.height() > cententHeight.height()){
  366. $("#pullUp").hide();
  367. }else{
  368. $("#pullUp").show();
  369. }
  370. }
  371. function clear(){
  372. if (localStorage.hasOwnProperty(id+"Index")) {
  373. localStorage.removeItem(id+"Index");
  374. }
  375. if (localStorage.hasOwnProperty(id+"IndexY")) {
  376. localStorage.removeItem(id+"IndexY");
  377. }
  378. if (localStorage.hasOwnProperty(id+"IndexPage")) {
  379. localStorage.removeItem(id+"IndexPage");
  380. }
  381. }