consulting-doctor.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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. d.show();
  715. var params = {}
  716. params.code = consult;
  717. //发送ajax请求, 查询设备列表信息
  718. sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
  719. function finish_Successs(res){
  720. if (res.status == 200) {
  721. d.close();
  722. location.reload();
  723. // window.location.href = "doctor-consultation.html";
  724. }
  725. else{
  726. submitFailed3(res);
  727. }
  728. }
  729. },
  730. cancel: function () {
  731. return;
  732. }
  733. }).showModal();
  734. }
  735. function submitFailed3(res) {
  736. if (res && res.msg) {
  737. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  738. } else {
  739. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'操作失败'}).show();
  740. }
  741. }
  742. //查看图片
  743. function viewImg(dom) {
  744. var $img = $(dom);
  745. var thissrc = $img.attr("src");
  746. var mWid = $(window).width();
  747. var mHei = $(window).height();
  748. 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>';
  749. $("body").append(nHtml);
  750. $(".delimgpop").click(function() {
  751. $(this).remove()
  752. });
  753. }
  754. //微信上传图片
  755. var serverId = "";
  756. var images = [];
  757. function chooseImageWx(){
  758. wx.chooseImage({
  759. count: 3,
  760. success: function (res) {
  761. for (var i in res.localIds) {
  762. images.push(res.localIds[i]);
  763. }
  764. dd.showModal();
  765. uploadImage();
  766. }
  767. });
  768. }
  769. function uploadImage(){
  770. if (images.length == 0) {
  771. dd.close();
  772. return;
  773. }
  774. var i = 0, length = images.length;
  775. serverId = "";
  776. var faillength = 0 ;
  777. function upload() {
  778. wx.uploadImage({
  779. localId: images[i],
  780. isShowProgressTips: 0,
  781. success: function (res) {
  782. faillength= 0;
  783. dd.close();
  784. i++;
  785. if(serverId.length == 0){
  786. serverId = res.serverId;
  787. }
  788. else{
  789. serverId =serverId + "," + res.serverId;
  790. }
  791. if (i < length) {
  792. upload();
  793. }
  794. if(i == images.length){
  795. sendImages();
  796. }
  797. },
  798. fail: function (res) {
  799. dd.close();
  800. faillength+=1;
  801. if(faillength<=5){
  802. //失败从传
  803. upload();
  804. }else{
  805. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
  806. }
  807. }
  808. });
  809. }
  810. upload();
  811. }
  812. //保存图片
  813. function sendImages(){
  814. var now = new Date();
  815. timeStr = "";
  816. if(now.getMonth()<9){
  817. //补0
  818. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  819. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  820. }else{
  821. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  822. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  823. }
  824. var data = {};
  825. data.consult = consult;
  826. data.content = "";
  827. data.mediaIds = serverId;
  828. data.type = 2;
  829. data.times = 0;
  830. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
  831. }
  832. function submitImageSuccess(res) {
  833. if (res.status == 200) {
  834. var data= JSON.parse(res.data)
  835. dd.close();
  836. addReply(2, data.content, timeStr, 2, "");
  837. dialroll.refresh();
  838. dialroll.scrollTo(0, dialroll.maxScrollY);
  839. } else {
  840. submitFailed(res);
  841. }
  842. }
  843. var aud = document.getElementById('audio');
  844. var $playingDom;
  845. function playSoundEnd(){
  846. $playingDom.removeClass('active');
  847. $playingDom = null;
  848. }
  849. function playError(){
  850. var src = $('#audio').attr('src');
  851. if(!$.trim(src)) {
  852. return ;
  853. }
  854. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
  855. $playingDom.removeClass('active');
  856. $playingDom = null;
  857. }
  858. $('.talk-box').on('click', '.word-bread img', function(){
  859. if(!$(this).closest(".word-bread").hasClass("preview-video")){
  860. var urls = [];
  861. $.each($('.word-bread img'), function(i, v) {
  862. urls.push($(v).attr('src'));
  863. });
  864. wx.previewImage({
  865. current: $(this).attr('src'), // 当前显示图片的http链接
  866. urls: urls // 需要预览的图片http链接列表
  867. });
  868. }
  869. })
  870. .on('touchstart', '.audio', function(){
  871. if($playingDom){
  872. aud.pause();
  873. //aud.stop();
  874. $playingDom.removeClass('active');
  875. if($playingDom[0] == this){
  876. $playingDom = null;
  877. return;
  878. }
  879. }
  880. $playingDom = $(this);
  881. $playingDom.addClass('active');
  882. var ser = JSON.parse($(this).attr('data-audio'));
  883. aud.src = getImgUrl(ser.path);
  884. aud.load();
  885. aud.play();
  886. })
  887. .on('click','.preview-video',function() {
  888. $(document.body).find('video').remove();
  889. var url = $(this).attr('data-video');
  890. var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'" ></video>';
  891. $(document.body).append(html);
  892. var video = $(document.body).find('video')[0];
  893. video.play();
  894. });
  895. var valLen = 0;
  896. var $ipt_content = $('#input_content');
  897. function showSendBtn(isShow){
  898. if(isShow){
  899. $('.tw-add').hide();
  900. $('#reply').fadeIn('fast', 'swing');
  901. } else if(valLen == 1 || isShow==false){
  902. $('#reply').fadeOut('fast', 'swing', function(){
  903. $('.tw-add').show();
  904. });
  905. }
  906. valLen = isShow ? isShow.length : 0;
  907. }
  908. /**
  909. * 显示发送按钮的事件
  910. */
  911. $ipt_content.on('input', function(e){
  912. showSendBtn($(this).text())
  913. })
  914. .on('tap', function(){
  915. $(".tw-add-detail").hide();
  916. $ipt_content.focus();
  917. })
  918. /*
  919. * 附加功能
  920. */
  921. $(".tw-add").click(function() {
  922. $(".tw-add-detail").toggle(200);
  923. });
  924. $('body')
  925. //隐藏打开的附加功能
  926. .on('tap', '#talkwrap', function(){
  927. $('.tw-add-detail').hide();
  928. $ipt_content.blur();
  929. })
  930. $(".yy-add").click(function() {
  931. if($('#msg-sound:visible').length){
  932. $ipt_content.show();
  933. ui.boxMsgSound.style.display = 'none';
  934. $(this).find('img:eq(0)').show().next().hide();
  935. } else {
  936. $ipt_content.hide();
  937. ui.boxMsgSound.style.display = 'block';
  938. $(this).find('img:eq(0)').hide().next().show();
  939. }
  940. });
  941. mui.init({
  942. gestureConfig:{
  943. hold:true,//默认为false,不监听
  944. release:true//默认为false,不监听
  945. }
  946. });
  947. var recordCancel = false;
  948. var recorder = null;
  949. var audio_tips = document.getElementById("audio_tips");
  950. var startTimestamp = null;
  951. var stopTimestamp = null;
  952. var stopTimer = null;
  953. var MIN_SOUND_TIME = 500;
  954. var ui = {
  955. body: document.querySelector('body'),
  956. btnMsgType: document.querySelector('#msg-type'),
  957. boxMsgText: document.querySelector('#msg-text'),
  958. boxMsgSound: document.querySelector('#msg-sound'),
  959. btnMsgImage: document.querySelector('#msg-image'),
  960. areaMsgList: document.querySelector('#msg-list'),
  961. boxSoundAlert: document.querySelector('#sound-alert')
  962. };
  963. var recordTimer = null;
  964. var realStartTime = 0;
  965. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  966. e.preventDefault();
  967. event.preventDefault();
  968. $(this).addClass('yy-hold');
  969. if(stopTimer)clearTimeout(stopTimer);
  970. recordCancel = false;
  971. audio_tips.innerHTML = "手指上划,取消发送";
  972. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  973. setSoundAlertVisable(true);
  974. startTimestamp = new Date().getTime();
  975. recordTimer = setTimeout(function(){
  976. wx.startRecord({
  977. success: function(){
  978. realStartTime = new Date().getTime();
  979. },
  980. fail: recordErr
  981. });
  982. wx.onVoiceRecordEnd({
  983. // 录音时间超过一分钟没有停止的时候会执行 complete 回调
  984. complete: function (res) {
  985. serverId = res.localId;
  986. sendSounds(60);
  987. },
  988. fail: recordErr
  989. });
  990. },MIN_SOUND_TIME);
  991. }, false);
  992. ui.boxMsgSound.addEventListener("touchend", function(e){
  993. e.preventDefault();
  994. event.preventDefault();
  995. $(this).removeClass('yy-hold');
  996. if (audio_tips.classList.contains("cancel")) {
  997. audio_tips.classList.remove("cancel");
  998. audio_tips.innerHTML = "手指上划,取消发送";
  999. }
  1000. var endTimestamp = new Date().getTime();
  1001. var times = endTimestamp - startTimestamp;
  1002. var realTimes = endTimestamp - realStartTime;
  1003. if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
  1004. audio_tips.innerHTML = "录音时间太短";
  1005. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1006. recordCancel = true;
  1007. stopTimer=setTimeout(function(){
  1008. setSoundAlertVisable(false);
  1009. },500);
  1010. startTimestamp = 0;
  1011. realStartTime = 0;
  1012. //小于300ms,不录音
  1013. clearTimeout(recordTimer);
  1014. wx.stopRecord({
  1015. success: function (res) {
  1016. },
  1017. fail: function(){}
  1018. });
  1019. }else{
  1020. setSoundAlertVisable(false);
  1021. wx.stopRecord({
  1022. success: function (res) {
  1023. if(!recordCancel) {
  1024. serverId = res.localId;
  1025. sendSounds(Math.round(times/1000));
  1026. }
  1027. },
  1028. fail: recordErr
  1029. });
  1030. }
  1031. }, false)
  1032. ui.body.addEventListener('drag', function(event) {
  1033. if (Math.abs(event.detail.deltaY) > 50) {
  1034. if (!recordCancel) {
  1035. recordCancel = true;
  1036. if (!audio_tips.classList.contains("cancel")) {
  1037. audio_tips.classList.add("cancel");
  1038. }
  1039. audio_tips.innerHTML = "松开手指,取消发送";
  1040. }
  1041. } else {
  1042. if (recordCancel) {
  1043. recordCancel = false;
  1044. if (audio_tips.classList.contains("cancel")) {
  1045. audio_tips.classList.remove("cancel");
  1046. }
  1047. audio_tips.innerHTML = "手指上划,取消发送";
  1048. }
  1049. }
  1050. }, false);
  1051. var setSoundAlertVisable=function(show){
  1052. if(show){
  1053. ui.boxSoundAlert.style.display = 'block';
  1054. ui.boxSoundAlert.style.opacity = 1;
  1055. }else{
  1056. ui.boxSoundAlert.style.opacity = 0;
  1057. //fadeOut 完成再真正隐藏
  1058. setTimeout(function(){
  1059. ui.boxSoundAlert.style.display = 'none';
  1060. },200);
  1061. }
  1062. };
  1063. function recordErr(res){
  1064. if(res && res.errMsg == "stopRecord:tooshort") {
  1065. audio_tips.innerHTML = "录音时间太短";
  1066. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1067. recordCancel = true;
  1068. stopTimer=setTimeout(function(){
  1069. setSoundAlertVisable(false);
  1070. },500);
  1071. startTimestamp = 0;
  1072. //小于300ms,不录音
  1073. if(recordTimer)clearTimeout(recordTimer);
  1074. return;
  1075. }
  1076. if(!recordCancel){
  1077. dialog({
  1078. content:'录音失败,请重试',
  1079. okValue:'我知道了',
  1080. ok: function() {}
  1081. }).showModal();
  1082. }
  1083. }
  1084. //保存图片
  1085. function sendSounds(times){
  1086. var now = new Date();
  1087. timeStr = "";
  1088. if(now.getMonth()<9){
  1089. //补0
  1090. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  1091. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  1092. }else{
  1093. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  1094. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  1095. }
  1096. var data = {};
  1097. data.consult = consult;
  1098. data.content = "";
  1099. data.type = 3;
  1100. data.times = times;
  1101. wx.uploadVoice({
  1102. localId: serverId,
  1103. success: function (res) {
  1104. data.voices = res.serverId;
  1105. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1106. function submitSoundSuccess(res) {
  1107. if (res.status == 200) {
  1108. dd.close();
  1109. var data = JSON.parse(res.data[0]);
  1110. addReply(2, data.content, timeStr, 3, "");
  1111. dialroll.refresh();
  1112. dialroll.scrollTo(0, dialroll.maxScrollY);
  1113. } else {
  1114. submitFailed(res);
  1115. }
  1116. });
  1117. }
  1118. });
  1119. }
  1120. function bindEvents(){
  1121. //录制视频
  1122. /*$(".lz-video-img").click(function(){
  1123. $("#upload_input").click();
  1124. //dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请录制10秒左右的短视频,以防录制完成后无法发送'}).show();
  1125. return false;
  1126. })*/
  1127. //立即发送
  1128. $("#lijifasong").on("tap", function(){
  1129. uploadVideo();
  1130. mui('#sheet1').popover('toggle');
  1131. return false;
  1132. });
  1133. //不再提醒
  1134. $("#buzaitixing").on("tap", function(){
  1135. window.localStorage.setItem("isTiXingVideoFaSong","1");
  1136. uploadVideo();
  1137. mui('#sheet1').popover('toggle');
  1138. return false;
  1139. });
  1140. // window.localStorage.removeItem("isTiXingVideoFaSong");//测试
  1141. //点击评价
  1142. $('body').on('tap','#noval',function(){
  1143. window.location.href = "manyidu.html?consult=" +consult;
  1144. })
  1145. $('body').on('tap','#hasval',function(){
  1146. window.location.href = "manyidu.html?consult=" +consult;
  1147. })
  1148. }
  1149. //录制视频回调
  1150. function videoFileChange(target) {
  1151. var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
  1152. if(parseInt(fileSize)>30){
  1153. dialog({
  1154. content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
  1155. okValue:'我知道了',
  1156. ok: function() {
  1157. return;
  1158. }
  1159. }).showModal();
  1160. }else{
  1161. if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
  1162. uploadVideo();
  1163. }else{
  1164. $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
  1165. mui('#sheet1').popover('toggle');
  1166. }
  1167. }
  1168. }
  1169. //上传视频
  1170. function uploadVideo(){
  1171. dd.showModal();
  1172. var fd=new FormData();
  1173. fd.append('file',document.getElementById("upload_input").files[0]);
  1174. $.ajax(server+"/upload/chat?type=4", {
  1175. data: fd,
  1176. contentType: false,
  1177. cache: false,
  1178. processData: false,
  1179. type: 'post',
  1180. success: function(resData) {
  1181. if(resData.status==200){
  1182. var data = {consult:consult,content:resData.urls,type:12};
  1183. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1184. function submitSoundSuccess(res) {
  1185. if (res.status == 200) {
  1186. dd.close();
  1187. var data = JSON.parse(res.data[0]);
  1188. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
  1189. dialroll.refresh();
  1190. dialroll.scrollTo(0, dialroll.maxScrollY);
  1191. } else {
  1192. submitFailed(res);
  1193. }
  1194. });
  1195. }else{
  1196. dd.close();
  1197. }
  1198. },
  1199. error:function (XMLHttpRequest, textStatus, errorThrown) {
  1200. console.log(XMLHttpRequest.status);
  1201. console.log(XMLHttpRequest.readyState);
  1202. console.log(textStatus)
  1203. }
  1204. });
  1205. }
  1206. Date.prototype.format = function(fmt) { //author: meizz
  1207. var o = {
  1208. "M+": this.getMonth() + 1, //月份
  1209. "d+": this.getDate(), //日
  1210. "h+": this.getHours(), //小时
  1211. "m+": this.getMinutes(), //分
  1212. "s+": this.getSeconds(), //秒
  1213. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1214. "S": this.getMilliseconds() //毫秒
  1215. };
  1216. if (/(y+)/.test(fmt))
  1217. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1218. for (var k in o)
  1219. if (new RegExp("(" + k + ")").test(fmt))
  1220. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1221. return fmt;
  1222. }