add_plan.js 12 KB

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