family.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. }, null, null);
  14. $(function(){
  15. // 判断是否登录
  16. checkUserAgent();
  17. getTemplateHelper();
  18. bindEvents();
  19. });
  20. //下拉刷新
  21. function pullDownAction(theScrollerTemp) {
  22. $(".pullDown").show();
  23. setTimeout(function () {
  24. $("#ul_family").html("");
  25. queryInit();
  26. }, 1000);
  27. }
  28. //上拉加载数据
  29. function pullUpAction(theScrollerTemp) {
  30. $(".pullUp").show();
  31. setTimeout(function () {
  32. queryInit();
  33. }, 1000);
  34. }
  35. // 禁止拖动
  36. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
  37. function bindEvents() {
  38. $('#msgContainer').on('tap',function() {
  39. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  40. window.location.href = "application-msg-list.html?member="+userAgent.uid;
  41. });
  42. // 点击咨询详情
  43. $("#ul_family").on("tap", "li.member-li", function () {
  44. var $this = $(this),
  45. objStr = $this.attr("data-json");
  46. // 缓存信息
  47. window.localStorage.removeItem("familyMemberInfo");
  48. window.localStorage.setItem("familyMemberInfo", objStr);
  49. // 跳转详情
  50. window.location.href = "family-detail.html";
  51. });
  52. //免疫关联
  53. $("#ul_family").on("tap", "li.childSick", function (){
  54. var $this = $(this)
  55. location.href="../../fybj/html/mianyijihua.html"
  56. })
  57. //绑定居民
  58. $("#ul_family").on("tap", "li.add-member", function(){
  59. window.location.href = "add-step1.html";
  60. return false;
  61. });
  62. $('#ul_family').on('tap','.cancel-btn',function(e) {
  63. e.stopPropagation();
  64. var id = $(this).attr('data-id');
  65. dialog({
  66. content: '确定撤销添加此家人的申请吗?',
  67. ok: function() {
  68. cancelApplicationPromise(id)
  69. .then(function(res) {
  70. if(res.status=="200") {
  71. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销成功"}).show();
  72. $("#ul_family").html("");
  73. queryInit();
  74. } else {
  75. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg||"撤销失败"}).show();
  76. }
  77. },function() {
  78. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销失败"}).show();
  79. }).catch(function(e) {
  80. console && console.error(e)
  81. })
  82. },
  83. cancel: function() {
  84. return;
  85. }
  86. }).showModal();
  87. }).on('tap','.retry-btn',function(e) {
  88. e.stopPropagation();
  89. var obj = $(this).data("json");
  90. retryApplication(obj.name, obj.code, obj.mobile, obj.familyRelation, obj.photo);
  91. }).on('tap','.immunememberConnec',function(e){
  92. e.stopPropagation();
  93. location.href="../../fybj/html/mianyijihua.html"
  94. });
  95. }
  96. /**
  97. * 界面数据初始化
  98. */
  99. function queryInit() {
  100. d.showModal();
  101. var data = {};
  102. sendPostNoCache("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
  103. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  104. getFamilyMesListPromise(userAgent.uid)
  105. .then(function(res) {
  106. if(res.status == "200") {
  107. if(res.data.mes && res.data.mes.length) {
  108. var unhandledMsgs = _.filter(res.data.mes,function(v) {
  109. return v.state == '0'
  110. });
  111. if(unhandledMsgs.length) {
  112. $('#msgNum').text('('+unhandledMsgs.length+')')
  113. }
  114. }
  115. } else {
  116. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  117. }
  118. });
  119. }
  120. function queryListFailed(res) {
  121. d.close();
  122. if (res && res.msg) {
  123. var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg});
  124. } else {
  125. var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'});
  126. }
  127. }
  128. function queryAppoListSuccesss(res) {
  129. if (res.status == 200) {
  130. var $list =$("#ul_family"),
  131. list = _.map(res.data.normalmembers, function(o){
  132. o.relation = getRelationName(o.familyRelation);
  133. o.signText = getSignText(o.signType);
  134. return o;
  135. })
  136. var html = template("member-tmp", {
  137. list: list,
  138. immunemembers: res.data.immunemembers
  139. });
  140. $list.append(html);
  141. d.close();
  142. scroller1.myScroll.refresh();
  143. $(".pullUp").hide();
  144. $(".pullDown").hide();
  145. } else {
  146. //非200则为失败
  147. queryListFailed(res);
  148. }
  149. mui('.mui-switch')['switch']();
  150. $('.mui-switch').on('tap',function(e) {
  151. e.stopPropagation();
  152. });
  153. $('.mui-switch').on('toggle',function(e) {
  154. e.stopPropagation();
  155. var event = e.originalEvent;
  156. d.show()
  157. var isAuthorize = event.detail.isActive?1:0;
  158. var msg = isAuthorize?'授权':'取消授权';
  159. sendPost("patient/family/member_authorize", {
  160. familyMember: $(this).data('code'),
  161. isAuthorize: isAuthorize
  162. }, "json", "post", function() {
  163. d.close();
  164. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg+'失败'}).show();
  165. }, function(){
  166. d.close();
  167. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:(msg+'成功')}).show();
  168. });
  169. })
  170. }
  171. function getFamilyMesListPromise(code) {
  172. return new Promise(function(resolve, reject) {
  173. sendPost("patient/family/getFamilyMesList", {
  174. code: code
  175. } , "json", "POST",
  176. function failed (res) {
  177. d.close();
  178. }, function(res) {
  179. resolve(res)
  180. });
  181. })
  182. }
  183. function cancelApplicationPromise(id) {
  184. d.show();
  185. return new Promise(function(resolve, reject) {
  186. sendPost("patient/family/member_revoke", {
  187. id: id
  188. } , "json", "POST",
  189. function failed (res) {
  190. d.close();
  191. reject(res);
  192. }, function(res) {
  193. d.close();
  194. resolve(res)
  195. });
  196. })
  197. }
  198. function checkMemberPromise(code) {
  199. return new Promise(function(resolve, reject) {
  200. sendPost("patient/family/check_member", {
  201. memberCode: code
  202. }, "json", "get", commitFailed, function(res) {
  203. resolve(res)
  204. });
  205. })
  206. }
  207. // 提交失败
  208. function commitFailed (res) {
  209. d.close();
  210. if (res && res.msg) {
  211. var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  212. } else {
  213. var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  214. }
  215. }
  216. function sendWXTempPromise(data) {
  217. return new Promise(function(resolve, reject) {
  218. sendPost("patient/family/sendWXTemp", data , "json", "POST", commitFailed, function(res) {
  219. resolve(res)
  220. });
  221. })
  222. }
  223. function retryApplication(name,code,mobile,relation,photo) {
  224. d.show();
  225. window.localStorage.removeItem("familyCode");
  226. window.localStorage.setItem("familyCode", code);
  227. window.localStorage.removeItem("familyName");
  228. window.localStorage.setItem("familyName", name);
  229. window.localStorage.removeItem("familyImgUrl");
  230. window.localStorage.setItem("familyImgUrl", photo);
  231. window.localStorage.removeItem("familyRelation");
  232. window.localStorage.setItem("familyRelation", relation);
  233. checkMemberPromise(code)
  234. .then(function(res) {
  235. d.close();
  236. if(res.status == "200") {
  237. var state = res.data.state;
  238. if(state == "0") { // 未绑定微信和手机
  239. window.location.href = 'add-step3.html';
  240. } else if(state == "1") { // 仅绑定微信
  241. sendWXTempPromise({
  242. member: code,
  243. relation: relation,
  244. reAdd: "1" // 重新申请
  245. })
  246. .then(function(res) {
  247. if(res.status=="200") {
  248. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"已发送添加申请"}).show();
  249. } else {
  250. if(res.msg){
  251. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  252. }else
  253. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"发送失败"}).show();
  254. }
  255. })
  256. } else if(state == "2") { // 仅绑定手机
  257. window.localStorage.removeItem("familyMobile");
  258. window.localStorage.setItem("familyMobile", mobile);
  259. window.location.href = 'add-step2.html';
  260. } else if(state== "3") { // 手机和微信都绑定
  261. window.localStorage.removeItem("familyMobile");
  262. window.localStorage.setItem("familyMobile", mobile);
  263. window.location.href = 'add-step2-pre.html?reAdd=1';
  264. }
  265. } else {
  266. d.close();
  267. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show()
  268. }
  269. })
  270. .catch(function(e) {
  271. d.close();
  272. console && console.error(e)
  273. })
  274. }
  275. function getTemplateHelper(){
  276. template.helper("getPhoto", function(p){
  277. if(p){
  278. return getImgUrl(p);
  279. }else{
  280. return "../../../images/p-female.png";
  281. }
  282. });
  283. template.helper("getJsonStr", function(obj){
  284. if(obj){
  285. return JSON.stringify(obj);
  286. }else{
  287. return "";
  288. }
  289. });
  290. template.helper("getSignTypeText", function(signType){
  291. return getSignText(signType);
  292. });
  293. template.helper("getRelationName", function(type){
  294. return getRelationName(type);
  295. })
  296. }
  297. function getSignText(signType){
  298. var signText = "";
  299. if (signType == 1) {
  300. signText = "三师共管";
  301. } else if (signType == 2) {
  302. signText = "家庭医生";
  303. } else if (signType == 3) {
  304. signText = "三师共管、家庭医生";
  305. }
  306. return signText;
  307. }
  308. function getRelationName(type){
  309. var relation = "";
  310. switch(type){
  311. case 0:
  312. relation = "其他";
  313. break;
  314. case 1:
  315. relation = "父亲";
  316. break;
  317. case 2:
  318. relation = "母亲";
  319. break;
  320. case 3:
  321. relation = "老公";
  322. break;
  323. case 4:
  324. relation = "老婆";
  325. break;
  326. case 5:
  327. relation = "儿子";
  328. break;
  329. case 6:
  330. relation = "女儿";
  331. break;
  332. default:
  333. relation = "未知";
  334. break;
  335. }
  336. return relation;
  337. }