family.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var id = 0;
  3. var pagetype = 22;
  4. var scroller1 = new IScrollPullUpDown('wrapper',{
  5. probeType:2,
  6. bounceTime: 250,
  7. bounceEasing: 'quadratic',
  8. mouseWheel:false,
  9. scrollbars:true,
  10. click:true,
  11. fadeScrollbars:true,
  12. interactiveScrollbars:false
  13. }, pullDownAction, null);
  14. $(function(){
  15. // 判断是否登录
  16. checkUserAgent();
  17. $('#msgContainer').on('tap',function() {
  18. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  19. window.location.href = "application-msg-list.html?member="+userAgent.uid;
  20. });
  21. // 点击咨询详情
  22. $("body").on("tap", ".n-list.tap-enable", function () {
  23. if ($(this).is(".list-last")) {
  24. window.location.href = "add-step1.html";
  25. } else {
  26. // 缓存信息
  27. var index = $(this).parents("li").index();
  28. var name = $(this).data("name");
  29. var imgUrl = $(this).find("img").attr("src");
  30. var code = $(this).data("code");
  31. var mobile = $(this).data("mobile");
  32. var idcard = $(this).data("idcard");
  33. var address = $(this).data("address");
  34. var sign = $(this).data("sign");
  35. var relation,
  36. relationIndex = "relation" + index;
  37. relation = $(this).data("relation");
  38. window.localStorage.removeItem(relationIndex);
  39. window.localStorage.setItem(relationIndex, relation);
  40. window.localStorage.removeItem("index");
  41. window.localStorage.setItem("index", index);
  42. window.localStorage.removeItem("name");
  43. window.localStorage.setItem("name", name);
  44. window.localStorage.removeItem("imgUrl");
  45. window.localStorage.setItem("imgUrl", imgUrl);
  46. window.localStorage.removeItem("code");
  47. window.localStorage.setItem("code", code);
  48. window.localStorage.removeItem("mobile");
  49. window.localStorage.setItem("mobile", mobile);
  50. window.localStorage.removeItem("idcard");
  51. window.localStorage.setItem("idcard", idcard);
  52. window.localStorage.removeItem("address");
  53. window.localStorage.setItem("address", address);
  54. window.localStorage.removeItem("sign");
  55. window.localStorage.setItem("sign", sign);
  56. // 跳转详情
  57. window.location.href = "family-detail.html";
  58. }
  59. });
  60. //免疫关联
  61. $("body").on("tap", ".n-list.childSick", function (){
  62. var $this = $(this)
  63. location.href="../../fybj/html/mianyijihua.html"
  64. })
  65. bindEvents();
  66. });
  67. //下拉刷新
  68. function pullDownAction(theScrollerTemp) {
  69. $(".pullDown").show();
  70. setTimeout(function () {
  71. $("#ul_family").html("");
  72. queryInit();
  73. }, 1000);
  74. }
  75. //上拉加载数据
  76. function pullUpAction(theScrollerTemp) {
  77. $(".pullUp").show();
  78. setTimeout(function () {
  79. queryInit();
  80. }, 1000);
  81. }
  82. // 禁止拖动
  83. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
  84. function bindEvents() {
  85. $('#wrapper').on('tap','.cancel-btn',function() {
  86. var id = $(this).attr('data-id');
  87. dialog({
  88. content: '确定撤销添加此家人的申请吗?',
  89. ok: function() {
  90. cancelApplicationPromise(id)
  91. .then(function(res) {
  92. if(res.status=="200") {
  93. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销成功"}).show();
  94. $("#ul_family").html("");
  95. queryInit();
  96. } else {
  97. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg||"撤销失败"}).show();
  98. }
  99. },function() {
  100. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销失败"}).show();
  101. }).catch(function(e) {
  102. console && console.error(e)
  103. })
  104. },
  105. cancel: function() {
  106. return;
  107. }
  108. }).showModal();
  109. }).on('tap','.retry-btn',function() {
  110. var code = $(this).attr('data-code');
  111. var mobile = $(this).attr('data-mobile');
  112. var name = $(this).attr('data-name');
  113. var relation = $(this).attr('data-relation');
  114. var photo = $(this).attr('data-photo');
  115. retryApplication(name,code,mobile,relation,photo);
  116. }).on('tap','.immunememberConnec',function(){
  117. location.href="../../fybj/html/mianyijihua.html"
  118. });
  119. }
  120. /**
  121. * 界面数据初始化
  122. */
  123. function queryInit() {
  124. d.show();
  125. var data = {};
  126. sendPostNoCache("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
  127. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  128. getFamilyMesListPromise(userAgent.uid)
  129. .then(function(res) {
  130. if(res.status == "200") {
  131. if(res.data.mes && res.data.mes.length) {
  132. var unhandledMsgs = _.filter(res.data.mes,function(v) {
  133. return v.state == '0'
  134. });
  135. if(unhandledMsgs.length) {
  136. $('#msgNum').text('('+unhandledMsgs.length+')')
  137. }
  138. }
  139. } else {
  140. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  141. }
  142. });
  143. }
  144. function queryListFailed(res) {
  145. d.close();
  146. if (res && res.msg) {
  147. var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg});
  148. } else {
  149. var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'});
  150. }
  151. }
  152. function queryAppoListSuccesss(res) {
  153. if (res.status == 200) {
  154. var $list = document.querySelector("#ul_family");
  155. if (res.data && res.data.normalmembers.length > 0) {
  156. var list = res.data.normalmembers;
  157. window.localStorage.removeItem("userfamily");
  158. window.localStorage.setItem("userfamily", JSON.stringify(res.data));
  159. for (var i = 0; i < list.length; i++) {
  160. var $li = document.createElement("li");
  161. var code = list[i].code;
  162. var name = list[i].name;
  163. var mobile = list[i].mobile;
  164. var idcard = list[i].idcard;
  165. var address = list[i].address;
  166. var familyRelation = list[i].familyRelation;
  167. var photo = getImgUrl(list[i].photo);
  168. var signType=list[i].signType;
  169. var isAuthorize = list[i].isAuthorize;
  170. var state = list[i].state; // 状态(0 :未处理;1:已同意;2:已拒绝;3:已撤销)
  171. var id = list[i].id;
  172. // 手机不存在默认显示未绑定手机
  173. if(mobile == undefined || mobile == null || mobile == ""){
  174. mobile = "未绑定手机";
  175. }
  176. // 地址不存在或者为空显示空
  177. if(address == undefined || address == null || address == ""){
  178. address = "";
  179. }
  180. // 头像为空设置默认头像
  181. if(photo == undefined || photo == null || photo == ""){
  182. photo = "../../../images/p-default.png";
  183. }
  184. // 家庭关系
  185. var relation = "";
  186. if (familyRelation == 0) {
  187. relation = "其他";
  188. } else if (familyRelation == 1) {
  189. relation = "父亲";
  190. } else if (familyRelation == 2) {
  191. relation = "母亲";
  192. } else if (familyRelation == 3) {
  193. relation = "老公";
  194. } else if (familyRelation == 4) {
  195. relation = "老婆";
  196. } else if (familyRelation == 5) {
  197. relation = "儿子";
  198. } else if (familyRelation == 6) {
  199. relation = "女儿";
  200. } else if (familyRelation == 7) {
  201. relation = "未知";
  202. };
  203. // 签约类型
  204. var signTmpl = "";
  205. var signText = "";
  206. if (signType == 0) {
  207. signTmpl = '<p class="red">未签约</p>';
  208. signText = "未签约";
  209. } else {
  210. if (signType == 1) {
  211. signText = "三师共管";
  212. } else if (signType == 2) {
  213. signText = "家庭医生";
  214. } else if (signType == 3) {
  215. signText = "三师共管、家庭医生";
  216. }
  217. signTmpl = '<p>签约类型:' + signText + '</p>'
  218. }
  219. var childContent = "";
  220. if(state == "1") {
  221. childContent = '<div class="c-list c-border dr-item list-wrap"><div class="n-list tap-enable" data-name="' + name + '" data-mobile="' + mobile + '" data-idcard="' + idcard + '" data-code="' + code + '" data-address="' + address + '" data-sign="' + signText + '" data-relation="' + familyRelation + '">'+
  222. '<div class="n-list-li">'+
  223. '<div class="n-list-key">'+
  224. '<div class="n-avatar-l">'+
  225. '<img class="c-images-cycle" src="' + photo + '">'+
  226. '</div>'+
  227. '</div>'+
  228. '<div class="n-list-info pl15">'+
  229. '<h2>' + name + '(' + relation + ')</h2>'+ signTmpl +
  230. '</div>'+
  231. '</div>'+
  232. '</div>'+
  233. '<li class="c-list-cover">'+
  234. '<div class="c-list-info">'+
  235. '<h4 class="c-nowrap c-f14">授权设置</h4>'+
  236. '<p class="c-nowrap">是否允许该家人处理您全部健康服务</p>'+
  237. '</div>'+
  238. '<div class="c-list-key">'+
  239. '<div data-code="' + code + '" class="mui-switch mui-switch-mini '+(isAuthorize=="1"?'mui-active':'')+
  240. '"><div class="mui-switch-handle"></div></div></div>'
  241. '</div>'+
  242. '</li>'
  243. ;
  244. } else if(state == "0") {
  245. childContent = '<div class="c-list c-border dr-item list-wrap"><div class="n-list" data-name="' + name + '" data-mobile="' + mobile + '" data-idcard="' + idcard + '" data-code="' + code + '" data-address="' + address + '" data-sign="' + signText + '" data-relation="' + familyRelation + '">'+
  246. '<div class="n-list-li">'+
  247. '<div class="n-list-key">'+
  248. '<div class="n-avatar-l">'+
  249. '<img class="c-images-cycle" src="' + photo + '">'+
  250. '</div>'+
  251. '</div>'+
  252. '<div class="n-list-info pl15">'+
  253. '<h2>' + name + '(' + relation + ')</h2>'+ '<p class="red">待对方确认关联</p>' +
  254. '</div>'+
  255. '</div>'+
  256. '</div>'+
  257. '<div class="ptb10 plr10 c-border-t">'+
  258. '<div class="c-row">'+
  259. '<div class="c-50"><div data-name="'+name+'" data-code="'+code+'" data-mobile="'+mobile+'" data-relation="'+familyRelation+'"data-photo="'+photo+'" class="c-btn c-btn-full c-btn-radius c-btn-4dcd70 retry-btn">重新添加</div></div>'+
  260. '<div class="c-50"><div data-id="'+id+'" class="c-btn c-btn-full c-btn-radius c-btn-fc6155 cancel-btn">&emsp;撤销&emsp;</div></div>'+
  261. '</div>'+
  262. '</div>'
  263. ;
  264. } else if(state == "2") {
  265. childContent = '<div class="c-list c-border dr-item list-wrap"><div class="n-list childSick" data-name="' + name + '" data-idcard="' + idcard + '" data-code="' + code + '">'+
  266. '<div class="n-list-li">'+
  267. '<div class="n-list-key">'+
  268. '<div class="n-avatar-l">'+
  269. '<img class="c-images-cycle" src="' + photo + '">'+
  270. '</div>'+
  271. '</div>'+
  272. '<div class="n-list-info pl15">'+
  273. '<h2>' + name + '(免疫关联)</h2>'+'<p>未签约</p>'
  274. '</div>'+
  275. '</div>'+
  276. '</div>';
  277. }
  278. $li.innerHTML = childContent;
  279. $list.appendChild($li);
  280. }
  281. if( res.data.immunemembers && res.data.immunemembers.length > 0){
  282. var listImmunemembers = res.data.immunemembers;
  283. for(var j = 0; j < listImmunemembers.length; j++){
  284. var $li = document.createElement("li");
  285. var immunememberName = listImmunemembers[j].name;
  286. var immunememberPhoto = getImgUrl(listImmunemembers[j].photo);
  287. // 头像为空设置默认头像
  288. if(immunememberPhoto == undefined || immunememberPhoto == null || immunememberPhoto == ""){
  289. immunememberPhoto = "../../../images/p-default.png";
  290. }
  291. childContent = '<div class="c-list c-border dr-item list-wrap immunememberConnec"><div class="n-list childSick" data-name="' + immunememberName + '" data-idcard="' + idcard + '" data-code="' + code + '">'+
  292. '<div class="n-list-li">'+
  293. '<div class="n-list-key">'+
  294. '<div class="n-avatar-l">'+
  295. '<img class="c-images-cycle" src="' + immunememberPhoto + '">'+
  296. '</div>'+
  297. '</div>'+
  298. '<div class="n-list-info pl15">'+
  299. '<h2>' + immunememberName + '(免疫关联)</h2>'
  300. // +'<p>未签约</p>'
  301. '</div>'+
  302. '</div>'+
  303. '</div>';
  304. $li.innerHTML = childContent;
  305. $list.appendChild($li);
  306. }
  307. }
  308. var $liLast = document.createElement("li");
  309. lastContent = '<div class="n-list tap-enable list-last dr-item c-t-center">'+
  310. '<i class="icon-add"></i>'+
  311. '<p>添加家人</p>'+
  312. '</div>';
  313. $liLast.innerHTML = lastContent;
  314. $list.appendChild($liLast);
  315. } else {
  316. var $li = document.createElement("li");
  317. var content = '<div class="n-list tap-enable list-last dr-item c-t-center">'+
  318. '<i class="icon-add"></i>'+
  319. '<p>添加家人</p>'+
  320. '</div>';
  321. $li.innerHTML = content;
  322. $list.appendChild($li);
  323. }
  324. d.close();
  325. scroller1.myScroll.refresh();
  326. $(".pullUp").hide();
  327. $(".pullDown").hide();
  328. } else {
  329. //非200则为失败
  330. queryListFailed(res);
  331. }
  332. mui('.mui-switch')['switch']();
  333. $('.mui-switch').on('toggle',function(e) {
  334. var event = e.originalEvent;
  335. d.show()
  336. var isAuthorize = event.detail.isActive?1:0;
  337. var msg = isAuthorize?'授权':'取消授权';
  338. sendPost("patient/family/member_authorize", {
  339. familyMember: $(this).data('code'),
  340. isAuthorize: isAuthorize
  341. }, "json", "post", function() {
  342. d.close();
  343. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg+'失败'}).show();
  344. }, function(){
  345. d.close();
  346. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:(msg+'成功')}).show();
  347. });
  348. })
  349. }
  350. function getFamilyMesListPromise(code) {
  351. return new Promise(function(resolve, reject) {
  352. sendPost("patient/family/getFamilyMesList", {
  353. code: code
  354. } , "json", "POST",
  355. function failed (res) {
  356. d.close();
  357. }, function(res) {
  358. resolve(res)
  359. });
  360. })
  361. }
  362. function cancelApplicationPromise(id) {
  363. d.show();
  364. return new Promise(function(resolve, reject) {
  365. sendPost("patient/family/member_revoke", {
  366. id: id
  367. } , "json", "POST",
  368. function failed (res) {
  369. d.close();
  370. reject(res);
  371. }, function(res) {
  372. d.close();
  373. resolve(res)
  374. });
  375. })
  376. }
  377. function checkMemberPromise(code) {
  378. return new Promise(function(resolve, reject) {
  379. sendPost("patient/family/check_member", {
  380. memberCode: code
  381. }, "json", "get", commitFailed, function(res) {
  382. resolve(res)
  383. });
  384. })
  385. }
  386. // 提交失败
  387. function commitFailed (res) {
  388. d.close();
  389. if (res && res.msg) {
  390. var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  391. } else {
  392. var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  393. }
  394. }
  395. function sendWXTempPromise(data) {
  396. return new Promise(function(resolve, reject) {
  397. sendPost("patient/family/sendWXTemp", data , "json", "POST", commitFailed, function(res) {
  398. resolve(res)
  399. });
  400. })
  401. }
  402. function retryApplication(name,code,mobile,relation,photo) {
  403. d.show();
  404. window.localStorage.removeItem("familyCode");
  405. window.localStorage.setItem("familyCode", code);
  406. window.localStorage.removeItem("familyName");
  407. window.localStorage.setItem("familyName", name);
  408. window.localStorage.removeItem("familyImgUrl");
  409. window.localStorage.setItem("familyImgUrl", photo);
  410. window.localStorage.removeItem("familyRelation");
  411. window.localStorage.setItem("familyRelation", relation);
  412. checkMemberPromise(code)
  413. .then(function(res) {
  414. d.close();
  415. if(res.status == "200") {
  416. var state = res.data.state;
  417. if(state == "0") { // 未绑定微信和手机
  418. window.location.href = 'add-step3.html';
  419. } else if(state == "1") { // 仅绑定微信
  420. sendWXTempPromise({
  421. member: code,
  422. relation: relation,
  423. reAdd: "1" // 重新申请
  424. })
  425. .then(function(res) {
  426. if(res.status=="200") {
  427. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"已发送添加申请"}).show();
  428. } else {
  429. if(res.msg){
  430. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  431. }else
  432. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"发送失败"}).show();
  433. }
  434. })
  435. } else if(state == "2") { // 仅绑定手机
  436. window.localStorage.removeItem("familyMobile");
  437. window.localStorage.setItem("familyMobile", mobile);
  438. window.location.href = 'add-step2.html';
  439. } else if(state== "3") { // 手机和微信都绑定
  440. window.localStorage.removeItem("familyMobile");
  441. window.localStorage.setItem("familyMobile", mobile);
  442. window.location.href = 'add-step2-pre.html?reAdd=1';
  443. }
  444. } else {
  445. d.close();
  446. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show()
  447. }
  448. })
  449. .catch(function(e) {
  450. d.close();
  451. console && console.error(e)
  452. })
  453. }