signing-doctors.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // 页面标识,未登录时将重定向到登录页面,根据这个pagetype来保证登录后的跳转到该页面
  2. var pagetype = -1;
  3. var Request = GetRequest();
  4. var d = dialog({contentType:'load', skin:'bk-popup'});
  5. var userAgent = window.localStorage.getItem(agentName);
  6. var toUser = Request["toUser"];
  7. var toName = decodeURIComponent(Request["toName"]);
  8. var openid = Request["openid"];
  9. var represented = Request["represented"];
  10. uid = "",
  11. code = Request["code"],
  12. reqPromise = function(url,data) {
  13. return new Promise(function(resolve, reject) {
  14. sendPost(url, data, "json", "post",
  15. function queryFailed (res) {
  16. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  17. // TODO 开启示例数据
  18. // resolve({});
  19. }
  20. , function success(res) {
  21. resolve(res);
  22. });
  23. });
  24. },
  25. // 对数据按照签约类型进行分组,并添加额外信息
  26. handleData = function(list) {
  27. if(!list) return [];
  28. // 签约状态对应的文本
  29. var signStatus = ["审核中","已签约","待解约"],
  30. // 签约状态应用的样式类列表
  31. signStyleClass = ["to-signed","be-signed","to-surrender"],
  32. groups = _.chain(list).map(function(o) {
  33. o.signStatusText = signStatus[o.signStatus] || "";
  34. o.signStyleClass = signStyleClass[o.signStatus] || "";
  35. o.dateText = (function() {
  36. switch(o.signStatus) {
  37. case 0: return "申请时间:"+o.sqDate
  38. case 1: return "时效:"+o.qyDate+' ~ '+o.endDate
  39. case 2: return "提交时间:"+o.qyDate
  40. }
  41. })();
  42. return o;
  43. }).groupBy(function(o) {
  44. return o.signType;
  45. }).value();
  46. return groups;
  47. },
  48. // 更新签约Card列表视图
  49. updateCardView = function($card,data) {
  50. if(!data.list.length) {
  51. $card.hide();
  52. return ;
  53. } else {
  54. $card.show();
  55. }
  56. var html = template("doctor_li_tmpl", data);
  57. $('.signing-docotors',$card).html(html);
  58. $('.date-text',$card).text(data.list[0].dateText);
  59. $('.status-text',$card).text(data.list[0].signStatusText);
  60. $('.status',$card).addClass(data.list[0].signStyleClass);
  61. },
  62. getReqPromises = function() {
  63. return Promise.all(_.map([{url: "weixin/getOpenidByCode",data:{code:code}},
  64. {url:"patient/family_contract/getSignMessage",data:{patientCode:uid}}],
  65. function(param){
  66. return reqPromise(param.url,param.data);
  67. }));
  68. },
  69. wxInit= function(){
  70. var params = {};
  71. params.pageUrl = window.location.href;
  72. $.ajax(server + "weixin/getSign", {
  73. data: params,
  74. dataType: "json",
  75. type: "post",
  76. success: function(res) {
  77. if(res.status == 200) {
  78. var t = res.data.timestamp;
  79. var noncestr = res.data.noncestr;
  80. var signature = res.data.signature;
  81. wx.config({
  82. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  83. appId: appId, // 必填,公众号的唯一标识
  84. timestamp: t, // 必填,生成签名的时间戳
  85. nonceStr: noncestr, // 必填,生成签名的随机串
  86. signature: signature, // 必填,签名,见附录1
  87. jsApiList: [
  88. 'closeWindow'
  89. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  90. });
  91. }
  92. }
  93. });
  94. }
  95. $(function(){
  96. wxInit();
  97. if(!userAgent) {
  98. window.location.href = server + "wx/html/home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype;
  99. return false;
  100. }else{
  101. queryInit();
  102. }
  103. })
  104. function queryInit(){
  105. new Promise(function(resolve, reject) {
  106. localStorage.setItem("toUser",toUser);
  107. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  108. //判断关系
  109. function hasFamilyRelation(a,b){
  110. return new Promise(function(resolve, reject) {
  111. var data={
  112. patient:a,
  113. familyMember:b
  114. }
  115. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  116. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  117. }, function(res){
  118. if(res.status == 200) {
  119. window.localStorage.setItem('nowPatientName',res.data.name);
  120. resolve(res)
  121. }else if(res.status == 100) {
  122. dialog({
  123. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  124. okValue:'切换账号',
  125. ok: function() {
  126. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  127. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  128. },
  129. cancelValue: '我不看了',
  130. cancel: function () {
  131. wx.closeWindow();
  132. }
  133. }).showModal();
  134. }else{
  135. relogin();
  136. }
  137. })
  138. })
  139. }
  140. //重新登录操作
  141. function relogin(){
  142. dialog({
  143. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  144. okValue:'切换账号',
  145. ok: function() {
  146. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  147. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  148. },
  149. cancelValue: '我不看了',
  150. cancel: function () {
  151. wx.closeWindow();
  152. }
  153. }).showModal();
  154. }
  155. //保存信息
  156. function saveUserInfo(a,b){
  157. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  158. newUaObj.represented = represented;
  159. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  160. userAgent = JSON.parse(window.localStorage.getItem(agentName))
  161. nextWork();
  162. })
  163. }
  164. function initFamilyData () {
  165. //从微信模板消息进入
  166. if(represented && userAgent && toUser){
  167. if(toUser == represented){
  168. saveUserInfo(represented,newUaObj.uid)
  169. }else if(toUser != represented && represented == newUaObj.uid){
  170. //本人代理
  171. saveUserInfo(represented,newUaObj.uid)
  172. }else if(toUser != represented && toUser == newUaObj.uid){
  173. //需要判定关系 200有授权 100家人 1无关系
  174. saveUserInfo(represented,newUaObj.uid)
  175. }else{
  176. //重新登录
  177. relogin();
  178. }
  179. }else{
  180. userAgent = JSON.parse(window.localStorage.getItem(agentName))
  181. nextWork();
  182. }
  183. }
  184. initFamilyData();
  185. function nextWork(){
  186. uid = userAgent.represented?userAgent.represented:userAgent.uid;
  187. sendPost("patient/family_contract/getSignMessage", {patientCode:uid}, "json", "post",
  188. function queryFailed () {
  189. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  190. },function success(req) {
  191. // TODO 启用示例数据
  192. // resolve(req);
  193. if (req.status == 200) {
  194. resolve(req);
  195. } else {
  196. reject(Error(req.status));
  197. }
  198. });
  199. }
  200. }).then(function(data) {
  201. // TODO 示例数据
  202. //data = []||{"msg":"获取列表成功!","list":[{"jobName":"健康管理师","code":"D2016080006","disease":1,"level":3,"endDate":"2017-08-04","sex":1,"signStatus":1,"name":"大米健管师2","photo":"","hosptialName":"嘉莲社区医疗服务中心","signType":"1","qyDate":"2016-08-04"},{"jobName":" 全科医师","code":"D2016080005","disease":1,"level":2,"endDate":"2017-08-04","sex":2,"signStatus":1,"name":"大米全科2","photo":"","hosptialName":"嘉莲社区医疗服务中心","signType":"1","qyDate":"2016-08-04"},{"jobName":"专科医师","code":"D2016080004","disease":1,"level":1,"endDate":"2017-08-04","sex":1,"signStatus":1,"name":"大米专科2","photo":"","hosptialName":"厦门大学附属第一医院思明分院","signType":"1","qyDate":"2016-08-04"},{"jobName":" 全科医师","code":"D2016080005","disease":1,"level":2,"endDate":"2017-08-15","sex":2,"signStatus":0,"name":"大米全科2","photo":"","hosptialName":"嘉莲社区医疗服务中心","signType":"2","sqDate":"2016-08-15"}],"status":200};
  203. // 根据签约类型signType分组,groups[1]为家庭医生, groups[2]为慢病管理
  204. var groups = handleData(data.list),
  205. familyList = groups[2] || [],
  206. sanshiList = groups[1] || [],
  207. $hasContent = $('.has-content'),
  208. $noContent = $('.none-content'),
  209. $onlySanshi = $('.only-sanshi'),
  210. $otherView = $('#other_view');
  211. // 签约类型
  212. var type;
  213. // 签约三师(也就是慢病管理)医生的level=2(表示“全科”)的医生
  214. var quanKeDoctor;
  215. // 没有任何类型的签约医生
  216. if(!familyList.length && !sanshiList.length) {
  217. $hasContent.hide();
  218. $noContent.show();
  219. $otherView.show();
  220. $(document.body).addClass('bc-9beaf6');
  221. type = 0;
  222. }
  223. // 仅有家庭签约医生
  224. else if(familyList.length && !sanshiList.length) {
  225. $hasContent.show();
  226. $otherView.show();
  227. $noContent.hide();
  228. $otherView.find('.btn-wrap').hide();
  229. type = 1;
  230. }
  231. // 仅有慢病管理签约医生
  232. else if(sanshiList.length && !familyList.length) {
  233. $hasContent.show();
  234. $noContent.hide();
  235. $otherView.show();
  236. type = 2;
  237. // 查找到全科医生,level:1专科医生,2全科医生,3健康管理师
  238. var quanKeDoctor = _.find(sanshiList,function(obj) {
  239. return obj.level==2;
  240. });
  241. }
  242. // 既有慢病管理签约医生,也有家庭签约医生
  243. else {
  244. $hasContent.show();
  245. $otherView.hide();
  246. type = 3;
  247. }
  248. // 更新家庭医生签约列表
  249. updateCardView($('#family_card'),{list: familyList});
  250. // 更新慢病管理签约列表
  251. updateCardView($('#sanshi_card'),{list: sanshiList});
  252. // 仅有慢病管理签约医生或者没有任何签约医生时页面底部按钮显示方式控制
  253. if( $hasContent[0].scrollHeight+$onlySanshi[0].scrollHeight>document.body.offsetHeight) {
  254. $onlySanshi.css('position','relative');
  255. }
  256. d.close();
  257. return {type: type,quanKeDoctor: quanKeDoctor};
  258. }).then(function(data) {
  259. // 签约类型
  260. var type = data.type,
  261. // 签约的慢病管理全科医生
  262. quanKeDoctor = data.quanKeDoctor,
  263. url = "select-doctor.html";
  264. if(type == 2) { // 仅有慢病管理签约医生
  265. url += "?existedSanShi=1&doctor="+quanKeDoctor.code+"&doctorName="+quanKeDoctor.name;
  266. }
  267. $('#sign_family_doctor_btn').click(function() {
  268. location.href = url
  269. });
  270. }).catch(function(e) {
  271. console && console.error(e);
  272. });
  273. }
  274. template.helper('getPhoto', function(str){
  275. return getImgUrl(str);
  276. })