family-members.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. }
  69. //关联被代理人
  70. var $ul = $obj.find('.mui-control-item');
  71. if(userAgent.represented){
  72. for(var i=0;i<$ul.length;i++){
  73. if($ul.eq(i).data('code') == userAgent.represented){
  74. active($ul.eq(i));
  75. window.localStorage.setItem('nowPatientName',$ul.eq(i).data('name'))
  76. }
  77. }
  78. }else{
  79. active($ul.eq(0));
  80. window.localStorage.setItem('nowPatientName',$ul.eq(0).data('name'))
  81. }
  82. $obj.on('tap','.mui-control-item',function(){
  83. var $this = $(this),
  84. $code = $this.data('code');
  85. window.localStorage.setItem('nowPatientName',$this.data('name'))
  86. //添加represented字段
  87. var userobj = userAgent;
  88. userobj.represented = $code;
  89. var str = JSON.stringify(userobj);
  90. window.localStorage.setItem(agentName,str)
  91. $('.mui-control-item').find('img').css({width: '40px',height: '40px'});
  92. $('.mui-control-item').find('.name').css({'font-size': '12px','line-height':'20px'});
  93. active($this);
  94. fun && fun.call(this,$code);
  95. })
  96. }
  97. }
  98. //获取家庭所有成员
  99. function familyAllMembers(){
  100. var data = {};
  101. return new Promise(function(resolve, reject) {
  102. sendPost("patient/family/authorize_members", data, "json", "get", queryFailed, function(res){
  103. if (res.status == 200) {
  104. if (res.data.length > 0){
  105. resolve(res.data);
  106. } else {
  107. }
  108. }else{
  109. //非200则为失败
  110. queryFailed(res);
  111. }
  112. });
  113. })
  114. function queryFailed(res) {
  115. if (res && res.msg) {
  116. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  117. } else {
  118. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  119. }
  120. }
  121. }