guidance-detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. Request = GetRequest();
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var id = Request["id"];
  4. var photo = Request["photo"];
  5. var toUser = Request["toUser"];
  6. var openid = Request["openid"];
  7. var toName = decodeURIComponent(Request["toName"]);
  8. var represented = Request["represented"];
  9. var pagetype=25;
  10. var type;
  11. var doctorCode;
  12. var userAgent = window.localStorage.getItem(agentName);
  13. var expensesStatus; //标记缴费状态
  14. $(function(){
  15. if(!userAgent) {
  16. localStorage.setItem("toUser",toUser);
  17. localStorage.setItem("id",id);
  18. window.location.href = server + "wx/html/home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype;
  19. return false;
  20. }
  21. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  22. //判断关系
  23. function hasFamilyRelation(a,b){
  24. return new Promise(function(resolve, reject) {
  25. var data={
  26. patient:a,
  27. familyMember:b
  28. }
  29. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  30. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  31. }, function(res){
  32. if(res.status == 200) {
  33. window.localStorage.setItem('nowPatientName',res.data.name);
  34. resolve(res)
  35. }else if(res.status == 100) {
  36. dialog({
  37. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  38. okValue:'切换账号',
  39. ok: function() {
  40. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  41. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  42. },
  43. cancelValue: '我不看了',
  44. cancel: function () {
  45. wx.closeWindow();
  46. }
  47. }).showModal();
  48. }else{
  49. relogin();
  50. }
  51. })
  52. })
  53. }
  54. //重新登录操作
  55. function relogin(){
  56. dialog({
  57. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  58. okValue:'切换账号',
  59. ok: function() {
  60. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  61. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  62. },
  63. cancelValue: '我不看了',
  64. cancel: function () {
  65. wx.closeWindow();
  66. }
  67. }).showModal();
  68. }
  69. //保存信息
  70. function saveUserInfo(a,b){
  71. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  72. newUaObj.represented = represented;
  73. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  74. userAgent = window.localStorage.getItem(agentName);
  75. queryInit();
  76. // 点击咨询详情
  77. $("#detail").on("tap", function () {
  78. querySignType();
  79. });
  80. })
  81. }
  82. function initFamilyData () {
  83. //从微信模板消息进入
  84. if(represented && userAgent && toUser){
  85. if(toUser == represented){
  86. saveUserInfo(represented,newUaObj.uid)
  87. }else if(toUser != represented && represented == newUaObj.uid){
  88. //本人代理
  89. saveUserInfo(represented,newUaObj.uid)
  90. }else if(toUser != represented && toUser == newUaObj.uid){
  91. //需要判定关系 200有授权 100家人 1无关系
  92. saveUserInfo(represented,newUaObj.uid)
  93. }else{
  94. //重新登录
  95. relogin();
  96. }
  97. }else{
  98. queryInit();
  99. // 点击咨询详情
  100. $("#detail").on("tap", function () {
  101. querySignType();
  102. });
  103. }
  104. }
  105. initFamilyData();
  106. });
  107. /**
  108. * 界面数据初始化
  109. */
  110. function queryInit() {
  111. d.show();
  112. var data = {};
  113. data.id = id;
  114. sendPost("patient/health/guidance/id", data, "json", "post", queryListFailed, queryAppoListSuccesss);
  115. getPatientInfo();
  116. }
  117. function queryListFailed(res) {
  118. d.close();
  119. if (res && res.msg) {
  120. var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg});
  121. } else {
  122. var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'});
  123. }
  124. }
  125. function queryAppoListSuccesss(res) {
  126. if (res.status == 200) {
  127. var data = res.data;
  128. if (data) {
  129. doctorCode = data.doctor;
  130. // type = data.del;
  131. window.localStorage.setItem("guidance",data.content);
  132. var regN = /\n/g;
  133. var regRN = /\r\n/g;
  134. var content = data.content.replace(/ /g, " ");
  135. content = content.replace(regN,"<br/>");
  136. $("#content_text").html(content);
  137. var images = data.images?data.images.split(","):[];
  138. var imgTmp = "";
  139. for(i=0; i<images.length; i++){
  140. imgTmp += "<div><img src='"+ getImgUrl(images[i])+"' width='100%'></div>";
  141. }
  142. $(".main").append(imgTmp);
  143. }
  144. d.close();
  145. } else {
  146. //非200则为失败
  147. queryListFailed(res);
  148. }
  149. }
  150. function getPatientInfo(){
  151. //先获取患者缴费信息,然后未缴费的需要判断是否已经达到咨询上线
  152. sendPost('patient/baseinfo', {}, 'json', 'post', queryFailed, function(res){
  153. if(res.status == 200){
  154. expensesStatus = res.data.expensesStatus;
  155. }else{
  156. queryFailed(res);
  157. }
  158. })
  159. }
  160. function querySignType(){
  161. //判断该居民是否已经缴费 1为已经交费 ""没有签约信息 "0"未扣费 "1"已扣费 "2"已退费
  162. if(expensesStatus == 1){
  163. querySignType2();
  164. }else{
  165. limitZxTimes();
  166. }
  167. }
  168. function querySignType2(){
  169. d.show();
  170. sendPost('patient/sign_doctors', {}, 'json', 'post', querySignTypeFailed, querySignTypeSuccess);
  171. }
  172. function querySignTypeFailed(res) {
  173. d.close();
  174. if (res && res.msg) {
  175. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  176. } else {
  177. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取咨询类型失败'}).show();
  178. }
  179. }
  180. function querySignTypeSuccess(data) {
  181. if (data.status == 200) {
  182. var doctors = data.familyDoctors;
  183. type = 2;
  184. var docInfo,docQkInfo;
  185. if(doctors.length == 0){
  186. doctors = data.teamDoctors;
  187. type = 1;
  188. }
  189. $.each(doctors, function(i, v) {
  190. if(v.teamlevel){
  191. if(v.teamlevel == 3){
  192. docInfo = v;
  193. }
  194. if(v.teamlevel == 2){
  195. docQkInfo = v;
  196. }
  197. }else{
  198. if(v.level == 3){
  199. docInfo = v;
  200. }
  201. if(v.level == 2){
  202. docQkInfo = v;
  203. }
  204. }
  205. });
  206. if(!docInfo){
  207. docInfo = docQkInfo;
  208. }
  209. sendPost('patient/consult/is_consult_unfinished', {doctor: docInfo ? docInfo.code : docQkInfo.code}, 'json', 'post',
  210. function(res){
  211. d.close();
  212. if (res && res.msg) {
  213. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  214. } else {
  215. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取是否存在咨询失败'}).show();
  216. }
  217. }, function(res){
  218. if(res.status == 200){
  219. if(res.data == ""){
  220. //不存在
  221. // window.location.href = "add-consult.html?id=" + id + "&type=0&doctorCode=" + doctorCode;
  222. checkDocInWork(0, doctorCode, id);
  223. } else {
  224. d.close();
  225. dialog({
  226. content: '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,无法发起新的咨询',
  227. okValue:'前往查看',
  228. ok: function (){
  229. var userInfo = JSON.parse(userAgent);
  230. // if(type == "2"){ //家庭签约
  231. // window.location.href = ""
  232. // }else{//三师签约
  233. var rep = userInfo.represented?userInfo.represented:userInfo.uid;
  234. window.location.href = "../../yszx/html/consulting-doctor.html?consult=" + res.data +"&toUser="+rep+"&type="+type+"&doctor="+docInfo.code;
  235. // }
  236. },
  237. cancelValue: '我知道了',
  238. cancel: function () {
  239. return;
  240. }
  241. }).showModal();
  242. }
  243. } else {
  244. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  245. }
  246. }
  247. );
  248. } else {
  249. querySignTypeFailed(res);
  250. }
  251. }
  252. function checkDocInWork(type, doctor, id){
  253. sendPost('patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'get', queryFailed, function(res){
  254. if(res.status==200){
  255. d.close();
  256. if(res.data==2){
  257. dialog({
  258. content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  259. okValue:'查看医生工作时间',
  260. ok: function (){
  261. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + doctor;
  262. },
  263. cancelValue: '继续新增咨询',
  264. cancel: function () {
  265. window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
  266. }
  267. }).showModal();
  268. }else if(res.data==0){//医生不接受咨询
  269. dialog({
  270. content: '对不起,该医生暂时关闭了咨询功能,<br/>暂时无法咨询该医生',
  271. cancelValue: '我知道了',
  272. cancel: function () {
  273. wx.closeWindow();
  274. }
  275. }).showModal();
  276. }else{
  277. //三师咨询或家庭签约咨询,跳转到新增咨询页面
  278. window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
  279. }
  280. }else{
  281. queryFailed(res);
  282. }
  283. })
  284. }
  285. //未缴费时,判断剩余咨询次数
  286. function limitZxTimes(){
  287. //获取剩余家庭咨询次数
  288. var url = '/patient/consult/remainConsultTimes';
  289. var remainTimes;//剩余咨询次数
  290. var countTimes;//总咨询次数
  291. var zxTimes;//已咨询次数
  292. d.show();
  293. sendPost(url, {}, 'json', 'get', queryFailed, function(res){
  294. if(res.status == 200){
  295. d.close();
  296. remainTimes = res.data.amount;
  297. countTimes = res.data.count;
  298. zxTimes = countTimes - remainTimes;
  299. if(zxTimes == countTimes){
  300. //未缴费的总咨询次数已达上限 提示去缴费
  301. dialog({
  302. content: '您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.如果需要家庭医生继续为您提供服务,请尽快完成缴费操作',
  303. okValue:'前往缴费',
  304. ok: function (){
  305. window.location.href = "../../qygl/html/signing_management.html";
  306. }
  307. }).showModal();
  308. }else{
  309. dialog({
  310. content: '您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:'+remainTimes+'次.为避免影响您的服务体验,请尽快完成缴费操作',
  311. okValue:'前往缴费',
  312. ok: function (){
  313. window.location.href = "../../qygl/html/signing_management.html";
  314. },
  315. cancelValue: '开始咨询',
  316. cancel: function () {
  317. querySignType2();
  318. }
  319. }).showModal();
  320. }
  321. }else{
  322. queryFailed(res);
  323. }
  324. });
  325. }
  326. //查询失败
  327. function queryFailed(res) {
  328. d.close();
  329. if (res && res.msg) {
  330. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  331. } else {
  332. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'查询失败'}).show();
  333. }
  334. }
  335. //判断是否缴费
  336. function payCost() {
  337. var url = "/patient/consult/remainConsultTimes",
  338. params = {};
  339. sendPost(url, params, "json", "get", queryFailed, function(res) {
  340. if(expensesStatus == 1) {
  341. querySignType(2);
  342. } else {
  343. if(expensesStatus == 0) {
  344. if(res.status == 200) {
  345. if(res.data > 0) {
  346. dialog({
  347. content: "您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:" + res.data + "次.为避免影响您的服务体验,请尽快完成缴费操作",
  348. cancelValue: '前往缴费',
  349. cancel: function() {
  350. window.location.href = "../../qygl/html/signing_management.html?id"
  351. },
  352. okValue: '开始咨询',
  353. ok: function() {
  354. querySignType();
  355. // window.location.href = "../../yszx/html/add-consult.html?type=" + request.type + "&doctorCode=" + request.doctor;
  356. },
  357. }).showModal()
  358. } else {
  359. dialog({
  360. content: "您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.为避免影响您的服务体验,请尽快完成缴费操作",
  361. cancelValue: '前往缴费',
  362. cancel: function() {
  363. window.location.href = "../../qygl/html/signing_management.html?id"
  364. },
  365. }).showModal()
  366. }
  367. } else {
  368. queryFailed(res)
  369. }
  370. }
  371. if(expensesStatus == 2) {
  372. }
  373. }
  374. })
  375. }
  376. //请求失败处理事件
  377. function queryFailed(res, message) {
  378. d.close();
  379. if(message) {
  380. dialog({
  381. contentType: 'tipsbox',
  382. bottom: true,
  383. skin: 'bk-popup',
  384. content: message
  385. }).show();
  386. } else {
  387. if(res && res.msg) {
  388. dialog({
  389. contentType: 'tipsbox',
  390. bottom: true,
  391. skin: 'bk-popup',
  392. content: res.msg
  393. }).show();
  394. } else {
  395. dialog({
  396. contentType: 'tipsbox',
  397. bottom: true,
  398. skin: 'bk-popup',
  399. content: '加载失败'
  400. }).show();
  401. }
  402. }
  403. }