consulting-doctor.js 40 KB

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