prescription-consulting.js 25 KB

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