sanshitijiao.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. Request = GetRequest();
  2. var chooseType = Request["type"];//界面传送的类型 0不定义类型 1.慢病咨询 2.家庭医生咨询 6.名医咨询
  3. var doctorCode = Request["doctorCode"];
  4. var id = Request["id"];
  5. var guidance = "";
  6. var workTime = "";//医生工作时间
  7. var doctorName = "";//医生名称
  8. var patientName = window.localStorage.getItem('nowPatientName');
  9. var fromPage = Request["fromPage"];
  10. // updateTitle();
  11. //修改header 的标题
  12. function updateTitle(title){
  13. //需要jQuery
  14. var $body = $('body');
  15. document.title = title;
  16. // hack在微信等webview中无法修改document.title的情况
  17. var $iframe = $('<iframe src="/favicon.ico"></iframe>');
  18. $iframe.on('load',function() {
  19. setTimeout(function() {
  20. $iframe.off('load').remove();
  21. }, 0);
  22. }).appendTo($body);
  23. }
  24. $(function(){
  25. if(fromPage && fromPage=="jkzx") {
  26. updateTitle("新增医生健康咨询")
  27. } else {
  28. guidance = window.localStorage.getItem("guidance")
  29. }
  30. // 指导内容显示
  31. if (guidance) {
  32. $("#guidance").html(guidance);
  33. } else {
  34. $("#guidanceWrap").hide();
  35. }
  36. // 咨询类别
  37. if(chooseType==1){
  38. //$(".span-type").html("慢病管理");
  39. querySignType();//填充下拉框
  40. }else if(chooseType==2){
  41. //$(".span-type").html("家庭医生");
  42. querySignType();//填充下拉框
  43. }else if(chooseType==0) {
  44. querySignType();//填充下拉框
  45. }
  46. /* 复选框兼容 */
  47. $(document).on("click", ".input-group-pack > input[type=checkbox]", function() {
  48. var $cpChk = $(this).parent();
  49. if ($(this).attr("checked") == "checked") {
  50. $cpChk.removeClass("checked");
  51. $(this).removeAttr("checked");
  52. } else {
  53. $cpChk.addClass("checked");
  54. $(this).attr("checked", true);
  55. }
  56. });
  57. //弹窗
  58. $('.broadcast-icon').on('click',function(){
  59. $('.broadcast-shadow-panel').removeClass('c-hide');
  60. });
  61. $('.win-cancle').on('click',function(){
  62. $('.broadcast-shadow-panel').addClass('c-hide');
  63. });
  64. //从后台那边获取签名等信息
  65. var params = {};
  66. params.pageUrl = window.location.href;
  67. $.ajax(server + "weixin/getSign", {
  68. data: params,
  69. dataType: "json",
  70. type: "post",
  71. success: function(res){
  72. if (res.status == 200) {
  73. var t = res.data.timestamp;
  74. var noncestr = res.data.noncestr;
  75. var signature = res.data.signature;
  76. wx.config({
  77. // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  78. appId: appId, // 必填,公众号的唯一标识
  79. timestamp: t, // 必填,生成签名的时间戳
  80. nonceStr: noncestr, // 必填,生成签名的随机串
  81. signature: signature,// 必填,签名,见附录1
  82. jsApiList: [
  83. 'chooseImage',
  84. 'uploadImage'
  85. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  86. });
  87. }
  88. else{
  89. dialog({
  90. title:'提示',
  91. skin:"ui-dialog ax-popup pror",
  92. content:"获取微信签名失败",
  93. ok: function (){}
  94. }).showModal();
  95. window.location.href = "doctor-guidance.html";
  96. }
  97. }
  98. });
  99. function successFun(res){
  100. if(res.status==200){
  101. var dataList = res.data.doctor;
  102. doctorName = dataList.name;
  103. $("#lbl_doctor").html(dataList.name+"("+dataList.jobName+")");
  104. $("#lbl_patient").html(patientName);
  105. }else{
  106. getListFail(res);
  107. }
  108. }
  109. function getListFail(res){
  110. if (res && res.msg) {
  111. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  112. } else {
  113. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  114. }
  115. }
  116. //提交咨询
  117. $("#commit").click(function() {
  118. if($(this).hasClass("active")){
  119. var data = {};
  120. data.type = Number($("#txtTypeCode").val());
  121. if($("#txtContent").val() == null)
  122. data.symptoms = "";
  123. else
  124. data.symptoms = utf16toEntities($("#txtContent").val().replace(/\s+/g,""));
  125. data.voice = "";
  126. if (validate(data)) {
  127. //验证通过执行
  128. dd.showModal();
  129. var images = getImages();
  130. if(images.length == 0){
  131. $("#commit").css("pointer-events","none");
  132. doSubmit(data);
  133. }
  134. else{
  135. uploadImage(data);
  136. }
  137. }
  138. }
  139. });
  140. });
  141. function checkInWork(doctor){
  142. sendPost('/patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'post', queryFailed, function(res){
  143. if(res.status==200){
  144. if(res.data==0){
  145. dialog({
  146. title: '提示',
  147. content: '您好,由于您的签约医生工作繁忙,所以设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复',
  148. okValue:'我知道了',
  149. ok: function (){
  150. return;
  151. },
  152. cancelValue: '查看时间',
  153. cancel: function () {
  154. alert("查看时间")
  155. }
  156. }).showModal();
  157. }
  158. }else{
  159. queryFailed(res);
  160. }
  161. });
  162. }
  163. //查询咨询类型
  164. function querySignType(){
  165. d.show();
  166. sendPost('patient/sign_status', {}, 'json', 'post', querySignTypeFailed, querySignTypeSuccess);
  167. }
  168. function querySignTypeFailed(res) {
  169. d.close();
  170. if (res && res.msg) {
  171. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  172. } else {
  173. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取咨询类型失败'}).show();
  174. }
  175. }
  176. function querySignTypeSuccess(res) {
  177. if (res.status == 200) {
  178. $('#txtTypeCode').val(chooseType);
  179. $('#lbl_doctor').html(getSignDoctor(res,chooseType));
  180. $("#lbl_patient").html(patientName);
  181. var arr_key=[];
  182. var arr_value=[];
  183. var sign = Number(res.data);
  184. if(sign == 1){
  185. arr_key=[1];
  186. arr_value=['慢病管理'];
  187. }
  188. else if(sign == 2){
  189. arr_key=[2];
  190. arr_value=['家庭医生'];
  191. }
  192. else if(sign == 3&&chooseType==0){
  193. arr_key=[1,2,6];
  194. arr_value=['慢病管理', '家庭医生'];
  195. }else if(sign == 3&&chooseType==1){
  196. arr_key=[1];
  197. arr_value=['慢病管理'];
  198. }else if(sign == 3&&chooseType==2){
  199. arr_key=[2];
  200. arr_value=['家庭医生'];
  201. }
  202. else{
  203. arr_key=[];
  204. arr_value=[];
  205. }
  206. //签约类型
  207. var option1 = {
  208. theme: 'ios',
  209. lang: 'zh',
  210. formatValue: function(d) {
  211. return d.join(',');
  212. },
  213. customWheels: true,
  214. wheels: [
  215. [{
  216. keys: arr_key,
  217. values: arr_value
  218. }]
  219. ],
  220. onSelect: function(valueText, inst) {
  221. var dd = eval("[" + valueText + "]");
  222. $('#txtTypeCode').val(dd[0].keys);
  223. $('#txtTypeName').val(dd[0].values);
  224. $('#lbl_doctor').html(getSignDoctor(res,dd[0].keys));
  225. }
  226. };
  227. $('#txtTypeName').mobiscroll(option1);
  228. $('#txtTypeName').val(option1.wheels[0][0].values[0]);
  229. $('#txtTypeCode').val(option1.wheels[0][0].keys[0]);
  230. $('#lbl_doctor').html(getSignDoctor(res,option1.wheels[0][0].keys[0]));
  231. //选择发病时间
  232. $('li.ill-time').mobiscroll({
  233. theme: 'ios',
  234. lang: 'zh',
  235. formatValue: function(d) {
  236. return d.join(',');
  237. },
  238. customWheels: true,
  239. wheels: [
  240. [{
  241. keys: ['0', '1', '2', '3', '4', '5'],
  242. values: ['最近24小时', '最近一周', '最近三个月', '最近一年', '一年以上', '不清楚']
  243. }]
  244. ],
  245. onSelect: function(valueText, inst) {
  246. var dd = eval("[" + valueText + "]");
  247. $('input[data-time=illTime]').val(dd[0].values);
  248. }
  249. });
  250. d.close();
  251. } else {
  252. querySignTypeFailed(res);
  253. }
  254. }
  255. //获取医生信息
  256. function getSignDoctor(data,type){
  257. var doctor_name = "";
  258. var doctor_type = "";
  259. switch(Number(type))
  260. {
  261. case 1:
  262. doctor_type = data.teamDoctors;
  263. break;
  264. case 2:
  265. doctor_type = data.familyDoctors;
  266. break;
  267. default:
  268. break;
  269. }
  270. for(var i=0; i < doctor_type.length; i++){
  271. doctor_name += doctor_type[i] + ",";
  272. }
  273. if(doctor_name.length > 0){
  274. doctor_name = doctor_name.substring(0, doctor_name.length-1);
  275. }
  276. return doctor_name;
  277. }
  278. //验证信息
  279. function validate(data) {
  280. // if (data.type == '') {
  281. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择咨询类型'}).show();
  282. // return false;
  283. // }
  284. // if (data.when == '') {
  285. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择发病时间'}).show();
  286. // return false;
  287. // }
  288. if (data.symptoms.length < 10) {
  289. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请至少用10个字描述您的症状'}).show();
  290. return false;
  291. }
  292. if (data.symptoms.length > 500) {
  293. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请在500字以内完成您的症状描述'}).show();
  294. return false;
  295. }
  296. if(!$(".input-group-pack > input[type=checkbox]").attr("checked")){
  297. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请勾选"我已阅读咨询说明"'}).show();
  298. return false;
  299. }
  300. return true;
  301. }
  302. var serverId = "";
  303. function chooseImage(){
  304. wx.chooseImage({
  305. count: 9-getImages().length,
  306. success: function (res) {
  307. for (var i in res.localIds) {
  308. appendFile(res.localIds[i]);
  309. }
  310. }
  311. });
  312. }
  313. function uploadImage(data){
  314. $("#commit").css("pointer-events","none");
  315. var images = getImages();
  316. if (images.length == 0) {
  317. return;
  318. }
  319. var i = 0, length = images.length;
  320. serverId = "";
  321. function upload() {
  322. wx.uploadImage({
  323. localId: images[i],
  324. isShowProgressTips: 0,
  325. success: function (res) {
  326. i++;
  327. if(serverId.length == 0){
  328. serverId = res.serverId;
  329. }
  330. else{
  331. serverId =serverId + "," + res.serverId;
  332. }
  333. if (i < length) {
  334. upload();
  335. }
  336. if(i == images.length){
  337. doSubmit(data);
  338. }
  339. },
  340. fail: function (res) {
  341. $("#commit").css("pointer-events","");
  342. alert(JSON.stringify(res));
  343. }
  344. });
  345. }
  346. upload();
  347. }
  348. // 添加文件
  349. function appendFile(p) {
  350. var amount = getImages().length;
  351. if (amount >= 8) {
  352. $("#add_img_li").hide();
  353. }
  354. if(amount < 9){
  355. var $li = $('<li>' + ' <img src="' + p + '" data-src="' + p + '" onclick="viewImg(this)">' + ' <a href="javascript:;" class="del-img" onclick="delImg(this)"><i class="iconfont icon-laji"></i></a>' + '</li>');
  356. var $add_img_li = $("#add_img_li");
  357. $add_img_li.before($li);
  358. $("#image_tips").text(getImages().length + "/9");
  359. }
  360. }
  361. //获取需要上传的图片
  362. function getImages() {
  363. var images = [];
  364. $("#img_ul").find("img").each(function() {
  365. var imgSrc = $(this).attr("data-src");
  366. images.push(imgSrc);
  367. });
  368. return images;
  369. }
  370. //查看图片
  371. function viewImg(dom) {
  372. var $img = $(dom);
  373. var thissrc = $img.attr("data-src");
  374. var mWid = $(window).width();
  375. var mHei = $(window).height();
  376. var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
  377. $("body").append(nHtml);
  378. $(".delimgpop").click(function() {
  379. $(this).remove()
  380. });
  381. };
  382. //删除图片
  383. function delImg(dom) {
  384. var $li = $(dom).parent();
  385. $li.remove();
  386. $("#image_tips").text(getImages().length + "/9");
  387. var amount = getImages().length;
  388. if(amount <= 8){
  389. $("#add_img_li").show();
  390. }
  391. return;
  392. }
  393. //微信sdk配置出错
  394. wx.error(function (res) {
  395. alert("wx.error:" + res.errMsg);
  396. });
  397. //提交咨询
  398. function doSubmit(data) {
  399. data.images = serverId;
  400. var url = 'patient/consult/add';//新增三师或家庭
  401. data.guidance = id;
  402. sendPost(url, data, 'json', 'post', submitFailed, submitSuccess);
  403. }
  404. function time_range(beginTime, endTime, nowTime) {
  405. var strb = beginTime.split (":");
  406. if (strb.length != 2) {
  407. return false;
  408. }
  409. var stre = endTime.split (":");
  410. if (stre.length != 2) {
  411. return false;
  412. }
  413. var strn = nowTime.split (":");
  414. if (stre.length != 2) {
  415. return false;
  416. }
  417. var b = new Date ();
  418. var e = new Date ();
  419. var n = new Date ();
  420. b.setHours (strb[0]);
  421. b.setMinutes (strb[1]);
  422. e.setHours (stre[0]);
  423. e.setMinutes (stre[1]);
  424. n.setHours (strn[0]);
  425. n.setMinutes (strn[1]);
  426. if (n.getTime () - b.getTime () > 0 && n.getTime () - e.getTime () < 0) {
  427. return "1";//在时间范围内
  428. } else {
  429. return "0";//不在工作时间内
  430. }
  431. }
  432. function CompareDate(t1,t2)
  433. {
  434. var date = new Date();
  435. var a = t1.split(":");
  436. var b = t2.split(":");
  437. return date.setHours(a[0],a[1]) > date.setHours(b[0],b[1]);
  438. }
  439. //判断医生是否在工作时间内
  440. function isWordTime(curWorkTime){
  441. dd.close();
  442. var week = new Date().getDay();
  443. var myDate = new Date();
  444. debugger
  445. if(curWorkTime){//有上班时间
  446. var cosultTimeArr = curWorkTime.split("~");
  447. var curHours = myDate.getHours(); //获取当前小时数(0-23)
  448. var curMinutes = myDate.getMinutes();//获取当前分钟数(0-59)
  449. var curTime = curHours+":"+curMinutes;
  450. var timeRange = time_range(cosultTimeArr[0],cosultTimeArr[1],curTime)
  451. if(timeRange=="1"){//在工作时间内,查询某个医生名医当前剩余咨询次数
  452. consultTimesRemain();
  453. }else{//不在工作时间内,判断早晚
  454. var isFlag1 = CompareDate(curTime,cosultTimeArr[0]);
  455. var isFlag2 = CompareDate(curTime,cosultTimeArr[1]);
  456. if(!isFlag1){//来早了
  457. dialog({
  458. content: '您来早了哦,'+doctorName+'医生将在'+cosultTimeArr[0]+'准时开始接受咨询~',
  459. cancelValue: '我知道了',
  460. cancel: function () {
  461. $("#commit").removeClass("active");
  462. dd.close();
  463. return;
  464. }
  465. }).showModal();
  466. return false;
  467. }
  468. if(isFlag2){//来晚了
  469. dialog({
  470. content: '您来晚了哦~'+doctorName+'医生本日咨询时间已过,请改日再来~',
  471. cancelValue: '我知道了',
  472. cancel: function () {
  473. $("#commit").removeClass("active");
  474. dd.close();
  475. return;
  476. }
  477. }).showModal();
  478. return false;
  479. }
  480. }
  481. }else{
  482. dialog({
  483. content: '医生今天不上班哦,请在医生咨询计划时间段内咨询',
  484. cancelValue: '我知道了',
  485. cancel: function () {
  486. $("#commit").removeClass("active");
  487. dd.close();
  488. return;
  489. }
  490. }).showModal();
  491. return false;
  492. }
  493. }
  494. function submitFailed(res) {
  495. $("#commit").css("pointer-events","");
  496. dd.close();
  497. if (res && res.msg) {
  498. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  499. } else {
  500. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show();
  501. }
  502. }
  503. function submitSuccess(res) {
  504. if (res.status == 200) {
  505. $("#commit").css("pointer-events","");
  506. dd.close();
  507. window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=http%3a%2f%2f" + weixinUrl + "%2f" + urlName + "%2fwx%2fhtml%2fyszx%2fhtml%2fdoctor-consultation.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  508. //window.location.href = "vedio-consulting-commit-success.html?type=2";
  509. } else {
  510. submitFailed(res);
  511. }
  512. }
  513. //function voicePop(n) {
  514. // $(".win-broadcast,.win-broadcast-mb").show();
  515. // $("#voice-finish").click(function() {
  516. // $("#voice" + n).show();
  517. // $(".win-broadcast,.win-broadcast-mb").hide();
  518. // });
  519. //}
  520. //
  521. //function voicePopClose() {
  522. // $(".win-broadcast,.win-broadcast-mb").hide();
  523. //}