doctor-consultation_new.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. //家庭医生咨询分页参数
  2. var id = 0;
  3. var pageSize = 15;
  4. //续方咨询分页参数
  5. var xfId = 0;
  6. var xfPageSize = 15;
  7. var d = dialog({contentType:'load', skin:'bk-popup'});
  8. var patientcode ="",
  9. patientName = "";
  10. //var isHealthSearch = false,
  11. // isPreSearch = false;
  12. var userAgent = window.localStorage.getItem(agentName);
  13. var pagetype = 1;
  14. var chooseType; //记录选择的咨询类型
  15. var loaded = [true, false]; //标记两个tab是否已经加载过
  16. var chooseTab = 1; //默认选中的是家庭健康咨询
  17. var expensesStatus ="";//'扣费状态 【""没有签约信息 "0"未扣费 "1"已扣费 "2"已退费】'
  18. var is_sign = 0;
  19. //页面初始化
  20. $(function(){
  21. checkUserAgent();
  22. // queryInit();
  23. });
  24. function queryInit(){
  25. initScroller();
  26. // initFamilyData();
  27. initPageData();
  28. bindEvents();
  29. wxGetSign();
  30. }
  31. function initScroller(){
  32. //阻尼系数
  33. var deceleration = mui.os.ios?0.003:0.0009;
  34. mui('.mui-scroll-wrapper1').scroll({
  35. scrollY: false, //是否竖向滚动
  36. scrollX: true, //是否横向滚动
  37. startX: 0, //初始化时滚动至x
  38. startY: 0, //初始化时滚动至y
  39. bounce: false,
  40. indicators: true, //是否显示滚动条
  41. deceleration:deceleration
  42. });
  43. mui.ready(function() {
  44. //循环初始化所有下拉刷新,上拉加载。
  45. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  46. mui(pullRefreshEl).pullRefresh({
  47. up: {
  48. callback: function() {
  49. var self = this;
  50. setTimeout(function() {
  51. if(index == 0){
  52. getHealthConsulationList(false);
  53. // }else{
  54. // getPreConsultList();
  55. }
  56. self.endPullupToRefresh();
  57. }, 1000);
  58. }
  59. }
  60. });
  61. });
  62. });
  63. }
  64. function initFamilyData(){
  65. appendFamilyMember($('#memberContainer'),function(){
  66. //切换家庭成员,默认选中健康咨询tab显示
  67. id = 0;
  68. xfId = 0;
  69. chooseType = 1;
  70. loaded = [true, false];
  71. $("#healthTab a").click();
  72. initPageData();
  73. },function(t){
  74. //判断有授权家人,修改样式,只在初始的时候执行一次
  75. var height = $('#memberContainer').height();
  76. $("#slider").css({
  77. 'top': height,
  78. 'height': 'calc(100% - '+height+'px)'
  79. });
  80. });
  81. }
  82. function initPageData(){
  83. var userInfo= JSON.parse(userAgent);
  84. patientcode = userInfo.uid;
  85. getPatientInfo();
  86. }
  87. //获得患者信息
  88. function getPatientInfo(){
  89. d.show();
  90. var data={};
  91. sendPost('patient/baseinfo', data, 'json', 'post', queryFailed, function(res){
  92. if (res.status == 200) {
  93. var data = res.data,
  94. ssc = data.ssc;
  95. expensesStatus = res.data.expensesStatus;
  96. patientName = data.name;
  97. mui('#slider').slider().gotoItem(0);
  98. $("#preTab").hide();
  99. mui('#slider').slider().setStopped(true);
  100. //获得咨询列表数据
  101. getHealthConsulationList(true);
  102. } else {
  103. queryFailed(res);
  104. }
  105. });
  106. }
  107. //获取健康咨询列表
  108. function getHealthConsulationList(isInit){
  109. if(isInit){
  110. id = 0;
  111. }
  112. var url = 'patient/consult/records',
  113. params = {
  114. id: id,
  115. pagesize: pageSize,
  116. title: $("#item1 .inp-search").val().trim()
  117. };
  118. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  119. if(res.status == 200){
  120. $("#healthConsulationPanel").css("top","50px");
  121. d.close();
  122. $('#healthConsulationPanel').show();
  123. if (res.list.length > 0) {
  124. $('#ul_jiating_consultation').show();
  125. $('#item1 .vertical-line').show();
  126. $("#item1 .div-no-search-info").hide();
  127. $("#item1 .div-no-info").hide();
  128. var searchText = $("#item1 .inp-search").val().trim();
  129. var list = _.map(res.list, function(o){
  130. o.jsonStr = JSON.stringify(o);
  131. //针对搜索字体
  132. if(searchText.length > 0){
  133. var reg = new RegExp(searchText,"g");
  134. o.symptoms = o.symptoms.replace(reg, '<em>'+searchText+"</em>");
  135. }
  136. var divStatus = "";
  137. // if(o.type==2){
  138. if(o.status==0){
  139. //咨询中
  140. divStatus = "div-beginning";
  141. }else if(o.evaluate ==1){
  142. divStatus = "div-hasvalue";//是否有评价 0无 1有
  143. }else{
  144. divStatus = "div-novalue";
  145. }
  146. // }
  147. o.statusClass = divStatus;
  148. return o;
  149. });
  150. var html = template('healthConsulation_tmp', {list: list});
  151. if(id == 0){
  152. $("#ul_jiating_consultation").empty().append(html);
  153. }else{
  154. $("#ul_jiating_consultation").append(html);
  155. }
  156. if(res.list.length < pageSize){
  157. mui("#item1 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  158. }
  159. id = res.list[res.list.length-1].id;
  160. }else{
  161. if(isInit){
  162. $('#ul_jiating_consultation').hide();
  163. $('#item1 .vertical-line').hide();
  164. $("#item1 .div-no-search-info").show();
  165. }else{
  166. mui("#item1 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  167. }
  168. }
  169. }else{
  170. queryFailed(res);
  171. }
  172. });
  173. }
  174. //判断是否有未结束的咨询
  175. function isConsultUnfinished(docInfo,docQkInfo){
  176. var url = 'patient/consult/is_consult_unfinished',
  177. params = {doctor: docInfo.code};
  178. sendPost(url, params, 'json', 'post', function(res){
  179. queryFailed(res, '获取是否存在咨询失败');
  180. },function(res){
  181. d.close();
  182. if(res.status == 200){
  183. if(res.data == ""){
  184. //不存在
  185. checkDocInWork(chooseType, docInfo,docQkInfo);
  186. } else {
  187. dialog({
  188. content: '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,无法发起新的咨询',
  189. okValue:'前往查看',
  190. ok: function (){
  191. var userInfo = JSON.parse(userAgent);
  192. var rep = userInfo.uid;
  193. window.location.href = "consulting-doctor.html?consult=" + res.data +"&toUser="+rep;
  194. },
  195. cancelValue: '我知道了',
  196. cancel: function () {
  197. $(".modal-overlay").trigger("click");
  198. $(".jiating-icon").removeClass("active");
  199. $(".mingyi-icon").removeClass("active");
  200. return;
  201. }
  202. }).showModal();
  203. }
  204. } else {
  205. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  206. }
  207. });
  208. }
  209. //获取签约医生的工作时间
  210. function checkDocInWork(type, doctor,docQkInfo){
  211. var url = 'patient/consult/isDoctorWorkWhenconsult',
  212. params = {doctor:docQkInfo.code,healthDoctor:doctor.code};
  213. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  214. if(res.status == 200){
  215. // data:0-医生不接受咨询/1-医生当前接受咨询/2-全科医生和健管师当前都不在工作时间/3-全科医生当前不在工作时间/4-健管师当前不在工作时间 健管师当前不在工作时间
  216. if(res.data==2){
  217. dialog({
  218. content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  219. okValue:'查看医生工作时间',
  220. ok: function (){
  221. window.location.href = "doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  222. },
  223. cancelValue: '继续新增咨询',
  224. cancel: function () {
  225. window.location.href = "add-consult.html?type=" +type+"&doctorCode="+doctor.code;
  226. }
  227. }).showModal();
  228. }else if(res.data==3){
  229. dialog({
  230. content: '您好,由于您的签约全科医生工作繁忙……,您的咨询将不会马上获得全科医生的回复 。',
  231. okValue:'查看医生工作时间',
  232. ok: function (){
  233. window.location.href = "doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  234. },
  235. cancelValue: '继续新增咨询',
  236. cancel: function () {
  237. window.location.href = "add-consult.html?type=" +type+"&doctorCode="+doctor.code;
  238. }
  239. }).showModal();
  240. }else if(res.data==4){
  241. dialog({
  242. content: '您好,由于您的签约健康管理师工作繁忙……,您的咨询将不会马上获得健康管理师的回复 。',
  243. okValue:'查看医生工作时间',
  244. ok: function (){
  245. window.location.href = "doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  246. },
  247. cancelValue: '继续新增咨询',
  248. cancel: function () {
  249. window.location.href = "add-consult.html?type=" +type+"&doctorCode="+doctor.code;
  250. }
  251. }).showModal();
  252. }else{
  253. //跳转到新增咨询页面
  254. window.location.href = "add-consult.html?type="+type+"&doctorCode="+doctor.code;
  255. }
  256. }else{
  257. queryFailed(res);
  258. }
  259. });
  260. }
  261. //判断是否可以新增续方咨询
  262. function checkCanPreConsult(){
  263. var url = "/patient/consult/isPrescriptionConsult",
  264. params = {patient: patientcode};
  265. d.show();
  266. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  267. if(res.status == 200){
  268. //成功及可以发起续方咨询,跳转去新增续方咨询页面
  269. //TODO 待处理事件
  270. window.location.href = "add-prescription-consult.html?patient="+patientcode+"&name="+patientName;
  271. }else{
  272. queryFailed(res);
  273. }
  274. });
  275. }
  276. //显示搜索输入文字
  277. function showSearchSuggest(text, type){
  278. var suggestText = '搜索“'+text+'”';
  279. // 如果text不为空,则显示;否则隐藏
  280. if(text&&text.trim().length) {
  281. if(type == 1){//家庭医生咨询
  282. $("#search_suggest_text").text(suggestText);
  283. $("#search_suggest_text").show();
  284. }else if(type == 2){//续方咨询
  285. $("#xf_search_suggest_text").text(suggestText);
  286. $("#xf_search_suggest_text").show();
  287. }
  288. } else {
  289. if(type == 1){//家庭医生咨询
  290. $("#search_suggest_text").text('');
  291. $("#search_suggest_text").hide();
  292. }else if(type == 2){//续方咨询
  293. $("#xf_search_suggest_text").text('');
  294. $("#xf_search_suggest_text").hide();
  295. }
  296. }
  297. }
  298. //搜索操作
  299. function search(type){
  300. d.show();
  301. if(type == 1){//家庭医生咨询
  302. // isHealthSearch = true;
  303. // id = 0;
  304. $("#search_suggest_text").text('');
  305. $("#search_suggest_text").hide();
  306. $("#item1 .searchbar-cancel").hide();
  307. $("#item1 .searchbar-cancel").css("opacity","0");
  308. $("#item1 .div-no-info").hide();
  309. $("#item1 .div-no-search-info").hide();
  310. d.show();
  311. getHealthConsulationList(true);
  312. }else if(type == 2){//续方咨询
  313. // isPreSearch = true;
  314. // xfId = 0;
  315. $("#xf_search_suggest_text").text('');
  316. $("#xf_search_suggest_text").hide();
  317. $("#item2 .searchbar-cancel").hide();
  318. $("#item2 .searchbar-cancel").css("opacity","0");
  319. $("#item2 .div-no-info").hide();
  320. $("#item2 .div-no-search-info").hide();
  321. getPreConsultList();
  322. }
  323. }
  324. function bindEvents(){
  325. //监听tab切换动作
  326. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  327. var index = event.detail.slideNumber;
  328. chooseTab = index + 1;
  329. if(!loaded[index]){ //tab未加载过,则加载数据
  330. d.show();
  331. getPreConsultList();
  332. loaded[index] = true;
  333. }
  334. });
  335. $("#ul_jiating_consultation").on("tap",'li', function(){
  336. var userInfo = JSON.parse(userAgent);
  337. var jsonData = JSON.parse(this.getAttribute("data-json"));
  338. if(jsonData.status == 0){
  339. window.location.href = "../../qygl/html/sign_info.html?consult="+jsonData.code+"&doctor="+jsonData.doctorCode;
  340. }else{
  341. localStorage.setItem("evaluate",jsonData.evaluate);
  342. window.location.href = "consulting-doctor.html?consult=" + jsonData.code+"&type="+jsonData.type+"&toUser="+userInfo.uid+"&doctor="+jsonData.doctorCode;
  343. }
  344. });
  345. $("#ul_xufang_consultation").on("tap",'li', function(){
  346. var userInfo = JSON.parse(userAgent);
  347. var jsonData = JSON.parse(this.getAttribute("data-json"));
  348. localStorage.setItem("evaluate",jsonData.evaluate);
  349. //跳转去续方咨询页面
  350. window.location.href = 'prescription-consulting.html?consult='+jsonData.code+'&type='+jsonData.type+"&toUser="+userInfo.uid+"&doctor="+jsonData.doctorCode;
  351. });
  352. //新增按钮事件
  353. $(".div-add-btn").on("click",function(){
  354. //现在固定显示咨询可以选择类型,不做三师等的判断
  355. // $(this).hide();
  356. // $(".div-dialog-content").show();
  357. // $(".modal-overlay").addClass("modal-overlay-visible");
  358. //直接跳转去选择医生列表
  359. window.location.href = "select-consult-doctor.html";
  360. });
  361. //点击遮罩事件
  362. $(".modal-overlay").on("click",function(){
  363. $(".modal-overlay").removeClass("modal-overlay-visible");
  364. $(".div-dialog-content").hide();
  365. $(".div-add-btn").removeClass("active");
  366. if(is_sign == 1){
  367. $(".div-add-btn").show();
  368. }else{
  369. $(".div-add-btn").hide();
  370. }
  371. });
  372. //点击家庭医生事件
  373. $(".jiating-icon").on("click",function(){
  374. $(this).addClass("active");
  375. if(is_sign == 1){
  376. //判断该居民是否已经缴费 1为已经交费 ""没有签约信息 "0"未扣费 "1"已扣费 "2"已退费
  377. if(expensesStatus == 1){
  378. querySignType(2);
  379. }else{
  380. //未缴费居民限制咨询次数
  381. limitZxTimes();
  382. }
  383. }else{
  384. $(".div-dialog-content").show();
  385. dialog({
  386. content: '没有有效的签约信息,请前往签约',
  387. okValue:'前往签约',
  388. ok: function (){
  389. window.location.href = "../../qygl/html/signing_management.html";
  390. },
  391. cancelValue: '我知道了',
  392. cancel: function () {
  393. $(".modal-overlay").trigger("click");
  394. $(".jiating-icon").removeClass("active");
  395. $(".mingyi-icon").removeClass("active");
  396. return;
  397. }
  398. }).showModal();
  399. }
  400. // if(expensesStatus == 1){
  401. // querySignType(2);
  402. // }else if(expensesStatus == ""){
  403. // d.close();
  404. // $(".mui-content").hide();
  405. // $(".div-no-sign").show();
  406. // }else{
  407. // //未缴费居民限制咨询次数
  408. // limitZxTimes();
  409. // }
  410. });
  411. //点击名医咨询事件
  412. $(".mingyi-icon").on("click",function(){
  413. $(this).addClass("active");
  414. if(is_sign == 1){
  415. window.location.href = "select-consult-doctor.html";
  416. }else{
  417. dialog({
  418. content: '没有有效的签约信息,请前往签约',
  419. okValue:'前往签约',
  420. ok: function (){
  421. window.location.href = "../../qygl/html/signing_management.html";
  422. },
  423. cancelValue: '我知道了',
  424. cancel: function () {
  425. $(".modal-overlay").trigger("click");
  426. $(".jiating-icon").removeClass("active");
  427. $(".mingyi-icon").removeClass("active");
  428. return;
  429. }
  430. }).showModal();
  431. }
  432. });
  433. //取消事件
  434. $(".quxiao").on("click",function(){
  435. $(".modal-overlay").trigger("click");
  436. });
  437. //查看签约
  438. $('#signing-btn').on('click',function(){
  439. window.location.href = "../../qygl/html/signing_management.html";
  440. });
  441. //跳转去签约管理页面
  442. $("#goToSign").on('click', function(){
  443. window.location.href = "../../qygl/html/signing_management.html";
  444. });
  445. //点击发起咨询事件
  446. $("#launch-btn").on("tap",function(){
  447. // $(".div-add-btn").trigger("click");
  448. window.location.href = "select-consult-doctor.html";
  449. });
  450. //点击续方tab内发起咨询的事件
  451. $("#launch-btn2").on("tap", function(){
  452. //判断是否可以续方咨询
  453. checkCanPreConsult();
  454. })
  455. //点击续方申请事件
  456. $(".xufangsq-icon").on("click",function(){
  457. $(this).addClass("active");
  458. //判断是否可以续方咨询
  459. checkCanPreConsult();
  460. });
  461. //搜索框事件
  462. $(".inp-search").on("input",function(){
  463. var text = $(this).val().trim(),
  464. type = $(this).attr("data-val");
  465. if(type == 1){//家庭医生咨询
  466. $('#healthConsulationPanel').hide();
  467. }else if(type == 2){//续方咨询
  468. $('#re-prescriptionConsulationPanel').hide();
  469. }
  470. showSearchSuggest(text, type);
  471. var $searchCancelBtn = $(".searchbar-clear");
  472. if(text){
  473. // $searchCancelBtn.css("opacity","1");
  474. }else{
  475. // $searchCancelBtn.css("opacity","0");
  476. search(type);
  477. }
  478. }).on('keydown',function(e) {
  479. var type = $(this).attr("data-val");
  480. if (e.which === 13) {
  481. search(type);
  482. }
  483. });
  484. $("#search_suggest_text").on("click", function(){
  485. search(1);
  486. });
  487. $("#xf_search_suggest_text").on("click", function(){
  488. search(2);
  489. });
  490. $(".searchbar-clear").on("click", function(){
  491. $(this).css("opacity","0");
  492. var $input = $(this).closest('.inp-search'),
  493. type = $input.attr("data-val");
  494. $input.val('');
  495. if(type == 1){//家庭医生咨询
  496. $("#search_suggest_text").text('');
  497. $("#search_suggest_text").hide();
  498. }else if(type == 2){//续方咨询
  499. $("#xf_search_suggest_text").text('');
  500. $("#xf_search_suggest_text").hide();
  501. }
  502. search(type);
  503. });
  504. //限制左右滑动
  505. // 左滑事件
  506. document.addEventListener("swipeleft", function(event) {
  507. console.log(event);
  508. event.preventDefault();
  509. return false;
  510. });
  511. // 右滑事件
  512. document.addEventListener("swiperight", function(event) {
  513. console.log(event);
  514. event.preventDefault();
  515. return false;
  516. });
  517. }
  518. //未缴费居民限制咨询次数
  519. function limitZxTimes(){
  520. //获取剩余家庭咨询次数
  521. var url = '/patient/consult/remainConsultTimes';
  522. var remainTimes;//剩余咨询次数
  523. var countTimes;//总咨询次数
  524. var zxTimes;//已咨询次数
  525. d.show();
  526. sendPost(url, {}, 'json', 'get', queryFailed, function(res){
  527. if(res.status == 200){
  528. d.close();
  529. remainTimes = res.data.amount;
  530. countTimes = res.data.count;
  531. zxTimes = countTimes - remainTimes;
  532. if(zxTimes == countTimes){
  533. //未缴费的总咨询次数已达上限 提示去缴费
  534. dialog({
  535. content: '您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.如果需要家庭医生继续为您提供服务,请尽快完成缴费操作',
  536. okValue:'前往缴费',
  537. ok: function (){
  538. window.location.href = "../../qygl/html/signing_management.html";
  539. }
  540. }).showModal();
  541. }else{
  542. dialog({
  543. content: '您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:'+remainTimes+'次.为避免影响您的服务体验,请尽快完成缴费操作',
  544. okValue:'前往缴费',
  545. ok: function (){
  546. window.location.href = "../../qygl/html/signing_management.html";
  547. },
  548. cancelValue: '开始咨询',
  549. cancel: function () {
  550. querySignType(2)
  551. }
  552. }).showModal();
  553. }
  554. }else{
  555. queryFailed(res);
  556. }
  557. });
  558. }
  559. //请求失败处理事件
  560. function queryFailed(res, message){
  561. d.close();
  562. if(message){
  563. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  564. }else{
  565. if (res && res.msg) {
  566. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  567. } else {
  568. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  569. }
  570. }
  571. }
  572. //获取微信信息,并配置微信api接口
  573. function wxGetSign(){
  574. var params = {};
  575. params.pageUrl = window.location.href;
  576. $.ajax(server + "weixin/getSign", {
  577. data: params,
  578. dataType: "json",
  579. type: "post",
  580. success: function(res){
  581. if (res.status == 200) {
  582. var t = res.data.timestamp;
  583. var noncestr = res.data.noncestr;
  584. var signature = res.data.signature;
  585. wx.config({
  586. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  587. appId: appId, // 必填,公众号的唯一标识
  588. timestamp: t, // 必填,生成签名的时间戳
  589. nonceStr: noncestr, // 必填,生成签名的随机串
  590. signature: signature,// 必填,签名,见附录1
  591. jsApiList: [
  592. 'closeWindow'
  593. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  594. });
  595. }
  596. }
  597. });
  598. }