user.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. var new_interval = 1;//消息提醒计时
  2. var connect = 0;//连接状态
  3. var new_msg = 0;//新消息数
  4. var obj = {};
  5. var chat_log = {};
  6. var connect_list = {};
  7. var connect_n = 0;
  8. var web_info = new Array();//页面信息
  9. var friend_list = new Array();//我的好友
  10. var follow_list = new Array();//我关注的人
  11. var recent_list = new Array();//最近联系人
  12. var user_list = new Array();//所有会员信息
  13. var msg_list = new Array();//收到消息
  14. var goods_list = new Array();//所有商品信息
  15. var store_goods = new Array();//店铺推荐的商品
  16. var dialog_show = 0;//对话框是否打开
  17. var user_show = 0;//当前选择的会员
  18. var msg_max = 20;//消息数
  19. var chat_audio = 1;//消息提醒声音开关
  20. var audio_info = '<object width="1" height="1" style="position: absolute; left: -1px;" id="msg_audio" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">' +
  21. '<param value="' + CHAT_SITE_URL + '/audio.swf" name="movie"><param value="always" name="allowscriptaccess">' +
  22. '<embed width="1" height="1" allowscriptaccess="always" src="' + CHAT_SITE_URL + '/audio.swf" name="msg_audio"></object>';
  23. $(function () {
  24. if (user['u_id'] != '') {
  25. web_info['chat_goods_html'] = '';
  26. web_info['html_title'] = $(document).attr('title');
  27. web_info['msg_dialog'] = '<div id="new_msg_dialog" class="msg-windows"><div class="user-tab-bar"><ul class="user-list" id="user_list"></ul></div>' +
  28. '<div class="msg-dialog"><div class="dialog-body">' +
  29. '<div id="msg_list" class="msg-contnet"><div id="user_msg_list"></div></div>' +
  30. '<div class="msg-input-box"><div class="msg-input-title"><div class="chat_tools"><i id="chat_show_smilies" class="iconfont">&#xe669;</i></div>' +
  31. '<span class="title">输入聊天信息</span><span class="chat-log-btn off" onclick="show_chat_log();">聊天记录<i></i></span></div>' +
  32. '<form id="msg_form"><textarea name="send_message" id="send_message" class="textarea" onkeyup="send_keyup(event);" onfocus="send_focus();" ></textarea>' +
  33. '<div class="msg-bottom"><div id="msg_count"></div><a href="JavaScript:void(0);" onclick="send_msg();" class="msg-button"><i></i>发送消息</a><div id="send_alert"></div></div></form></div></div>' +
  34. '<div id="dialog_chat_right" class="dialog-chat-right"></div><div id="dialog_chat_log" class="dialog_chat_log"></div></div>' +
  35. '<div id="dialog_clear" class="dialog_clear"></div></div>';
  36. var chat_user_list = '<div class="chat-box"><div class="chat-list"><div class="chat-list-top"><img class="avatar" src="' + user['avatar'] + '?' + Math.floor(Math.random() * 100) + '" /><h1>' + user['u_name'] + '</h1><span class="minimize-chat-list iconfont" onclick="chat_show_list();">&#xe6e6;</span></div>' +
  37. '<div id="chat_user_list" class="chat-list-content"><div><dl id="chat_user_friends"><dt onclick="chat_show_user_list(\'friends\');">' +
  38. '<span class="show"></span>我的好友</dt><dd id="chat_friends" style="display: none;"></dd></dl>' +
  39. '<dl id="chat_user_follow"><dt onclick="chat_show_user_list(\'follow\');"><span class="show"></span>我关注的人</dt><dd id="chat_follow" style="display: none;"></dd></dl>' +
  40. '<dl id="chat_user_recent"><dt onclick="chat_show_user_list(\'recent\');"><span class="show"></span>最近联系人</dt><dd id="chat_recent" style="display: none;"></dd></dl></div></div>' +
  41. '<div class="bottom-bar"><a href="' + HOMESITEURL + '/Membersnsfriend/index.html" target="_blank"><i class="iconfont">&#xe76d;</i></a></div>' +
  42. '</div></div>';
  43. var ajaxurl = HOMESITEURL + '/MemberInstantMessage/get_user_list?n=99&f_id=' + user['u_id'];
  44. $.ajax({
  45. type: "GET",
  46. url: ajaxurl,
  47. dataType: "json",
  48. async: true,
  49. success: function (res) {
  50. if (res.code != 10000) {
  51. return false;
  52. }
  53. var u_list = res.result.user_list
  54. for (var i in u_list) {
  55. var user_info = u_list[i];
  56. var u_id = user_info['u_id']
  57. connect_list[u_id] = 0;
  58. connect_n++;
  59. set_user_info(u_id, "u_name", user_info['u_name']);
  60. set_user_info(u_id, "avatar", user_info['avatar']);
  61. if (user_info['friend'] == 1)
  62. friend_list[u_id] = user_info;
  63. if (user_info['follow'] == 1)
  64. follow_list[u_id] = user_info;
  65. if (user_info['recent'] == 1)
  66. recent_list[u_id] = user_info;
  67. }
  68. setTimeout("getconnect()", 1000);
  69. $("#web_chat_dialog").prepend(chat_user_list);
  70. $('#chat_user_list').perfectScrollbar();
  71. $("#chat_show_user").click(function () {
  72. chat_show_list();
  73. });
  74. }
  75. });
  76. } else {
  77. var n = send_state();
  78. if (n > 0)
  79. setTimeout("getconnect()", 2000);
  80. $("#chat_show_user").click(function () {
  81. $('div[dstype="a-barLoginBox"]').trigger("click");
  82. });
  83. }
  84. });
  85. $("#web_chat_dialog").after(audio_info);
  86. function msg_dialog_close(id) {
  87. if (dialog_show == 1) {
  88. $("#" + id).hide("slide", {direction: 'right'}, 300);
  89. }
  90. dialog_show = 0;
  91. close_chat_log(user_show);
  92. if (connect === 1) {
  93. $("#web_chat_dialog").show();
  94. }
  95. }
  96. function msg_dialog_show(id) {
  97. if (dialog_show == 0) {
  98. $("#" + id).show("slide", {direction: 'right'}, 600,
  99. function () {
  100. $("#send_message").focus();
  101. var obj_msg = obj.find("div[select_user_msg='" + user_show + "']");
  102. obj.find("#msg_list").scrollTop(obj_msg.height());
  103. });
  104. } else {
  105. $("#send_message").focus();
  106. }
  107. dialog_show = 1;
  108. if ($("#msg_count").html() == '') {
  109. $("#send_message").charCount({//输入字数控制
  110. allowed: 255,
  111. warning: 10,
  112. counterContainerID: 'msg_count',
  113. firstCounterText: '还可以输入',
  114. endCounterText: '字',
  115. errorCounterText: '已经超出'
  116. });
  117. $("#chat_show_smilies").smilies({smilies_id: "send_message"});
  118. }
  119. }
  120. function send_state() { //向服务器请求页面中的相关会员的在线状态
  121. var u_list = connect_list;
  122. var n = connect_n;
  123. switch (controller_act) {
  124. case "brand_list":
  125. case "search_index":
  126. $(".list_pic em[member_id]").each(function () {
  127. n++;
  128. var u_id = $(this).attr("member_id");
  129. if (u_id > 0 && u_id != user['u_id'])
  130. u_list[u_id] = 0;
  131. });
  132. break;
  133. default:
  134. $("[member_id]").each(function () {
  135. n++;
  136. var u_id = $(this).attr("member_id");
  137. if (u_id > 0 && u_id != user['u_id'])
  138. u_list[u_id] = 0;
  139. });
  140. break;
  141. }
  142. $('[dstype="mcard"]').each(function () {
  143. var data_str = $(this).attr('data-param');
  144. eval('var mcard_obj = ' + data_str);
  145. var u_id = mcard_obj["id"];
  146. if (u_id > 0 && u_id != user['u_id']) {
  147. n++;
  148. u_list[u_id] = 0;
  149. }
  150. });
  151. if (connect === 1) {
  152. if (n > 0) {
  153. var u_ids = Object.keys(u_list)
  154. ws.send('get_state:' + u_ids.join(','))
  155. } else {
  156. if (user['u_id'] == '') {
  157. ws.close();
  158. }
  159. }
  160. } else {
  161. return n;
  162. }
  163. }
  164. function get_state(list) {//返回会员的状态并在页面显示
  165. var u_list = list['u_state'];
  166. //店铺页面 唤起对话框
  167. if (layout == 'store' || controller_act == 'Goods_index') {
  168. var store_id = 0;
  169. var store_name = '';
  170. $("[member_id]").each(function () {
  171. var u_id = $(this).attr("member_id");
  172. if (store_id > 0) {
  173. set_user_info(u_id, "s_id", store_id);
  174. set_user_info(u_id, "s_name", store_name);
  175. }
  176. set_user_info(u_id, "online", u_list[u_id]);
  177. if ($(this).find(".chat").size() == 0) {
  178. $(this).prepend(get_chat(u_id, u_list[u_id]));
  179. if ($(this).attr("c_name")) {//店铺客服
  180. var c_name = $(this).attr("c_name");
  181. set_user_info(u_id, "c_name", c_name);
  182. $(this).find(".chat").attr("href", "JavaScript:store_chat(" + u_id + ",'" + c_name + "');");
  183. }
  184. }
  185. });
  186. } else {
  187. switch (controller_act) {
  188. case "brand_list":
  189. case "search_index":
  190. $(".list_pic em[member_id]").each(function () {
  191. var u_id = $(this).attr("member_id");
  192. if ($(this).find(".chat").size() == 0) {
  193. $(this).prepend(get_chat(u_id, u_list[u_id]));
  194. $(this).after("<p>在线客服</p>");
  195. }
  196. set_user_info(u_id, "online", u_list[u_id]);
  197. });
  198. break;
  199. default:
  200. $("[member_id]").each(function () {
  201. var u_id = $(this).attr("member_id");
  202. if ($(this).find(".chat").size() == 0) {
  203. $(this).prepend(get_chat(u_id, u_list[u_id]));
  204. }
  205. set_user_info(u_id, "online", u_list[u_id]);
  206. });
  207. break;
  208. }
  209. }
  210. if (user['u_id'] != '') {
  211. update_recent(u_list);
  212. update_friends(u_list);
  213. update_follow(u_list);
  214. } else {
  215. ws.close();
  216. }
  217. }
  218. function show_obj() {//弹出框
  219. if (user_show < 1) {
  220. chat_show_list();
  221. return false;
  222. }
  223. msg_dialog_show('new_msg_dialog');
  224. }
  225. function send_focus() {
  226. $("#send_alert").html('');
  227. }
  228. function send_keyup(event) {//回车发消息
  229. var t_msg = $.trim($("#send_message").val());
  230. if (event.keyCode == 13 && t_msg.length > 0) {
  231. send_msg();
  232. }
  233. }
  234. function send_msg(type=0,goods_id=0) {//发消息
  235. if (user_show < 1) {
  236. $("#send_alert").html('未选择聊天会员');
  237. return false;
  238. }
  239. var msg = {};
  240. msg['to_id'] = user_show;
  241. if(type==0){
  242. msg['message'] = $.trim($("#send_message").val());
  243. msg['message_type'] = 0
  244. if (msg['message'].length < 1) {
  245. $("#send_alert").html('发送内容不能为空');
  246. return false;
  247. }
  248. if (msg['message'].length > 255) {
  249. $("#send_alert").html('一次最多只能发送255字');
  250. return false;
  251. }
  252. }else{
  253. if(goods_id > 0){
  254. msg['message'] = goods_id
  255. }else{
  256. msg['message'] = chat_goods_id
  257. }
  258. msg['message_type'] = 1
  259. }
  260. if (connect < 1) {
  261. $("#send_alert").html('处于离线状态,稍后再试');
  262. return false;
  263. }
  264. $.ajax({
  265. type: "POST",
  266. url: HOMESITEURL + '/MemberInstantMessage/add',
  267. dataType: "json",
  268. data: msg,
  269. async: false,
  270. success: function (res) {
  271. if (res['code'] != 10000) {
  272. $("#send_alert").html('' + res['message']);
  273. return false;
  274. } else {
  275. var t_msg = res.result.instant_message_data
  276. if (connect === 1) {
  277. $("#send_message").val('');
  278. $("#send_message").focus();
  279. $("#send_alert").html('');
  280. show_t_msg(t_msg);
  281. return true;
  282. } else {
  283. $("#send_alert").html('由于网络原因未发送成功,稍后再试');
  284. return false;
  285. }
  286. }
  287. }
  288. });
  289. }
  290. function get_msg(list) {//接收消息
  291. var msg = {};
  292. for (var k in list) {
  293. msg = list[k];
  294. var m_id = msg['instant_message_id'];
  295. var u_id = msg['instant_message_from_id'];
  296. set_user(u_id, msg['instant_message_from_name']);
  297. if (typeof msg_list[u_id][m_id] === "object") {//防止重复计数
  298. continue;
  299. }
  300. if (typeof msg['user'] === "object" && typeof msg['user']['avatar'] !== "undefined") {
  301. var user_info = msg['user'];
  302. var u_name = user_info['u_name'];
  303. set_user_info(u_id, "u_name", u_name);
  304. set_user_info(u_id, "s_id", user_info['s_id']);
  305. set_user_info(u_id, "s_name", user_info['s_name']);
  306. set_user_info(u_id, "avatar", user_info['avatar']);
  307. set_user_info(u_id, "s_avatar", user_info['s_avatar']);
  308. if (user_info['online'] > 0)
  309. set_user_info(u_id, "online", 1);
  310. }
  311. if (typeof user_list[u_id]['avatar'] === "undefined") {//当没获得会员信息时调用一次
  312. var ajaxurl = HOMESITEURL + '/MemberInstantMessage/get_info?t=member&u_id=' + u_id;
  313. $.ajax({
  314. type: "GET",
  315. url: ajaxurl,
  316. dataType: "json",
  317. async: false,
  318. success: function (res) {
  319. if (res.code != 10000) {
  320. return false
  321. }
  322. var member = res.result.user_info
  323. var u_name = member['member_name'];
  324. set_user_info(u_id, "s_id", member['store_id']);
  325. set_user_info(u_id, "s_name", member['store_name']);
  326. set_user_info(u_id, "avatar", member['member_avatar']);
  327. set_user_info(u_id, "s_avatar", member['store_avatar']);
  328. }
  329. });
  330. }
  331. msg_list[u_id][m_id] = msg;
  332. if (dialog_show == 0 || obj.find("li[select_u_id='" + u_id + "']").size() == 0) {//没有打开对话窗口时计数
  333. user_list[u_id]['new_msg']++;
  334. new_msg++;
  335. } else {
  336. if (user_show == u_id) {
  337. show_msg(u_id);//当前对话的会员消息设为已读
  338. play_audio();
  339. } else {
  340. user_list[u_id]['new_msg']++;
  341. new_msg++;
  342. }
  343. }
  344. alert_user_msg(u_id);
  345. }
  346. alert_msg();
  347. }
  348. function get_chat_log(time_from) {
  349. var obj_chat_log = $("#dialog_chat_log");
  350. if (obj_chat_log.html() == '') {
  351. var chat_log_list = '<div class="chat-log-top"><h1><i class="iconfont">&#xe71b;</i>聊天记录</h1><span class="close-chat-log iconfont" onclick="show_chat_log();">&#xe696;</span></div>' +
  352. '<div id="chat_log_list" class="chat_log_list"><div id="chat_log_msg" class="chat-log-msg"></div></div><div class="chat-log-bottom"><div id="chat_time_from" class="chat_time_from">' +
  353. '<span time_id="7" onclick="get_chat_log(7);" class="current">7天</span><span time_id="15" onclick="get_chat_log(15);">15天</span><span time_id="30" onclick="get_chat_log(30);">30天</span></div>' +
  354. '<div class="chat_log_first"><p>已到第一页</p></div><div class="chat_log_last"><p>已到最后一页</p></div>' +
  355. '<div id="chat_log_page" class="chat_log_page"><span onclick="get_chat_previous();" class="previous iconfont" title="上一页">&#xe619;</span><span onclick="get_chat_next();" class="next iconfont" title="下一页">&#xe618;</span></div></div>';
  356. obj_chat_log.append(chat_log_list);
  357. }
  358. obj_chat_log.show();
  359. chat_log['u_id'] = user_show;
  360. chat_log['now_page'] = 0;
  361. chat_log['total_page'] = 0;
  362. chat_log['time_from'] = 7;
  363. chat_log['list'] = new Array();
  364. var time_id = obj_chat_log.find("span.current").attr("time_id");
  365. if (time_from != time_id) {
  366. obj_chat_log.find("span.current").removeClass("current");
  367. obj_chat_log.find("span[time_id='" + time_from + "']").addClass("current");
  368. chat_log['time_from'] = time_from;
  369. }
  370. get_chat_msg(false);
  371. }
  372. function get_chat_next() {
  373. var now_page = chat_log['now_page'] - 1;
  374. if (now_page >= 1) {
  375. show_chat_msg(now_page);
  376. chat_log['now_page'] = now_page;
  377. } else {
  378. $('.chat_log_last').show();
  379. setTimeout("$('.chat_log_last').hide()", 2000);
  380. }
  381. }
  382. function get_chat_previous() {
  383. var now_page = chat_log['now_page'] + 1;
  384. if (chat_log['total_page'] >= now_page) {
  385. if (typeof chat_log['list'][now_page] === "undefined") {
  386. get_chat_msg(false);
  387. } else {
  388. show_chat_msg(now_page);
  389. chat_log['now_page'] = now_page;
  390. if (chat_log['total_page'] > now_page && typeof chat_log['list'][now_page + 1] === "undefined")
  391. get_chat_msg(true);
  392. }
  393. } else {
  394. $('.chat_log_first').show();
  395. setTimeout("$('.chat_log_first').hide()", 2000);
  396. }
  397. }
  398. function get_chat_msg(t) {
  399. var ajaxurl = HOMESITEURL + '/MemberInstantMessage/get_chat_log.html?f_id=' + user['u_id'] + '&t_id=' + chat_log['u_id'] + '&t=' + chat_log['time_from'];
  400. if (chat_log['now_page'] > 0)
  401. ajaxurl += '&page=' + (chat_log['now_page'] + 1);
  402. $.ajax({
  403. type: "GET",
  404. url: ajaxurl,
  405. dataType: "json",
  406. async: t,
  407. success: function (res) {
  408. if (res.code != 10000) {
  409. return false
  410. }
  411. var chat_msg = res.result
  412. var now_page = chat_log['now_page'] + 1;
  413. chat_log['list'][now_page] = chat_msg['instant_message_list'];
  414. if (t == false) {
  415. chat_log['now_page'] = now_page;
  416. show_chat_msg(now_page);
  417. }
  418. chat_log['total_page'] = chat_msg['total_page'];
  419. if (chat_log['total_page'] > 1 && chat_log['total_page'] > now_page && t == false) {
  420. get_chat_msg(true);
  421. }
  422. }
  423. });
  424. }
  425. function get_goods_list(s_id) {
  426. if (typeof store_goods[s_id] !== "undefined") {
  427. $("#chat_goods_list").html(store_goods[s_id]);
  428. $("#chat_goods_list").show();
  429. return;
  430. }
  431. var ajaxurl = HOMESITEURL + '/MemberInstantMessage/get_goods_list?s_id=' + s_id;
  432. $.ajax({
  433. type: "GET",
  434. url: ajaxurl,
  435. dataType: "json",
  436. async: true,
  437. success: function (res) {
  438. if (res.code != 10000) {
  439. return false
  440. }
  441. var list = res.result.goods_list
  442. var text_append = '<div class="title">店铺推荐</div><div class="content"><ul>';
  443. for (var k in list) {
  444. var goods = list[k];
  445. var text_goods = '<li>';
  446. text_goods += '<div class="goods-pic"><a href="' + goods['url'] + '" target="_blank">';
  447. text_goods += '<img title="' + goods['goods_name'] + '" alt="' + goods['goods_name'] + '" src="' + goods['pic'] + '"/></a></div>';
  448. text_goods += '<div class="goods-price">&yen;' + goods['goods_promotion_price'] + '</div>';
  449. text_goods += '<div class="goods-id" onclick="send_msg(1,' + goods['goods_id'] + ');">发给客服</div>';
  450. text_goods += '</li>';
  451. text_append += text_goods;
  452. }
  453. text_append += '</ul></div>';
  454. store_goods[s_id] = text_append;
  455. get_goods_list(s_id);
  456. }
  457. });
  458. }
  459. function update_msg(u_id) {//更新已读
  460. var u_name = user_list[u_id]['u_name'];
  461. user_list[u_id]['new_msg'] = 0;
  462. alert_user_msg(u_id);
  463. new_msg--;
  464. alert_msg();
  465. }
  466. //店铺客服对话窗口
  467. function store_chat(u_id, c_name) {
  468. set_user_info(u_id, "c_name", c_name);//设置客服别名
  469. chat(u_id);
  470. }
  471. //打开对话窗口
  472. function chat(u_id) {
  473. if (user['u_id'] == '') {//未登录时弹出登录窗口
  474. login_dialog();
  475. return;
  476. }
  477. if (u_id == user['u_id'])
  478. return;
  479. if (1 || typeof user_list[u_id] === "undefined" || typeof user_list[u_id]['avatar'] === "undefined") {
  480. var ajaxurl = HOMESITEURL + '/MemberInstantMessage/get_info.html?t=member&u_id=' + u_id;
  481. $.ajax({
  482. type: "GET",
  483. url: ajaxurl,
  484. dataType: "json",
  485. async: false,
  486. success: function (res) {
  487. if (res.code != 10000) {
  488. return false
  489. }
  490. var member = res.result.user_info
  491. var u_name = member['member_name'];
  492. if (typeof u_name === "undefined" || u_name == '')
  493. return false;
  494. set_user_info(u_id, "u_name", u_name);
  495. set_user_info(u_id, "s_id", member['store_id']);
  496. set_user_info(u_id, "s_name", member['store_name']);
  497. set_user_info(u_id, "avatar", member['member_avatar']);
  498. set_user_info(u_id, "s_avatar", member['store_avatar']);
  499. }
  500. });
  501. }
  502. update_user(u_id);
  503. show_msg(u_id);
  504. show_obj();
  505. }
  506. //显示窗口
  507. function show_dialog() {
  508. update_dialog();
  509. show_obj();
  510. }
  511. //显示会员的对话
  512. function update_dialog() {
  513. if (new_msg < 1)
  514. return true;
  515. var select_user = 0;
  516. for (var u_id in user_list) {
  517. if (user_list[u_id]['new_msg'] > 0) {
  518. update_user(u_id);
  519. obj.find("em[unread_id='" + u_id + "']").addClass("unread");
  520. obj.find("em[unread_id='" + u_id + "']").html(user_list[u_id]['new_msg']);
  521. }
  522. }
  523. select_user = obj.find(".unread").first().attr("unread_id");
  524. if (select_user > 0)
  525. show_msg(select_user);
  526. }
  527. function show_chat_log() {
  528. if (user_show < 1) {
  529. $("#send_alert").html('未选择聊天会员');
  530. return false;
  531. }
  532. if (typeof chat_log['u_id'] === "undefined" || chat_log['u_id'] != user_show) {
  533. // $("#web_chat_dialog").hide();
  534. obj.find(".chat-log-btn").removeClass("off");
  535. obj.find(".chat-log-btn").addClass("on");
  536. get_chat_log(7);
  537. } else {
  538. close_chat_log(user_show);
  539. }
  540. }
  541. //显示会员的消息
  542. function show_msg(u_id) {
  543. var user_info = user_list[u_id];
  544. var u_name = user_info['u_name'];
  545. if (obj.find("div[select_user_msg='" + u_id + "']").size() == 0) {
  546. obj.find("#user_msg_list").prepend('<div class="msg_list" select_user_msg="' + u_id + '"></div>');
  547. }
  548. obj.find(".msg_list").hide();
  549. obj.find("div[select_user_msg='" + u_id + "']").show();
  550. obj.find("li[select_u_id]").removeClass("select_user");
  551. obj.find("li[select_u_id='" + u_id + "']").addClass("select_user");
  552. if (user_show != u_id) {
  553. close_chat_log(user_show);
  554. $("#chat_user_avatar").attr("src", user_info['avatar']);
  555. $("#chat_goods_list").hide();
  556. var add_html = '';
  557. var store_html = '';
  558. if (typeof user_info['c_name'] !== "undefined")
  559. add_html = '--' + user_info['c_name'];
  560. if (typeof user_info['s_name'] !== "undefined" && user_info['s_name'] !== "") {
  561. get_goods_list(user_info['s_id']);//异步调用店铺推荐的商品
  562. $("#chat_user_avatar").attr("src", user_info['s_avatar']);
  563. store_html = '<a target="_blank" href="' + HOMESITEURL + '/Store/index.html?store_id=' + user_info['s_id'] + '">' + user_info['s_name'] + '</a>';
  564. u_name = '客服:' + u_name;
  565. }
  566. var online_html = '<i class="offline" title="离线"></i>';
  567. if (user_info['online'] > 0) {
  568. online_html = '<i class="online" title="在线"></i>';
  569. }
  570. $("#chat_user_name").html(u_name + add_html + online_html);
  571. $("#chat_user_store").html(store_html);
  572. obj.find('#msg_list').perfectScrollbar('destroy');
  573. obj.find('#msg_list').perfectScrollbar();
  574. }
  575. user_show = u_id;
  576. var max_id = 0;
  577. for (var m_id in msg_list[u_id]) {
  578. if (obj.find("div[m_id='" + m_id + "']").size() == 0) {
  579. var msg = msg_list[u_id][m_id];
  580. show_f_msg(msg);
  581. update_msg(u_id);
  582. delete msg_list[u_id][m_id];//删除消息
  583. if (m_id > max_id)
  584. max_id = m_id;
  585. }
  586. }
  587. if(max_id){
  588. //将消息设置为已读
  589. $.getJSON(HOMESITEURL + '/MemberInstantMessage/set_message',{max_id:max_id,f_id:u_id})
  590. }
  591. var obj_msg = obj.find("div[select_user_msg='" + u_id + "']");
  592. obj.find("#msg_list").scrollTop(obj_msg.height());
  593. $("#send_message").focus();
  594. }
  595. //显示收到的消息
  596. function show_f_msg(msg) {
  597. var u_id = msg['instant_message_from_id'];
  598. var user_info = user_list[u_id];
  599. var text_append = '';
  600. var obj_msg = obj.find("div[select_user_msg='" + u_id + "']");
  601. text_append += '<div class="from_msg" m_id="' + msg['instant_message_id'] + '">';
  602. text_append += '<span class="user-avatar"><img src="' + user_info['avatar'] + '"></span>';
  603. text_append += '<dl><dt class="from-msg-time">';
  604. text_append += timetrans(msg['instant_message_add_time']) + '</dt>';
  605. text_append += '<dd class="from-msg-text">';
  606. text_append += update_chat_msg(msg) + '</dd>';
  607. text_append += '</dl>';
  608. text_append += '</div>';
  609. obj_msg.append(text_append);
  610. var n = obj_msg.find("div[m_id]").size();
  611. if (n >= msg_max && n % msg_max == 1) {
  612. obj_msg.append('<div clear_id="' + msg['instant_message_id'] + '" onclick="clear_msg(' + u_id + ',' + msg['instant_message_id'] +
  613. ');" class="clear_msg"><a href="Javascript: void(0);">清除已上历史消息</a></div>');
  614. }
  615. obj.find("#msg_list").scrollTop(obj_msg.height());
  616. }
  617. function show_t_msg(msg) {//显示发出的消息
  618. var user_info = user;
  619. var u_id = msg['instant_message_to_id'];
  620. var text_append = '';
  621. var obj_msg = obj.find("div[select_user_msg='" + u_id + "']");
  622. text_append += '<div class="to_msg" m_id="' + msg['instant_message_id'] + '">';
  623. text_append += '<span class="user-avatar"><img src="' + user_info['avatar'] + '"></span>';
  624. text_append += '<dl><dt class="to-msg-time">';
  625. text_append += timetrans(msg['instant_message_add_time']) + '</dt>';
  626. text_append += '<dd class="to-msg-text">';
  627. text_append += update_chat_msg(msg) + '</dd>';
  628. text_append += '</dl>';
  629. text_append += '</div>';
  630. obj_msg.append(text_append);
  631. var n = obj_msg.find("div[m_id]").size();
  632. if (n >= msg_max && n % msg_max == 1) {
  633. obj_msg.append('<div clear_id="' + msg['instant_message_id'] + '" onclick="clear_msg(' + u_id + ',' + msg['instant_message_id'] +
  634. ');" class="clear_msg"><a href="Javascript: void(0);">清除已上历史消息</a></div>');
  635. }
  636. obj.find("#msg_list").scrollTop(obj_msg.height());
  637. }
  638. function show_chat_msg(now_page) {
  639. var log_list = chat_log['list'][now_page];
  640. $('#chat_log_msg').html('');
  641. for (var k in log_list) {
  642. var class_html = '';
  643. var text_append = '';
  644. var msg = log_list[k];
  645. msg['u_name'] = msg['instant_message_from_name'];
  646. if (msg['instant_message_from_id'] == user['u_id']) {
  647. msg['u_name'] = '我';
  648. class_html = 'chat_user';
  649. }
  650. text_append += '<div class="chat_msg ' + class_html + '" m_id="' + msg['instant_message_id'] + '">';
  651. text_append += '<p class="user-log"><span class="user-name">' + msg['u_name'] + '</span>';
  652. text_append += '<span class="user-time">' + timetrans(msg['instant_message_add_time']) + '</span></p>';
  653. text_append += '<p class="user-msg">' + update_chat_msg(msg) + '</p>';
  654. text_append += '</div>';
  655. $('#chat_log_msg').prepend(text_append);
  656. }
  657. $('#chat_log_list').perfectScrollbar('destroy');
  658. $('#chat_log_list').perfectScrollbar();
  659. $('#chat_log_list').scrollTop($('#chat_log_msg').height());
  660. }
  661. function chat_show_user_list(chat_show) {
  662. var obj_chat = $("#chat_user_" + chat_show);
  663. if (obj_chat.find("dt span").attr("class") == 'hide') {
  664. obj_chat.find("dd[u_id]").show();
  665. obj_chat.find("dt span").attr("class", "show");
  666. } else {
  667. obj_chat.find("dd[u_id]").hide();
  668. obj_chat.find("dt span").attr("class", "hide");
  669. }
  670. }
  671. function chat_show_list() {
  672. if (user['u_id'] == '') {
  673. return;
  674. }
  675. var obj_chat = $(".chat-list");
  676. if (new_msg > 0 || obj_chat.css("display") == 'none') {
  677. obj_chat.show("slide", {direction: 'right'}, 300);
  678. } else {
  679. obj_chat.hide("slide", {direction: 'right'}, 300);
  680. }
  681. }
  682. function del_msg(msg) {//已读消息处理
  683. var max_id = msg['max_id'];//最大的消息编号
  684. var u_id = msg['f_id'];//消息发送人
  685. for (var m_id in msg_list[u_id]) {
  686. if (max_id >= m_id) {
  687. delete msg_list[u_id][m_id];
  688. if (user_list[u_id]['new_msg'] > 0)
  689. user_list[u_id]['new_msg']--;
  690. if (new_msg > 0)
  691. new_msg--;
  692. alert_user_msg(u_id);
  693. }
  694. }
  695. alert_msg();
  696. }
  697. function alert_user_msg(u_id) {
  698. if (user_list[u_id]['new_msg'] > 0) {
  699. obj.find("em[unread_id='" + u_id + "']").addClass("unread");
  700. obj.find("em[unread_id='" + u_id + "']").html(user_list[u_id]['new_msg']);
  701. $("#chat_user_recent dd[u_id='" + u_id + "'] a").addClass("msg");
  702. } else {
  703. obj.find("em[unread_id='" + u_id + "']").html("");
  704. obj.find("em[unread_id='" + u_id + "']").removeClass("unread");
  705. $("#chat_user_recent dd[u_id='" + u_id + "'] a").removeClass("msg");
  706. }
  707. }
  708. function alert_msg() {
  709. var new_n = 0;
  710. clearInterval(new_interval);
  711. if (new_msg > 0) {//消息提醒
  712. new_interval = setInterval(function () {
  713. new_n++;
  714. if (connect === 1)
  715. $(document).attr('title', '新消息(' + new_msg + ') ' + web_info['html_title']);
  716. if (new_n % 3 > 1)
  717. $(document).attr('title', web_info['html_title']);
  718. }, 500);
  719. $("#new_msg").show().html(new_msg);
  720. play_audio();
  721. } else {
  722. new_msg = 0;
  723. $("#new_msg").hide().html('');
  724. }
  725. $(document).attr('title', web_info['html_title']);
  726. }
  727. function get_chat(u_id, online) {//显示链接地址
  728. var add_html = '<a class="chat chat_online" title="在线联系" href="JavaScript:layer.msg(\'不能和自己聊天\')">在线</a>';
  729. if (u_id != user['u_id'] && u_id > 0) {
  730. var class_html = 'chat_offline';
  731. var text_html = '离线';
  732. if (online > 0) {
  733. class_html = 'chat_online';
  734. text_html = '在线';
  735. }
  736. add_html = '<a class="chat ' + class_html + '" title="在线联系" href="JavaScript:chat(' + u_id + ');">' + text_html + '</a>';
  737. }
  738. return add_html;
  739. }
  740. function clear_msg(u_id, m_id) {//清除消息处理
  741. var obj_msg = obj.find("div[select_user_msg='" + u_id + "']");
  742. obj_msg.find("div[clear_id='" + m_id + "']").prevAll().remove();
  743. obj_msg.find("div[clear_id='" + m_id + "']").remove();
  744. }
  745. function play_audio() {//提示声音
  746. if (chat_audio === 1) {
  747. var swf = document["msg_audio"];
  748. if (typeof swf.pplay === "function") {
  749. swf.load(CHAT_SITE_URL + '/msg.mp3');
  750. swf.pplay();
  751. }
  752. }
  753. }
  754. function set_user(u_id, u_name) {//初始化会员信息
  755. var user_info = new Array();
  756. user_info['u_id'] = u_id;
  757. user_info['u_name'] = u_name;
  758. user_info['new_msg'] = 0;
  759. user_info['online'] = 0;
  760. if (typeof user_list[u_id] === "undefined") {
  761. user_list[u_id] = user_info;
  762. }
  763. if (typeof msg_list[u_id] === "undefined") {
  764. msg_list[u_id] = new Array();
  765. }
  766. }
  767. function set_user_info(u_id, k, v) {//设置会员信息
  768. if (typeof user_list[u_id] === "undefined") {
  769. set_user(u_id, '');
  770. }
  771. user_list[u_id][k] = v;
  772. }
  773. function close_chat_log(u_id) {
  774. if (user_show == 0 || chat_log['u_id'] == u_id) {
  775. chat_log = {};
  776. $("#dialog_chat_log").hide();
  777. $('#chat_log_msg').html('');
  778. obj.find(".chat-log-btn").removeClass("on");
  779. obj.find(".chat-log-btn").addClass("off");
  780. if (connect === 1)
  781. $("#web_chat_dialog").show();
  782. }
  783. }
  784. function close_dialog(u_id) {
  785. obj.find("li[select_u_id='" + u_id + "']").remove();
  786. obj.find("div[select_user_msg='" + u_id + "']").hide();
  787. if (obj.find("li[select_u_id]").size() == 0) {
  788. msg_dialog_close('new_msg_dialog');
  789. } else {
  790. if (user_show == u_id)
  791. obj.find("li[select_u_id]").first().trigger("click");
  792. }
  793. if (user_show == u_id) {
  794. user_show = 0;
  795. close_chat_log(u_id);
  796. }
  797. if (obj.find("li[select_u_id]").size() < 2) {
  798. obj.find(".user-tab-bar").hide();
  799. $("#new_msg_dialog").css('width', '742px')
  800. }
  801. }
  802. function update_chat_msg(res) {
  803. if (res['instant_message_type'] == 1) {
  804. var chat_goods = res['instant_message']
  805. var msg = '<div class="dstouch-chat-product"> <a href="' + HOMESITEURL + '/goods/index?goods_id=' + chat_goods.goods_id + '" target="_blank"><div class="goods-pic"><img src="' + chat_goods.goods_image_url + '" alt=""/></div><div class="goods-info"><div class="goods-name">' + chat_goods.goods_name + '</div><div class="goods-price">¥' + chat_goods.goods_price + "</div></div></a> </div>";
  806. } else {
  807. var msg=res['instant_message']
  808. if (typeof smilies_array !== "undefined") {
  809. msg = '' + msg;
  810. for (var i in smilies_array[1]) {
  811. var s = smilies_array[1][i];
  812. var re = new RegExp("" + s[1], "g");
  813. var smilieimg = '<img width="28" height="28" title="' + s[6] + '" alt="' + s[6] + '" src="' + BASESITEROOT + '/static/plugins/js/smilies/images/' + s[2] + '">';
  814. msg = msg.replace(re, smilieimg);
  815. }
  816. }
  817. }
  818. return msg;
  819. }
  820. function update_friends(u_list) {
  821. var obj_friend = $("#chat_friends");
  822. for (var u_id in friend_list) {
  823. set_user_info(u_id, "online", u_list[u_id]);
  824. if (obj_friend.parent().find("dd[u_id='" + u_id + "']").size() == 0) {
  825. if (user_list[u_id]['online'] > 0) {
  826. obj_friend.before('<dd u_id="' + u_id + '" onclick="chat(' + u_id + ');"><span class="user-avatar avatar-1"><img alt="' + user_list[u_id]['u_name']
  827. + '" src="' + user_list[u_id]['avatar'] + '?' + Math.floor(Math.random() * 100) + '"><i class="online"></i></span><h5>' + user_list[u_id]['u_name'] + '</h5><a class="iconfont" href="javascript:void(0)">&#xe71b;</a></dd>');
  828. } else {
  829. obj_friend.after('<dd u_id="' + u_id + '" onclick="chat(' + u_id + ');"><span class="user-avatar avatar-0"><img alt="' + user_list[u_id]['u_name']
  830. + '" src="' + user_list[u_id]['avatar'] + '?' + Math.floor(Math.random() * 100) + '"><i class="offline"></i></span><h5>' + user_list[u_id]['u_name'] + '</h5><a class="iconfont" href="javascript:void(0)">&#xe71b;</a></dd>');
  831. }
  832. }
  833. }
  834. obj_friend.remove();
  835. chat_show_user_list('friends');
  836. }
  837. function update_follow(u_list) {
  838. var obj_follow = $("#chat_follow");
  839. for (var u_id in follow_list) {
  840. set_user_info(u_id, "online", u_list[u_id]);
  841. if (obj_follow.parent().find("dd[u_id='" + u_id + "']").size() == 0) {
  842. if (user_list[u_id]['online'] > 0) {
  843. obj_follow.before('<dd u_id="' + u_id + '" onclick="chat(' + u_id + ');"><span class="user-avatar avatar-1"><img alt="' + user_list[u_id]['u_name']
  844. + '" src="' + user_list[u_id]['avatar'] + '?' + Math.floor(Math.random() * 100) + '"><i class="online"></i></span><h5>' + user_list[u_id]['u_name'] + '</h5><a class="iconfont" href="javascript:void(0)">&#xe71b;</a></dd>');
  845. } else {
  846. obj_follow.after('<dd u_id="' + u_id + '" onclick="chat(' + u_id + ');"><span class="user-avatar avatar-0"><img alt="' + user_list[u_id]['u_name']
  847. + '" src="' + user_list[u_id]['avatar'] + '?' + Math.floor(Math.random() * 100) + '"><i class="offline"></i></span><h5>' + user_list[u_id]['u_name'] + '</h5><a class="iconfont" href="javascript:void(0)">&#xe71b;</a></dd>');
  848. }
  849. }
  850. }
  851. obj_follow.remove();
  852. chat_show_user_list('follow');
  853. }
  854. function update_recent(u_list) {
  855. var obj_recent = $("#chat_recent");
  856. for (var u_id in recent_list) {
  857. set_user_info(u_id, "online", u_list[u_id]);
  858. if (obj_recent.parent().find("dd[u_id='" + u_id + "']").size() == 0) {
  859. if (user_list[u_id]['online'] > 0) {
  860. obj_recent.before('<dd u_id="' + u_id + '" title="最后对话:' + recent_list[u_id]['time'] + '" onclick="chat(' + u_id + ');"><span class="user-avatar avatar-1"><img alt="' + user_list[u_id]['u_name']
  861. + '" src="' + user_list[u_id]['avatar'] + '?' + Math.floor(Math.random() * 100) + '"><i class="online"></i></span><h5>' + user_list[u_id]['u_name'] + '</h5><a class="iconfont" href="javascript:void(0)">&#xe71b;</a></dd>');
  862. } else {
  863. obj_recent.after('<dd u_id="' + u_id + '" title="最后对话:' + recent_list[u_id]['time'] + '" onclick="chat(' + u_id + ');"><span class="user-avatar avatar-0"><img alt="' + user_list[u_id]['u_name']
  864. + '" src="' + user_list[u_id]['avatar'] + '?' + Math.floor(Math.random() * 100) + '"><i class="offline"></i></span><h5>' + user_list[u_id]['u_name'] + '</h5><a class="iconfont" href="javascript:void(0)">&#xe71b;</a></dd>');
  865. }
  866. }
  867. }
  868. obj_recent.remove();
  869. }
  870. function update_user(u_id) {
  871. if ($("#dialog_chat_right").html() == '') {
  872. var text_append = '<span class="dialog-close iconfont" onclick="msg_dialog_close(\'new_msg_dialog\');">&#xe6e6;&nbsp;</span>';
  873. text_append += '<div class="user-info">';
  874. text_append += '<div class="user-avatar">';
  875. text_append += '<img id="chat_user_avatar" src=""></div>';
  876. text_append += '<div id="chat_user_store" class="store-name"></div>';
  877. text_append += '<div id="chat_user_name" class="user-name"></div>';
  878. text_append += '</div>';
  879. text_append += '<div id="chat_goods_list" class="goods-list"></div>';
  880. $("#dialog_chat_right").append(text_append + web_info['chat_goods_html']);
  881. }
  882. if (obj.find("li[select_u_id='" + u_id + "']").size() == 0) {
  883. var user_info = user_list[u_id];
  884. var u_name = user_info['u_name'];
  885. var text_append = '';
  886. var class_html = 'offline';
  887. if (user_info['online'] > 0)
  888. class_html = 'online';
  889. text_append += '<li class="user" select_u_id="' + u_id + '" onclick="show_msg(' + u_id + ');">';
  890. text_append += '<i class="' + class_html + '"></i>';
  891. text_append += '<span class="user-avatar avatar-' + user_info['online'] + '" title="' + u_name + '"><img alt="' + u_name + '" src="' + user_info['avatar'] + '"></span>';
  892. text_append += '<span class="user-name" title="' + u_name + '">';
  893. text_append += u_name + '<em></em></span>';
  894. text_append += '<em unread_id="' + u_id + '" class=""></em>';
  895. text_append += '<a class="ac-ico iconfont">&#xe64b;</a>';
  896. text_append += '</li>';
  897. obj.find("#user_list").append(text_append);
  898. obj.find("#user_list").sortable({items: 'li'});
  899. obj.find("li[select_u_id='" + u_id + "'] .ac-ico").bind("click", function () {
  900. close_dialog(u_id);
  901. return false;
  902. });
  903. if (obj.find("li[select_u_id]").size() > 1) {
  904. obj.find(".user-tab-bar").show();
  905. $("#new_msg_dialog").css('width', '942px')
  906. }
  907. }
  908. obj.find(".user-tab-bar").perfectScrollbar();
  909. }
  910. var ws
  911. var lockReconnect = false
  912. var timeOut = false
  913. function getconnect() {
  914. try {
  915. ws = new WebSocket(connect_url)
  916. init()
  917. } catch (e) {
  918. reconnect()
  919. }
  920. }
  921. function init() {
  922. ws.onopen = wsOpen
  923. ws.onmessage = wsMessage
  924. ws.onclose = wsClose
  925. ws.onerror = wsError
  926. }
  927. function reconnect() {
  928. if (lockReconnect) {
  929. return
  930. }
  931. lockReconnect = true
  932. // 没连接上会一直重连,设置延迟避免请求过多
  933. timeOut && clearTimeout(timeOut)
  934. timeOut = setTimeout(function () {
  935. getconnect()
  936. lockReconnect = false
  937. }, 4000)
  938. }
  939. function wsOpen() {
  940. connect = 1
  941. send_state();
  942. if (user['u_id'] == '')
  943. return false;//未登录时不取消息
  944. $("#web_chat_dialog").show();
  945. if ($("#new_msg_dialog").size() == 0)
  946. {
  947. $("#web_chat_dialog").after(web_info['msg_dialog']);
  948. $("#new_msg_dialog").draggable({containment: "body"});
  949. }
  950. obj = $("#new_msg_dialog");
  951. // 心跳检测重置
  952. heartCheck.start()
  953. }
  954. function wsMessage(res) {
  955. var message = JSON.parse(res.data)
  956. if (!message) {
  957. console.log(res)
  958. return
  959. }
  960. var type = message.type || ''
  961. switch (type) {
  962. // Events.php中返回的init类型的消息,将client_id发给后台进行uid绑定
  963. case 'init':
  964. var clientId = message.client_id
  965. //获取未读消息
  966. $.getJSON(HOMESITEURL + '/MemberInstantMessage/join',{client_id:clientId})
  967. break
  968. case 'leave':
  969. break
  970. case 'get_state'://用户状态
  971. get_state(message)
  972. break
  973. case 'get_msg'://未读消息
  974. get_msg(message.msg_list)
  975. break
  976. default:
  977. get_msg([message])
  978. }
  979. heartCheck.start()
  980. }
  981. function wsClose(res) {
  982. connect = 0
  983. console.log(res)
  984. $("#web_chat_dialog").hide();
  985. reconnect()
  986. }
  987. function wsError(res) {
  988. console.log(res)
  989. reconnect()
  990. }
  991. // 心跳检测
  992. var heartCheck = {
  993. timeout: 3000,
  994. timeoutObj: null,
  995. start: function () {
  996. var self = this
  997. this.timeoutObj && clearTimeout(this.timeoutObj)
  998. this.timeoutObj = setInterval(function () {
  999. // 这里发送一个心跳,后端收到后,返回一个心跳消息,
  1000. ws.send('123456789')
  1001. }, this.timeout)
  1002. }
  1003. }
  1004. function timetrans(date) {
  1005. var date = new Date(date * 1000);//如果date为13位不需要乘1000
  1006. var Y = date.getFullYear() + '-';
  1007. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  1008. var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  1009. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  1010. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  1011. var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  1012. return Y + M + D + h + m + s;
  1013. }