prescription-consulting.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. var request = getRequest(),
  2. sessionId = request.sessionId,
  3. patiCode,
  4. patiName,
  5. consultCode,
  6. prescriptionStatus,
  7. prescriptionCode,
  8. page = 1,
  9. members = [],
  10. fv_id,
  11. quickReplyList,
  12. survey_1_obj, //身体异常症状问卷obj
  13. survey_2_obj; //体征及生活方式调查问卷obj
  14. var docInfo = window.localStorage.getItem("docInfo");
  15. docInfo = JSON.parse(docInfo);
  16. $(function(){
  17. //续方咨询的sessionId 格式 居民code+咨询code+咨询类型( 8 )
  18. patiCode = sessionId.split("_")[0];
  19. consultCode = sessionId.split("_")[1];
  20. getConsultStatus();
  21. //获得会话参与人员
  22. consultingAPI.getMembers(sessionId).then(function(res){
  23. members = res;
  24. for(var i=0; i<members.length; i++){
  25. if(members[i].is_patient == 1){
  26. patiName = members[i].name;
  27. break;
  28. }
  29. }
  30. getMessage(true);
  31. })
  32. getPrescriptionInfo();
  33. getPatientServiceType(); //获得患者的标签类型
  34. connectSocket();
  35. bindEvents();
  36. })
  37. function getConsultStatus(){
  38. var params = {consult: consultCode};
  39. consultingAPI.getConsultStatus({data: params}).then(function(res){
  40. if(res.status == 200){
  41. //咨询状态(0进行中,1已完成,-1患者取消,-2超时未响应自动关闭)
  42. if(res.data == 0) { //咨询未结束
  43. } else { //咨询已结束
  44. $('.info-panel').html('咨询求助已结束');
  45. $('.send-btn').addClass("disabled");
  46. $("#file_head").attr("disabled", true);
  47. $('.icon-reply').hide()
  48. }
  49. }else{
  50. }
  51. });
  52. }
  53. function getMessage(isInit){
  54. var params = {
  55. page: page,
  56. pagesize: 10,
  57. end_msg_id: '',
  58. start_msg_id: '',
  59. user: docInfo.code,
  60. session_id: sessionId,
  61. content_type: '',
  62. isoffset: ''
  63. }
  64. consultingAPI.getMessages(sessionId, {data: params}).then(function(res){
  65. var list = res;
  66. if (list && list.length > 0) {
  67. id = list[list.length - 1].id;
  68. var html = '',
  69. length = list.length;
  70. for (var j = list.length-1; j >= 0; j--) {
  71. var reply = list[j];
  72. html += formatMsg(reply);
  73. }
  74. if(isInit){
  75. $("#talkBox").append(html);
  76. $("#talkBox").slimScroll({
  77. height: '100%',
  78. width: '100%',
  79. alwaysVisible: true,
  80. start : 'bottom',
  81. }).bind('slimscroll', function(e, pos) {
  82. if(pos == 'top'){
  83. if(length == 10){
  84. page++;
  85. getMessage();
  86. }
  87. }
  88. });
  89. }else{
  90. $("#talkBox").prepend(html);
  91. $("#talkBox").slimScroll({
  92. scrollTo: 'bottom'
  93. });
  94. }
  95. $(".fancybox").fancybox({openEffect:"none",closeEffect:"none"});
  96. plyr.setup();
  97. }
  98. });
  99. }
  100. function formatMsg(reply){
  101. try{
  102. reply = JSON.parse(reply);
  103. }catch(e){
  104. }
  105. var isSelf = (reply.sender_id==docInfo.code) ? true : false;
  106. var isSystem = reply.sender_id == 'system';
  107. var html = '';
  108. if(reply.content_type == 7 || reply.content_type == 10 || reply.content_type == 13 || reply.content_type == 14){
  109. var content = reply.content;
  110. if(isSystem){
  111. content = '居民24小时内未回复,系统自动结束咨询';
  112. }
  113. html = template('sys_msg_tmp', {content: content});
  114. }else{
  115. var member;
  116. for(var i=0; i<members.length; i++){
  117. if(reply.sender_id == members[i].id){
  118. member = members[i];
  119. break;
  120. }
  121. }
  122. var img = APIService.getImgUrl(member.avatar);
  123. if((img.indexOf('http') == -1) && (img.indexOf("https") == -1)){
  124. img = member.is_patient ? 'img/p-default.png' : 'img/d-male.png';
  125. }
  126. var content = '';
  127. try{
  128. content = JSON.parse(reply.content);
  129. }catch(e){
  130. if(reply.content_type == 12){ //视频文件
  131. var arr = reply.content.split(",");
  132. content = {};
  133. content.img = arr[0];
  134. content.path = arr[1];
  135. content.time = arr[2];
  136. }else{
  137. content = reply.content;
  138. }
  139. }
  140. var obj = {
  141. isSelf: isSelf,
  142. time: new Date(reply.timestamp).format('yyyy-MM-dd HH:mm:ss'),
  143. type: reply.content_type,
  144. name: member.name,
  145. img: img,
  146. content: content
  147. };
  148. html = template('msg_tmp', obj);
  149. }
  150. return html;
  151. }
  152. function getPrescriptionInfo(){
  153. var params = { consult: consultCode};
  154. consultingAPI.getPrescriptionInfo({data: params}).then(function(res){
  155. if(res.status == 200){
  156. //获得随访相关内容
  157. var followup = res.data.followup;
  158. if(followup){
  159. followup = JSON.parse(followup);
  160. fv_id = followup.id;
  161. }
  162. var html = template('prescriptionInfo_tmp', res.data);
  163. prescriptionStatus = res.data.status;
  164. prescriptionCode = res.data.code;
  165. var statusName = getStatusName(res.data.status == '69' ? '61' : res.data.status);
  166. $(".status-btn").text(statusName);
  167. if(res.data.status < 0){
  168. //取消的续方不可以填写药品信息到随访记录中
  169. $("#importDrugs").addClass("hidden");
  170. }else{
  171. $("#importDrugs").removeClass("hidden");
  172. }
  173. $("#prescriptionInfo").empty().append(html);
  174. $("#prescriptionInfo").slimscroll({
  175. height: '100%',
  176. width: '100%'
  177. });
  178. }else{
  179. showWarningMsg(res.msg)
  180. }
  181. });
  182. }
  183. function getPatientServiceType(){
  184. var params = {patient: patiCode};
  185. consultingAPI.getPatientServiceType({data: params}).then(function(res){
  186. if(res.status == 200){
  187. //slowDiseasePatient: 0 //0表示没有慢病服务类型,1表示有
  188. if(res.data.slowDiseasePatient == 0){
  189. $(".diseaseInfo").html("此居民未被标注【慢病】相关标签,请在i健康APP上核实");
  190. }else{
  191. var disease = "";
  192. for(var i=0; i<res.data.signFamilyServer.length; i++){
  193. var item = res.data.signFamilyServer[i];
  194. if(i>0){
  195. disease += ','+item.name;
  196. }else{
  197. disease += item.name;
  198. }
  199. }
  200. $(".diseaseInfo").text("该居民为"+disease+"患者");
  201. }
  202. }else{
  203. showWarningMsg(res.msg)
  204. }
  205. });
  206. }
  207. function connectSocket(){
  208. jQuery.getScript(APIService.socketUrl+"/socket.io/socket.io.js").done(function() {
  209. var socket = io.connect(APIService.socketUrl );
  210. socket.emit('login', {
  211. userId: docInfo.code,
  212. password: docInfo.code,
  213. sessionId: sessionId,
  214. clientType: "pc_doctor"
  215. });
  216. socket.on('message', function (data) {
  217. console.log(data);
  218. if(data.read && data.read == "all"){
  219. return ;
  220. }
  221. var html = formatMsg(data);
  222. $("#talkBox").append(html);
  223. $("#talkBox").slimscroll({
  224. scrollTo: 'bottom'
  225. });
  226. });
  227. socket.on('error', function (data) {
  228. console.log(data)
  229. });
  230. socket.on('ack', function (data) {
  231. });
  232. }).fail(function() {
  233. // dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
  234. });
  235. }
  236. function sendMessage(contentType, content){
  237. var params = {
  238. sender_id: docInfo.code,
  239. sender_name: docInfo.name,
  240. content_type: contentType,
  241. content: content,
  242. view: 0
  243. };
  244. consultingAPI.sendMessage(sessionId, {data: params}).then(function(res){
  245. console.log(res);
  246. // var html = "";
  247. // for(var i=0; i<res.messages.length; i++){
  248. // var reply = res.messages[i];
  249. // console.log(reply);
  250. // html += formatMsg(reply);
  251. // }
  252. // $("#talkBox").append(html);
  253. // $("#talkBox").slimscroll({
  254. // scrollTo: this.height
  255. // });
  256. });
  257. }
  258. //结束咨询
  259. function finish(){
  260. //判断续方状态,如果未审核,则不可以结束咨询
  261. if(prescriptionStatus > 0 && prescriptionStatus < 21){
  262. dialog({
  263. content:'续方申请未审核,不能结束咨询',
  264. width: 460,
  265. okValue:'我知道了',
  266. ok: function() {
  267. return;
  268. }
  269. }).width(320).showModal();
  270. return false;
  271. }
  272. dialog({
  273. content:'结束咨询后,居民及所有医生均无法再次回复,是否确认继续结束?',
  274. width: '460px',
  275. okValue:'继续结束',
  276. ok: function() {
  277. var params = {consult: consultCode};
  278. consultingAPI.finishConsult({data: params}).then(function(res){
  279. if(res.status == 200) {
  280. var content = docInfo.name+'结束了咨询',
  281. html = template('sys_msg_tmp', {content: content});
  282. $("#talkBox").append(html);
  283. $("#talkBox").slimScroll({
  284. scrollTo: 'bottom'
  285. });
  286. $('.info-panel').html("咨询求助已结束");
  287. $(".send-btn").addClass("disabled");
  288. $("#file_head").attr("disabled", true);
  289. $('.icon-reply').hide()
  290. showSuccessMsg("已结束咨询");
  291. } else {
  292. showErrorMsg(res.msg);
  293. }
  294. })
  295. },
  296. cancelValue: '我再看看',
  297. cancel: function(){}
  298. }).showModal();
  299. }
  300. function bindEvents(){
  301. $(".send-btn").on('click', function(){
  302. var $this = $(this);
  303. if($this.hasClass("disabled")){
  304. return false;
  305. }else{
  306. var text = $.trim($("#input_content").text());
  307. if(text.length == 0){
  308. showWarningMsg('发送内容不能为空');
  309. return false;
  310. }else{
  311. sendMessage(1, text);
  312. $("#input_content").text('');
  313. var obj = {
  314. content: text,
  315. content_type: '1',
  316. sender_id: docInfo.code,
  317. timestamp: new Date().getTime()
  318. }
  319. var html = formatMsg(obj);
  320. $("#talkBox").append(html);
  321. $("#talkBox").slimscroll({
  322. scrollTo: 'bottom'
  323. });
  324. }
  325. }
  326. });
  327. $("#file_head").on('change', function(){
  328. var file = this.files[0];
  329. //先上传图片去服务器,然后再发送消息
  330. var fd=new FormData();
  331. fd.append("action", "UploadVMKImagePath");
  332. fd.append("file", file); //加入文件对象
  333. fd.append("type", '2');
  334. var ajaxObj = {
  335. data: fd,
  336. cache: false,
  337. processData: false,
  338. contentType: false
  339. }
  340. consultingAPI.uploadImage(ajaxObj).then(function(res){
  341. if(res.status == 200){
  342. sendMessage(2, res.urls);
  343. var obj = {
  344. content: res.urls,
  345. content_type: '2',
  346. sender_id: docInfo.code,
  347. timestamp: new Date().getTime()
  348. }
  349. var html = formatMsg(obj);
  350. $("#talkBox").append(html);
  351. $("#talkBox").slimscroll({
  352. scrollTo: 'bottom'
  353. });
  354. }else{
  355. }
  356. });
  357. });
  358. //查看详情
  359. $("body").on('click', '.view-detail', function(){
  360. //修改顶部tab页面的
  361. var url = parent.document.getElementById("tab").src;
  362. parent.document.getElementById("tab").src = "prescription-tabs.html?sessionId="+sessionId+"&patiCode="+patiCode+"&code="+prescriptionCode+"&tab=1&fromTabIdx=0";
  363. });
  364. template.helper('getSourceUrl', function(str){
  365. return APIService.getImgUrl(str);
  366. });
  367. //导入随访相关控件监听
  368. $("body").on('click', '.import-fv', function(){
  369. var $this = $(this),
  370. type = $this.attr("data-type"), // 1-血压,2-血糖
  371. health = $this.attr("data-health"),
  372. params = {
  373. prescriptioncode: prescriptionCode,
  374. followupid: fv_id,
  375. healthindexid: health
  376. };
  377. if(type == 1){
  378. consultingAPI.importbloodpressure(params).then(function(res){
  379. if(res.status == 200){
  380. showSuccessMsg("已填入");
  381. }else{
  382. showErrorMsg(res.msg)
  383. }
  384. })
  385. }else if(type == 2){
  386. consultingAPI.importbloodsugar(params).then(function(res){
  387. if(res.status == 200){
  388. showSuccessMsg("已填入");
  389. }else{
  390. showErrorMsg(res.msg)
  391. }
  392. })
  393. }
  394. });
  395. //导入药品到随访记录中
  396. $(".import-drugs").on('click', function(){
  397. var params = {
  398. prescriptioncode: prescriptionCode,
  399. followupid: fv_id
  400. };
  401. consultingAPI.importdrugs(params).then(function(res){
  402. if(res.status == 200){
  403. showSuccessMsg("已将续方药品填入本次随访记录");
  404. }else{
  405. showErrorMsg(res.msg);
  406. }
  407. });
  408. });
  409. //查看问卷记录
  410. $("body").on('click', '.view-survey', function(){
  411. var $this = $(this),
  412. msgType = $this.attr("data-type");
  413. parent.gotoPrescriptionTab(8);
  414. });
  415. //快捷回复相关监听事件
  416. bindReplyEvents();
  417. }
  418. //-------------------------------快捷回复相关内容--------------------------
  419. var count = 0;
  420. function showQuickReplyPanel(e){
  421. var $el = $(e),
  422. offset = $el.offset();
  423. if(count == 0){
  424. $(".quick-reply-panel").css({"left": offset.left});
  425. //获得快捷回复列表
  426. getQuickReplayList();
  427. $(".quick-reply-panel").toggle("show");
  428. }else{
  429. //渲染前4条记录
  430. var list = quickReplyList.slice(0, 4),
  431. html = template("quick_reply_tmp", {list: list});
  432. $(".quick-reply-panel ul").empty().append(html);
  433. $(".quick-reply-panel").toggle("show");
  434. }
  435. }
  436. function getQuickReplayList(){
  437. consultingAPI.getReplyList({type: 1}).then(function(res){
  438. if(res.status == 200){
  439. count ++;
  440. formatReplyList(res.data);
  441. //渲染前4条记录
  442. var list = quickReplyList.slice(0, 4),
  443. html = template("quick_reply_tmp", {list: list});
  444. $(".quick-reply-panel ul").empty().append(html);
  445. //判断问卷是否填写
  446. getFollowupContentList();
  447. }else{
  448. showErrorMsg(res.msg);
  449. }
  450. })
  451. }
  452. function formatReplyList(data){
  453. quickReplyList = _.map(data, function(o){
  454. //"systag":0为医生自定义消息,大于0的为系统该消息,1体征生活方式 2症状 3血糖 4血压
  455. if(o.systag == 1 || o.systag == 2){
  456. o.name = "survey"; //问卷
  457. }else if(o.systag == 3 || o.systag == 4){
  458. o.name = "test"; //体检
  459. }else{
  460. o.name = "";
  461. }
  462. if(o.systag == 1 || o.systag == 3){
  463. o.tagType = 2;
  464. }else if(o.systag == 2 || o.systag == 4){
  465. o.tagType = 1;
  466. }else{
  467. o.tagType = 0;
  468. }
  469. return o;
  470. });
  471. }
  472. //获得问卷列表,判断个问卷是否已经填写
  473. function getFollowupContentList(){
  474. var params = {
  475. prescriptioncode: prescriptionCode
  476. };
  477. consultingAPI.getFollowupCountList(params).then(function(res){
  478. if(res.status == 200){
  479. //'type': '1',//1身份异常症状问卷,2体征及生活方式调查问卷
  480. // 'statue': '1',//1已填写,2未填写
  481. var len = res.data.length;
  482. for(i=0; i<len; i++){
  483. var item = res.data[i];
  484. if(item.type == '1'){
  485. survey_1_obj = item;
  486. }
  487. if(item.type == '2'){
  488. survey_2_obj = item;
  489. }
  490. }
  491. }else{
  492. showErrorMsg(res.msg);
  493. }
  494. })
  495. }
  496. function bindReplyEvents(){
  497. $("body").on('click', ".reply-item", function(){
  498. var $this = $(this),
  499. json = $this.data("json"),
  500. name = json.name,
  501. type = json.tagType;
  502. var params = {
  503. prescriptionCode: prescriptionCode,
  504. type: type,
  505. followupid: fv_id
  506. };
  507. if(name == "test"){ //发送血糖血压快捷回复咨询
  508. consultingAPI.addPrescriptionBloodStatusConsult(params).then(function(res){
  509. if(res.status == 200){
  510. $(".quick-reply-panel").hide();
  511. layer.close(layer.index);
  512. //发送成功后,socket会响应退出最新的消息
  513. }else{
  514. showErrorMsg(res.msg);
  515. }
  516. })
  517. }else if(name == "survey"){//发送问卷快捷回复咨询
  518. //判断是否已经填写过问卷
  519. if(type == '1' && survey_1_obj.statue == '1'){
  520. var content = "居民"+patiName+"已在"+survey_1_obj.createtime+"填写"+survey_1_obj.name;
  521. layer.open({
  522. title: " ",
  523. content: content,
  524. skin: 'alert-info',
  525. btn: ['查看问卷'],
  526. yes: function(index){
  527. parent.gotoPrescriptionTab(8);
  528. layer.close(index);
  529. }
  530. });
  531. return false;
  532. }
  533. if(type == '2' && survey_2_obj.statue == '1'){
  534. var content = "居民"+patiName+"已在<br/>"+survey_2_obj.createtime+"填写"+survey_2_obj.name;
  535. layer.open({
  536. title: " ",
  537. content: content,
  538. skin: 'alert-info',
  539. btn: ['查看问卷'],
  540. yes: function(index){
  541. parent.gotoPrescriptionTab(8);
  542. layer.close(index);
  543. }
  544. });
  545. return false;
  546. }
  547. consultingAPI.addPrescriptionFollowupContentConsult(params).then(function(res){
  548. if(res.status == 200){
  549. layer.close(layer.index);
  550. $(".quick-reply-panel").hide();
  551. //发送成功后,socket会响应退出最新的消息
  552. }else{
  553. showErrorMsg(res.msg);
  554. }
  555. })
  556. }else{
  557. //发送普通文本
  558. sendMessage(1, json.content);
  559. var obj = {
  560. content: json.content,
  561. content_type: '1',
  562. sender_id: docInfo.code,
  563. timestamp: new Date().getTime()
  564. }
  565. var html = formatMsg(obj);
  566. $("#talkBox").append(html);
  567. $("#talkBox").slimscroll({
  568. scrollTo: 'bottom'
  569. });
  570. layer.close(layer.index);
  571. $(".quick-reply-panel").hide();
  572. }
  573. });
  574. $("body").on("click", '.addMore', function(){
  575. showReplyListPanel();
  576. $(".quick-reply-panel").hide();
  577. })
  578. template.helper("getJsonStr", function(obj){
  579. if(typeof obj == "object"){
  580. return JSON.stringify(obj);
  581. }else{
  582. return "";
  583. }
  584. });
  585. $("body").on("click", ".del-icon", function(e){
  586. e.stopPropagation();
  587. var $this = $(this),
  588. $parent = $this.closest(".reply-item"),
  589. json = $parent.data("json"),
  590. systag = json.systag;
  591. if(systag > 0){
  592. layer.msg('系统默认回复内容不可删除');
  593. }else{
  594. //删除快捷回复
  595. consultingAPI.deleteQuickReply({id: json.id}).then(function(res){
  596. if(res.status == 200){
  597. showSuccessMsg(res.msg);
  598. $parent.remove();
  599. //将quickReplyList数组中对应的元素删除
  600. for(i=0; i< quickReplyList.length; i++){
  601. var item = quickReplyList[i];
  602. if(item.id == json.id){
  603. quickReplyList.splice(i, 1);
  604. break;
  605. }
  606. }
  607. }else{
  608. showErrorMsg(res.msg);
  609. }
  610. });
  611. }
  612. });
  613. $("body").on('click', '.up-icon', function(e){
  614. e.stopPropagation();
  615. var li = this.parentNode.parentNode;
  616. if(li.previousElementSibling){
  617. swapNode(li,li.previousElementSibling);
  618. }
  619. });
  620. $("body").on('click', '.down-icon', function(e){
  621. e.stopPropagation();
  622. //通过链接对象获取表格行的引用
  623. var li = this.parentNode.parentNode;
  624. //如果不是最后一行,则与下一行交换顺序
  625. if(li.nextElementSibling){
  626. swapNode(li,li.nextElementSibling);
  627. }
  628. })
  629. }
  630. function showReplyListPanel(){
  631. //准备content html 内容
  632. var html = template('reply_tmp', {list: quickReplyList});
  633. layer.open({
  634. type: "1",
  635. title: '<img src="img/shezi_tankuang_icon.png" class="mr10">快捷回复设置',
  636. content: html,
  637. area: ['430px', '360px'],
  638. skin: 'quick-reply-setting',
  639. btn: ['添加', '取消'],
  640. yes: function(index){
  641. var html2 = '<div class="pl30 pr20"><p>回复内容:</p><textarea style="margin:0px; width: 100%; height: 80px;" maxlength="100" id="reply_content"></textarea></div>';
  642. layer.open({
  643. type: "1",
  644. title: '<img src="img/shezi_tankuang_icon.png" class="mr10">添加自动回复',
  645. content: html2,
  646. area: ['420px', '227px'],
  647. skin: 'quick-reply-setting',
  648. btn: ['确定', '取消'],
  649. yes: function(index2){
  650. var text = $.trim($("#reply_content").val());
  651. saveNewReply(text, index2);
  652. }
  653. });
  654. }
  655. });
  656. }
  657. //定义通用的函数交换两个结点显示的内容,不移动DOM
  658. function swapNode(node1,node2){
  659. //获取两个节点的json数据和content数据
  660. var json1 = $(node1).attr("data-json"),
  661. content1 = $(node1).find(".content").text(),
  662. id1 = $(node1).data("id"),
  663. json2 = $(node2).attr("data-json"),
  664. content2 = $(node2).find(".content").text(),
  665. id2 = $(node2).data("id");
  666. $(node1).attr("data-json", json2);
  667. //data修改和attr修改不一致
  668. $(node1).data("id", id2);
  669. $(node1).attr("data-id", id2);
  670. $(node1).find(".content").text(content2);
  671. $(node2).attr("data-json", json1);
  672. $(node2).data("id", id1);
  673. $(node2).attr("data-id", id1);
  674. $(node2).find(".content").text(content1);
  675. //请求排序接口
  676. sortQuickReply();
  677. }
  678. function sortQuickReply(){
  679. var $lis = $(".reply-list2 li"),
  680. len = $lis.length,
  681. ids = [];
  682. for(i=0; i<len; i++){
  683. var $li = $($lis[i]),
  684. id = $li.data("id");
  685. ids.push(id);
  686. }
  687. //重新排序
  688. var params = {
  689. id: ids.join(","),
  690. type: 1 //"type":1,//快捷回复类型(1为续方咨询,0为健康咨询)
  691. };
  692. consultingAPI.sortList(params).then(function(res){
  693. consultingAPI.getReplyList({type: 1}).then(function(res){
  694. if(res.status == 200){
  695. formatReplyList(res.data);
  696. }
  697. })
  698. })
  699. }
  700. function saveNewReply(text, layerIndex){
  701. var params = {
  702. content: text,
  703. type: 1
  704. }
  705. consultingAPI.addQuickReply(params).then(function(res){
  706. if(res.status == 200){
  707. showSuccessMsg("保存成功");
  708. consultingAPI.getReplyList({type: 1}).then(function(res){
  709. if(res.status == 200){
  710. formatReplyList(res.data);
  711. //重新渲染列表
  712. var html = template('reply_tmp', {list: quickReplyList});
  713. var preLayerIndex = layerIndex - 1;
  714. $("#layui-layer"+preLayerIndex).find(".layui-layer-content").empty().append(html);
  715. layer.close(layerIndex);
  716. }
  717. })
  718. }else{
  719. showErrorMsg(res.msg);
  720. }
  721. });
  722. }