prescription-consulting.js 25 KB

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