consulting-doctor.js 40 KB

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