consulting-doctor.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
  3. var userAgent = window.localStorage.getItem(agentName);
  4. var dialroll;
  5. var doctorInfo;
  6. var content = "";
  7. var timeStr = "";
  8. var id = 0;
  9. var pagesize = 10;
  10. var Request = new Object();
  11. Request = GetRequest();
  12. var consult = Request["consult"];
  13. var status = Request["status"];
  14. var docMsg = 0;
  15. $(function() {
  16. checkStatus();
  17. //点击内容区域输入框失焦
  18. $('#talkwrap').click(function(){
  19. $("#chatTxtCon").blur();
  20. dialroll.refresh();
  21. dialroll.scrollTo(0, dialroll.maxScrollY);
  22. return false;
  23. });
  24. //发送以后定位至最底部
  25. $(".talk-send a").click(function() {
  26. send();
  27. });
  28. //从后台那边获取签名等信息
  29. var params = {};
  30. var url1 = "";
  31. if(status == 0 || status == 1){
  32. url1 = server + "wx/html/zxwz/html/consulting-doctor.html?status=" + status + "&consult=" + consult;
  33. }else{
  34. url1 = server + "wx/html/zxwz/html/consulting-doctor.html?consult=" + consult;
  35. }
  36. params.pageUrl = url1;
  37. $.ajax(server + "weixin/getSign", {
  38. data: params,
  39. dataType: "json",
  40. type: "post",
  41. success: function(res){
  42. if (res.status == 200) {
  43. var t = res.data.timestamp;
  44. var noncestr = res.data.noncestr;
  45. var signature = res.data.signature;
  46. wx.config({
  47. appId: appId, // 必填,公众号的唯一标识
  48. timestamp: t, // 必填,生成签名的时间戳
  49. nonceStr: noncestr, // 必填,生成签名的随机串
  50. signature: signature,// 必填,签名,见附录1
  51. jsApiList: [
  52. 'chooseImage',
  53. 'uploadImage'
  54. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  55. });
  56. }
  57. }
  58. });
  59. });
  60. //控制“发送”按钮的变化
  61. function sendBtn() {
  62. var tval = $(".talk-input input").val();
  63. if (tval != "") {
  64. $(".talk-send a").removeClass("disab");
  65. } else {
  66. $(".talk-send a").addClass("disab");
  67. }
  68. }
  69. //控制页面高度
  70. function winSize(h) {
  71. var totH = $(window).height();
  72. $("#talkwrap").height(totH - h);
  73. }
  74. //判断记录的状态
  75. function checkStatus(){
  76. d.show();
  77. if(status == 0 || status == 1){
  78. if(status == 0){
  79. $("#divBottom").show();
  80. $("#finish_list").show();
  81. winSize(102);
  82. }else{
  83. $("#divBottom").hide();
  84. $("#finish_list").hide();
  85. winSize(0);
  86. }
  87. //页面初始化查询
  88. queryList();
  89. var pulldownAction = function() {
  90. getPage(this);
  91. };
  92. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  93. dialroll.refresh();
  94. dialroll.scrollTo(0, dialroll.maxScrollY);
  95. $(window).resize(function() {
  96. if(status == 0){
  97. winSize(102);
  98. }
  99. else{
  100. winSize(0);
  101. }
  102. });
  103. }else{
  104. var data = {};
  105. data.consult = consult;
  106. sendPost('patient/consult/status', data, 'json', 'post', queryFailed, querySuccess);
  107. }
  108. }
  109. function queryFailed(res) {
  110. d.close();
  111. if (res && res.msg) {
  112. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  113. } else {
  114. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'获取咨询记录状态失败'}).show();
  115. }
  116. }
  117. function querySuccess(res) {
  118. if (res.status == 200) {
  119. if(res.data == 0){
  120. $("#divBottom").show();
  121. $("#finish_list").show();
  122. winSize(102);
  123. }else{
  124. $("#divBottom").hide();
  125. $("#finish_list").hide();
  126. winSize(0);
  127. }
  128. //聊天记录填充
  129. queryList();
  130. var pulldownAction = function() {
  131. getPage(this);
  132. };
  133. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  134. dialroll.refresh();
  135. dialroll.scrollTo(0, dialroll.maxScrollY);
  136. $(window).resize(function() {
  137. if(res.data == 0){
  138. winSize(102);
  139. }
  140. else{
  141. winSize(0);
  142. }
  143. });
  144. }
  145. else{
  146. queryFailed(res);
  147. }
  148. }
  149. //页面初始化
  150. function queryList(){
  151. var data = {};
  152. data.consult = consult;
  153. data.id = id;
  154. data.pagesize = pagesize;
  155. sendPost('patient/consult/loglist', data, 'json', 'post', queryFailed2, querySuccess2);
  156. }
  157. function queryFailed2(res) {
  158. d.close();
  159. if (res && res.msg) {
  160. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  161. } else {
  162. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  163. }
  164. }
  165. function querySuccess2(res) {
  166. if (res.status == 200) {
  167. var list = res.list;
  168. if (list && list.length > 0) {
  169. id = list[list.length - 1].id;
  170. docMsg = list[list.length - 1].type;
  171. for (var j = list.length-1; j >=0; j--) {
  172. var reply = list[j];
  173. //type为1时,医生发的
  174. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName);
  175. }
  176. dialroll.refresh();
  177. dialroll.scrollTo(0, dialroll.maxScrollY);
  178. }
  179. d.close();
  180. }
  181. else{
  182. queryFailed2(res);
  183. }
  184. }
  185. //点击发送按钮
  186. function send(){
  187. content = $("#chatTxtCon").val().replace(/\s+/g,"");
  188. if (content && content != null && content != "") {
  189. var now = new Date();
  190. timeStr = "";
  191. if(now.getMonth()<9){
  192. //补0
  193. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  194. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  195. }else{
  196. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  197. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  198. }
  199. $("#chatTxtCon").blur();
  200. dialroll.refresh();
  201. dialroll.scrollTo(0, dialroll.maxScrollY);
  202. dd.showModal();
  203. var data = {};
  204. data.consult = consult;
  205. data.content = utf16toEntities(content);
  206. data.type = 1;
  207. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitSuccess);
  208. } else {
  209. return;
  210. }
  211. }
  212. function submitFailed(res) {
  213. dd.close();
  214. if (res && res.msg) {
  215. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  216. } else {
  217. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'发送失败'}).show();
  218. }
  219. }
  220. function submitSuccess(res) {
  221. if (res.status == 200) {
  222. //置空
  223. $("#chatTxtCon").val("");
  224. $(".talk-send a").addClass("disab");
  225. addReply(2, content, timeStr, 1, "");
  226. dialroll.refresh();
  227. dialroll.scrollTo(0, dialroll.maxScrollY);
  228. dd.close();
  229. } else {
  230. submitFailed(res);
  231. }
  232. }
  233. //回复单条内容填写
  234. var defaultPhoto = "../../../images/p-default.png";
  235. var doctorDefaultPhoto = "../../../images/d-default.png";
  236. function addReply(type, content, time, msgType, doctorName) {
  237. //time = time.substr(10);
  238. var doctorPhoto = doctorDefaultPhoto;
  239. var patientPhoto = defaultPhoto;
  240. var $div = $("<div></div>");
  241. if (type == 1) {
  242. if(msgType == 2){
  243. $div.addClass('talk-left');
  244. $div.addClass('clearfix');
  245. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
  246. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  247. +'<div class="rightpart">'
  248. +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  249. +'</div>');
  250. }
  251. else{
  252. $div.addClass('talk-left');
  253. $div.addClass('clearfix');
  254. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
  255. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time + '</span>'
  256. +'<div class="rightpart">'
  257. +' <s class="rightjt jt-left"><s></s></s>'+content
  258. +'</div>');
  259. }
  260. } else {
  261. if(msgType == 2){
  262. $div.addClass('talk-right');
  263. $div.addClass('clearfix');
  264. $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
  265. +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
  266. +'<div class="rightpart">'
  267. +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  268. +'</div>');
  269. }
  270. else{
  271. $div.addClass('talk-right');
  272. $div.addClass('clearfix');
  273. $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
  274. + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
  275. + '<div class="rightpart">' + content + '</div>');
  276. }
  277. }
  278. $(".talk-box").append($div);
  279. }
  280. //向上拉取更多
  281. function addReplyBefore(type, content, time, msgType, doctorName) {
  282. //time = time.substr(10);
  283. var doctorPhoto = doctorDefaultPhoto;
  284. var patientPhoto = defaultPhoto;
  285. var $div = $("<div></div>");
  286. if (type == 1) {
  287. if(msgType == 2){
  288. $div.addClass('talk-left');
  289. $div.addClass('clearfix');
  290. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
  291. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  292. +'<div class="rightpart">'
  293. +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+content+'" onclick="viewImg(this)"/>'
  294. +'</div>');
  295. }
  296. else{
  297. $div.addClass('talk-left');
  298. $div.addClass('clearfix');
  299. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
  300. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  301. +'<div class="rightpart">'
  302. +' <s class="rightjt jt-left"><s></s></s>'+content
  303. +'</div>');
  304. }
  305. } else {
  306. if(msgType == 2){
  307. $div.addClass('talk-right');
  308. $div.addClass('clearfix');
  309. $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
  310. +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
  311. +'<div class="rightpart">'
  312. +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  313. +'</div>');
  314. }
  315. else{
  316. $div.addClass('talk-right');
  317. $div.addClass('clearfix');
  318. $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
  319. + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
  320. + '<div class="rightpart">' + content + '</div>');
  321. }
  322. }
  323. $(".talk-box").prepend($div);
  324. }
  325. //页面初始化
  326. function getPage(t){
  327. var data = {};
  328. data.consult = consult;
  329. data.id = id;
  330. data.pagesize = pagesize;
  331. $.ajax(server + "patient/consult/loglist", {
  332. data: data,
  333. type: 'POST',
  334. dataType: 'json',
  335. beforeSend: function(request) {
  336. request.setRequestHeader("userAgent", userAgent);
  337. },
  338. error: function(res) {
  339. if(res.status == 999 || res.status == 998 || res.status == 997){
  340. loginUrl(res.status);
  341. return;
  342. }
  343. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"加载失败"}).show();
  344. },
  345. success: function(res) {
  346. if(res.status == 999 || res.status == 998 || res.status == 997){
  347. loginUrl(res.status);
  348. }
  349. else if (res.status == 200) {
  350. var list = res.list;
  351. if (list && list.length > 0) {
  352. id = list[list.length - 1].id;
  353. for (var j = 0; j < list.length; j++) {
  354. var reply = list[j];
  355. //type为1时,医生发的
  356. addReplyBefore(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName);
  357. }
  358. }
  359. t.refresh();
  360. } else {
  361. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  362. }
  363. }
  364. });
  365. }
  366. //结束咨询
  367. function finish(){
  368. dialog({
  369. title:'提示',
  370. content:'您确定结束这次咨询之旅了吗?',
  371. ok: function (){
  372. var params = {}
  373. params.code = consult;
  374. //发送ajax请求, 查询设备列表信息
  375. sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
  376. function finish_Successs(res){
  377. if (res.status == 200) {
  378. window.history.go(-1);
  379. //window.location.href = "teachers-consulting-list.html";
  380. }
  381. else{
  382. submitFailed3(res);
  383. }
  384. }
  385. },
  386. cancel: function () {
  387. return;
  388. }
  389. }).showModal();
  390. }
  391. function submitFailed3(res) {
  392. if (res && res.msg) {
  393. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  394. } else {
  395. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'操作失败'}).show();
  396. }
  397. }
  398. //查看图片
  399. function viewImg(dom) {
  400. var $img = $(dom);
  401. var thissrc = $img.attr("src");
  402. var mWid = $(window).width();
  403. var mHei = $(window).height();
  404. 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>';
  405. $("body").append(nHtml);
  406. $(".delimgpop").click(function() {
  407. $(this).remove()
  408. });
  409. }
  410. //微信上传图片
  411. var serverId = "";
  412. var images = [];
  413. function chooseImage(){
  414. wx.chooseImage({
  415. count: 3,
  416. success: function (res) {
  417. for (var i in res.localIds) {
  418. images.push(res.localIds[i]);
  419. }
  420. dd.showModal();
  421. uploadImage();
  422. }
  423. });
  424. }
  425. function uploadImage(){
  426. if (images.length == 0) {
  427. dd.close();
  428. return;
  429. }
  430. var i = 0, length = images.length;
  431. serverId = "";
  432. var faillength = 0 ;
  433. function upload() {
  434. wx.uploadImage({
  435. localId: images[i],
  436. isShowProgressTips: 0,
  437. success: function (res) {
  438. faillength= 0;
  439. dd.close();
  440. i++;
  441. if(serverId.length == 0){
  442. serverId = res.serverId;
  443. }
  444. else{
  445. serverId =serverId + "," + res.serverId;
  446. }
  447. if (i < length) {
  448. upload();
  449. }
  450. if(i == images.length){
  451. sendImages();
  452. }
  453. },
  454. fail: function (res) {
  455. dd.close();
  456. faillength+=1;
  457. if(faillength<=5){
  458. //失败从传
  459. upload();
  460. }else{
  461. alert(JSON.stringify(res));
  462. }
  463. }
  464. });
  465. }
  466. upload();
  467. }
  468. //保存图片
  469. function sendImages(){
  470. var now = new Date();
  471. timeStr = "";
  472. if(now.getMonth()<9){
  473. //补0
  474. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  475. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  476. }else{
  477. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  478. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  479. }
  480. var data = {};
  481. data.consult = consult;
  482. data.content = "";
  483. data.mediaIds = serverId;
  484. data.type = 2;
  485. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
  486. }
  487. function submitImageSuccess(res) {
  488. if (res.status == 200) {
  489. dd.close();
  490. var imageList = res.data.split(',');
  491. for(var i=0; i < imageList.length; i++){
  492. addReply(2, imageList[i], timeStr, 2, "");
  493. }
  494. dialroll.refresh();
  495. dialroll.scrollTo(0, dialroll.maxScrollY);
  496. } else {
  497. submitFailed(res);
  498. }
  499. }