consulting-doctor.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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/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. //未结束的咨询跳转去咨询页面
  309. window.location.href = "../../qygl/html/sign_info.html?doctor="+doctor+"&consult="+consult;
  310. }else{
  311. $("#divBottom").hide();
  312. $("#finish_list").hide();
  313. $("#input_div").hide();
  314. winSize(0);
  315. //新增评价状态 1、已评价 0、未评价
  316. var data = {};
  317. data.consult = consult;
  318. sendPost('patient/consult/evaluateStatus', data, 'json', 'get', queryFailed, function(res){
  319. if (res.status == 200) {
  320. evaluate = res.data;
  321. //显示评价按钮
  322. if(evaluate == 0){
  323. $('#valFoot').show();
  324. $('#noval').show();
  325. $('#hasval').hide();
  326. }else if(evaluate == 1){
  327. $('#valFoot').show();
  328. $('#noval').hide();
  329. $('#hasval').show();
  330. }
  331. }else{
  332. queryFailed(res);
  333. }
  334. });
  335. }
  336. status = res.data;
  337. //聊天记录填充
  338. queryList();
  339. var pulldownAction = function() {
  340. getPage(this);
  341. };
  342. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  343. dialroll.refresh();
  344. dialroll.scrollTo(0, dialroll.maxScrollY);
  345. $(window).resize(function() {
  346. if(res.data == 0){
  347. winSize(102);
  348. }
  349. else{
  350. winSize(0);
  351. }
  352. });
  353. d.close();
  354. }
  355. else{
  356. queryFailed(res);
  357. }
  358. }
  359. //页面初始化
  360. function queryList(){
  361. var data = {};
  362. data.consult = consult;
  363. data.page = id;
  364. data.pagesize = pagesize;
  365. sendPost('patient/consult/loglist', data, 'json', 'GET', queryFailed2, querySuccess2);
  366. }
  367. function queryMsg(logId,msgType){
  368. var data={};
  369. data.consult = consult;
  370. data.logId = logId;
  371. data.msgType=msgType;
  372. sendPost('patient/consult/oneLog', data, 'json', 'GET', queryFailed2, function(res){
  373. if(res.status==200){
  374. var reply = res.consult;
  375. if((reply.msgType == 1) || (reply.msgType == 2) || (reply.msgType == 6)){
  376. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo);
  377. setTimeout(function(){
  378. dialroll.refresh();
  379. dialroll.scrollTo(0, dialroll.maxScrollY);
  380. },300)
  381. }
  382. }
  383. d.close();
  384. });
  385. }
  386. function queryFailed2(res) {
  387. d.close();
  388. if (res && res.msg) {
  389. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  390. } else {
  391. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载失败'}).show();
  392. }
  393. }
  394. function querySuccess2(res) {
  395. if (res.status == 200) {
  396. id++;
  397. res = res.list;
  398. var doctorPar = [];//储存参与咨询的医生
  399. for(var k in res.users){
  400. if(res.users[k].is_patient == 0 && res.users[k].id==doctor){
  401. doctorPar.push(res.users[k])
  402. }else if(res.users[k].is_patient == 0 && res.users[k].id!=doctor){
  403. doctorPar.unshift(res.users[k])
  404. }
  405. }
  406. doctorPar=JSON.stringify(doctorPar)
  407. window.localStorage.setItem('doctorPar',doctorPar);
  408. var list = res.list;
  409. if (list && list.length > 0) {
  410. docMsg = list[list.length - 1].content_type;
  411. var doctor = "";
  412. for (var j = list.length-1; j >=0; j--) {
  413. var reply = JSON.parse(list[j]);
  414. //type为1时,医生发的
  415. if((reply.content_type == 3) || (reply.content_type == 1) || (reply.content_type == 2) || (reply.content_type == 6) || (reply.content_type == 12)){
  416. var date = new Date();
  417. date.setTime(reply.timestamp);
  418. var time = date.format('yyyy-MM-dd hh:mm:ss');
  419. var p;
  420. for(var k in res.users){
  421. if(res.users[k].id==reply.sender_id){
  422. p = res.users[k].avatar;
  423. }
  424. }
  425. addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p);
  426. }
  427. }
  428. if(status==0){
  429. getDoctorWork();
  430. }
  431. dialroll.refresh();
  432. dialroll.scrollTo(0, dialroll.maxScrollY);
  433. }
  434. d.close();
  435. }
  436. else{
  437. queryFailed2(res);
  438. }
  439. }
  440. function getNowFormatDate() {
  441. var date = new Date();
  442. var seperator1 = "-";
  443. var seperator2 = ":";
  444. var month = date.getMonth() + 1;
  445. var strDate = date.getDate();
  446. if (month >= 1 && month <= 9) {
  447. month = "0" + month;
  448. }
  449. if (strDate >= 0 && strDate <= 9) {
  450. strDate = "0" + strDate;
  451. }
  452. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  453. + " " + date.getHours() + seperator2 + date.getMinutes()
  454. + seperator2 + date.getSeconds();
  455. return currentdate;
  456. }
  457. //点击发送按钮
  458. function send(){
  459. content = $("#input_content").text().replace(/\s+/g,"");
  460. if (content && content != null && content != "") {
  461. var now = new Date();
  462. timeStr = "";
  463. if(now.getMonth()<9){
  464. //补0
  465. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  466. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  467. }else{
  468. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  469. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  470. }
  471. $("#input_content").blur();
  472. dialroll.refresh();
  473. dialroll.scrollTo(0, dialroll.maxScrollY);
  474. // dd.showModal();
  475. var data = {};
  476. data.consult = consult;
  477. data.content = utf16toEntities(content);
  478. data.type = 1;
  479. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitSuccess);
  480. } else {
  481. return;
  482. }
  483. }
  484. function submitFailed(res) {
  485. dd.close();
  486. if (res && res.msg) {
  487. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  488. } else {
  489. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'发送失败'}).show();
  490. }
  491. }
  492. function submitSuccess(res) {
  493. if (res.status == 200) {
  494. //置空
  495. $("#input_content").text("");
  496. $(".talk-send a").addClass("disab");
  497. addReply(2, content, timeStr, 1, "");
  498. dialroll.refresh();
  499. dialroll.scrollTo(0, dialroll.maxScrollY);
  500. showSendBtn(false);
  501. dd.close();
  502. } else {
  503. submitFailed(res);
  504. }
  505. }
  506. //回复单条内容填写
  507. var defaultPhoto = "../../../images/p-default.png";
  508. var doctorDefaultPhoto = "../../../images/d-default.png";
  509. function addReply(type, content, time, msgType, doctorName,photo,prepend) {
  510. //time = time.substr(10);
  511. var doctorPhoto = photo ? getImgUrl(photo) : doctorDefaultPhoto;
  512. var $div = $("<dl></dl>");
  513. if(type == 7){
  514. if(prepend){
  515. $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  516. } else
  517. $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  518. return;
  519. }
  520. if (type == 1) {
  521. $div.addClass('chat-left');
  522. img = doctorPhoto;
  523. name = doctorName;
  524. } else {
  525. $div.addClass('chat-right');
  526. img = photo?getImgUrl(photo):defaultPhoto;
  527. defaultPhoto = img;
  528. name = window.localStorage.getItem("nowPatientName");
  529. }
  530. var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
  531. '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
  532. switch(parseInt(msgType)) {
  533. case 1://信息
  534. case 6://咨询问题
  535. temp += '<dd class="word-bread"><span>' + content + '</span></dd></dl>';
  536. break;
  537. case 2://图片
  538. temp += '<dd class="word-bread wb-img"><img width="100" height="100" src="'+ getImgUrl(content) +'" /></dd></dl>';
  539. break;
  540. case 3://语音
  541. var rec = JSON.parse(content);
  542. temp += "<div class='c-msg'><dd class='word-bread audio' data-type='3' data-audio='" + getImgUrl(content) + "'>"+
  543. "<div class='soundWav'>" +
  544. "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
  545. "</div>"+
  546. "</dd></div>";
  547. break;
  548. case 12://视频
  549. var videoInfo = content.split(",");
  550. var shichang = formatSeconds(videoInfo[2]);//时长
  551. if(type == 1){
  552. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  553. '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
  554. '<img class="bofang-icon-left" src="../images/bofang_icon.png">'+
  555. '<img class="jianjiao-icon-left" src="../images/zuoshanjiao_bg.png">'+
  556. '<span class="shichang-time-left">'+shichang+'</span>'+
  557. '</dd>';
  558. }else{
  559. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  560. '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
  561. '<img class="bofang-icon-right" src="../images/bofang_icon.png">'+
  562. '<img class="jianjiao-icon-right" src="../images/youshanjiao_bg.png">'+
  563. '<span class="shichang-time-right">'+shichang+'</span>'+
  564. '</dd>';
  565. }
  566. break;
  567. }
  568. if(prepend){
  569. $(".talk-box").prepend($div.append(temp)).prepend('<div class="time-tips"><span>' + time + '</span></div>');
  570. } else
  571. $(".talk-box").append('<div class="time-tips"><span>' + time + '</span></div>').append($div.append(temp));
  572. if(type != null && type != 1) {
  573. $(".tw-add-detail").hide(200);
  574. }
  575. }
  576. //毫秒转换成时分秒
  577. function formatSeconds(value) {
  578. var theTime = parseInt(value/1000);// 秒
  579. var theTime1 = 0;// 分
  580. var theTime2 = 0;// 小时
  581. if(theTime > 60) {
  582. theTime1 = parseInt(theTime/60);
  583. theTime = parseInt(theTime%60);
  584. if(theTime1 > 60) {
  585. theTime2 = parseInt(theTime1/60);
  586. theTime1 = parseInt(theTime1%60);
  587. }
  588. }
  589. var result = ""+parseInt(theTime);//秒
  590. if(parseInt(theTime)<=9){
  591. result = "0"+parseInt(theTime);//秒
  592. }
  593. if(theTime1 > 0) {//分
  594. if(parseInt(theTime1)>9){
  595. result = ""+parseInt(theTime1)+":"+result;
  596. }else{
  597. result = "0"+parseInt(theTime1)+":"+result;
  598. }
  599. }
  600. if(theTime2 > 0) {//小时
  601. if(parseInt(theTime2)>9){
  602. result = ""+parseInt(theTime2)+":"+result;
  603. }else{
  604. result = "0"+parseInt(theTime2)+":"+result;
  605. }
  606. }
  607. var resResult = "";
  608. if(result.split(":").length==1){//秒
  609. resResult = "00:"+result;
  610. }else if(result.split(":").length==2){//分
  611. resResult = "00:"+result;
  612. }else{//时
  613. resResult = result;
  614. }
  615. return resResult;
  616. }
  617. //向上拉取更多
  618. function addReplyBefore(type, content, time, msgType, doctorName) {
  619. //time = time.substr(10);
  620. var doctorPhoto = doctorDefaultPhoto;
  621. var patientPhoto = defaultPhoto;
  622. var $div = $("<div></div>");
  623. if (type == 1) {
  624. if(msgType == 2){
  625. $div.addClass('talk-left');
  626. $div.addClass('clearfix');
  627. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;max-width: 40px;">'+ doctorName + '</p></div> '
  628. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  629. +'<div class="rightpart">'
  630. +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  631. +'</div>');
  632. }
  633. else{
  634. $div.addClass('talk-left');
  635. $div.addClass('clearfix');
  636. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;max-width: 40px;">'+ doctorName + '</p></div> '
  637. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  638. +'<div class="rightpart">'
  639. +' <s class="rightjt jt-left"><s></s></s>'+content
  640. +'</div>');
  641. }
  642. } else {
  643. if(msgType == 2){
  644. $div.addClass('talk-right');
  645. $div.addClass('clearfix');
  646. $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
  647. +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
  648. +'<div class="rightpart">'
  649. +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  650. +'</div>');
  651. }
  652. else{
  653. $div.addClass('talk-right');
  654. $div.addClass('clearfix');
  655. $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
  656. + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
  657. + '<div class="rightpart">' + content + '</div>');
  658. }
  659. }
  660. $(".talk-box").prepend($div);
  661. }
  662. //页面初始化
  663. function getPage(t){
  664. // $(".talk-box").html("");
  665. var data = {};
  666. data.consult = consult;
  667. data.page = id;
  668. data.pagesize = pagesize;
  669. $.ajax(server + "patient/consult/loglist", {
  670. data: data,
  671. type: 'POST',
  672. dataType: 'json',
  673. beforeSend: function(request) {
  674. request.setRequestHeader("userAgent", userAgent);
  675. },
  676. error: function(res) {
  677. if(res.status == 999 || res.status == 998 || res.status == 997){
  678. loginUrl(res.status);
  679. return;
  680. }
  681. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"加载失败"}).show();
  682. },
  683. success: function(res) {
  684. if(res.status == 999 || res.status == 998 || res.status == 997){
  685. loginUrl(res.status);
  686. }
  687. else if (res.status == 200) {
  688. id++;
  689. var list = res.list;
  690. if (list && list.length > 0) {
  691. id = list[list.length - 1].id;
  692. for (var j = 0; j < list.length; j++) {
  693. var reply = list[j];
  694. //type为1时,医生发的
  695. if((reply.msgType == 1)|| (reply.msgType == 3) || (reply.msgType == 2) || (reply.msgType == 6)){
  696. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo, true);
  697. }
  698. }
  699. }
  700. t.refresh();
  701. } else {
  702. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  703. }
  704. }
  705. });
  706. }
  707. //结束咨询
  708. function finish(){
  709. dialog({
  710. content:'是否确认结束该次咨询?结束后医生将无法回复',
  711. ok: function (){
  712. var params = {}
  713. params.code = consult;
  714. //发送ajax请求, 查询设备列表信息
  715. sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
  716. function finish_Successs(res){
  717. if (res.status == 200) {
  718. location.reload();
  719. // window.location.href = "doctor-consultation.html";
  720. }
  721. else{
  722. submitFailed3(res);
  723. }
  724. }
  725. },
  726. cancel: function () {
  727. return;
  728. }
  729. }).showModal();
  730. }
  731. function submitFailed3(res) {
  732. if (res && res.msg) {
  733. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  734. } else {
  735. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'操作失败'}).show();
  736. }
  737. }
  738. //查看图片
  739. function viewImg(dom) {
  740. var $img = $(dom);
  741. var thissrc = $img.attr("src");
  742. var mWid = $(window).width();
  743. var mHei = $(window).height();
  744. 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>';
  745. $("body").append(nHtml);
  746. $(".delimgpop").click(function() {
  747. $(this).remove()
  748. });
  749. }
  750. //微信上传图片
  751. var serverId = "";
  752. var images = [];
  753. function chooseImageWx(){
  754. wx.chooseImage({
  755. count: 3,
  756. success: function (res) {
  757. for (var i in res.localIds) {
  758. images.push(res.localIds[i]);
  759. }
  760. dd.showModal();
  761. uploadImage();
  762. }
  763. });
  764. }
  765. function uploadImage(){
  766. if (images.length == 0) {
  767. dd.close();
  768. return;
  769. }
  770. var i = 0, length = images.length;
  771. serverId = "";
  772. var faillength = 0 ;
  773. function upload() {
  774. wx.uploadImage({
  775. localId: images[i],
  776. isShowProgressTips: 0,
  777. success: function (res) {
  778. faillength= 0;
  779. dd.close();
  780. i++;
  781. if(serverId.length == 0){
  782. serverId = res.serverId;
  783. }
  784. else{
  785. serverId =serverId + "," + res.serverId;
  786. }
  787. if (i < length) {
  788. upload();
  789. }
  790. if(i == images.length){
  791. sendImages();
  792. }
  793. },
  794. fail: function (res) {
  795. dd.close();
  796. faillength+=1;
  797. if(faillength<=5){
  798. //失败从传
  799. upload();
  800. }else{
  801. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
  802. }
  803. }
  804. });
  805. }
  806. upload();
  807. }
  808. //保存图片
  809. function sendImages(){
  810. var now = new Date();
  811. timeStr = "";
  812. if(now.getMonth()<9){
  813. //补0
  814. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  815. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  816. }else{
  817. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  818. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  819. }
  820. var data = {};
  821. data.consult = consult;
  822. data.content = "";
  823. data.mediaIds = serverId;
  824. data.type = 2;
  825. data.times = 0;
  826. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
  827. }
  828. function submitImageSuccess(res) {
  829. if (res.status == 200) {
  830. var data= JSON.parse(res.data)
  831. dd.close();
  832. addReply(2, data.content, timeStr, 2, "");
  833. dialroll.refresh();
  834. dialroll.scrollTo(0, dialroll.maxScrollY);
  835. } else {
  836. submitFailed(res);
  837. }
  838. }
  839. var aud = document.getElementById('audio');
  840. var $playingDom;
  841. function playSoundEnd(){
  842. $playingDom.removeClass('active');
  843. $playingDom = null;
  844. }
  845. function playError(){
  846. var src = $('#audio').attr('src');
  847. if(!$.trim(src)) {
  848. return ;
  849. }
  850. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
  851. $playingDom.removeClass('active');
  852. $playingDom = null;
  853. }
  854. $('.talk-box').on('click', '.word-bread img', function(){
  855. if(!$(this).closest(".word-bread").hasClass("preview-video")){
  856. var urls = [];
  857. $.each($('.word-bread img'), function(i, v) {
  858. urls.push($(v).attr('src'));
  859. });
  860. wx.previewImage({
  861. current: $(this).attr('src'), // 当前显示图片的http链接
  862. urls: urls // 需要预览的图片http链接列表
  863. });
  864. }
  865. })
  866. .on('touchstart', '.audio', function(){
  867. if($playingDom){
  868. aud.pause();
  869. //aud.stop();
  870. $playingDom.removeClass('active');
  871. if($playingDom[0] == this){
  872. $playingDom = null;
  873. return;
  874. }
  875. }
  876. $playingDom = $(this);
  877. $playingDom.addClass('active');
  878. var ser = JSON.parse($(this).attr('data-audio'));
  879. aud.src = getImgUrl(ser.path);
  880. aud.load();
  881. aud.play();
  882. })
  883. .on('click','.preview-video',function() {
  884. $(document.body).find('video').remove();
  885. var url = $(this).attr('data-video');
  886. var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'" ></video>';
  887. $(document.body).append(html);
  888. var video = $(document.body).find('video')[0];
  889. video.play();
  890. });
  891. var valLen = 0;
  892. var $ipt_content = $('#input_content');
  893. function showSendBtn(isShow){
  894. if(isShow){
  895. $('.tw-add').hide();
  896. $('#reply').fadeIn('fast', 'swing');
  897. } else if(valLen == 1 || isShow==false){
  898. $('#reply').fadeOut('fast', 'swing', function(){
  899. $('.tw-add').show();
  900. });
  901. }
  902. valLen = isShow ? isShow.length : 0;
  903. }
  904. /**
  905. * 显示发送按钮的事件
  906. */
  907. $ipt_content.on('input', function(e){
  908. showSendBtn($(this).text())
  909. })
  910. .on('tap', function(){
  911. $(".tw-add-detail").hide();
  912. $ipt_content.focus();
  913. })
  914. /*
  915. * 附加功能
  916. */
  917. $(".tw-add").click(function() {
  918. $(".tw-add-detail").toggle(200);
  919. });
  920. $('body')
  921. //隐藏打开的附加功能
  922. .on('tap', '#talkwrap', function(){
  923. $('.tw-add-detail').hide();
  924. $ipt_content.blur();
  925. })
  926. $(".yy-add").click(function() {
  927. if($('#msg-sound:visible').length){
  928. $ipt_content.show();
  929. ui.boxMsgSound.style.display = 'none';
  930. $(this).find('img:eq(0)').show().next().hide();
  931. } else {
  932. $ipt_content.hide();
  933. ui.boxMsgSound.style.display = 'block';
  934. $(this).find('img:eq(0)').hide().next().show();
  935. }
  936. });
  937. mui.init({
  938. gestureConfig:{
  939. hold:true,//默认为false,不监听
  940. release:true//默认为false,不监听
  941. }
  942. });
  943. var recordCancel = false;
  944. var recorder = null;
  945. var audio_tips = document.getElementById("audio_tips");
  946. var startTimestamp = null;
  947. var stopTimestamp = null;
  948. var stopTimer = null;
  949. var MIN_SOUND_TIME = 500;
  950. var ui = {
  951. body: document.querySelector('body'),
  952. btnMsgType: document.querySelector('#msg-type'),
  953. boxMsgText: document.querySelector('#msg-text'),
  954. boxMsgSound: document.querySelector('#msg-sound'),
  955. btnMsgImage: document.querySelector('#msg-image'),
  956. areaMsgList: document.querySelector('#msg-list'),
  957. boxSoundAlert: document.querySelector('#sound-alert')
  958. };
  959. var recordTimer = null;
  960. var realStartTime = 0;
  961. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  962. e.preventDefault();
  963. event.preventDefault();
  964. $(this).addClass('yy-hold');
  965. if(stopTimer)clearTimeout(stopTimer);
  966. recordCancel = false;
  967. audio_tips.innerHTML = "手指上划,取消发送";
  968. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  969. setSoundAlertVisable(true);
  970. startTimestamp = new Date().getTime();
  971. recordTimer = setTimeout(function(){
  972. wx.startRecord({
  973. success: function(){
  974. realStartTime = new Date().getTime();
  975. },
  976. fail: recordErr
  977. });
  978. wx.onVoiceRecordEnd({
  979. // 录音时间超过一分钟没有停止的时候会执行 complete 回调
  980. complete: function (res) {
  981. serverId = res.localId;
  982. sendSounds(60);
  983. },
  984. fail: recordErr
  985. });
  986. },MIN_SOUND_TIME);
  987. }, false);
  988. ui.boxMsgSound.addEventListener("touchend", function(e){
  989. e.preventDefault();
  990. event.preventDefault();
  991. $(this).removeClass('yy-hold');
  992. if (audio_tips.classList.contains("cancel")) {
  993. audio_tips.classList.remove("cancel");
  994. audio_tips.innerHTML = "手指上划,取消发送";
  995. }
  996. var endTimestamp = new Date().getTime();
  997. var times = endTimestamp - startTimestamp;
  998. var realTimes = endTimestamp - realStartTime;
  999. if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
  1000. audio_tips.innerHTML = "录音时间太短";
  1001. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1002. recordCancel = true;
  1003. stopTimer=setTimeout(function(){
  1004. setSoundAlertVisable(false);
  1005. },500);
  1006. startTimestamp = 0;
  1007. realStartTime = 0;
  1008. //小于300ms,不录音
  1009. clearTimeout(recordTimer);
  1010. wx.stopRecord({
  1011. success: function (res) {
  1012. },
  1013. fail: function(){}
  1014. });
  1015. }else{
  1016. setSoundAlertVisable(false);
  1017. wx.stopRecord({
  1018. success: function (res) {
  1019. if(!recordCancel) {
  1020. serverId = res.localId;
  1021. sendSounds(Math.round(times/1000));
  1022. }
  1023. },
  1024. fail: recordErr
  1025. });
  1026. }
  1027. }, false)
  1028. ui.body.addEventListener('drag', function(event) {
  1029. if (Math.abs(event.detail.deltaY) > 50) {
  1030. if (!recordCancel) {
  1031. recordCancel = true;
  1032. if (!audio_tips.classList.contains("cancel")) {
  1033. audio_tips.classList.add("cancel");
  1034. }
  1035. audio_tips.innerHTML = "松开手指,取消发送";
  1036. }
  1037. } else {
  1038. if (recordCancel) {
  1039. recordCancel = false;
  1040. if (audio_tips.classList.contains("cancel")) {
  1041. audio_tips.classList.remove("cancel");
  1042. }
  1043. audio_tips.innerHTML = "手指上划,取消发送";
  1044. }
  1045. }
  1046. }, false);
  1047. var setSoundAlertVisable=function(show){
  1048. if(show){
  1049. ui.boxSoundAlert.style.display = 'block';
  1050. ui.boxSoundAlert.style.opacity = 1;
  1051. }else{
  1052. ui.boxSoundAlert.style.opacity = 0;
  1053. //fadeOut 完成再真正隐藏
  1054. setTimeout(function(){
  1055. ui.boxSoundAlert.style.display = 'none';
  1056. },200);
  1057. }
  1058. };
  1059. function recordErr(res){
  1060. if(res && res.errMsg == "stopRecord:tooshort") {
  1061. audio_tips.innerHTML = "录音时间太短";
  1062. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1063. recordCancel = true;
  1064. stopTimer=setTimeout(function(){
  1065. setSoundAlertVisable(false);
  1066. },500);
  1067. startTimestamp = 0;
  1068. //小于300ms,不录音
  1069. if(recordTimer)clearTimeout(recordTimer);
  1070. return;
  1071. }
  1072. if(!recordCancel){
  1073. dialog({
  1074. content:'录音失败,请重试',
  1075. okValue:'我知道了',
  1076. ok: function() {}
  1077. }).showModal();
  1078. }
  1079. }
  1080. //保存图片
  1081. function sendSounds(times){
  1082. var now = new Date();
  1083. timeStr = "";
  1084. if(now.getMonth()<9){
  1085. //补0
  1086. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  1087. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  1088. }else{
  1089. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  1090. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  1091. }
  1092. var data = {};
  1093. data.consult = consult;
  1094. data.content = "";
  1095. data.type = 3;
  1096. data.times = times;
  1097. wx.uploadVoice({
  1098. localId: serverId,
  1099. success: function (res) {
  1100. data.voices = res.serverId;
  1101. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1102. function submitSoundSuccess(res) {
  1103. if (res.status == 200) {
  1104. dd.close();
  1105. var data = JSON.parse(res.data[0]);
  1106. addReply(2, data.content, timeStr, 3, "");
  1107. dialroll.refresh();
  1108. dialroll.scrollTo(0, dialroll.maxScrollY);
  1109. } else {
  1110. submitFailed(res);
  1111. }
  1112. });
  1113. }
  1114. });
  1115. }
  1116. function bindEvents(){
  1117. //录制视频
  1118. /*$(".lz-video-img").click(function(){
  1119. $("#upload_input").click();
  1120. //dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请录制10秒左右的短视频,以防录制完成后无法发送'}).show();
  1121. return false;
  1122. })*/
  1123. //立即发送
  1124. $("#lijifasong").on("tap", function(){
  1125. uploadVideo();
  1126. mui('#sheet1').popover('toggle');
  1127. return false;
  1128. });
  1129. //不再提醒
  1130. $("#buzaitixing").on("tap", function(){
  1131. window.localStorage.setItem("isTiXingVideoFaSong","1");
  1132. uploadVideo();
  1133. mui('#sheet1').popover('toggle');
  1134. return false;
  1135. });
  1136. // window.localStorage.removeItem("isTiXingVideoFaSong");//测试
  1137. //点击评价
  1138. $('body').on('tap','#noval',function(){
  1139. window.location.href = "manyidu.html?consult=" +consult;
  1140. })
  1141. $('body').on('tap','#hasval',function(){
  1142. window.location.href = "manyidu.html?consult=" +consult;
  1143. })
  1144. }
  1145. //录制视频回调
  1146. function videoFileChange(target) {
  1147. var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
  1148. if(parseInt(fileSize)>30){
  1149. dialog({
  1150. content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
  1151. okValue:'我知道了',
  1152. ok: function() {
  1153. return;
  1154. }
  1155. }).showModal();
  1156. }else{
  1157. if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
  1158. uploadVideo();
  1159. }else{
  1160. $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
  1161. mui('#sheet1').popover('toggle');
  1162. }
  1163. }
  1164. }
  1165. //上传视频
  1166. function uploadVideo(){
  1167. dd.showModal();
  1168. var fd=new FormData();
  1169. fd.append('file',document.getElementById("upload_input").files[0]);
  1170. $.ajax(server+"/upload/chat?type=4", {
  1171. data: fd,
  1172. contentType: false,
  1173. cache: false,
  1174. processData: false,
  1175. type: 'post',
  1176. success: function(resData) {
  1177. if(resData.status==200){
  1178. var data = {consult:consult,content:resData.urls,type:12};
  1179. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1180. function submitSoundSuccess(res) {
  1181. if (res.status == 200) {
  1182. dd.close();
  1183. var data = JSON.parse(res.data[0]);
  1184. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
  1185. dialroll.refresh();
  1186. dialroll.scrollTo(0, dialroll.maxScrollY);
  1187. } else {
  1188. submitFailed(res);
  1189. }
  1190. });
  1191. }else{
  1192. dd.close();
  1193. }
  1194. },
  1195. error:function (XMLHttpRequest, textStatus, errorThrown) {
  1196. console.log(XMLHttpRequest.status);
  1197. console.log(XMLHttpRequest.readyState);
  1198. console.log(textStatus)
  1199. }
  1200. });
  1201. }
  1202. Date.prototype.format = function(fmt) { //author: meizz
  1203. var o = {
  1204. "M+": this.getMonth() + 1, //月份
  1205. "d+": this.getDate(), //日
  1206. "h+": this.getHours(), //小时
  1207. "m+": this.getMinutes(), //分
  1208. "s+": this.getSeconds(), //秒
  1209. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1210. "S": this.getMilliseconds() //毫秒
  1211. };
  1212. if (/(y+)/.test(fmt))
  1213. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1214. for (var k in o)
  1215. if (new RegExp("(" + k + ")").test(fmt))
  1216. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1217. return fmt;
  1218. }