guanlian-family-members.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //基于mui的scroll之上
  2. function appendFamilyMember(obj,fun,cssfun,opts){
  3. var data = {},
  4. $obj = obj;
  5. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  6. if(userAgent){
  7. //删除represented字段
  8. if(userAgent.represented){
  9. delete userAgent.represented
  10. }
  11. window.localStorage.setItem(agentName,JSON.stringify(userAgent))
  12. }
  13. sendPost("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
  14. function queryAppoListSuccesss(res){
  15. if (res.status == 200) {
  16. // if (res.data.immunemembers > 0) {
  17. showMember(res);
  18. cssfun && cssfun.call(this);
  19. // }else{
  20. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  21. // }
  22. }else{
  23. //非200则为失败
  24. // queryListFailed(res);
  25. }
  26. }
  27. function queryListFailed(res) {
  28. // if (res && res.msg) {
  29. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  30. // } else {
  31. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  32. // }
  33. }
  34. function showMember(res){
  35. var html='',
  36. data=res.data.immunemembers;
  37. for(var i=0;i<data.length;i++){
  38. //"relation": 1//---1父亲 2母亲 3老公 4老婆 5儿子 6女儿 7其他
  39. if(data[i].relation==5){
  40. data[i].familyRelationName = '儿子'
  41. }else if(data[i].relation==6){
  42. data[i].familyRelationName = '女儿'
  43. }else{
  44. data[i].familyRelationName = '其他'
  45. }
  46. html = html + '<div class="mui-control-item" data-code="'+data[i].code+'" data-name="'+data[i].name+'" style="display: inline-block;margin-right: 15px;-webkit-user-select: none;vertical-align: middle;text-align: center;">\
  47. <div class="name" style="font-size: 12px;color: #333;line-height: 20px;">'+data[i].name+'('+data[i].familyRelationName+')</div></div>'
  48. }
  49. if(opts && opts.btns) {
  50. for(var i=0;i<opts.btns.length;i++){
  51. html = html + '<div id="'+(opts.btns[i].id||"")+'" style="display: inline-block;margin-right: 15px;-webkit-user-select: none;vertical-align: middle;text-align: center;">\
  52. <img style="width: 40px;height: 40px;border-radius: 50%;overflow: hidden;border:solid 1px #dcdcdc;" src="'+ opts.btns[i].img +'"/>\
  53. <div class="name" style="font-size: 12px;color: #333;line-height: 20px;">'+opts.btns[i].text+'</div></div>'
  54. }
  55. }
  56. html = '<div class="mui-scroll-wrapper family-member" style="position: absolute;z-index: 999;top: 0;bottom: 0;left: 0;overflow: hidden;width: 100%;height: 90px;background-color:#f3f3f3;padding-left: 15px;padding-top: 7px;border-bottom:solid 1px #dcdcdc;box-sizing: border-box;">\
  57. <div class="mui-scroll" style="position: absolute;width: auto;z-index: 99;white-space: nowrap;-webkit-transform: translateZ(0);transform: translateZ(0);">'+html+'</div></div>';
  58. $obj.append(html);
  59. setTimeout(function(){
  60. addEvent();
  61. },200)
  62. }
  63. function addEvent(){
  64. mui('.family-member').scroll({
  65. scrollY: false, //是否竖向滚动
  66. scrollX: true, //是否横向滚动
  67. });
  68. function active(one){
  69. one.find('img').css({width: '55px',height: '55px'});
  70. one.find('.name').css({'font-size': '14px','line-height':'23px'});
  71. }
  72. //关联被代理人
  73. var $ul = $obj.find('.mui-control-item');
  74. if(userAgent.represented){
  75. for(var i=0;i<$ul.length;i++){
  76. if($ul.eq(i).data('code') == userAgent.represented){
  77. active($ul.eq(i));
  78. window.localStorage.setItem('nowPatientName',$ul.eq(i).data('name'))
  79. }
  80. }
  81. }else{
  82. active($ul.eq(0));
  83. window.localStorage.setItem('nowPatientName',$ul.eq(0).data('name'))
  84. window.localStorage.setItem('nowPatientcode',$ul.eq(0).data('code'))
  85. }
  86. $obj.on('tap','.mui-control-item',function(){
  87. var $this = $(this),
  88. $code = $this.data('code');
  89. window.localStorage.setItem('nowPatientName',$this.data('name'))
  90. //添加represented字段
  91. var userobj = userAgent;
  92. userobj.represented = $code;
  93. var str = JSON.stringify(userobj);
  94. window.localStorage.setItem(agentName,str)
  95. $('.mui-control-item').find('img').css({width: '40px',height: '40px'});
  96. $('.mui-control-item').find('.name').css({'font-size': '12px','line-height':'20px'});
  97. active($this);
  98. fun && fun.call(this,$code);
  99. })
  100. }
  101. }
  102. //获取家庭所有成员
  103. function familyAllMembers(){
  104. var data = {};
  105. return new Promise(function(resolve, reject) {
  106. sendPost("patient/family/authorize_members", data, "json", "get", queryFailed, function(res){
  107. if (res.status == 200) {
  108. if (res.data.length > 0){
  109. resolve(res.data);
  110. } else {
  111. }
  112. }else{
  113. //非200则为失败
  114. queryFailed(res);
  115. }
  116. });
  117. })
  118. function queryFailed(res) {
  119. if (res && res.msg) {
  120. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  121. } else {
  122. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  123. }
  124. }
  125. }