article.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. var userAgent = window.localStorage.getItem(agentName);
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var Request = GetRequest();
  4. var openid = Request["openid"];
  5. var dataId=null,scroller1=null,articleId='';
  6. var pagetype=27;
  7. var toUser = Request["toUser"];
  8. var toName = decodeURIComponent(Request["toName"]);
  9. var represented = Request["represented"];
  10. var doctorCode;
  11. localStorage.setItem("toUser",toUser);
  12. $(function(){
  13. dataId = Request["dataId"];
  14. articleId = Request.articleId;
  15. localStorage.setItem("article",dataId);
  16. article.closeWindow();
  17. if(!userAgent) {
  18. localStorage.setItem("toUser",toUser);
  19. window.location.href = server + "wx/html/home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype;
  20. return false;
  21. }else{
  22. queryInit();
  23. }
  24. })
  25. function queryInit(){
  26. article.initPage();
  27. }
  28. var article={
  29. initPage:function(){
  30. article.initScroll();
  31. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  32. //判断关系
  33. function hasFamilyRelation(a,b){
  34. return new Promise(function(resolve, reject) {
  35. var data={
  36. patient:a,
  37. familyMember:b
  38. }
  39. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  40. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  41. }, function(res){
  42. if(res.status == 200) {
  43. window.localStorage.setItem('nowPatientName',res.data.name);
  44. resolve(res)
  45. }else if(res.status == 100) {
  46. dialog({
  47. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  48. okValue:'切换账号',
  49. ok: function() {
  50. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  51. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  52. },
  53. cancelValue: '我不看了',
  54. cancel: function () {
  55. wx.closeWindow();
  56. }
  57. }).showModal();
  58. }else{
  59. relogin();
  60. }
  61. })
  62. })
  63. }
  64. //重新登录操作
  65. function relogin(){
  66. dialog({
  67. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  68. okValue:'切换账号',
  69. ok: function() {
  70. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  71. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  72. },
  73. cancelValue: '我不看了',
  74. cancel: function () {
  75. wx.closeWindow();
  76. }
  77. }).showModal();
  78. }
  79. //保存信息
  80. function saveUserInfo(a,b){
  81. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  82. newUaObj.represented = represented;
  83. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  84. userAgent = window.localStorage.getItem(agentName);
  85. article.initData();
  86. article.bindEvents();
  87. })
  88. }
  89. function initFamilyData () {
  90. //从微信模板消息进入
  91. if(represented && userAgent && toUser){
  92. if(toUser == represented){
  93. saveUserInfo(represented,newUaObj.uid)
  94. }else if(toUser != represented && represented == newUaObj.uid){
  95. //本人代理
  96. saveUserInfo(represented,newUaObj.uid)
  97. }else if(toUser != represented && toUser == newUaObj.uid){
  98. //需要判定关系 200有授权 100家人 1无关系
  99. saveUserInfo(represented,newUaObj.uid)
  100. }else{
  101. //重新登录
  102. relogin();
  103. }
  104. }else{
  105. article.initData();
  106. article.bindEvents();
  107. }
  108. }
  109. initFamilyData();
  110. },
  111. initData:function(){
  112. d.show();
  113. var params = {};
  114. params.article = dataId;
  115. sendPost("/patient/health/edu/article",params,"JSON","POST",article.queryFailed,article.querySuccess);
  116. },
  117. initScroll:function(){
  118. scroller1 = new IScrollPullUpDown('wrapper1',{
  119. probeType:2,
  120. bounceTime: 250,
  121. bounceEasing: 'quadratic',
  122. mouseWheel:false,
  123. scrollbars:true,
  124. fadeScrollbars:true,
  125. click:true,
  126. interactiveScrollbars:false
  127. },null,null);
  128. function pullDownAction(theScrollerTemp) {
  129. $(".pullDown").show();
  130. $(".pullDownLabel").html("数据刷新中....");
  131. setTimeout(function () {
  132. article.initData();
  133. }, 1000);
  134. }
  135. },queryFailed:function(res){
  136. $(".pullUp,.pullDown").hide();
  137. d.close();
  138. if(res.msg){
  139. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  140. }else{
  141. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'数据加载失败!',bottom:true}).show();
  142. }
  143. },querySuccess:function(res){
  144. $(".pullUp,.pullDown").hide();
  145. d.close();
  146. if(res.status==200){
  147. var data = res.data;
  148. var html = template("article_temp",data);
  149. $(".iScroller").html(html);
  150. setTimeout(function(){
  151. scroller1.myScroll.refresh();
  152. },1000);
  153. }else{
  154. if(res.status==-2){
  155. dialog({
  156. content:'对不起,该消息不是您的消息,您无法查看哦~',
  157. okValue:'我知道了',
  158. ok: function() {
  159. wx.closeWindow();
  160. }
  161. }).showModal();
  162. }
  163. article.queryFailed();
  164. }
  165. },closeWindow:function(){
  166. var params = {};
  167. params.pageUrl = window.location.href;
  168. $.ajax(server + "weixin/getSign", {
  169. data: params,
  170. dataType: "json",
  171. type: "post",
  172. success: function(res) {
  173. if(res.status == 200) {
  174. var t = res.data.timestamp;
  175. var noncestr = res.data.noncestr;
  176. var signature = res.data.signature;
  177. wx.config({
  178. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  179. appId: appId, // 必填,公众号的唯一标识
  180. timestamp: t, // 必填,生成签名的时间戳
  181. nonceStr: noncestr, // 必填,生成签名的随机串
  182. signature: signature, // 必填,签名,见附录1
  183. jsApiList: [
  184. 'closeWindow'
  185. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  186. });
  187. }
  188. }
  189. });
  190. },
  191. bindEvents: function() {
  192. $("#zixun").on("click", function () {
  193. article.querySignType();
  194. });
  195. },
  196. querySignType: function() {
  197. d.show();
  198. sendPost('patient/sign_doctors', {}, 'json', 'post', article.querySignTypeFailed, article.querySignTypeSuccess);
  199. },
  200. querySignTypeFailed: function(res) {
  201. d.close();
  202. if (res && res.msg) {
  203. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  204. } else {
  205. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取咨询类型失败'}).show();
  206. }
  207. },
  208. querySignTypeSuccess: function(data) {
  209. if (data.status == 200) {
  210. var doctors = data.familyDoctors;
  211. type = 2;
  212. var docInfo,docQkInfo;
  213. if(doctors.length == 0){
  214. doctors = data.teamDoctors;
  215. type = 1;
  216. }
  217. $.each(doctors, function(i, v) {
  218. if(v.teamlevel){
  219. if(v.teamlevel == 3){
  220. docInfo = v;
  221. }
  222. if(v.teamlevel == 2){
  223. docQkInfo = v;
  224. }
  225. }else{
  226. if(v.level == 3){
  227. docInfo = v;
  228. }
  229. if(v.level == 2){
  230. docQkInfo = v;
  231. }
  232. }
  233. });
  234. if(!docInfo){
  235. docInfo = docQkInfo;
  236. }
  237. sendPost('patient/consult/is_consult_unfinished', {doctor: docInfo ? docInfo.code : docQkInfo.code}, 'json', 'post',
  238. function(res){
  239. d.close();
  240. if (res && res.msg) {
  241. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  242. } else {
  243. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取是否存在咨询失败'}).show();
  244. }
  245. }, function(res){
  246. if(res.status == 200){
  247. if(res.data == ""){
  248. checkDocInWork(0, docInfo.code, articleId);
  249. } else {
  250. d.close();
  251. dialog({
  252. content: '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,无法发起新的咨询',
  253. okValue:'前往查看',
  254. ok: function (){
  255. var userInfo = JSON.parse(userAgent);
  256. var rep = userInfo.represented?userInfo.represented:userInfo.uid;
  257. window.location.href = "../../yszx/html/consulting-doctor.html?consult=" + res.data +"&toUser="+rep+"&type="+type+"&doctor="+docInfo.code;
  258. },
  259. cancelValue: '我知道了',
  260. cancel: function () {
  261. return;
  262. }
  263. }).showModal();
  264. }
  265. } else {
  266. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  267. }
  268. }
  269. );
  270. } else {
  271. article.querySignTypeFailed(res);
  272. }
  273. }
  274. }
  275. function queryFailed(res){
  276. d.close();
  277. if(res.msg){
  278. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  279. }else{
  280. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'操作失败!',bottom:true}).show();
  281. }
  282. }
  283. function checkDocInWork(type, doctor, id){
  284. sendPost('patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'get', queryFailed, function(res){
  285. if(res.status==200){
  286. d.close();
  287. if(res.data==2){
  288. dialog({
  289. content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  290. okValue:'查看医生工作时间',
  291. ok: function (){
  292. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + doctor;
  293. },
  294. cancelValue: '继续新增咨询',
  295. cancel: function () {
  296. // window.location.href = "../../yszx/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
  297. window.location.href = "../../yszd/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor+'&fromPage=jkzx';
  298. }
  299. }).showModal();
  300. }else if(res.data==0){//医生不接受咨询
  301. dialog({
  302. content: '对不起,该医生暂时关闭了咨询功能,<br/>暂时无法咨询该医生',
  303. cancelValue: '我知道了',
  304. cancel: function () {
  305. wx.closeWindow();
  306. }
  307. }).showModal();
  308. }else{
  309. //三师咨询或家庭签约咨询,跳转到新增咨询页面
  310. // window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
  311. window.location.href = "../../yszd/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor+'&fromPage=jkzx';
  312. }
  313. }else{
  314. queryFailed(res);
  315. }
  316. })
  317. }
  318. template.helper("setPhoto", function(p) {
  319. return getImgUrl(p);
  320. });