information.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. var d = dialog({contentType:'load', skin:'bk-popup', content:'加载中...'});
  2. var mySwiper;
  3. var pagetype = 33;
  4. var signStatus;
  5. var Request = GetRequest();
  6. var userAgent = localStorage.getItem(agentName);
  7. var changeDoctor = Request.changeDoctor || 0; //标记是否是医生发起的模板消息,1-医生发起的
  8. $(function(){
  9. var toUser = Request["toUser"];
  10. var toName = decodeURIComponent(Request["toName"]);
  11. var openid = Request["openid"];
  12. var represented = Request["represented"];
  13. if(!userAgent) {
  14. window.location.href = server + "wx/html/home/html/login.html?type=" + pagetype + "&openid=" + openid;
  15. return false;
  16. }
  17. var newUaObj = JSON.parse(userAgent)
  18. //判断关系
  19. function hasFamilyRelation(a,b){
  20. return new Promise(function(resolve, reject) {
  21. var data={
  22. patient:a,
  23. familyMember:b
  24. }
  25. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  26. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  27. }, function(res){
  28. if(res.status == 200) {
  29. window.localStorage.setItem('nowPatientName',res.data.name);
  30. resolve(res)
  31. }else if(res.status == 100) {
  32. dialog({
  33. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  34. okValue:'切换账号',
  35. ok: function() {
  36. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  37. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  38. },
  39. cancelValue: '我不看了',
  40. cancel: function () {
  41. wx.closeWindow();
  42. }
  43. }).showModal();
  44. }else{
  45. relogin();
  46. }
  47. })
  48. })
  49. }
  50. //重新登录操作
  51. function relogin(){
  52. dialog({
  53. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  54. okValue:'切换账号',
  55. ok: function() {
  56. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  57. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  58. },
  59. cancelValue: '我不看了',
  60. cancel: function () {
  61. wx.closeWindow();
  62. }
  63. }).showModal();
  64. }
  65. //保存信息
  66. function saveUserInfo(a,b){
  67. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  68. newUaObj.represented = represented;
  69. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  70. userAgent = JSON.parse(localStorage.getItem(agentName));
  71. queryInit()
  72. })
  73. }
  74. function initFamilyData () {
  75. //从微信模板消息进入
  76. if(represented && userAgent && toUser){
  77. if(toUser == represented){
  78. saveUserInfo(represented,newUaObj.uid)
  79. }else if(toUser != represented && represented == newUaObj.uid){
  80. //本人代理
  81. saveUserInfo(represented,newUaObj.uid)
  82. }else if(toUser != represented && toUser == newUaObj.uid){
  83. //需要判定关系 200有授权 100家人 1无关系
  84. saveUserInfo(represented,newUaObj.uid)
  85. }else{
  86. //重新登录
  87. relogin();
  88. }
  89. }else{
  90. userAgent = JSON.parse(userAgent);
  91. queryInit()
  92. }
  93. }
  94. initFamilyData();
  95. $('.swiper-slide,.swiper-container').css({
  96. height: $(window).height()
  97. });
  98. $(window).on('resize',function(){
  99. $('.swiper-slide,.swiper-container').css({
  100. height: $(window).height()
  101. });
  102. });
  103. });
  104. function queryInit(){
  105. var date = new Date();
  106. getStatistics(); //获得统计数据
  107. bindEvents();
  108. getWeixinSign();
  109. }
  110. function reqFailed(res){
  111. d.close();
  112. if(res.msg){
  113. dialog({
  114. contentType:'tipsbox',
  115. bottom:true,
  116. skin:'bk-popup',
  117. content: res.msg
  118. }).show();
  119. }else{
  120. dialog({
  121. contentType:'tipsbox',
  122. bottom:true,
  123. skin:'bk-popup',
  124. content: "请求失败,请重试"
  125. }).show();
  126. }
  127. }
  128. function initSwiper(){
  129. mySwiper = new Swiper('.swiper-container',{
  130. setWrapperSize :true,
  131. direction:"vertical",
  132. speed : 1000,
  133. longSwipesRatio : 0.3,
  134. grabCursor:true,
  135. nextButton:'.next-btn',
  136. prevButton:'.pre-btn',
  137. mousewheelControl : true,
  138. lazyLoading : true,
  139. lazyLoadingInPrevNext : true,
  140. lazyLoadingOnTransitionStart : true,
  141. onInit: function(swiper){
  142. setTimeout(function(){
  143. $("#loading").remove();
  144. $(".swiper-container").css({"opacity":"1"});
  145. swiperAnimateCache(swiper);
  146. swiperAnimate(swiper);
  147. },1000);
  148. },
  149. onSlideChangeEnd: function(swiper){
  150. swiperAnimate(swiper);
  151. },
  152. onTransitionEnd: function(swiper){
  153. swiperAnimate(swiper);
  154. }
  155. });
  156. }
  157. function getStatistics(){
  158. d.show();
  159. var url = "/patient/family_contract/getSignCountInfoInYear",
  160. params = {patient: userAgent.represented?userAgent.represented:userAgent.uid};
  161. sendPost(url, params, "JSON", "get", reqFailed, function(res){
  162. if(res.status == 200){
  163. d.close();
  164. var data = res.data,
  165. consultTotal = data.consultTotal,
  166. articleCount = data.articleResult[0].articleCount,
  167. guidanceCount = data.guidanceResult[0].guidanceCount,
  168. reservationCount = data.reservationResult[0].reservationCount,
  169. totalCount = articleCount + guidanceCount + reservationCount;
  170. if(consultTotal == 0 && totalCount == 0){
  171. $(".result-info").html("您没有该年度的服务记录");
  172. $("#directBtn").text("了解更多授权续签");
  173. $("#directBtn").parent().show();
  174. $("#directBtn").attr("href", "agreement.html?changeDoctor="+changeDoctor);
  175. return;
  176. }
  177. $("#skip").show();
  178. $(".page1-text-1").text(res.data.consultTotal);
  179. var len = res.data.consultResult.length;
  180. var newRs = _.sortBy(res.data.consultResult, function(o){
  181. return -o.consultCount;
  182. });
  183. var page1html = "";
  184. for(i=0; i<len; i++){
  185. var item = newRs[i];
  186. var mt = "";
  187. if(i > 0){
  188. mt = "mt10";
  189. }
  190. if(i < 3){
  191. page1html += '<div class="mlr10 bgc-2e2068 plr10 page1-text '+mt+' ani" swiper-animate-effect="lightSpeedIn" swiper-animate-duration="0.5s" swiper-animate-delay="'+(i*0.5)+'s">'+
  192. '<span class="c-f16 c-00e669">'+item.doctorName+'</span>'+
  193. '<img src="../images/01xuanqian_img02_bg.png">'+
  194. '<span class="c-f20 c-00e669 num">'+item.consultCount+'</span></div>';
  195. }else{
  196. page1html += '<div class="ani c-t-center mt10" swiper-animate-effect="lightSpeedIn" swiper-animate-duration="0.5s" swiper-animate-delay="'+(i*0.5)+'s"><img src="../images/icon_more.png"></div>'
  197. break;
  198. }
  199. }
  200. $(".swiper-slide1").append(page1html);
  201. //第二页内容填充
  202. var page2html = '<p class="page2-text-1"><span class="c-24 c-bold c-fff mr5">今年</span>';
  203. var docLen = res.data.doctors.length;
  204. if(docLen == 0){
  205. page2html += '<span class="c-f16 c-ffff00">没有</span>';
  206. }
  207. for(j=0; j<docLen; j++){
  208. var item = res.data.doctors[j];
  209. if(j > 0){
  210. page2html += '<span class="c-f16 c-ffff00">、</span>';
  211. }
  212. page2html += '<span class="c-f16 c-ffff00 ani" swiper-animate-effect="fadeInDown" swiper-animate-duration="0.5s" swiper-animate-delay="'+(j*0.5)+'s">'+item.name+'</span>';
  213. }
  214. page2html += '<span class="c-24 c-bold c-fff ml5">医生</span></p>';
  215. $(".page2-div1").append(page2html);
  216. $(".page2-text-3").text(totalCount);
  217. $(".page2-text-4").text(reservationCount);
  218. $(".page2-text-5").text(guidanceCount);
  219. $(".page2-text-6").text(articleCount);
  220. initSwiper();
  221. }else{
  222. if(res.status == -1){
  223. //请求判断是和情况
  224. var url = "/patient/family_contract/checkCanRenew",
  225. params = {patient: userAgent.represented?userAgent.represented:userAgent.uid};
  226. sendPost(url, params, "json", "post", reqFailed , function(res){
  227. if(res.status == 200){
  228. var code = res.data.code,
  229. msg = "您没有签约关系<br/>请前往签约管理页面签约医生",
  230. enable = true;
  231. switch (parseInt(code)){
  232. case -4:
  233. msg = "您当前无可续签的家庭医生<br/>可在签约管理页面签约医生";
  234. enable = false;
  235. break;
  236. case -2:
  237. msg = "您已完成新年度的签约<br/>不能再次签约";
  238. enable = false;
  239. break;
  240. case -1:
  241. msg = "当前时间段不允许续签<br/>可前往签约管理页面签约医生";
  242. enable = false;
  243. break;
  244. }
  245. $(".result-info").html(msg);
  246. $("#directBtn").text("我知道了");
  247. $("#directBtn").parent().show();
  248. $("#directBtn").attr("href", "../../qygl/html/signing_management.html");
  249. }else{
  250. $(".result-info").html("您没有签约关系<br/>请前往签约管理页面签约医生");
  251. $("#directBtn").text("我知道了");
  252. $("#directBtn").parent().show();
  253. $("#directBtn").attr("href", "../../qygl/html/signing_management.html");
  254. }
  255. d.close();
  256. });
  257. }
  258. }
  259. });
  260. }
  261. function bindEvents(){
  262. $(".more-btn").on('tap', function(){
  263. window.location.href = "agreement.html?signStatus="+signStatus+"&changeDoctor="+changeDoctor;
  264. });
  265. $("#skip").on("tap", function(){
  266. window.location.href = "agreement.html?signStatus="+signStatus+"&changeDoctor="+changeDoctor;
  267. })
  268. }
  269. function getWeixinSign(){
  270. var params = {};
  271. params.pageUrl = window.location.href;
  272. $.ajax(server + "weixin/getSign", {
  273. data: params,
  274. dataType: "json",
  275. type: "post",
  276. success: function(res) {
  277. if(res.status == 200) {
  278. var t = res.data.timestamp;
  279. var noncestr = res.data.noncestr;
  280. var signature = res.data.signature;
  281. wx.config({
  282. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  283. appId: appId, // 必填,公众号的唯一标识
  284. timestamp: t, // 必填,生成签名的时间戳
  285. nonceStr: noncestr, // 必填,生成签名的随机串
  286. signature: signature, // 必填,签名,见附录1
  287. jsApiList: [
  288. 'closeWindow'
  289. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  290. });
  291. }
  292. }
  293. });
  294. }