family-members.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/authorize_members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
  14. function queryAppoListSuccesss(res){
  15. if (res.status == 200) {
  16. if (res.data.length > 0) {
  17. showMember(res);
  18. if(res.data.length == 1){
  19. $obj.hide();
  20. }else{
  21. cssfun && cssfun.call(this);
  22. }
  23. }else{
  24. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  25. }
  26. }else{
  27. //非200则为失败
  28. // queryListFailed(res);
  29. }
  30. }
  31. function queryListFailed(res) {
  32. // if (res && res.msg) {
  33. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  34. // } else {
  35. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  36. // }
  37. }
  38. function showMember(res){
  39. var html='',
  40. data=res.data;
  41. for(var i=0;i<data.length;i++){
  42. 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;">\
  43. <img style="width: 40px;height: 40px;border-radius: 50%;overflow: hidden;border:solid 1px #dcdcdc;" src="'+ getImgUrl(data[i].photo)+'"/>\
  44. <div class="name" style="font-size: 12px;color: #333;line-height: 20px;">'+data[i].name+'('+data[i].familyRelationName+')</div></div>'
  45. }
  46. if(opts && opts.btns) {
  47. for(var i=0;i<opts.btns.length;i++){
  48. 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;">\
  49. <img style="width: 40px;height: 40px;border-radius: 50%;overflow: hidden;border:solid 1px #dcdcdc;" src="'+ opts.btns[i].img +'"/>\
  50. <div class="name" style="font-size: 12px;color: #333;line-height: 20px;">'+opts.btns[i].text+'</div></div>'
  51. }
  52. }
  53. 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;">\
  54. <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>';
  55. $obj.append(html);
  56. setTimeout(function(){
  57. addEvent();
  58. },100)
  59. }
  60. function addEvent(){
  61. mui('.family-member').scroll({
  62. scrollY: false, //是否竖向滚动
  63. scrollX: true, //是否横向滚动
  64. });
  65. function active(one){
  66. one.find('img').css({width: '55px',height: '55px'});
  67. one.find('.name').css({'font-size': '14px','line-height':'23px'});
  68. window.localStorage.setItem('nowPatientCode',one.attr("data-code"))
  69. }
  70. //关联被代理人
  71. var $ul = $obj.find('.mui-control-item');
  72. if(userAgent.represented){
  73. for(var i=0;i<$ul.length;i++){
  74. if($ul.eq(i).data('code') == userAgent.represented){
  75. active($ul.eq(i));
  76. window.localStorage.setItem('nowPatientName',$ul.eq(i).data('name'))
  77. }
  78. }
  79. }else{
  80. active($ul.eq(0));
  81. window.localStorage.setItem('nowPatientName',$ul.eq(0).data('name'))
  82. }
  83. $obj.on('tap','.mui-control-item',function(){
  84. var $this = $(this),
  85. $code = $this.data('code');
  86. window.localStorage.setItem('nowPatientName',$this.data('name'))
  87. //添加represented字段
  88. var userobj = userAgent;
  89. userobj.represented = $code;
  90. var str = JSON.stringify(userobj);
  91. window.localStorage.setItem(agentName,str)
  92. $('.mui-control-item').find('img').css({width: '40px',height: '40px'});
  93. $('.mui-control-item').find('.name').css({'font-size': '12px','line-height':'20px'});
  94. active($this);
  95. fun && fun.call(this,$code);
  96. })
  97. }
  98. }
  99. //获取家庭所有成员
  100. function familyAllMembers(){
  101. var data = {};
  102. return new Promise(function(resolve, reject) {
  103. sendPost("patient/family/authorize_members", data, "json", "get", queryFailed, function(res){
  104. if (res.status == 200) {
  105. if (res.data.length > 0){
  106. resolve(res.data);
  107. } else {
  108. }
  109. }else{
  110. //非200则为失败
  111. queryFailed(res);
  112. }
  113. });
  114. })
  115. function queryFailed(res) {
  116. if (res && res.msg) {
  117. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  118. } else {
  119. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  120. }
  121. }
  122. }