consulting-doctor.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
  3. var dialroll;
  4. var doctorInfo;
  5. var content = "";
  6. var timeStr = "";
  7. var id = 1;
  8. var pagesize = 500;
  9. var Request = new Object();
  10. Request = GetRequest();
  11. var consult = Request["consult"];
  12. var status = Request["status"];
  13. var doctorType = Request["type"];
  14. var doctor = Request['doctor'];
  15. var toUser = Request["toUser"];
  16. var toName = decodeURIComponent(Request["toName"]);
  17. var openid = Request["openid"];
  18. var represented = Request["represented"];
  19. //var evaluate = localStorage.getItem("evaluate");//1为有评价 0为无评价
  20. var evaluate = 0;
  21. var docMsg = 0;
  22. var patientcode = "";
  23. var pagetype=24;
  24. var networkStatus = "";
  25. var userAgent = window.localStorage.getItem(agentName);
  26. var userInfo = '';
  27. $(function() {
  28. if(!userAgent) {
  29. localStorage.setItem("toUser",toUser);
  30. localStorage.setItem("consultCode",consult);
  31. window.location.href = "../../home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype;
  32. return false;
  33. }
  34. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  35. patientcode = newUaObj.represented?newUaObj.represented:newUaObj.uid;
  36. //判断关系
  37. function hasFamilyRelation(a,b){
  38. return new Promise(function(resolve, reject) {
  39. var data={
  40. patient:a,
  41. familyMember:b
  42. }
  43. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  44. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  45. }, function(res){
  46. if(res.status == 200) {
  47. window.localStorage.setItem('nowPatientName',res.data.name);
  48. resolve(res)
  49. }else if(res.status == 100) {
  50. dialog({
  51. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  52. okValue:'切换账号',
  53. ok: function() {
  54. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  55. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  56. },
  57. cancelValue: '我不看了',
  58. cancel: function () {
  59. wx.closeWindow();
  60. }
  61. }).showModal();
  62. }else{
  63. relogin();
  64. }
  65. })
  66. })
  67. }
  68. //重新登录操作
  69. function relogin(){
  70. dialog({
  71. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  72. okValue:'切换账号',
  73. ok: function() {
  74. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  75. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  76. },
  77. cancelValue: '我不看了',
  78. cancel: function () {
  79. wx.closeWindow();
  80. }
  81. }).showModal();
  82. }
  83. //保存信息
  84. function saveUserInfo(a,b){
  85. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  86. newUaObj.represented = represented;
  87. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  88. userInfo = JSON.parse(window.localStorage.getItem(agentName));
  89. bindEvents();
  90. checkStatus();
  91. })
  92. }
  93. function initFamilyData () {
  94. //从微信模板消息进入
  95. if(represented && userAgent && toUser){
  96. if(toUser == represented){
  97. saveUserInfo(represented,newUaObj.uid)
  98. }else if(toUser != represented && represented == newUaObj.uid){
  99. //本人代理
  100. saveUserInfo(represented,newUaObj.uid)
  101. }else if(toUser != represented && toUser == newUaObj.uid){
  102. //需要判定关系 200有授权 100家人 1无关系
  103. saveUserInfo(represented,newUaObj.uid)
  104. }else{
  105. //重新登录
  106. relogin();
  107. }
  108. }else{
  109. userInfo = JSON.parse(window.localStorage.getItem(agentName));
  110. bindEvents();
  111. checkStatus();
  112. }
  113. }
  114. initFamilyData();
  115. //点击内容区域输入框失焦
  116. $('#talkwrap').click(function(){
  117. $("#input_content").blur();
  118. return false;
  119. });
  120. //发送以后定位至最底部
  121. $("#reply a").click(function() {
  122. send();
  123. });
  124. //从后台那边获取签名等信息
  125. var params = {};
  126. var url1 = window.location.href;
  127. params.pageUrl = url1;
  128. $.ajax(server + "weixin/getSign", {
  129. data: params,
  130. dataType: "json",
  131. type: "post",
  132. success: function(res){
  133. if (res.status == 200) {
  134. var t = res.data.timestamp;
  135. var noncestr = res.data.noncestr;
  136. var signature = res.data.signature;
  137. wx.config({
  138. appId: appId, // 必填,公众号的唯一标识
  139. timestamp: t, // 必填,生成签名的时间戳
  140. nonceStr: noncestr, // 必填,生成签名的随机串
  141. signature: signature,// 必填,签名,见附录1
  142. jsApiList: [
  143. 'chooseImage',
  144. 'uploadImage',
  145. 'startRecord',
  146. 'stopRecord',
  147. 'onVoiceRecordEnd',
  148. 'playVoice',
  149. 'pauseVoice',
  150. 'stopVoice',
  151. 'onVoicePlayEnd',
  152. 'uploadVoice',
  153. 'getNetworkType'
  154. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  155. });
  156. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  157. wx.ready(function(){
  158. wx.getNetworkType({
  159. success: function (res) {
  160. networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
  161. }
  162. });
  163. });
  164. }
  165. }
  166. });
  167. //获取sessionId
  168. sendPost('/patient/consult/getTopic', {consult:consult}, 'json', 'GET', queryFailed2, function(res){
  169. if(res.status==200){
  170. var sessionId = JSON.parse(res.msg)[0].session_id;
  171. //加载socket组件
  172. jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
  173. var socket = io.connect(imurl);
  174. var userInfo = JSON.parse(window.localStorage.getItem(agentName));
  175. socket.emit('login', {userId: userInfo.represented?userInfo.represented:userInfo.uid, password: userInfo.represented?userInfo.represented:userInfo.uid,sessionId:sessionId,clientType:"patient"});
  176. socket.on('message', function (data) {
  177. // console.log(data)
  178. if((data.type == 1) ||(data.type == 2) || (data.type == 6) || (data.type == 12)){
  179. addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
  180. setTimeout(function(){
  181. dialroll.refresh();
  182. dialroll.scrollTo(0, dialroll.maxScrollY);
  183. },300)
  184. }
  185. });
  186. socket.on('error', function (data) {
  187. // console.log(data);
  188. });
  189. socket.on('ack', function (data) {
  190. // console.log(data);
  191. });
  192. function getLocalTime(nS) {
  193. return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
  194. }
  195. })
  196. .fail(function() {
  197. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
  198. });
  199. }
  200. });
  201. });
  202. //控制“发送”按钮的变化
  203. function sendBtn() {
  204. var tval = $(".talk-input input").val();
  205. if (tval != "") {
  206. $(".talk-send a").removeClass("disab");
  207. } else {
  208. $(".talk-send a").addClass("disab");
  209. }
  210. }
  211. //控制页面高度
  212. function winSize(h) {
  213. var totH = $(window).height();
  214. $("#talkwrap").height(totH - h);
  215. }
  216. function getDoctorWork(){
  217. if(doctorType=="6") {
  218. checkDoctorInWork(doctor);
  219. } else {
  220. sendPost('patient/sign_doctors', {patientCode:patientcode}, 'json', 'post', queryFailed, function(res){
  221. if(res.status==200){
  222. var doctorArray = res.familyDoctors;//家庭
  223. if(doctorType==1){//三师
  224. doctorArray = res.teamDoctors
  225. }
  226. if(doctorArray){
  227. var doctorInfo ="";
  228. for(var j in doctorArray){
  229. if(doctorArray[j].level=="3"){
  230. doctorInfo = doctorArray[j];//取出健康管理师
  231. break;
  232. }
  233. }
  234. if(doctorInfo!=""){
  235. checkDoctorInWork(doctorInfo.code);
  236. }
  237. }
  238. }else{
  239. queryFailed(res);
  240. }
  241. })
  242. }
  243. }
  244. function checkDoctorInWork(doctor){
  245. sendPost('patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'post', queryFailed, function(res){
  246. if(res.status==200){
  247. if(res.data!=1){
  248. addReply(7, "医生不在工作时间,无法及时回复您的消息。<br/><a class='workhours' href='#'>查看工作时间!</a>", getNowFormatDate(),1, "系统消息");
  249. $(".workhours").on("click",function(){
  250. location.href='doctor-work-hours.html?doctor='+doctor;
  251. });
  252. setTimeout(function(){
  253. dialroll.refresh();
  254. dialroll.scrollTo(0, dialroll.maxScrollY);
  255. },20);
  256. }
  257. }else{
  258. queryFailed(res);
  259. }
  260. });
  261. }
  262. //判断记录的状态
  263. function checkStatus(){
  264. d.show();
  265. if(status == 0 || status == 1){
  266. if(status == 0){
  267. $("#divBottom").show();
  268. $("#finish_list").show();
  269. winSize(102);
  270. }else{
  271. $("#divBottom").hide();
  272. $("#finish_list").hide();
  273. winSize(0);
  274. }
  275. //页面初始化查询
  276. queryList();
  277. var pulldownAction = function() {
  278. getPage(this);
  279. };
  280. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  281. dialroll.refresh();
  282. dialroll.scrollTo(0, dialroll.maxScrollY);
  283. $(window).resize(function() {
  284. if(status == 0){
  285. winSize(102);
  286. }
  287. else{
  288. winSize(0);
  289. }
  290. });
  291. }else{
  292. var data = {};
  293. data.consult = consult;
  294. sendPost('patient/consult/status', data, 'json', 'get', queryFailed, querySuccess);
  295. }
  296. }
  297. function queryFailed(res) {
  298. d.close();
  299. if (res && res.msg) {
  300. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  301. } else {
  302. dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'获取咨询记录状态失败'}).show();
  303. }
  304. }
  305. function querySuccess(res) {
  306. if (res.status == 200) {
  307. if(res.data == 0){
  308. if(Request.type == "6" || Request.type == "1"){ //名医咨询和三师咨询均使用旧的页面
  309. $("#divBottom").show();
  310. $("#finish_list").show();
  311. $("#input_div").show();
  312. winSize(102);
  313. }else{
  314. //进行中的咨询跳转去签约管理页面的咨询tab显示
  315. //获取teamcode
  316. var url = "patient/sign_status",
  317. params = {};
  318. sendPost(url, params, "json", "post", queryFailed, function(res1){
  319. var teamCode = res1["teamCode_2"];
  320. var signCode = res1["signCode_2"];
  321. localStorage.setItem("signInfo_tab", "1");
  322. if(doctor){
  323. window.location.href = "../../qygl/html/sign_info.html?code="+signCode+"&teamCode="+teamCode+"&type=2&doctor="+doctor+"&consult="+consult;
  324. }else{
  325. var url2 = "/patient/consult/getConsult";
  326. sendPost(url2, {consult: consult}, "json", "post", queryFailed, function(res2){
  327. if(res2.status == 200){
  328. var doctor = res2.data.doctor;
  329. window.location.href = "../../qygl/html/sign_info.html?code="+signCode+"&teamCode="+teamCode+"&type=2&doctor="+doctor+"&consult="+consult;
  330. }
  331. })
  332. }
  333. });
  334. }
  335. }else{
  336. $("#divBottom").hide();
  337. $("#finish_list").hide();
  338. $("#input_div").hide();
  339. winSize(0);
  340. //新增评价状态 1、已评价 0、未评价
  341. var data = {};
  342. data.consult = consult;
  343. sendPost('patient/consult/evaluateStatus', data, 'json', 'get', queryFailed, function(res){
  344. if (res.status == 200) {
  345. evaluate = res.data;
  346. //显示评价按钮
  347. if(evaluate == 0 && doctorType==2 ){
  348. $('#valFoot').show();
  349. $('#noval').show();
  350. $('#hasval').hide();
  351. }else if(evaluate == 1 && doctorType==2){
  352. $('#valFoot').show();
  353. $('#noval').hide();
  354. $('#hasval').show();
  355. }
  356. }else{
  357. queryFailed(res);
  358. }
  359. });
  360. }
  361. status = res.data;
  362. //聊天记录填充
  363. queryList();
  364. var pulldownAction = function() {
  365. getPage(this);
  366. };
  367. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  368. dialroll.refresh();
  369. dialroll.scrollTo(0, dialroll.maxScrollY);
  370. $(window).resize(function() {
  371. if(res.data == 0){
  372. winSize(102);
  373. }
  374. else{
  375. winSize(0);
  376. }
  377. });
  378. d.close();
  379. }
  380. else{
  381. queryFailed(res);
  382. }
  383. }
  384. //页面初始化
  385. function queryList(){
  386. var data = {};
  387. data.consult = consult;
  388. data.page = id;
  389. data.pagesize = pagesize;
  390. sendPost('patient/consult/loglist', data, 'json', 'GET', queryFailed2, querySuccess2);
  391. }
  392. function queryMsg(logId,msgType){
  393. var data={};
  394. data.consult = consult;
  395. data.logId = logId;
  396. data.msgType=msgType;
  397. sendPost('patient/consult/oneLog', data, 'json', 'GET', queryFailed2, function(res){
  398. if(res.status==200){
  399. var reply = res.consult;
  400. if((reply.msgType == 1) || (reply.msgType == 2) || (reply.msgType == 6)){
  401. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo);
  402. setTimeout(function(){
  403. dialroll.refresh();
  404. dialroll.scrollTo(0, dialroll.maxScrollY);
  405. },300)
  406. }
  407. }
  408. d.close();
  409. });
  410. }
  411. function queryFailed2(res) {
  412. d.close();
  413. if (res && res.msg) {
  414. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  415. } else {
  416. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载失败'}).show();
  417. }
  418. }
  419. function querySuccess2(res) {
  420. if (res.status == 200) {
  421. id++;
  422. res = res.list;
  423. var doctorPar = [];//储存参与咨询的医生
  424. for(var k in res.users){
  425. if(res.users[k].is_patient == 0 && res.users[k].id==doctor){
  426. doctorPar.push(res.users[k])
  427. }else if(res.users[k].is_patient == 0 && res.users[k].id!=doctor){
  428. doctorPar.unshift(res.users[k])
  429. }
  430. }
  431. doctorPar=JSON.stringify(doctorPar)
  432. window.localStorage.setItem('doctorPar',doctorPar);
  433. var list = res.list;
  434. if (list && list.length > 0) {
  435. docMsg = list[list.length - 1].content_type;
  436. var doctor = "";
  437. for (var j = list.length-1; j >=0; j--) {
  438. var reply = JSON.parse(list[j]);
  439. //type为1时,医生发的
  440. if((reply.content_type == 3) || (reply.content_type == 1) || (reply.content_type == 2) || (reply.content_type == 6) || (reply.content_type == 12)){
  441. var date = new Date();
  442. date.setTime(reply.timestamp);
  443. var time = date.format('yyyy-MM-dd hh:mm:ss');
  444. var p;
  445. for(var k in res.users){
  446. if(res.users[k].id==reply.sender_id){
  447. p = res.users[k].avatar;
  448. }
  449. }
  450. addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p);
  451. }
  452. }
  453. if(status==0){
  454. getDoctorWork();
  455. }
  456. dialroll.refresh();
  457. dialroll.scrollTo(0, dialroll.maxScrollY);
  458. }
  459. d.close();
  460. }
  461. else{
  462. queryFailed2(res);
  463. }
  464. }
  465. function getNowFormatDate() {
  466. var date = new Date();
  467. var seperator1 = "-";
  468. var seperator2 = ":";
  469. var month = date.getMonth() + 1;
  470. var strDate = date.getDate();
  471. if (month >= 1 && month <= 9) {
  472. month = "0" + month;
  473. }
  474. if (strDate >= 0 && strDate <= 9) {
  475. strDate = "0" + strDate;
  476. }
  477. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  478. + " " + date.getHours() + seperator2 + date.getMinutes()
  479. + seperator2 + date.getSeconds();
  480. return currentdate;
  481. }
  482. //点击发送按钮
  483. function send(){
  484. content = $("#input_content").text().replace(/\s+/g,"");
  485. if (content && content != null && content != "") {
  486. var now = new Date();
  487. timeStr = "";
  488. if(now.getMonth()<9){
  489. //补0
  490. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  491. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  492. }else{
  493. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  494. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  495. }
  496. $("#input_content").blur();
  497. dialroll.refresh();
  498. dialroll.scrollTo(0, dialroll.maxScrollY);
  499. // dd.showModal();
  500. var data = {};
  501. data.consult = consult;
  502. data.content = utf16toEntities(content);
  503. data.type = 1;
  504. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitSuccess);
  505. } else {
  506. return;
  507. }
  508. }
  509. function submitFailed(res) {
  510. dd.close();
  511. if (res && res.msg) {
  512. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  513. } else {
  514. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'发送失败'}).show();
  515. }
  516. }
  517. function submitSuccess(res) {
  518. if (res.status == 200) {
  519. //置空
  520. $("#input_content").text("");
  521. $(".talk-send a").addClass("disab");
  522. addReply(2, content, timeStr, 1, "");
  523. dialroll.refresh();
  524. dialroll.scrollTo(0, dialroll.maxScrollY);
  525. showSendBtn(false);
  526. dd.close();
  527. } else {
  528. submitFailed(res);
  529. }
  530. }
  531. //回复单条内容填写
  532. var defaultPhoto = "../../../images/p-default.png";
  533. var doctorDefaultPhoto = "../../../images/d-default.png";
  534. function addReply(type, content, time, msgType, doctorName,photo,prepend) {
  535. //time = time.substr(10);
  536. var doctorPhoto = photo ? getImgUrl(photo) : doctorDefaultPhoto;
  537. var $div = $("<dl></dl>");
  538. if(type == 7){
  539. if(prepend){
  540. $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  541. } else
  542. $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  543. return;
  544. }
  545. if (type == 1) {
  546. $div.addClass('chat-left');
  547. img = doctorPhoto;
  548. name = doctorName;
  549. } else {
  550. $div.addClass('chat-right');
  551. img = photo?getImgUrl(photo):defaultPhoto;
  552. defaultPhoto = img;
  553. name = window.localStorage.getItem("nowPatientName");
  554. }
  555. var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
  556. '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
  557. switch(parseInt(msgType)) {
  558. case 1://信息
  559. case 6://咨询问题
  560. temp += '<dd class="word-bread"><span>' + content + '</span></dd></dl>';
  561. break;
  562. case 2://图片
  563. temp += '<dd class="word-bread wb-img"><img width="100" height="100" src="'+ getImgUrl(content) +'" /></dd></dl>';
  564. break;
  565. case 3://语音
  566. var rec = JSON.parse(content);
  567. temp += "<div class='c-msg'><dd class='word-bread audio' data-type='3' data-audio='" + getImgUrl(content) + "'>"+
  568. "<div class='soundWav'>" +
  569. "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
  570. "</div>"+
  571. "</dd></div>";
  572. break;
  573. case 12://视频
  574. var videoInfo = content.split(",");
  575. var shichang = formatSeconds(videoInfo[2]);//时长
  576. if(type == 1){
  577. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  578. '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
  579. '<img class="bofang-icon-left" src="../images/bofang_icon.png">'+
  580. '<img class="jianjiao-icon-left" src="../images/zuoshanjiao_bg.png">'+
  581. '<span class="shichang-time-left">'+shichang+'</span>'+
  582. '</dd>';
  583. }else{
  584. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  585. '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
  586. '<img class="bofang-icon-right" src="../images/bofang_icon.png">'+
  587. '<img class="jianjiao-icon-right" src="../images/youshanjiao_bg.png">'+
  588. '<span class="shichang-time-right">'+shichang+'</span>'+
  589. '</dd>';
  590. }
  591. break;
  592. }
  593. if(prepend){
  594. $(".talk-box").prepend($div.append(temp)).prepend('<div class="time-tips"><span>' + time + '</span></div>');
  595. } else
  596. $(".talk-box").append('<div class="time-tips"><span>' + time + '</span></div>').append($div.append(temp));
  597. if(type != null && type != 1) {
  598. $(".tw-add-detail").hide(200);
  599. }
  600. }
  601. //毫秒转换成时分秒
  602. function formatSeconds(value) {
  603. var theTime = parseInt(value/1000);// 秒
  604. var theTime1 = 0;// 分
  605. var theTime2 = 0;// 小时
  606. if(theTime > 60) {
  607. theTime1 = parseInt(theTime/60);
  608. theTime = parseInt(theTime%60);
  609. if(theTime1 > 60) {
  610. theTime2 = parseInt(theTime1/60);
  611. theTime1 = parseInt(theTime1%60);
  612. }
  613. }
  614. var result = ""+parseInt(theTime);//秒
  615. if(parseInt(theTime)<=9){
  616. result = "0"+parseInt(theTime);//秒
  617. }
  618. if(theTime1 > 0) {//分
  619. if(parseInt(theTime1)>9){
  620. result = ""+parseInt(theTime1)+":"+result;
  621. }else{
  622. result = "0"+parseInt(theTime1)+":"+result;
  623. }
  624. }
  625. if(theTime2 > 0) {//小时
  626. if(parseInt(theTime2)>9){
  627. result = ""+parseInt(theTime2)+":"+result;
  628. }else{
  629. result = "0"+parseInt(theTime2)+":"+result;
  630. }
  631. }
  632. var resResult = "";
  633. if(result.split(":").length==1){//秒
  634. resResult = "00:"+result;
  635. }else if(result.split(":").length==2){//分
  636. resResult = "00:"+result;
  637. }else{//时
  638. resResult = result;
  639. }
  640. return resResult;
  641. }
  642. //向上拉取更多
  643. function addReplyBefore(type, content, time, msgType, doctorName) {
  644. //time = time.substr(10);
  645. var doctorPhoto = doctorDefaultPhoto;
  646. var patientPhoto = defaultPhoto;
  647. var $div = $("<div></div>");
  648. if (type == 1) {
  649. if(msgType == 2){
  650. $div.addClass('talk-left');
  651. $div.addClass('clearfix');
  652. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;max-width: 40px;">'+ doctorName + '</p></div> '
  653. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  654. +'<div class="rightpart">'
  655. +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  656. +'</div>');
  657. }
  658. else{
  659. $div.addClass('talk-left');
  660. $div.addClass('clearfix');
  661. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;max-width: 40px;">'+ doctorName + '</p></div> '
  662. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  663. +'<div class="rightpart">'
  664. +' <s class="rightjt jt-left"><s></s></s>'+content
  665. +'</div>');
  666. }
  667. } else {
  668. if(msgType == 2){
  669. $div.addClass('talk-right');
  670. $div.addClass('clearfix');
  671. $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
  672. +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
  673. +'<div class="rightpart">'
  674. +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  675. +'</div>');
  676. }
  677. else{
  678. $div.addClass('talk-right');
  679. $div.addClass('clearfix');
  680. $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
  681. + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
  682. + '<div class="rightpart">' + content + '</div>');
  683. }
  684. }
  685. $(".talk-box").prepend($div);
  686. }
  687. //页面初始化
  688. function getPage(t){
  689. // $(".talk-box").html("");
  690. var data = {};
  691. data.consult = consult;
  692. data.page = id;
  693. data.pagesize = pagesize;
  694. $.ajax(server + "patient/consult/loglist", {
  695. data: data,
  696. type: 'POST',
  697. dataType: 'json',
  698. beforeSend: function(request) {
  699. request.setRequestHeader("userAgent", userAgent);
  700. },
  701. error: function(res) {
  702. if(res.status == 999 || res.status == 998 || res.status == 997){
  703. loginUrl(res.status);
  704. return;
  705. }
  706. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"加载失败"}).show();
  707. },
  708. success: function(res) {
  709. if(res.status == 999 || res.status == 998 || res.status == 997){
  710. loginUrl(res.status);
  711. }
  712. else if (res.status == 200) {
  713. id++;
  714. var list = res.list;
  715. if (list && list.length > 0) {
  716. id = list[list.length - 1].id;
  717. for (var j = 0; j < list.length; j++) {
  718. var reply = list[j];
  719. //type为1时,医生发的
  720. if((reply.msgType == 1)|| (reply.msgType == 3) || (reply.msgType == 2) || (reply.msgType == 6)){
  721. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo, true);
  722. }
  723. }
  724. }
  725. t.refresh();
  726. } else {
  727. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  728. }
  729. }
  730. });
  731. }
  732. //结束咨询
  733. function finish(){
  734. dialog({
  735. content:'是否确认结束该次咨询?结束后医生将无法回复',
  736. ok: function (){
  737. var params = {}
  738. params.code = consult;
  739. //发送ajax请求, 查询设备列表信息
  740. sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
  741. function finish_Successs(res){
  742. if (res.status == 200) {
  743. location.reload();
  744. // window.location.href = "doctor-consultation.html";
  745. }
  746. else{
  747. submitFailed3(res);
  748. }
  749. }
  750. },
  751. cancel: function () {
  752. return;
  753. }
  754. }).showModal();
  755. }
  756. function submitFailed3(res) {
  757. if (res && res.msg) {
  758. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  759. } else {
  760. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'操作失败'}).show();
  761. }
  762. }
  763. //查看图片
  764. function viewImg(dom) {
  765. var $img = $(dom);
  766. var thissrc = $img.attr("src");
  767. var mWid = $(window).width();
  768. var mHei = $(window).height();
  769. 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>';
  770. $("body").append(nHtml);
  771. $(".delimgpop").click(function() {
  772. $(this).remove()
  773. });
  774. }
  775. //微信上传图片
  776. var serverId = "";
  777. var images = [];
  778. function chooseImageWx(){
  779. wx.chooseImage({
  780. count: 3,
  781. success: function (res) {
  782. for (var i in res.localIds) {
  783. images.push(res.localIds[i]);
  784. }
  785. dd.showModal();
  786. uploadImage();
  787. }
  788. });
  789. }
  790. function uploadImage(){
  791. if (images.length == 0) {
  792. dd.close();
  793. return;
  794. }
  795. var i = 0, length = images.length;
  796. serverId = "";
  797. var faillength = 0 ;
  798. function upload() {
  799. wx.uploadImage({
  800. localId: images[i],
  801. isShowProgressTips: 0,
  802. success: function (res) {
  803. faillength= 0;
  804. dd.close();
  805. i++;
  806. if(serverId.length == 0){
  807. serverId = res.serverId;
  808. }
  809. else{
  810. serverId =serverId + "," + res.serverId;
  811. }
  812. if (i < length) {
  813. upload();
  814. }
  815. if(i == images.length){
  816. sendImages();
  817. }
  818. },
  819. fail: function (res) {
  820. dd.close();
  821. faillength+=1;
  822. if(faillength<=5){
  823. //失败从传
  824. upload();
  825. }else{
  826. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
  827. }
  828. }
  829. });
  830. }
  831. upload();
  832. }
  833. //保存图片
  834. function sendImages(){
  835. var now = new Date();
  836. timeStr = "";
  837. if(now.getMonth()<9){
  838. //补0
  839. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  840. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  841. }else{
  842. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  843. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  844. }
  845. var data = {};
  846. data.consult = consult;
  847. data.content = "";
  848. data.mediaIds = serverId;
  849. data.type = 2;
  850. data.times = 0;
  851. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
  852. }
  853. function submitImageSuccess(res) {
  854. if (res.status == 200) {
  855. var data= JSON.parse(res.data)
  856. dd.close();
  857. addReply(2, data.content, timeStr, 2, "");
  858. dialroll.refresh();
  859. dialroll.scrollTo(0, dialroll.maxScrollY);
  860. } else {
  861. submitFailed(res);
  862. }
  863. }
  864. var aud = document.getElementById('audio');
  865. var $playingDom;
  866. function playSoundEnd(){
  867. $playingDom.removeClass('active');
  868. $playingDom = null;
  869. }
  870. function playError(){
  871. var src = $('#audio').attr('src');
  872. if(!$.trim(src)) {
  873. return ;
  874. }
  875. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
  876. $playingDom.removeClass('active');
  877. $playingDom = null;
  878. }
  879. $('.talk-box').on('click', '.word-bread img', function(){
  880. if(!$(this).closest(".word-bread").hasClass("preview-video")){
  881. var urls = [];
  882. $.each($('.word-bread img'), function(i, v) {
  883. urls.push($(v).attr('src'));
  884. });
  885. wx.previewImage({
  886. current: $(this).attr('src'), // 当前显示图片的http链接
  887. urls: urls // 需要预览的图片http链接列表
  888. });
  889. }
  890. })
  891. .on('touchstart', '.audio', function(){
  892. if($playingDom){
  893. aud.pause();
  894. //aud.stop();
  895. $playingDom.removeClass('active');
  896. if($playingDom[0] == this){
  897. $playingDom = null;
  898. return;
  899. }
  900. }
  901. $playingDom = $(this);
  902. $playingDom.addClass('active');
  903. var ser = JSON.parse($(this).attr('data-audio'));
  904. aud.src = getImgUrl(ser.path);
  905. aud.load();
  906. aud.play();
  907. })
  908. .on('click','.preview-video',function() {
  909. $(document.body).find('video').remove();
  910. var url = $(this).attr('data-video');
  911. var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'" ></video>';
  912. $(document.body).append(html);
  913. var video = $(document.body).find('video')[0];
  914. video.play();
  915. });
  916. var valLen = 0;
  917. var $ipt_content = $('#input_content');
  918. function showSendBtn(isShow){
  919. if(isShow){
  920. $('.tw-add').hide();
  921. $('#reply').fadeIn('fast', 'swing');
  922. } else if(valLen == 1 || isShow==false){
  923. $('#reply').fadeOut('fast', 'swing', function(){
  924. $('.tw-add').show();
  925. });
  926. }
  927. valLen = isShow ? isShow.length : 0;
  928. }
  929. /**
  930. * 显示发送按钮的事件
  931. */
  932. $ipt_content.on('input', function(e){
  933. showSendBtn($(this).text())
  934. })
  935. .on('tap', function(){
  936. $(".tw-add-detail").hide();
  937. $ipt_content.focus();
  938. })
  939. /*
  940. * 附加功能
  941. */
  942. $(".tw-add").click(function() {
  943. $(".tw-add-detail").toggle(200);
  944. });
  945. $('body')
  946. //隐藏打开的附加功能
  947. .on('tap', '#talkwrap', function(){
  948. $('.tw-add-detail').hide();
  949. $ipt_content.blur();
  950. })
  951. $(".yy-add").click(function() {
  952. if($('#msg-sound:visible').length){
  953. $ipt_content.show();
  954. ui.boxMsgSound.style.display = 'none';
  955. $(this).find('img:eq(0)').show().next().hide();
  956. } else {
  957. $ipt_content.hide();
  958. ui.boxMsgSound.style.display = 'block';
  959. $(this).find('img:eq(0)').hide().next().show();
  960. }
  961. });
  962. mui.init({
  963. gestureConfig:{
  964. hold:true,//默认为false,不监听
  965. release:true//默认为false,不监听
  966. }
  967. });
  968. var recordCancel = false;
  969. var recorder = null;
  970. var audio_tips = document.getElementById("audio_tips");
  971. var startTimestamp = null;
  972. var stopTimestamp = null;
  973. var stopTimer = null;
  974. var MIN_SOUND_TIME = 500;
  975. var ui = {
  976. body: document.querySelector('body'),
  977. btnMsgType: document.querySelector('#msg-type'),
  978. boxMsgText: document.querySelector('#msg-text'),
  979. boxMsgSound: document.querySelector('#msg-sound'),
  980. btnMsgImage: document.querySelector('#msg-image'),
  981. areaMsgList: document.querySelector('#msg-list'),
  982. boxSoundAlert: document.querySelector('#sound-alert')
  983. };
  984. var recordTimer = null;
  985. var realStartTime = 0;
  986. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  987. e.preventDefault();
  988. event.preventDefault();
  989. $(this).addClass('yy-hold');
  990. if(stopTimer)clearTimeout(stopTimer);
  991. recordCancel = false;
  992. audio_tips.innerHTML = "手指上划,取消发送";
  993. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  994. setSoundAlertVisable(true);
  995. startTimestamp = new Date().getTime();
  996. recordTimer = setTimeout(function(){
  997. wx.startRecord({
  998. success: function(){
  999. realStartTime = new Date().getTime();
  1000. },
  1001. fail: recordErr
  1002. });
  1003. wx.onVoiceRecordEnd({
  1004. // 录音时间超过一分钟没有停止的时候会执行 complete 回调
  1005. complete: function (res) {
  1006. serverId = res.localId;
  1007. sendSounds(60);
  1008. },
  1009. fail: recordErr
  1010. });
  1011. },MIN_SOUND_TIME);
  1012. }, false);
  1013. ui.boxMsgSound.addEventListener("touchend", function(e){
  1014. e.preventDefault();
  1015. event.preventDefault();
  1016. $(this).removeClass('yy-hold');
  1017. if (audio_tips.classList.contains("cancel")) {
  1018. audio_tips.classList.remove("cancel");
  1019. audio_tips.innerHTML = "手指上划,取消发送";
  1020. }
  1021. var endTimestamp = new Date().getTime();
  1022. var times = endTimestamp - startTimestamp;
  1023. var realTimes = endTimestamp - realStartTime;
  1024. if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
  1025. audio_tips.innerHTML = "录音时间太短";
  1026. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1027. recordCancel = true;
  1028. stopTimer=setTimeout(function(){
  1029. setSoundAlertVisable(false);
  1030. },500);
  1031. startTimestamp = 0;
  1032. realStartTime = 0;
  1033. //小于300ms,不录音
  1034. clearTimeout(recordTimer);
  1035. wx.stopRecord({
  1036. success: function (res) {
  1037. },
  1038. fail: function(){}
  1039. });
  1040. }else{
  1041. setSoundAlertVisable(false);
  1042. wx.stopRecord({
  1043. success: function (res) {
  1044. if(!recordCancel) {
  1045. serverId = res.localId;
  1046. sendSounds(Math.round(times/1000));
  1047. }
  1048. },
  1049. fail: recordErr
  1050. });
  1051. }
  1052. }, false)
  1053. ui.body.addEventListener('drag', function(event) {
  1054. if (Math.abs(event.detail.deltaY) > 50) {
  1055. if (!recordCancel) {
  1056. recordCancel = true;
  1057. if (!audio_tips.classList.contains("cancel")) {
  1058. audio_tips.classList.add("cancel");
  1059. }
  1060. audio_tips.innerHTML = "松开手指,取消发送";
  1061. }
  1062. } else {
  1063. if (recordCancel) {
  1064. recordCancel = false;
  1065. if (audio_tips.classList.contains("cancel")) {
  1066. audio_tips.classList.remove("cancel");
  1067. }
  1068. audio_tips.innerHTML = "手指上划,取消发送";
  1069. }
  1070. }
  1071. }, false);
  1072. var setSoundAlertVisable=function(show){
  1073. if(show){
  1074. ui.boxSoundAlert.style.display = 'block';
  1075. ui.boxSoundAlert.style.opacity = 1;
  1076. }else{
  1077. ui.boxSoundAlert.style.opacity = 0;
  1078. //fadeOut 完成再真正隐藏
  1079. setTimeout(function(){
  1080. ui.boxSoundAlert.style.display = 'none';
  1081. },200);
  1082. }
  1083. };
  1084. function recordErr(res){
  1085. if(res && res.errMsg == "stopRecord:tooshort") {
  1086. audio_tips.innerHTML = "录音时间太短";
  1087. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1088. recordCancel = true;
  1089. stopTimer=setTimeout(function(){
  1090. setSoundAlertVisable(false);
  1091. },500);
  1092. startTimestamp = 0;
  1093. //小于300ms,不录音
  1094. if(recordTimer)clearTimeout(recordTimer);
  1095. return;
  1096. }
  1097. if(!recordCancel){
  1098. dialog({
  1099. content:'录音失败,请重试',
  1100. okValue:'我知道了',
  1101. ok: function() {}
  1102. }).showModal();
  1103. }
  1104. }
  1105. //保存图片
  1106. function sendSounds(times){
  1107. var now = new Date();
  1108. timeStr = "";
  1109. if(now.getMonth()<9){
  1110. //补0
  1111. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  1112. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  1113. }else{
  1114. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  1115. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  1116. }
  1117. var data = {};
  1118. data.consult = consult;
  1119. data.content = "";
  1120. data.type = 3;
  1121. data.times = times;
  1122. wx.uploadVoice({
  1123. localId: serverId,
  1124. success: function (res) {
  1125. data.voices = res.serverId;
  1126. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1127. function submitSoundSuccess(res) {
  1128. if (res.status == 200) {
  1129. dd.close();
  1130. var data = JSON.parse(res.data[0]);
  1131. addReply(2, data.content, timeStr, 3, "");
  1132. dialroll.refresh();
  1133. dialroll.scrollTo(0, dialroll.maxScrollY);
  1134. } else {
  1135. submitFailed(res);
  1136. }
  1137. });
  1138. }
  1139. });
  1140. }
  1141. function bindEvents(){
  1142. //录制视频
  1143. /*$(".lz-video-img").click(function(){
  1144. $("#upload_input").click();
  1145. //dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请录制10秒左右的短视频,以防录制完成后无法发送'}).show();
  1146. return false;
  1147. })*/
  1148. //立即发送
  1149. $("#lijifasong").on("tap", function(){
  1150. uploadVideo();
  1151. mui('#sheet1').popover('toggle');
  1152. return false;
  1153. });
  1154. //不再提醒
  1155. $("#buzaitixing").on("tap", function(){
  1156. window.localStorage.setItem("isTiXingVideoFaSong","1");
  1157. uploadVideo();
  1158. mui('#sheet1').popover('toggle');
  1159. return false;
  1160. });
  1161. // window.localStorage.removeItem("isTiXingVideoFaSong");//测试
  1162. //点击评价
  1163. $('body').on('tap','#noval',function(){
  1164. window.location.href = "manyidu.html?consult=" +consult;
  1165. })
  1166. $('body').on('tap','#hasval',function(){
  1167. window.location.href = "manyidu.html?consult=" +consult;
  1168. })
  1169. }
  1170. //录制视频回调
  1171. function videoFileChange(target) {
  1172. var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
  1173. if(parseInt(fileSize)>30){
  1174. dialog({
  1175. content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
  1176. okValue:'我知道了',
  1177. ok: function() {
  1178. return;
  1179. }
  1180. }).showModal();
  1181. }else{
  1182. if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
  1183. uploadVideo();
  1184. }else{
  1185. $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
  1186. mui('#sheet1').popover('toggle');
  1187. }
  1188. }
  1189. }
  1190. //上传视频
  1191. function uploadVideo(){
  1192. dd.showModal();
  1193. var fd=new FormData();
  1194. fd.append('file',document.getElementById("upload_input").files[0]);
  1195. $.ajax(server+"/upload/chat?type=4", {
  1196. data: fd,
  1197. contentType: false,
  1198. cache: false,
  1199. processData: false,
  1200. type: 'post',
  1201. success: function(resData) {
  1202. if(resData.status==200){
  1203. var data = {consult:consult,content:resData.urls,type:12};
  1204. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1205. function submitSoundSuccess(res) {
  1206. if (res.status == 200) {
  1207. dd.close();
  1208. var data = JSON.parse(res.data[0]);
  1209. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
  1210. dialroll.refresh();
  1211. dialroll.scrollTo(0, dialroll.maxScrollY);
  1212. } else {
  1213. submitFailed(res);
  1214. }
  1215. });
  1216. }else{
  1217. dd.close();
  1218. }
  1219. },
  1220. error:function (XMLHttpRequest, textStatus, errorThrown) {
  1221. console.log(XMLHttpRequest.status);
  1222. console.log(XMLHttpRequest.readyState);
  1223. console.log(textStatus)
  1224. }
  1225. });
  1226. }
  1227. Date.prototype.format = function(fmt) { //author: meizz
  1228. var o = {
  1229. "M+": this.getMonth() + 1, //月份
  1230. "d+": this.getDate(), //日
  1231. "h+": this.getHours(), //小时
  1232. "m+": this.getMinutes(), //分
  1233. "s+": this.getSeconds(), //秒
  1234. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1235. "S": this.getMilliseconds() //毫秒
  1236. };
  1237. if (/(y+)/.test(fmt))
  1238. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1239. for (var k in o)
  1240. if (new RegExp("(" + k + ")").test(fmt))
  1241. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1242. return fmt;
  1243. }