change-login.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var dd = dialog({contentType:'load', skin:'bk-popup', content:'提交中...'});
  3. var id = 0;
  4. var openid =null;
  5. var userUid =null;
  6. //var firstUid = window.localStorage.getItem("firstUid");
  7. //var firstName = window.localStorage.getItem("firstName");
  8. var userAgent = window.localStorage.getItem(agentName);
  9. var username = "";
  10. var userphoto = "../../../images/p-default.png";
  11. var index = 0;
  12. var usercode = "";
  13. var chooseName = "";
  14. var pagetype=11;
  15. if(userAgent){
  16. var jsonstr = $.parseJSON(userAgent);
  17. openid = jsonstr.openid;
  18. userUid = jsonstr.uid;
  19. }
  20. var scroller1 = new IScrollPullUpDown('wrapper',{
  21. probeType:2,
  22. bounceTime: 250,
  23. bounceEasing: 'quadratic',
  24. mouseWheel:false,
  25. scrollbars:true,
  26. fadeScrollbars:true,
  27. click:true,
  28. interactiveScrollbars:false
  29. }, pullDownAction, null);
  30. $(function(){
  31. $(".tips a").on("click", function () {
  32. window.location.href = server + "wx/html/home/html/login.html?type=11&openid=" + openid;
  33. });
  34. // 判断是否登录
  35. checkUserAgent();
  36. // 点击咨询详情
  37. $("body").on("tap", ".n-list", function () {
  38. index = $(this).parents("li").index();
  39. if ($(this).is(".list-last")) {
  40. window.location.href = "../../jtgx/html/add-step1.html";
  41. } else if ($(this).is(".on")) {
  42. return ;
  43. } else {
  44. dd.show();
  45. chooseName = $(this).find("h2").html();
  46. var data = {};
  47. data.family = $(this).data("code");
  48. data.openid = openid;
  49. sendPost("patient/switch_account", data, "json", "post", changeFailed, changeSuccesss);
  50. }
  51. });
  52. // 点击登录
  53. $("#login").on("click", function () {
  54. clearAgent();
  55. window.location.href = "../../home/html/login.html?type=11&openid="+openid;
  56. });
  57. });
  58. //下拉刷新
  59. function pullDownAction(theScrollerTemp) {
  60. $(".pullDown").show();
  61. setTimeout(function () {
  62. $("#ul_family").html("");
  63. queryInit();
  64. }, 1000);
  65. }
  66. //上拉加载数据
  67. function pullUpAction(theScrollerTemp) {
  68. $(".pullUp").show();
  69. setTimeout(function () {
  70. queryInit();
  71. }, 1000);
  72. }
  73. // 禁止拖动
  74. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
  75. /**
  76. * 界面数据初始化
  77. */
  78. function queryInit() {
  79. d.show();
  80. var data={};
  81. sendPost('patient/baseinfo', data, 'json', 'post', queryFailed, querySuccess);
  82. }
  83. function queryFailed(res) {
  84. d.close();
  85. if (res && res.msg) {
  86. var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  87. } else {
  88. var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  89. }
  90. }
  91. function querySuccess(res) {
  92. if (res.status == 200) {
  93. var resData = res.data;
  94. if (resData.name) {
  95. username = resData.name;
  96. // 提示
  97. // var text;
  98. // if (userUid == firstUid) {
  99. // text = '您可在首次登录账号的家人中自由切换,若需切换到其他账号,请直接登录其账号。<a id="login" href="javascript:;">登陆其他账号</a>'
  100. // } else {
  101. // text = '因您通过' + firstName + '账号切换过来,故只可切换至与' + firstName + '有家庭关系的账号,已自动过滤不可切换的账号。若想切换到' + username + '的其他家人账号,请直接登录' + username + '账号后切换。<a id="login" href="javascript:;">登陆其他账号</a>';
  102. // }
  103. // $("#tip").html(text);
  104. }
  105. if (resData.photo && resData.photo != "") {
  106. userphoto = getImgUrl(resData.photo);
  107. }
  108. var data = {};
  109. data.patient = userUid;
  110. usercode = resData.code;
  111. data.isAgree = 1;//已经同意授权
  112. sendPost("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
  113. } else {
  114. //非200则为失败
  115. queryFailed(res);
  116. }
  117. }
  118. function queryListFailed(res) {
  119. d.close();
  120. if (res && res.msg) {
  121. var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  122. } else {
  123. var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  124. }
  125. }
  126. function queryAppoListSuccesss(res) {
  127. if (res.status == 200) {
  128. var $list = document.querySelector("#ul_family");
  129. var $liFirst = document.createElement("li");
  130. firstContent = '<div class="n-list dr-item c-border on" data-code="' + usercode + '">'+
  131. '<div class="n-list-li">'+
  132. '<div class="n-list-key">'+
  133. '<div class="n-avatar-l">'+
  134. '<img class="c-images-cycle" src="' + userphoto + '">'+
  135. '</div>'+
  136. '</div>'+
  137. '<div class="n-list-info pl15">'+
  138. '<h2>' + username + '</h2>'+
  139. // '<p>自己</p>'+
  140. '</div>'+
  141. '<div class="n-list-key checked">'+
  142. '<i class="icon-checked"></i>'+
  143. '</div>'+
  144. '</div>'+
  145. '</div>';
  146. $liFirst.innerHTML = firstContent;
  147. $list.appendChild($liFirst);
  148. if (res.data.normalmembers.length > 0) {
  149. var list = res.data.normalmembers;
  150. for (var i = 0; i < list.length; i++) {
  151. var $li = document.createElement("li");
  152. var code = list[i].code;
  153. var name = list[i].name;
  154. var familyRelationName = list[i].familyRelationName;
  155. var photo = getImgUrl(list[i].photo);
  156. if(userUid == code){
  157. continue;
  158. }
  159. // 头像为空设置默认头像
  160. if(photo == undefined || photo == null || photo == ""){
  161. photo = "../../../images/p-default.png";
  162. }
  163. var childContent = "";
  164. childContent = '<div class="n-list dr-item c-border" data-code="' + code + '">'+
  165. '<div class="n-list-li">'+
  166. '<div class="n-list-key">'+
  167. '<div class="n-avatar-l">'+
  168. '<img class="c-images-cycle" src="' + photo + '">'+
  169. '</div>'+
  170. '</div>'+
  171. '<div class="n-list-info pl15">'+
  172. '<h2>' + name + '</h2>'+
  173. // '<p>' + familyRelationName + '</p>'+
  174. '</div>'+
  175. '<div class="n-list-key checked">'+
  176. '<i class="icon-checked"></i>'+
  177. '</div>'+
  178. '</div>'+
  179. '</div>';
  180. $li.innerHTML = childContent;
  181. $list.appendChild($li);
  182. }
  183. // var $liLast = document.createElement("li");
  184. // lastContent = '<div class="n-list list-last dr-item c-t-center">'+
  185. // '<i class="icon-add"></i>'+
  186. // '<p>添加家人</p>'+
  187. // '</div>';
  188. // $liLast.innerHTML = lastContent;
  189. // $list.appendChild($liLast);
  190. }
  191. // else {
  192. // var $li = document.createElement("li");
  193. // var content = '<div class="n-list list-last dr-item c-t-center">'+
  194. // '<i class="icon-add"></i>'+
  195. // '<p>添加家人</p>'+
  196. // '</div>';
  197. // $li.innerHTML = content;
  198. // $list.appendChild($li);
  199. // }
  200. d.close();
  201. scroller1.myScroll.refresh();
  202. $(".pullUp").hide();
  203. $(".pullDown").hide();
  204. } else {
  205. //非200则为失败
  206. queryListFailed(res);
  207. }
  208. }
  209. function changeFailed(res) {
  210. dd.close();
  211. if (res && res.msg) {
  212. var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  213. } else {
  214. var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  215. }
  216. }
  217. function changeSuccesss(res) {
  218. if (res.status == 200) {
  219. dd.close();
  220. var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  221. var resData = res.data;
  222. $("#ul_family").find(".n-list").removeClass("on");
  223. $("#ul_family").find("li").eq(index).find(".n-list").addClass("on");
  224. wxSaveUserAgent(resData.id, resData.uid, openid, resData.token,resData.lastUid);
  225. wxSaveUserAgent1(resData.uid, resData.name, resData.photo);
  226. setTimeout(function () {
  227. window.location.href = "my-detail.html";
  228. }, 1000);
  229. } else {
  230. //非200则为失败
  231. changeFailed(res);
  232. }
  233. // else if (res.status == -2) {
  234. // dd.close();
  235. // var d2 = dialog({
  236. // content:'对不起,您与' + chooseName + '无家庭关系哦,如需登录' + chooseName + '账号,请直接登录或登录' + chooseName + '账号后切换',
  237. // okValue: "直接登录",
  238. // ok: function (){
  239. // var jsonstr = $.parseJSON(agentOpenid);
  240. // var openid = jsonstr.openid;
  241. // window.location.href = server + "wx/html/home/html/login.html?type=11&openid=" + openid;
  242. // },
  243. // cancelValue: "不了,谢谢",
  244. // cancel: function () {
  245. // }
  246. // }).showModal();
  247. // }
  248. }