article2.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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='',type="";
  6. var pagetype=50;
  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 || dataId;
  15. type = Request.type;
  16. window.localStorage.setItem("article2",dataId);
  17. article.closeWindow();
  18. if(!userAgent) {
  19. window.localStorage.setItem("toUser",toUser);
  20. window.location.href = "../../home/html/login.html?openid=" + openid+"&type="+pagetype;
  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.articleId = articleId;
  115. params.userType = '2';
  116. sendPost("/third/jkEdu/Article/getArticalById",params,"JSON","GET",article.queryFailed,article.querySuccess);
  117. // 更新浏览量
  118. sendPost("patient/jkEdu/article/saveBehavior",{
  119. articleId: articleId,
  120. behaviorAction: 4
  121. },"JSON","POST",function fail() {
  122. dialog({contentType:'tipsbox', skin:'bk-popup' , content: "浏览量更新失败",bottom:true}).show();
  123. },function success(res) {
  124. if(res.status !=200){
  125. dialog({contentType:'tipsbox', skin:'bk-popup' , content: res.msg || "浏览量更新失败",bottom:true}).show();
  126. }
  127. });
  128. },
  129. initScroll:function(){
  130. scroller1 = new IScrollPullUpDown('wrapper1',{
  131. probeType:2,
  132. bounceTime: 250,
  133. bounceEasing: 'quadratic',
  134. mouseWheel:false,
  135. scrollbars:true,
  136. fadeScrollbars:true,
  137. click:true,
  138. interactiveScrollbars:false
  139. },null,null);
  140. function pullDownAction(theScrollerTemp) {
  141. $(".pullDown").show();
  142. $(".pullDownLabel").html("数据刷新中....");
  143. setTimeout(function () {
  144. article.initData();
  145. }, 1000);
  146. }
  147. },queryFailed:function(res){
  148. $(".pullUp,.pullDown").hide();
  149. d.close();
  150. if(res.msg){
  151. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  152. }else{
  153. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'数据加载失败!',bottom:true}).show();
  154. }
  155. },querySuccess:function(res){
  156. $(".pullUp,.pullDown").hide();
  157. d.close();
  158. if(res.status==200){
  159. var content = res.data.articleContent;
  160. var reg=/group1\//g;
  161. content = content.replace(reg,imgUrlDomain+ 'group1/');
  162. var data = res.data;
  163. var html = template("article_temp",{ it: res.data, content: content});
  164. $(".iScroller").html(html);
  165. // if(type==1||type==2){
  166. var html2 = template("article_temp2",data);
  167. $(".handle-bar").html(html2);
  168. // }
  169. setTimeout(function(){
  170. scroller1.myScroll.refresh();
  171. },1000);
  172. }else{
  173. if(res.status==-1){
  174. // dialog({
  175. // content:'查询失败',
  176. // ok: function() {
  177. // wx.closeWindow();
  178. // }
  179. // }).showModal();
  180. }
  181. article.queryFailed(res);
  182. }
  183. },closeWindow:function(){
  184. var params = {};
  185. params.pageUrl = window.location.href;
  186. $.ajax(server + "weixin/getSign", {
  187. data: params,
  188. dataType: "json",
  189. type: "post",
  190. success: function(res) {
  191. if(res.status == 200) {
  192. var t = res.data.timestamp;
  193. var noncestr = res.data.noncestr;
  194. var signature = res.data.signature;
  195. wx.config({
  196. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  197. appId: appId, // 必填,公众号的唯一标识
  198. timestamp: t, // 必填,生成签名的时间戳
  199. nonceStr: noncestr, // 必填,生成签名的随机串
  200. signature: signature, // 必填,签名,见附录1
  201. jsApiList: [
  202. 'closeWindow'
  203. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  204. });
  205. }
  206. }
  207. });
  208. },
  209. bindEvents: function() {
  210. // $("#zixun").on("click", function () {
  211. // article.querySignType();
  212. // });
  213. $(".handle-bar").on("click",".collection",function(){
  214. var status = $(this).attr("data-status");
  215. var id = $(this).attr("article-id");
  216. if(status==0){
  217. collectionArticle(article,$(this),id)
  218. }else{
  219. unCollectionArticle(article,$(this),id)
  220. }
  221. return;
  222. });
  223. },
  224. querySignType: function() {
  225. d.show();
  226. sendPost('patient/sign_doctors', {}, 'json', 'post', article.querySignTypeFailed, article.querySignTypeSuccess);
  227. },
  228. querySignTypeFailed: function(res) {
  229. d.close();
  230. if (res && res.msg) {
  231. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  232. } else {
  233. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取咨询类型失败'}).show();
  234. }
  235. },
  236. querySignTypeSuccess: function(data) {
  237. if (data.status == 200) {
  238. var doctors = data.familyDoctors;
  239. type = 2;
  240. var docInfo,docQkInfo;
  241. if(doctors.length == 0){
  242. doctors = data.teamDoctors;
  243. type = 1;
  244. }
  245. $.each(doctors, function(i, v) {
  246. if(v.teamlevel){
  247. if(v.teamlevel == 3){
  248. docInfo = v;
  249. }
  250. if(v.teamlevel == 2){
  251. docQkInfo = v;
  252. }
  253. }else{
  254. if(v.level == 3){
  255. docInfo = v;
  256. }
  257. if(v.level == 2){
  258. docQkInfo = v;
  259. }
  260. }
  261. });
  262. if(!docInfo){
  263. docInfo = docQkInfo;
  264. }
  265. sendPost('patient/consult/is_consult_unfinished', {doctor: docInfo ? docInfo.code : docQkInfo.code}, 'json', 'post',
  266. function(res){
  267. d.close();
  268. if (res && res.msg) {
  269. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  270. } else {
  271. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取是否存在咨询失败'}).show();
  272. }
  273. }, function(res){
  274. if(res.status == 200){
  275. if(res.data == ""){
  276. checkDocInWork(0, docInfo.code, articleId);
  277. } else {
  278. d.close();
  279. dialog({
  280. content: '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,无法发起新的咨询',
  281. okValue:'前往查看',
  282. ok: function (){
  283. var userInfo = JSON.parse(userAgent);
  284. var rep = userInfo.represented?userInfo.represented:userInfo.uid;
  285. window.location.href = "../../yszx/html/consulting-doctor.html?consult=" + res.data +"&toUser="+rep+"&type="+type+"&doctor="+docInfo.code;
  286. },
  287. cancelValue: '我知道了',
  288. cancel: function () {
  289. return;
  290. }
  291. }).showModal();
  292. }
  293. } else {
  294. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  295. }
  296. }
  297. );
  298. } else {
  299. article.querySignTypeFailed(res);
  300. }
  301. }
  302. }
  303. function queryFailed(res){
  304. d.close();
  305. if(res.msg){
  306. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  307. }else{
  308. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'操作失败!',bottom:true}).show();
  309. }
  310. }
  311. function checkDocInWork(type, doctor, id){
  312. sendPost('patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'get', queryFailed, function(res){
  313. if(res.status==200){
  314. d.close();
  315. if(res.data==2){
  316. dialog({
  317. content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  318. okValue:'查看医生工作时间',
  319. ok: function (){
  320. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + doctor;
  321. },
  322. cancelValue: '继续新增咨询',
  323. cancel: function () {
  324. // window.location.href = "../../yszx/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
  325. window.location.href = "../../yszd/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor+'&fromPage=jkzx';
  326. }
  327. }).showModal();
  328. }else if(res.data==0){//医生不接受咨询
  329. dialog({
  330. content: '对不起,该医生暂时关闭了咨询功能,<br/>暂时无法咨询该医生',
  331. cancelValue: '我知道了',
  332. cancel: function () {
  333. wx.closeWindow();
  334. }
  335. }).showModal();
  336. }else{
  337. //三师咨询或家庭签约咨询,跳转到新增咨询页面
  338. // window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
  339. window.location.href = "../../yszd/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor+'&fromPage=jkzx';
  340. }
  341. }else{
  342. queryFailed(res);
  343. }
  344. })
  345. }
  346. template.helper('setTimer',function(o){
  347. return o.substr(0,19)
  348. })
  349. template.helper("setPhoto", function(p) {
  350. return getImgUrl(p);
  351. });
  352. var collectionArticle=function(code,$this,id){
  353. d.showModal()
  354. var url = "/third/jkEdu/Article/saveArticleCollection",
  355. params = {
  356. articleId: articleId,
  357. userType: "2"
  358. };
  359. sendPost(url, params, 'json', 'POST', collecFailed, function(res){
  360. d.close();
  361. if(res.status == 200){
  362. $this.attr("data-status", 1);
  363. $this.find("img").attr("src", "../images/shoucang_pre.png");
  364. var span = $this.find("span");
  365. span.html("已收藏");
  366. dialog({
  367. contentType: 'tipsbox',
  368. skin: 'bk-popup',
  369. content: '收藏成功'
  370. }).show();
  371. }else{
  372. collecFailed(res);
  373. }
  374. })
  375. },
  376. collecFailed = function(res){
  377. d.close();
  378. if(res && res.msg) {
  379. dialog({
  380. contentType: 'tipsbox',
  381. skin: 'bk-popup',
  382. content: res.msg
  383. }).show();
  384. } else {
  385. dialog({
  386. contentType: 'tipsbox',
  387. skin: 'bk-popup',
  388. content: '收藏失败'
  389. }).show();
  390. }
  391. },
  392. unCollectionArticle=function(code,$this,id){
  393. d.showModal()
  394. var url = "/third/jkEdu/Article/cancelArticleCollection",
  395. params = {
  396. articleId: articleId,
  397. userType:2
  398. };
  399. sendPost(url, params, 'json', 'POST', unCollecFailed, function(res){
  400. d.close();
  401. if(res.status == 200){
  402. $this.attr("data-status", 0);
  403. $this.find("img").attr("src", "../images/shoucang_button.png");
  404. var span = $this.find("span");
  405. span.html("收藏");
  406. dialog({
  407. contentType: 'tipsbox',
  408. skin: 'bk-popup',
  409. content: '取消收藏成功'
  410. }).show();
  411. }else{
  412. unCollecFailed(res);
  413. }
  414. })
  415. },
  416. unCollecFailed = function(res){
  417. d.close();
  418. if(res && res.msg) {
  419. dialog({
  420. contentType: 'tipsbox',
  421. skin: 'bk-popup',
  422. content: res.msg
  423. }).show();
  424. } else {
  425. dialog({
  426. contentType: 'tipsbox',
  427. skin: 'bk-popup',
  428. content: '取消收藏失败'
  429. }).show();
  430. }
  431. };