add_plan.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. //var plus = null;
  3. // 基本信息(包括userAgent)
  4. var baseInfo = null,
  5. // 基础环境信息(包括当前webview、encry相关)
  6. baseEnv = null,
  7. docInfo = null,
  8. patientInfo = null,
  9. choose_date = "",
  10. team_msg = "",
  11. docList = null; //记录改患者可选的随访医生列表
  12. var currentNum=1;//当前选择下的记录
  13. //下拉弹框的数据
  14. var type_keys = [],
  15. type_vals = [],
  16. doc_keys = [],
  17. doc_vals = [];
  18. var defaultDoc = {};
  19. // 获取登录相关信息
  20. var getBaseInfo = function() {
  21. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  22. patientInfo = baseEnv.webview.patientInfo;
  23. choose_date = baseEnv.webview.chooseDate;
  24. if(choose_date){
  25. var now = new Date()
  26. var minute = now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes();
  27. var hour = now.getHours()<10?'0'+now.getHours():now.getHours();
  28. choose_date = choose_date+' '+hour+':'+minute;
  29. }
  30. // 登录的相关信息
  31. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  32. return {
  33. userAgent: userAgent
  34. }
  35. },
  36. // 获取基础环境信息
  37. getBaseEnvPromise = function () {
  38. var env = {
  39. webview: plus.webview.currentWebview()
  40. };
  41. // 因为有异步请求,需要等待数据返回之后进行处理,所以返回Promise
  42. return Promise.resolve().then(function(res) {
  43. return env;
  44. });
  45. },
  46. //初始化页面内容
  47. initPage = function(){
  48. $(".plan_doctor").attr("data-id", docInfo.code);
  49. $(".plan_doctor").text(docInfo.name);
  50. $(".plan_date").val(choose_date || "");
  51. //请求居民信息
  52. sendGet('doctor/patient/info',{patient:patientInfo.code},function(){
  53. mui.toast('请求失败')
  54. }, function(res){
  55. if(res.status == 200){
  56. var html = template('people_msg',{data:res.data})
  57. $('#ul_main').html(html)
  58. }else{
  59. mui.toast('获取居民信息失败')
  60. }
  61. })
  62. doctorLevel();//随访方式
  63. getDoctorList();
  64. },
  65. //获得随访医生的列表
  66. getDoctorList = function(){
  67. plus.nativeUI.showWaiting();
  68. var url = "/doctor/patient_group/sign_doctors",
  69. params = {patient: patientInfo.code};
  70. sendPost(url, params, null, function(res){
  71. if(res.data.list.length > 0){
  72. team_msg = res.data.list;
  73. for(var i = 0; i<res.data.list.length; i++){
  74. var item = res.data.list[i];
  75. doc_keys.push(item.code);
  76. doc_vals.push(item.name);
  77. if(item.code == docInfo.code){
  78. defaultDoc.keys=item.code;
  79. defaultDoc.values = item.name;
  80. }
  81. }
  82. }else{
  83. doc_keys.push(docInfo.code);
  84. doc_vals.push(docInfo.name);
  85. }
  86. // getFollowWay();
  87. initialize_select();
  88. plus.nativeUI.closeWaiting();
  89. },'GET');
  90. },
  91. //获得随访方式下拉数据
  92. //getFollowWay = function(){
  93. // var url = "common/getDictByDictName",
  94. // params = {name:'FOLLOWUP_WAY_DICT'};
  95. // sendPost(url,params, null, function(res){
  96. // if(res.list.length > 0){
  97. // for(var i=0; i< res.list.length; i++){
  98. // var item = res.list[i];
  99. // if(item.value == '电话'){
  100. // if(patientInfo.mobile){
  101. // type_keys.push(item.code);
  102. // type_vals.push(item.value);
  103. // }
  104. // }else{
  105. // type_keys.push(item.code);
  106. // type_vals.push(item.value);
  107. // }
  108. // }
  109. // }
  110. // initialize_select();
  111. // plus.nativeUI.closeWaiting();
  112. // },'GET');
  113. //},
  114. setDefaultSelect = function() {
  115. // 获取健康管理师下拉框mibiscroll实例
  116. // var doctorMobiscroll = $('[data-val=doctor]').mobiscroll('getInst');
  117. var valueText = "{keys:'"+defaultDoc.keys+"',values:'"+defaultDoc.values+"'}";
  118. doctorMobiscroll.setVal([valueText]);
  119. },
  120. //初始化下拉框的数据
  121. initialize_select = function(){
  122. //随访日期选择
  123. $('[data-val=date]').mobiscroll({
  124. preset: 'datetime',
  125. theme: 'ios',
  126. lang: 'zh',
  127. dateFormat: 'yy-mm-dd',
  128. timeFormat: 'HH:ii',
  129. showLabel: true,
  130. minDate: new Date()
  131. });
  132. //随访方式选择
  133. // $('[data-val=way]').mobiscroll({
  134. // theme: 'ios',
  135. // lang: 'zh',
  136. // customWheels: true,
  137. // wheels: [
  138. // [{
  139. // keys: type_keys,
  140. // values: type_vals
  141. // }]
  142. // ],
  143. // onSelect: function(valueText, inst) {
  144. // var dd = eval("[" + valueText + "]");
  145. // $(this).val(dd[0].values);
  146. // $(this).attr('data-id',dd[0].keys);
  147. // }
  148. // });
  149. //随访医生选择
  150. // $('[data-val=doctor]').mobiscroll({
  151. // theme: 'ios',
  152. // lang: 'zh',
  153. // customWheels: true,
  154. // wheels: [
  155. // [{
  156. // keys: doc_keys,
  157. // values: doc_vals
  158. // }]
  159. // ],
  160. // onSelect: function(valueText, inst) {
  161. // var dd = eval("[" + valueText + "]");
  162. // var $this = $(this)
  163. // $this.text(dd[0].values);
  164. // $this.attr('data-id',dd[0].keys);
  165. // //随访方式写死team_msg
  166. // $.map(team_msg,function(o,i){
  167. // if(dd[0].keys == o.code){
  168. // if(o.typename == "全科医生"){
  169. // $this.closest('ul.c-list').find(".plan_type").html('家庭(全科)')
  170. // $this.closest('ul.c-list').find(".plan_type").attr('data-id',22)
  171. // }
  172. // if(o.typename == "健康管理师"){
  173. // $this.closest('ul.c-list').find(".plan_type").html('健管师随访')
  174. // $this.closest('ul.c-list').find(".plan_type").attr('data-id',10)
  175. // }
  176. // if(o.typename == "专科医生"){
  177. // $this.closest('ul.c-list').find(".plan_type").html('专科医生随访')
  178. // $this.closest('ul.c-list').find(".plan_type").attr('data-id',13)
  179. // }
  180. // }
  181. // })
  182. // }
  183. // });
  184. // setDefaultSelect(); //设置默认医生选中
  185. },
  186. reflashBindEvent=function(){
  187. $(".plan_type").unbind("click")
  188. $(".mui-table-view-cell1").unbind("click")
  189. $(".plan_type").bind('click',function(){
  190. currentNum=$(this).parents(".scsf-item").data("num") || $(this).parents(".append_plan").data("num");
  191. mui('#sheet1').popover('toggle');
  192. })
  193. $(".mui-table-view-cell1").bind('click',function(){
  194. var _text=$(this).find('a').text();
  195. console.log(_text)
  196. if(_text=='电话随访'){
  197. if(patientInfo.mobile){
  198. mui.toast('该居民未留下电话号码无法进行电话随访');
  199. return ;
  200. }
  201. }
  202. if(_text=='网络随访'){
  203. if(patientInfo.isWX){
  204. mui.toast('该居民未关注公众号无法进行网络随访')
  205. return ;
  206. }
  207. }
  208. if(_text=='上门随访'){
  209. if(patientInfo.address){
  210. mui.toast('该居民未留下居住地址无法进行上门随访')
  211. return ;
  212. }
  213. }
  214. mui('#sheet1').popover('hide');
  215. $("[data-num="+currentNum+"]").find(".plan_type").text(_text).data('id',($(this).data("value")))
  216. })
  217. },
  218. //绑定事件
  219. bindEvents = function(){
  220. $('.main').on('click','.addplan',function (){
  221. var num = $('.plan_list').children('ul').last().data('num');
  222. ++num;
  223. var plan_html = $(".append_plan").prop("outerHTML");
  224. $('.plan_list').append(plan_html);
  225. $('.plan_list').children('ul').last().attr('data-num',num);
  226. $('.plan_list').children('ul').last().find('.sfnum').html('<i class="title-line"></i>第'+num+'次');
  227. $('.plan_list').children('ul').last().find('.plan_date').attr('id','date'+num);
  228. $('.plan_list').children('ul').last().find('.plan_type').attr('id','way'+num);
  229. $('.plan_list').children('ul').last().find('.plan_doctor').attr('id','doctor'+num);
  230. initialize_select(num);
  231. reflashBindEvent();
  232. });
  233. reflashBindEvent();
  234. //删除随访
  235. $('.main').on('click','.title-btn',function (){
  236. $(this).parents('.append_plan').remove();
  237. });
  238. //保存随访
  239. $('.submit').on('click',function (){
  240. var status = true;
  241. var plan_datas = [];
  242. $('.plan_list').children('ul').each(function (e){
  243. var plan_date = $(this).find('.plan_date').val();
  244. var plan_type = $(this).find('.plan_type').data('id');
  245. var plan_doctor = $(this).find('.plan_doctor').data('id');
  246. if(plan_date == '' || plan_date == '请选择'){
  247. status = 1;
  248. }
  249. if(plan_type == 3 && patientInfo.mobile == ''){ //type == 3,为电话随访
  250. status = 2;
  251. }
  252. if(plan_type == 6 && patientInfo.isWX == ''){ //type == 6,为网络随访
  253. status = 3;
  254. }
  255. if(plan_type == 2 && patientInfo.address == ''){ //type == 2,为上门随访
  256. status = 4;
  257. }
  258. plan_datas[e] = [];
  259. plan_datas[e] = {'date':plan_date+":00",'type':plan_type,'doctor':plan_doctor};
  260. })
  261. if(status === 1){
  262. mui.toast('随访日期未填写')
  263. return false;
  264. }
  265. if(status === 2){
  266. mui.toast('该居民未预留电话,不可以电话随访')
  267. return false;
  268. }
  269. if(status === 3){
  270. mui.toast('该居民未关注微信公众号,不可以网络随访')
  271. return false;
  272. }
  273. if(status === 4){
  274. mui.toast('该居民未填写地址,不可以上门随访')
  275. return false;
  276. }
  277. var params = {
  278. patient: patientInfo.code,
  279. data: JSON.stringify(plan_datas)
  280. };
  281. plus.nativeUI.showWaiting();
  282. sendPost("/doctor/followup/addFollowupPlan", params, null, function(res){
  283. if(res.status == 200){
  284. mui.toast("保存成功");
  285. var cur = plus.webview.currentWebview(),
  286. opener = cur.opener(),
  287. pre_opener = opener.opener(),
  288. index = plus.webview.getWebviewById('index'),
  289. server = plus.webview.getWebviewById('fuwujilu');
  290. suifangList = plus.webview.getWebviewById('suifang_list');
  291. if(suifangList){
  292. mui.fire(suifangList, "refresh2");
  293. backToPage(cur,'suifang_list')
  294. }else if(opener.id == "choose_suifang"){
  295. if(pre_opener && pre_opener.id == "suifang_detail"){
  296. //index->suifang_detail->choose_detail->add_plan
  297. if(index){
  298. mui.fire(index, "refresh");
  299. index.show();
  300. mui.later(function(){
  301. opener.close('none');
  302. cur.close('none');
  303. }, 300);
  304. }else if(server){
  305. mui.fire(server, "refresh2");
  306. mui.later(function(){
  307. pre_opener.close('none');
  308. opener.close('none');
  309. cur.close('none');
  310. }, 300);
  311. }
  312. }else{
  313. //IM/juminxinxi ->choose_suifang->add_plan
  314. var fuwujilu = plus.webview.getWebviewById("fuwujilu");
  315. if(fuwujilu){
  316. mui.fire(fuwujilu, "newPage", {type: 'sf', patientCode: patientInfo.code});
  317. }
  318. openWebview("../../huanzhe/html/fuwujilu.html", {type: 'sf', patientCode: patientInfo.code});
  319. mui.later(function(){
  320. opener.close('none');
  321. cur.close('none');
  322. }, 1000);
  323. }
  324. }else{
  325. mui.fire(index, 'refresh');
  326. var xuanzejumin = plus.webview.getWebviewById("xuanzejumin_one");
  327. var search_jumin = plus.webview.getWebviewById("sousuojumin_one");
  328. if(xuanzejumin){xuanzejumin.close('none')};
  329. if(search_jumin){search_jumin.close('none')};
  330. mui.later(function(){
  331. cur.close('none');
  332. }, 300);
  333. }
  334. }else{
  335. mui.toast(res.msg);
  336. }
  337. plus.nativeUI.closeWaiting();
  338. }, 'POST');
  339. })
  340. }
  341. var closeList = [];
  342. function backToPage(wv,id){
  343. if(wv.id == id){
  344. for(i=0; i<closeList.length; i++){
  345. closeList[i].close('none');
  346. }
  347. mui.later(function(){
  348. mui.back()
  349. },300)
  350. }else{
  351. var opener = wv.opener();
  352. if(opener.id != id){
  353. closeList.push(opener);
  354. }
  355. backToPage(opener,id);
  356. }
  357. }
  358. //随访方式写死 第一次初始化
  359. function doctorLevel(){
  360. // if(docInfo.level ==2){
  361. // $(".plan_type").html('家庭(全科)')
  362. // $(".plan_type").attr('data-id',22)
  363. // }else if(docInfo.level ==3){
  364. // $(".plan_type").html('健管师随访')
  365. // $(".plan_type").attr('data-id',10)
  366. // }else if(docInfo.level ==1){
  367. // $(".plan_type").html('专科医生随访')
  368. // $(".plan_type").attr('data-id',13)
  369. // }
  370. }
  371. // 页面业务处理流程开始
  372. new Promise(function(resolve, reject) {
  373. // TODO 临时放开
  374. //resolve(true);
  375. mui.plusReady(function() {
  376. // plus已经准备好,可以往下执行
  377. resolve(true);
  378. });
  379. }).then(function() {
  380. // 获取基础环境信息
  381. return getBaseEnvPromise().then(function(env) {
  382. baseEnv = env;
  383. }).then(function() {
  384. // 获取登录医生信息
  385. baseInfo = getBaseInfo();
  386. //初始化页面内容
  387. initPage();
  388. // 绑定页面事件
  389. bindEvents();
  390. })
  391. }).catch(function(e) {
  392. plus.nativeUI.closeWaiting();
  393. console && console.error(e);
  394. })
  395. template.helper("setPhoto", function(p) {
  396. return getImgUrl(p);
  397. })
  398. template.helper("setSex", function(p) {
  399. if(p == 2){return '女'}
  400. if(p == 1){return '男'}
  401. })