consulting-doctor.js 40 KB

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