consulting-doctor.js 38 KB

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