prescription-consulting.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. var request = getRequest(),
  2. sessionId = request.sessionId,
  3. patiCode,
  4. consultCode,
  5. prescriptionStatus,
  6. prescriptionCode;
  7. page = 1,
  8. members = [];
  9. var docInfo = window.localStorage.getItem("docInfo");
  10. docInfo = JSON.parse(docInfo);
  11. $(function(){
  12. //续方咨询的sessionId 格式 居民code+咨询code+咨询类型( 8 )
  13. patiCode = sessionId.split("_")[0];
  14. consultCode = sessionId.split("_")[1];
  15. getConsultStatus();
  16. //获得会话参与人员
  17. consultingAPI.getMembers(sessionId).then(function(res){
  18. members = res;
  19. getMessage(true);
  20. })
  21. getPrescriptionInfo();
  22. getPatientServiceType(); //获得患者的标签类型
  23. connectSocket();
  24. bindEvents();
  25. })
  26. function getConsultStatus(){
  27. var params = {consult: consultCode};
  28. consultingAPI.getConsultStatus({data: params}).then(function(res){
  29. if(res.status == 200){
  30. //咨询状态(0进行中,1已完成,-1患者取消,-2超时未响应自动关闭)
  31. if(res.data == 0) { //咨询未结束
  32. } else { //咨询已结束
  33. $('.info-panel').html('咨询求助已结束');
  34. $('.send-btn').addClass("disabled");
  35. $("#file_head").attr("disabled", true);
  36. }
  37. }else{
  38. }
  39. });
  40. }
  41. function getMessage(isInit){
  42. var params = {
  43. page: page,
  44. pagesize: 10,
  45. end_msg_id: '',
  46. start_msg_id: '',
  47. user: docInfo.code,
  48. session_id: sessionId,
  49. content_type: '',
  50. isoffset: ''
  51. }
  52. consultingAPI.getMessages(sessionId, {data: params}).then(function(res){
  53. var list = res;
  54. if (list && list.length > 0) {
  55. id = list[list.length - 1].id;
  56. var html = '',
  57. length = list.length;
  58. for (var j = list.length-1; j >= 0; j--) {
  59. var reply = list[j];
  60. html += formatMsg(reply);
  61. }
  62. if(isInit){
  63. $("#talkBox").append(html);
  64. $("#talkBox").slimScroll({
  65. height: '100%',
  66. width: '100%',
  67. alwaysVisible: true,
  68. start : 'bottom',
  69. }).bind('slimscroll', function(e, pos) {
  70. if(pos == 'top'){
  71. if(length == 10){
  72. page++;
  73. getMessage();
  74. }
  75. }
  76. });
  77. }else{
  78. $("#talkBox").prepend(html);
  79. $("#talkBox").slimScroll({
  80. scrollTo: 'bottom'
  81. });
  82. }
  83. $(".fancybox").fancybox({openEffect:"none",closeEffect:"none"});
  84. plyr.setup();
  85. }
  86. });
  87. }
  88. function formatMsg(reply){
  89. try{
  90. reply = JSON.parse(reply);
  91. }catch(e){
  92. }
  93. var isSelf = (reply.sender_id==docInfo.code) ? true : false;
  94. var isSystem = reply.sender_id == 'system';
  95. var html = '';
  96. if(reply.content_type == 7 || reply.content_type == 10){
  97. var content = reply.content;
  98. if(isSystem){
  99. content = '居民24小时内未回复,系统自动结束咨询';
  100. }
  101. html = template('sys_msg_tmp', {content: content});
  102. }else{
  103. var member;
  104. for(var i=0; i<members.length; i++){
  105. if(reply.sender_id == members[i].id){
  106. member = members[i];
  107. break;
  108. }
  109. }
  110. var img = APIService.getImgUrl(member.avatar);
  111. if((img.indexOf('http') == -1) && (img.indexOf("https") == -1)){
  112. img = member.is_patient ? 'img/p-default.png' : 'img/d-male.png';
  113. }
  114. var content = '';
  115. try{
  116. content = JSON.parse(reply.content);
  117. }catch(e){
  118. if(reply.content_type == 12){ //视频文件
  119. var arr = reply.content.split(",");
  120. content = {};
  121. content.img = arr[0];
  122. content.path = arr[1];
  123. content.time = arr[2];
  124. }else{
  125. content = reply.content;
  126. }
  127. }
  128. var obj = {
  129. isSelf: isSelf,
  130. time: new Date(reply.timestamp).format('yyyy-MM-dd HH:mm:ss'),
  131. type: reply.content_type,
  132. name: member.name,
  133. img: img,
  134. content: content
  135. };
  136. html = template('msg_tmp', obj);
  137. }
  138. return html;
  139. }
  140. function getPrescriptionInfo(){
  141. var params = { consult: consultCode};
  142. consultingAPI.getPrescriptionInfo({data: params}).then(function(res){
  143. if(res.status == 200){
  144. var html = template('prescriptionInfo_tmp', res.data);
  145. prescriptionStatus = res.data.status;
  146. prescriptionCode = res.data.code;
  147. var statusName = getStatusName(res.data.status);
  148. $(".status-btn").text(statusName);
  149. $("#prescriptionInfo").empty().append(html);
  150. $("#prescriptionInfo").slimscroll({
  151. height: 'calc(100% - 60px)',
  152. width: '100%'
  153. });
  154. }else{
  155. showWarningMsg(res.msg)
  156. }
  157. });
  158. }
  159. function getPatientServiceType(){
  160. var params = {patient: patiCode};
  161. consultingAPI.getPatientServiceType({data: params}).then(function(res){
  162. if(res.status == 200){
  163. //slowDiseasePatient: 0 //0表示没有慢病服务类型,1表示有
  164. if(res.data.slowDiseasePatient == 0){
  165. $(".diseaseInfo").html("此居民未被标注【慢病】相关标签,请在i健康APP上核实");
  166. }else{
  167. var disease = "";
  168. for(var i=0; i<res.data.signFamilyServer.length; i++){
  169. var item = res.data.signFamilyServer[i];
  170. if(i>0){
  171. disease += ','+item.name;
  172. }else{
  173. disease += item.name;
  174. }
  175. }
  176. $(".diseaseInfo").text("该居民为"+disease+"患者");
  177. }
  178. }else{
  179. showWarningMsg(res.msg)
  180. }
  181. });
  182. }
  183. function connectSocket(){
  184. jQuery.getScript(APIService.socketUrl+"/socket.io/socket.io.js").done(function() {
  185. var socket = io.connect(APIService.socketUrl );
  186. socket.emit('login', {
  187. userId: docInfo.code,
  188. password: docInfo.code,
  189. sessionId: sessionId,
  190. clientType: "doctor"
  191. });
  192. socket.on('message', function (data) {
  193. console.log(data);
  194. if(data.read && data.read == "all"){
  195. return ;
  196. }
  197. var html = formatMsg(data);
  198. $("#talkBox").append(html);
  199. $("#talkBox").slimscroll({
  200. scrollTo: 'bottom'
  201. });
  202. });
  203. socket.on('error', function (data) {
  204. console.log(data)
  205. });
  206. socket.on('ack', function (data) {
  207. });
  208. }).fail(function() {
  209. // dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
  210. });
  211. }
  212. function sendMessage(contentType, content){
  213. var params = {
  214. sender_id: docInfo.code,
  215. sender_name: docInfo.name,
  216. content_type: contentType,
  217. content: content,
  218. view: 0
  219. };
  220. consultingAPI.sendMessage(sessionId, {data: params}).then(function(res){
  221. console.log(res);
  222. // var html = "";
  223. // for(var i=0; i<res.messages.length; i++){
  224. // var reply = res.messages[i];
  225. // console.log(reply);
  226. // html += formatMsg(reply);
  227. // }
  228. // $("#talkBox").append(html);
  229. // $("#talkBox").slimscroll({
  230. // scrollTo: this.height
  231. // });
  232. });
  233. }
  234. //结束咨询
  235. function finish(){
  236. //判断续方状态,如果未审核,则不可以结束咨询
  237. if(prescriptionStatus > 0 && prescriptionStatus < 21){
  238. dialog({
  239. content:'续方申请未审核,不能结束咨询',
  240. width: 460,
  241. okValue:'我知道了',
  242. ok: function() {
  243. return;
  244. }
  245. }).width(320).showModal();
  246. return false;
  247. }
  248. dialog({
  249. content:'结束咨询后,居民及所有医生均无法再次回复,是否确认继续结束?',
  250. width: '460px',
  251. okValue:'继续结束',
  252. ok: function() {
  253. var params = {consult: consultCode};
  254. consultingAPI.finishConsult({data: params}).then(function(res){
  255. if(res.status == 200) {
  256. var content = docInfo.name+'结束了咨询',
  257. html = template('sys_msg_tmp', {content: content});
  258. $("#talkBox").append(html);
  259. $("#talkBox").slimScroll({
  260. scrollTo: 'bottom'
  261. });
  262. $('.info-panel').html("咨询求助已结束");
  263. $(".send-btn").addClass("disabled");
  264. $("#file_head").attr("disabled", true);
  265. showSuccessMsg("已结束咨询");
  266. } else {
  267. showErrorMsg(res.msg);
  268. }
  269. })
  270. },
  271. cancelValue: '我再看看',
  272. cancel: function(){}
  273. }).showModal();
  274. }
  275. function bindEvents(){
  276. $(".send-btn").on('click', function(){
  277. var $this = $(this);
  278. if($this.hasClass("disabled")){
  279. return false;
  280. }else{
  281. var text = $.trim($("#input_content").text());
  282. if(text.length == 0){
  283. showWarningMsg('发送内容不能为空');
  284. return false;
  285. }else{
  286. sendMessage(1, text);
  287. $("#input_content").text('');
  288. var obj = {
  289. content: text,
  290. content_type: '1',
  291. sender_id: docInfo.code,
  292. timestamp: new Date().getTime()
  293. }
  294. var html = formatMsg(obj);
  295. $("#talkBox").append(html);
  296. $("#talkBox").slimscroll({
  297. scrollTo: 'bottom'
  298. });
  299. }
  300. }
  301. });
  302. $("#file_head").on('change', function(){
  303. var file = this.files[0];
  304. //先上传图片去服务器,然后再发送消息
  305. var fd=new FormData();
  306. fd.append("action", "UploadVMKImagePath");
  307. fd.append("file", file); //加入文件对象
  308. fd.append("type", '2');
  309. var ajaxObj = {
  310. data: fd,
  311. cache: false,
  312. processData: false,
  313. contentType: false
  314. }
  315. consultingAPI.uploadImage(ajaxObj).then(function(res){
  316. if(res.status == 200){
  317. sendMessage(2, res.urls);
  318. var obj = {
  319. content: res.urls,
  320. content_type: '2',
  321. sender_id: docInfo.code,
  322. timestamp: new Date().getTime()
  323. }
  324. var html = formatMsg(obj);
  325. $("#talkBox").append(html);
  326. $("#talkBox").slimscroll({
  327. scrollTo: 'bottom'
  328. });
  329. }else{
  330. }
  331. });
  332. });
  333. //查看详情
  334. $("body").on('click', '.view-detail', function(res){
  335. //修改顶部tab页面的
  336. var url = parent.document.getElementById("tab").src;
  337. parent.document.getElementById("tab").src = "prescription-tabs.html?sessionId="+sessionId+"&patiCode="+patiCode+"&code="+prescriptionCode+"&tab=1&fromTabIdx=0";
  338. })
  339. }
  340. template.helper('getSourceUrl', function(str){
  341. return APIService.getImgUrl(str);
  342. })