bianjituanduimuban.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. var action,
  2. code ,
  3. reference, //标记入口
  4. patiCode,
  5. teamList,
  6. teamId,
  7. docInfo,
  8. tName,
  9. tId,
  10. signCode,
  11. is_sys = false,
  12. content_details,
  13. uploadImages = [],
  14. imMsg = '',
  15. imgUrls = [],
  16. teams= '',
  17. lableCode ='',
  18. spanlabel = '',
  19. spanCode = null;
  20. var $text_count = $("#text_count"),
  21. text_count = 0,
  22. $img_count = $("#img_count"),
  23. img_count = 0,
  24. $view_btn = $("#view_btn"),
  25. $teamDown = $('.team-down'),
  26. $comtop = $('.demo-comtop'),
  27. $linMask = $('.lin-mask'),
  28. $linSelGroup = $('.lin-sel-group'),
  29. $action_btn = $("#action_btn")
  30. $inTeams = $("#inTeams"),
  31. $teamNameCon = $('.team-name-con');
  32. mui.init({
  33. gestureConfig:{
  34. tap: true,
  35. doubletap: false,
  36. longtap: true
  37. }
  38. });
  39. mui.plusReady(function(){
  40. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  41. var self = plus.webview.currentWebview();
  42. action = self.action;
  43. reference = self.reference;
  44. imMsg = self.msg;
  45. code = self.code;
  46. teamList = self.teamList;
  47. patiCode = self.patiCode;
  48. teamId = self.teamId;
  49. tName = self.tName;
  50. tId = self.tId;
  51. labelCode = self.groupLabel;
  52. labelName = self.groupName;
  53. signCode = self.sign;
  54. console.log(signCode);
  55. content_details = self.content_details;
  56. if (imMsg) {
  57. $("textarea").val(imMsg);
  58. }
  59. var title = (action == "add") ? "新增" : "编辑";
  60. $("#title").text(title);
  61. var action_text = "";
  62. if(reference != "mine"){
  63. getTeams();
  64. if (docInfo.isLeader!=1) {
  65. $(".mui-switch").removeClass("mui-active");
  66. $('#guideLable').hide();
  67. }
  68. var text = "是否保存为您的模板";
  69. $("#save_as_self").find(".c-list-key").text(text);
  70. $("#save_as_self").show();
  71. $('#lableChoice').html(labelName);
  72. action_text = "发送";
  73. }else{
  74. $('#lableChoice').html(labelName);
  75. getTeams();
  76. if(action == "add"){
  77. plus.nativeUI.showWaiting();
  78. action_text = "新增";
  79. }else{
  80. action_text = "保存";
  81. }
  82. }
  83. $action_btn.text(action_text);
  84. getDetail();
  85. bindEvents();
  86. });
  87. //获取团队
  88. function getTeams () {
  89. sendGet( 'doctor/team/guidance/findDoctorLeaderTeam', {}, null, function(res){
  90. if(res.status == 200){
  91. var d = [],
  92. html = '';
  93. if (teamList) {
  94. d = teamList;
  95. teams = JSON.stringify(d);
  96. } else {
  97. // d = res.teamList;
  98. // teams = JSON.stringify(res.teamList);
  99. teams = JSON.stringify([{
  100. teamName: tName,
  101. teamId: tId
  102. }]);
  103. }
  104. for (var i = 0, len = d.length; i < len; i++) {
  105. html += d[i].teamName + ',';
  106. }
  107. if (action == 'add') {
  108. html = tName;
  109. } else {
  110. html = html.substring( 0, html.length - 1);
  111. }
  112. $teamNameCon.html(html);
  113. template.helper( 'checkData', function (v) {
  114. if (teamList) {
  115. for (var i = 0,len = teamList.length; i < len; i++) {
  116. if (v == teamList[i].teamId) {
  117. return 'selected';
  118. }
  119. }
  120. } else {
  121. if (v == tId) {
  122. return 'selected';
  123. }
  124. // return 'selected';
  125. }
  126. });
  127. $('#demo').html(template( 'seleceTmp', {list: res.teamList}));
  128. $('#demo').mobiscroll().select({
  129. theme: 'ios',
  130. display: 'bottom',
  131. lang: 'zh',
  132. onSelect: function ( valueText, inst) {
  133. var vArr = valueText.split(','),
  134. idArr = inst._tempValue,
  135. t = [];
  136. for (var i = 0; i < idArr.length; i++) {
  137. t.push({
  138. teamName: vArr[i].trim(),
  139. teamId: parseInt(idArr[i])
  140. })
  141. }
  142. teams = JSON.stringify(t);
  143. $teamNameCon.html(inst._value);
  144. }
  145. });
  146. } else {
  147. mui.toast(res.msg);
  148. }
  149. plus.nativeUI.closeWaiting();
  150. }, 'GET', '', true);
  151. }
  152. function getDetail(){
  153. if(content_details){
  154. $("#temp_name").val(content_details.title);
  155. $("textarea").val(content_details.content);
  156. $("#text_count").text(content_details.content.length);
  157. imgUrls = content_details.imagesUrl;
  158. if(imgUrls){ //填充模板中图片
  159. for(i=0; i<imgUrls.length; i++){
  160. fillImage(getImgUrl(imgUrls[i]));
  161. }
  162. }else{
  163. imgUrls = [];
  164. }
  165. }
  166. }
  167. function getPhoto(url){
  168. uploadImages.push(url);
  169. fillImage(url);
  170. }
  171. function fillImage(url){
  172. img_count ++;
  173. $img_count.text(img_count);
  174. var html = '<div class="c-position-r fl mr15 mt20"><img class="upload_img" src="'+url+'" width="65" height="65">'+
  175. '<div class="delete-icon"><img src="../images/delete_icon.png" width="18"></div></div>';
  176. $("#img_wrap").append(html);
  177. }
  178. //上传图片
  179. var upload_count = 0;
  180. function uploadImg(cb){
  181. var len = uploadImages.length;
  182. if(upload_count < len){
  183. var task = plus.uploader.createUpload(server + "/upload/fastDFSImag", {
  184. method: "post"
  185. }, function(t, sta) {
  186. if(sta == 200) {
  187. var msg = t.responseText;
  188. var oImg = JSON.parse(msg);
  189. // var imgUrl = oImg.urls;
  190. // var re = new RegExp("\\\\", "g");
  191. // imgUrl = imgUrl.replace(re, "/");
  192. // imgUrls.push(imgUrl);
  193. // uploadImg(cb);
  194. if(oImg.status == 200){
  195. imgUrls.push(oImg.data);
  196. upload_count ++;
  197. uploadImg(cb);
  198. }else{
  199. mui.toast("上传图片失败!");
  200. plus.nativeUI.closeWaiting();
  201. }
  202. // setTimeout(function () {
  203. // uploadImg(cb);
  204. // },300);
  205. } else {
  206. mui.toast("上传图片失败!");
  207. plus.nativeUI.closeWaiting();
  208. }
  209. });
  210. var url = uploadImages[upload_count];
  211. // upload_count ++;
  212. task.addFile(url, {key: "file"});
  213. task.start();
  214. }else{
  215. cb();
  216. }
  217. }
  218. function showGroupSel (e, isShow) {
  219. isShow = isShow || $('.lin-mask:hidden').length != 0;
  220. $linMask.toggle(isShow);
  221. $linSelGroup.toggle(isShow);
  222. }
  223. function guidanceLabel(){
  224. //先判断是否选择了团队
  225. if($teamNameCon.html()==""){
  226. mui.toast("请先选择团队");
  227. return
  228. }else{
  229. //跳转指导标签页面
  230. mui.openWindow({
  231. url:'zhidaobiaoqian.html',
  232. id:'zhidaobiaoqian',
  233. extras:{
  234. groupLabel:labelCode,
  235. groupName:labelName
  236. }
  237. })
  238. }
  239. }
  240. function bindEvents(){
  241. //团队选择
  242. $inTeams.on('click', function (){
  243. $('#demo').trigger('click');
  244. });
  245. $linMask.on( 'tap', function (e) {
  246. showGroupSel(e);
  247. var lis = $linSelGroup.find('[class=checked]'),
  248. ts = [],
  249. html = "";
  250. $.each( lis, function () {
  251. ts.push({
  252. teamName: $(this).attr('data-name'),
  253. teamId: $(this).attr('data-id')
  254. });
  255. html += '<span>' + $(this).attr('data-name') + '</span>';
  256. });
  257. $teamNameCon.html(html);
  258. teams = JSON.stringify(ts);
  259. });
  260. $linSelGroup.on('tap', 'li', function(){
  261. if ($(this).hasClass('checked')) {
  262. $(this).removeClass('checked');
  263. } else {
  264. $(this).addClass('checked');
  265. }
  266. });
  267. //指导标签页面
  268. $('#guideLable').on("tap", guidanceLabel);
  269. $(".mui-switch").on('tap',function(){
  270. var $this = $(this);
  271. if (docInfo.isLeader!=1) {
  272. $(".mui-switch").removeClass("mui-active");
  273. $this.find('.mui-switch-handle').removeAttr('style');
  274. return
  275. }
  276. if($this.hasClass('mui-active')){
  277. $('#guideLable').show();
  278. }else{
  279. $('#guideLable').hide();
  280. }
  281. })
  282. $("#add").on('click', function(){
  283. if(img_count < 9){
  284. var num = 9 - img_count;
  285. getAutoRecCompressImageLocalPath( getPhoto, num);
  286. }else{
  287. dialog({
  288. contentType: 'tipsbox',
  289. skin: 'bk-popup',
  290. content: '最多只能上传9张图片',
  291. closeTime: 2000
  292. }).showModal();
  293. }
  294. });
  295. //图片删除功能
  296. $(document).on('tap', '.delete-icon', function(){
  297. var $this = $(this);
  298. //获得图片路径
  299. var url = $this.parent().find(".upload_img").attr("src");
  300. for(var i=0; i<imgUrls.length; i++) {
  301. if(url.indexOf(imgUrls[i]) > -1) {
  302. imgUrls.splice(i, 1);
  303. break;
  304. }
  305. }
  306. for(var j=0; j<uploadImages.length; j++){
  307. if(uploadImages[j] == url){
  308. uploadImages.splice(j, 1);
  309. break;
  310. }
  311. }
  312. img_count --;
  313. $img_count.text(img_count);
  314. $this.parent().remove();
  315. });
  316. //文本框
  317. $("textarea").on('keyup', function(){
  318. var count = $(this).val().length;
  319. $text_count.text(count);
  320. });
  321. $("textarea").on('change', function(){
  322. var count = $(this).val().length;
  323. $text_count.text(count);
  324. });
  325. //预览功能
  326. $view_btn.on('tap', function(){
  327. var content = $("textarea").val(),
  328. $images_list = $(".upload_img"),
  329. images = [],
  330. tArr = JSON.parse(teams);
  331. for(i=0; i<img_count; i++){
  332. var item = $images_list[i];
  333. images.push($(item).attr("src"));
  334. }
  335. if(tArr.length == 0 || !tArr[0].teamId){
  336. dialog({
  337. contentType: 'tipsbox',
  338. skin: 'bk-popup',
  339. content: '请选择所属团队!',
  340. closeTime: 2000
  341. }).showModal();
  342. return false;
  343. }
  344. if(content.length == 0){
  345. dialog({
  346. contentType: 'tipsbox',
  347. skin: 'bk-popup',
  348. content: '请填先写模板内容!',
  349. closeTime: 2000
  350. }).showModal();
  351. return false;
  352. }
  353. openWebview("yulantuanduimuban.html",{
  354. teams: teams,
  355. code: code,
  356. detail:{content: content, images: images, imgUrls: imgUrls, uploadImages: uploadImages, title: $("#temp_name").val()},
  357. reference: reference,
  358. patiCode: patiCode,
  359. checked: $(".mui-switch").hasClass("mui-active"),
  360. teamId: teamId
  361. });
  362. });
  363. // $(".mui-switch").on( 'tap', function () {
  364. // if ($(this).hasClass("mui-active")) {
  365. // $('#mbName').show();
  366. // } else {
  367. // $('#mbName').hide();
  368. // }
  369. // });
  370. //action 按钮
  371. $action_btn.on('tap', function(){
  372. var content = $.trim($("textarea").val()),
  373. tArr = JSON.parse(teams);
  374. var title = $.trim($("#temp_name").val());
  375. var label = $.trim(spanlabel)||$('#lableChoice').html();
  376. var checked = $(".mui-switch").hasClass("mui-active");
  377. if(checked && title.length == 0){
  378. dialog({
  379. contentType: 'tipsbox',
  380. skin: 'bk-popup',
  381. content: '模板名称不能为空!',
  382. closeTime: 2000
  383. }).showModal();
  384. return false;
  385. }
  386. if(checked && label.length == 0){
  387. dialog({
  388. contentType: 'tipsbox',
  389. skin: 'bk-popup',
  390. content: '指导标签不能为空!',
  391. closeTime: 2000
  392. }).showModal();
  393. return false;
  394. }
  395. if(content.length == 0){
  396. dialog({
  397. contentType: 'tipsbox',
  398. skin: 'bk-popup',
  399. content: '指导内容不能为空!',
  400. closeTime: 2000
  401. }).showModal();
  402. return false;
  403. }
  404. if(tArr.length == 0 || !tArr[0].teamId){
  405. dialog({
  406. contentType: 'tipsbox',
  407. skin: 'bk-popup',
  408. content: '请选择所属团队!',
  409. closeTime: 2000
  410. }).showModal();
  411. return false;
  412. }
  413. //IM入口
  414. var url = "";
  415. var params = {
  416. content: $("textarea").val(),
  417. title: $("#temp_name").val()
  418. };
  419. if(reference != "mine"){
  420. dialog({
  421. content: "发出后无法变更,是否确认发送给居民?",
  422. okValue: "继续发送",
  423. ok: function(){
  424. plus.nativeUI.showWaiting();
  425. //先将新增的图片上传然后再处理其他业务
  426. uploadImg(function(){
  427. params.images = imgUrls?imgUrls.join(","):"";
  428. params.teamInfo = teams;
  429. params.isLeader = docInfo.isLeader;
  430. if(spanCode){
  431. params.labelCode = spanCode;
  432. }
  433. if(checked){
  434. //先将内容保存为自己模板
  435. params.saveAsGuidance = 1;
  436. } else {
  437. params.saveAsGuidance = 0;
  438. }
  439. if(action == "add"){
  440. url = "doctor/team/guidance/saveTeamGuidance";
  441. }else{
  442. //编辑
  443. url = "doctor/team/guidance/modifyTeamGuidance";
  444. params.guidanceCode = code;
  445. params.isLeader = docInfo.isLeader;
  446. if(spanCode){
  447. params.labelCode = spanCode;
  448. }
  449. }
  450. var reqInfo = [];
  451. if(checked){
  452. reqInfo.push({url: url, data: params, reqType: 'POST'});
  453. }
  454. //团队模板发送时只和医生点击哪个团队中的模板有关,指导绑定的另外的团队没有关系
  455. var list = JSON.parse(teams);
  456. var chooseTeam = _.find(list, {teamId: parseInt(tId)}),
  457. arr = [];
  458. if(chooseTeam){
  459. arr.push(chooseTeam);
  460. }else{
  461. //匹配不了说明医生修改了指导所属的 团队,并且入口团队并不在选中的列表中。则默认选择选中团队中的第一个团队来发送
  462. arr.push(list[0]);
  463. }
  464. reqInfo.push({
  465. url: "doctor/team/guidance/sendTeamGuidance",
  466. data: {
  467. patient: patiCode,
  468. content: $("textarea").val(),
  469. guidanceCode: code || "",
  470. images: imgUrls?imgUrls.join(","):"",
  471. // teamId: teamId
  472. tzCode : signCode||"",
  473. teamId: JSON.stringify(arr)
  474. }
  475. });
  476. if(reqInfo.length == 1) {
  477. return getReqPromises(reqInfo, true).then(function(res) {
  478. if(res[0].status == 200){
  479. mui.toast("发送成功");
  480. otherBackAction();
  481. } else {
  482. mui.toast("发送失败请重试 !");
  483. }
  484. plus.nativeUI.closeWaiting();
  485. })
  486. }else{
  487. return getReqPromise(reqInfo[0].url, reqInfo[0].data, "POST", true).then(function(res) {
  488. if(res.status == 200) {
  489. reqInfo[1].data.guidanceCode = res.guidanceCode;
  490. getReqPromise(reqInfo[1].url, reqInfo[1].data, "POST", true).then(function(res1) {
  491. if(res1.status == 200) {
  492. mui.toast("发送成功!");
  493. otherBackAction();
  494. } else {
  495. mui.toast( "保存成功,发送失败!")
  496. }
  497. })
  498. } else {
  499. mui.toast(res.msg || "保存失败无法发送!")
  500. }
  501. plus.nativeUI.closeWaiting();
  502. })
  503. }
  504. });
  505. },
  506. cancelValue : "不了,谢谢",
  507. cancel: function(){}
  508. }).showModal();
  509. }else{ //“我的”入口
  510. //先将新增的图片上传然后再处理其他业务
  511. plus.nativeUI.showWaiting();
  512. uploadImg(function(){
  513. params.images = imgUrls ? imgUrls.join(","): "";
  514. params.teamInfo = teams;
  515. if(spanCode){
  516. params.labelCode = spanCode;
  517. }
  518. if((action == "add") || is_sys){
  519. //新增模板或将系统模板保存为自己的
  520. url = "doctor/team/guidance/saveTeamGuidance";
  521. }else{
  522. params.saveAsGuidance = 0;
  523. params.guidanceCode = code;
  524. params.isLeader = docInfo.isLeader;
  525. if(spanCode){
  526. params.labelCode = spanCode;
  527. }
  528. //编辑
  529. url = "doctor/team/guidance/modifyTeamGuidance";
  530. }
  531. sendPost(url, params, null, function(res){
  532. if(res.status == 200){
  533. mineBackAction();
  534. }
  535. mui.toast(res.msg);
  536. plus.nativeUI.closeWaiting();
  537. }, 'POST', '', true);
  538. });
  539. }
  540. });
  541. }
  542. function otherBackAction(){
  543. var self = plus.webview.currentWebview(),
  544. opener = self.opener(),
  545. grant_opener = opener.opener();
  546. if(opener.id == "jkzd" || opener.id == "guidance_list"){ //新增
  547. if(grant_opener.id == "guidance_info"){
  548. //im->info->list->add
  549. var pre_opener = grant_opener.opener();
  550. mui.fire(pre_opener, "update");
  551. pre_opener.show();
  552. mui.later(function(){
  553. grant_opener.close();
  554. opener.close();
  555. self.close();
  556. }, 300);
  557. }else{
  558. //IM/huanzhexinxi->新增页面
  559. mui.fire(grant_opener, "update");
  560. grant_opener.show();
  561. mui.later(function(){
  562. opener.close();
  563. self.close();
  564. }, 300);
  565. }
  566. }else if(grant_opener.id == "jkzd" || grant_opener.id == "guidance_list"){ //详情 -> 编辑
  567. var pre_opener = grant_opener.opener();
  568. if(pre_opener.id == "guidance_info"){
  569. //im/huanzhexinxi -> info->list->detail->edit
  570. mui.fire(pre_opener.opener(), "update");
  571. pre_opener.opener().show();
  572. mui.later(function(){
  573. opener.close();
  574. grant_opener.close();
  575. pre_opener.close();
  576. self.close();
  577. }, 300);
  578. }else{
  579. //IM/huanzhexinxi->list->detail->edit
  580. mui.fire(pre_opener, "update");
  581. pre_opener.show();
  582. mui.later(function(){
  583. opener.close();
  584. grant_opener.close();
  585. self.close();
  586. }, 300);
  587. }
  588. }else{ //sys->detail->edit
  589. var pre_opener = grant_opener.opener(),
  590. pre_pre_opener = pre_opener.opener();
  591. if(pre_pre_opener.id == "guidance_info"){
  592. //IM/huanzhexinxi->info->list->sys->detail->edit
  593. mui.fire(pre_pre_opener.opener(), "update");
  594. pre_pre_opener.opener().show();
  595. mui.later(function(){
  596. pre_pre_opener.close();
  597. pre_opener.close();
  598. grant_opener.close();
  599. opener.close();
  600. self.close();
  601. }, 300);
  602. }else{
  603. //IM/huanzhexinxi->list->sys->detail->edit
  604. // var entrance = grant_opener.opener().opener();
  605. mui.fire(pre_pre_opener, "update");
  606. pre_pre_opener.show();
  607. mui.later(function(){
  608. pre_opener.close();
  609. grant_opener.close();
  610. opener.close();
  611. self.close();
  612. }, 300);
  613. }
  614. }
  615. }
  616. function mineBackAction(){
  617. var self = plus.webview.currentWebview(),
  618. opener = self.opener(),
  619. pre_opener = opener.opener();
  620. if(opener.id == "guidance_list"){ //mine->add
  621. mui.fire(opener, 'refresh');
  622. // opener.reload(true);
  623. self.close();
  624. mui.back();
  625. } else if(opener.id == "chakantuanduimuban"){
  626. mui.fire(pre_opener, "refresh");
  627. // pre_opener.reload(true);
  628. mui.later(function(){
  629. opener.close();
  630. self.close();
  631. }, 300);
  632. pre_opener.show();
  633. } else if (opener.id == 'p2dzixun' || opener.id == 'p2p') {
  634. mui.fire(pre_opener, "refresh");
  635. mui.later(function(){
  636. self.close();
  637. }, 300);
  638. opener.show();
  639. }else{ //mine->sys->detail->edit
  640. var pre_pre_opener = pre_opener.opener();
  641. mui.fire(pre_pre_opener, "refresh");
  642. mui.later(function(){
  643. pre_opener.close();
  644. opener.close();
  645. self.close();
  646. }, 300);
  647. pre_pre_opener.show();
  648. }
  649. }
  650. //监听指导标签
  651. window.addEventListener('listernLable',function(e){
  652. $('#lableChoice').html(e.detail.labelName);
  653. spanCode = e.detail.lablecode;
  654. spanlabel = e.detail.labelName;
  655. })