my-equipments.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. var pagesize = 15;
  2. var id = 0 ;
  3. var d = dialog({contentType:'load', skin:'bk-popup'});
  4. var scroller1 = null;
  5. var pagetype = 6;
  6. var prescriptionCode;//续方咨询跳转过来绑定
  7. $(function() {
  8. checkUserAgent();
  9. Request = GetRequest();
  10. var openid = Request["openid"];
  11. prescriptionCode = Request["prescriptionCode"];
  12. scroller1= new IScrollPullUpDown('wrapper',{
  13. probeType:2,
  14. bounceTime: 250,
  15. bounceEasing: 'quadratic',
  16. mouseWheel:true,
  17. scrollbars:true,
  18. click:true,
  19. fadeScrollbars:true,
  20. interactiveScrollbars:false
  21. },pullDownAction,pullUpAction);
  22. bindEvents();
  23. getEquipments();
  24. //下拉刷新
  25. function pullDownAction(theScrollerTemp) {
  26. // $(".pullUp").show();
  27. // setTimeout(function () {
  28. // $(".c-list").html("");
  29. // id=0;
  30. // getEquipments();
  31. // }, 1000);
  32. }
  33. //上拉加载数据
  34. function pullUpAction(theScrollerTemp) {
  35. // $(".pullUp").show();
  36. // setTimeout(function () {
  37. // getEquipments();
  38. // }, 1000);
  39. }
  40. })
  41. appendFamilyMember($('#memberContainer'),function(){
  42. $(".c-list").html("");
  43. $(".div-no-info").hide();
  44. $(".main").show();
  45. id=0;
  46. getEquipments()
  47. },function(){
  48. //判断有授权家人,修改样式
  49. if($('#memberContainer').is(':hidden')){
  50. $('#wrapper').css('top','0px');
  51. }else{
  52. $('#wrapper').css('top','90px');
  53. $('.div-no-info').css('padding-top','150px');
  54. }
  55. });
  56. function getEquipments(){
  57. var params = {};
  58. params.id=id;
  59. params.pagesize = pagesize;
  60. d.show();
  61. sendPost("patient/device/PatientDeviceList",params,"JSON","GET",queryListFailed,queryListSuccess);
  62. }
  63. function queryListSuccess(res){
  64. d.close();
  65. if(res.status==200){
  66. if(res.data&&res.data.length>0){
  67. for(var i in res.data){
  68. showList(res.data[i]);
  69. }
  70. id = res.data[res.data.length-1].id;
  71. console.log(id)
  72. scroller1.myScroll.refresh();
  73. }else{
  74. if(id==0){
  75. $(".div-no-info").show();
  76. $(".main").hide();
  77. }else{
  78. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'无更多设备!'}).show();
  79. }
  80. }
  81. $(".pullUp").hide();
  82. }else{
  83. queryListFailed(res);
  84. }
  85. }
  86. function showList(rowData){
  87. var img='xuetangyi_icon.png';
  88. if(rowData.categoryCode==2){
  89. img='xueyaji_icon.png';
  90. }
  91. var bindUser ="自己绑定";
  92. if(rowData.doctor){
  93. bindUser = "医生绑定";
  94. }else if(rowData.agent){
  95. bindUser = "家人绑定";
  96. }
  97. var showDomLi = '<li device-id="'+rowData.deviceId+'" data-type="'+rowData.categoryCode+'" data-id="'+rowData.id+'">'+
  98. '<div class="icon-div">'+
  99. '<img src="../images/'+img+'">'+
  100. '</div>'+
  101. '<div style="width: calc(100% - 90px);"><div class="div-content">'+rowData.deviceName+'</div>'+
  102. '<div class="div-sn"><span class="bullspan">&bull; </span>绑定时间:'+rowData.czrq+'</div>'+
  103. '<div class="div-name"><span class="bullspan">&bull;</span> '+bindUser+'</div></div>'+
  104. '</li>';
  105. $(".c-list").append(showDomLi);
  106. }
  107. function queryListFailed(res) {
  108. d.close();
  109. if (res && res.msg) {
  110. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  111. } else {
  112. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'加载设备列表失败'}).show();
  113. }
  114. }
  115. //绑定事件
  116. function bindEvents(){
  117. //绑定编辑和删除事件
  118. $(".c-list").on("click","li div",function(){
  119. var code = $(this.parentElement).attr("data-id");
  120. var deviceId = $(this.parentElement).attr("device-id");
  121. var type = $(this.parentElement).attr("data-type");
  122. if(type==1){
  123. location.href="view-xuetangyi.html?deviceId="+deviceId+"&id="+code;
  124. }else if(type==2){
  125. location.href="view-xueyaji.html?deviceId="+deviceId+"&id="+code;
  126. }
  127. })
  128. function deleteSn(code){
  129. sendPost("patient/device/DeletePatientDevice?id="+code,{},"JSON","DELETE",function(res){
  130. if (res && res.msg) {
  131. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  132. } else {
  133. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  134. }
  135. },function(res){
  136. if(res.status==200){
  137. $(".c-list").html("");
  138. id=0;
  139. getEquipments();
  140. }else{
  141. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  142. }
  143. })
  144. }
  145. //新增按钮事件
  146. $(".div-add-btn").on("click",function(){
  147. $(this).hide();
  148. if($(this).hasClass("active")){
  149. $(".modal-overlay").trigger("click");
  150. }else{
  151. $(this).addClass("active");
  152. $(".modal-overlay").addClass("modal-overlay-visible");
  153. $(".div-dialog-content").show();
  154. }
  155. });
  156. //点击遮罩事件
  157. $(".modal-overlay").on("click",function(){
  158. $(".modal-overlay").removeClass("modal-overlay-visible");
  159. $(".div-dialog-content").hide();
  160. $(".div-add-btn").removeClass("active");
  161. $(".div-add-btn").show();
  162. });
  163. //取消事件
  164. $(".quxiao").on("click",function(){
  165. $(".modal-overlay").trigger("click");
  166. });
  167. //点击血糖仪事件
  168. $(".xuetangyi-icon").on("click",function(){
  169. $(this).addClass("active");
  170. window.location.href = "list-xuetangyi.html?category_code=1&prescriptionCode="+prescriptionCode;
  171. });
  172. //点击血压计事件
  173. $(".xueyaji-icon").on("click",function(){
  174. $(this).addClass("active");
  175. window.location.href = "list-xueyaji.html?category_code=2&prescriptionCode="+prescriptionCode;
  176. });
  177. }
  178. //初始化左滑/右滑事件
  179. function initTouch(){
  180. //滑动事件
  181. $(function(){
  182. $.extend({CycTounch:function(EV,X,Y){
  183. var valx=50;
  184. console.log(EV.target)
  185. if((Math.abs(X)>Math.abs(Y))&& Math.abs(X)>50){
  186. var obj=$(EV.target).closest("li");
  187. if(X>0){
  188. obj.removeClass("on")
  189. obj.animate({"left":"0"})
  190. obj.find(".c-arrow-r").animate({"right":"10px"})
  191. obj.find(".del").animate({"right":"-75px"})
  192. console.log('右滑');
  193. }else{
  194. obj.addClass("on")
  195. obj.animate({"left":"-75px"})
  196. obj.find(".c-arrow-r").animate({"right":"10px"})
  197. obj.find(".del").animate({"right":"-75px"})
  198. console.log('左滑');
  199. }
  200. }
  201. }})
  202. })
  203. window.addEventListener('load',load, false);
  204. }
  205. function pushHistory() {
  206. var state = {
  207. title: "title",
  208. url: "#"
  209. };
  210. setTimeout(function (){
  211. window.history.pushState(state, "title", "#");
  212. },1000);
  213. }
  214. pushHistory();
  215. setTimeout( function () {
  216. window.addEventListener("popstate", function(e) {
  217. WeixinJSBridge.call('closeWindow');
  218. }, false);
  219. }, 300);