index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. //var plus = null;
  3. // 基本信息(包括userAgent)
  4. var baseInfo = null,
  5. // 基础环境信息(包括当前webview、encry相关)
  6. baseEnv = null,
  7. docInfo = null;
  8. var $noResultWrap = $("#no_result_wrap"),
  9. $resultWrap = $("#result_wrap"),
  10. $preWeek = $("#preWeek"),
  11. $nextWeek = $("#nextWeek"),
  12. $thisWeek = $("#thisWeek"),
  13. $planList = $("#plan_list"),
  14. $addPlan = $("#addPlan"),
  15. $linshiSF = $("#linshiSF");
  16. // iscroll 滚动条实例
  17. var iscroller,
  18. page = 1,
  19. pageSize = 15,
  20. curDate = new Date(), //表示当前时间
  21. curWeekHtml = "", //当前星期的时间
  22. preWeekHtml = "",
  23. nextWeekHtml = "",
  24. chooseDate,//点击的日期
  25. mySwiper = null;
  26. // 获取登录相关信息
  27. var getBaseInfo = function() {
  28. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  29. // 登录的相关信息
  30. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  31. var date = baseEnv.webview.date;
  32. if(date){
  33. curDate = new Date(date);
  34. }
  35. $("#month").find(".month").text((curDate.getMonth()+1) + "月");
  36. $("#month").find(".year").text(curDate.getFullYear());
  37. return {
  38. userAgent: userAgent,
  39. accessData: $.extend({},baseEnv.webview.accessData)
  40. }
  41. },
  42. // 获取基础环境信息
  43. getBaseEnvPromise = function () {
  44. var env = {
  45. webview: plus.webview.currentWebview()
  46. };
  47. baseEnv = env;
  48. },
  49. //获取随访列表
  50. getPlanList = function(){
  51. plus.nativeUI.showWaiting();
  52. var url = '/doctor/followup/list',
  53. month = (curDate.getMonth() + 1) < 10 ? "0"+(curDate.getMonth() + 1) : curDate.getMonth() + 1,
  54. day = curDate.getDate() < 10 ? "0" +curDate.getDate() : curDate.getDate();
  55. page = 1;
  56. var startDate = new Date(curDate),
  57. endDate = new Date(curDate);
  58. startDate.setDate(curDate.getDate() - curDate.getDay() + 0);
  59. endDate.setDate(curDate.getDate() - curDate.getDay() + 6);
  60. var start_month = (startDate.getMonth() + 1) < 10 ? "0"+(startDate.getMonth() + 1) : startDate.getMonth() + 1,
  61. start_day = startDate.getDate() < 10 ? "0" +startDate.getDate() : startDate.getDate(),
  62. end_month = (endDate.getMonth() + 1) < 10 ? "0"+(endDate.getMonth() + 1) : endDate.getMonth() + 1,
  63. end_day = endDate.getDate() < 10 ? "0" +endDate.getDate() : endDate.getDate();
  64. var params = {
  65. startTime: startDate.getFullYear()+"-"+start_month+"-"+start_day+" 00:00:00",
  66. endTime: endDate.getFullYear()+"-"+end_month+"-"+end_day+" 23:59:59",
  67. page: page,
  68. pageSize: pageSize
  69. };
  70. sendPost(url, params, function(){
  71. mui.toast("获取随访列表失败");
  72. }, function(res){
  73. page = page + 1;
  74. var list = [];
  75. var week = ["周日","周一","周二","周三","周四","周五","周六"];
  76. for(i=0; i< 7 ; i++){
  77. var showDate = new Date(curDate);
  78. showDate.setDate(curDate.getDate() - curDate.getDay() + i);
  79. var obj = {
  80. year: showDate.getFullYear(),
  81. month: showDate.getMonth()+1,
  82. day: showDate.getDate(),
  83. week: week[i],
  84. date: showDate.format("yyyy-MM-dd"),
  85. length: 0
  86. };
  87. if(showDate.format("yyyy-MM-dd") == curDate.format("yyyy-MM-dd")){
  88. obj.expand = 1;
  89. }
  90. var data = _.filter(res.data, function(o){
  91. if(o.date == showDate.format("yyyy-MM-dd")){
  92. o.length = o.list.length;
  93. if(o.length > 0){
  94. for(j=0; j<o.length; j++){
  95. o.list[j].jsonStr = JSON.stringify(o.list[j]);
  96. }
  97. }
  98. return o;
  99. }
  100. });
  101. $.extend(obj,data[0]);
  102. list.push(obj);
  103. }
  104. var html = template("plan_list_temp", {data:list});
  105. $planList.empty().append(html);
  106. if(res.status != 200){
  107. mui.toast("获取随防数据失败");
  108. }
  109. plus.nativeUI.closeWaiting();
  110. },"GET");
  111. },
  112. getWeekHtml = function(){
  113. curWeekHtml = "";
  114. preWeekHtml = "";
  115. nextWeekHtml = "";
  116. for(i=0; i< 7 ; i++){
  117. var showDate = new Date(curDate);
  118. showDate.setDate(curDate.getDate() - curDate.getDay() + i);
  119. var active = (showDate.getDate() == curDate.getDate())? "active" : "",
  120. date = showDate.format("yyyy-MM-dd");
  121. curWeekHtml += '<div class="ui-col-1 c-t-center c-f14 c-333 day"><span class="'+active+'" data-val="'+date+'">'+showDate.getDate()+'</span></div>';
  122. //填充前一个星期的数据
  123. var preWeekDate = new Date(curDate);
  124. preWeekDate.setDate(curDate.getDate() - curDate.getDay() - 7 + i);
  125. var preAct = (i == 1) ? "active":"",
  126. preDate = preWeekDate.format("yyyy-MM-dd");
  127. preWeekHtml += '<div class="ui-col-1 c-t-center c-f14 c-333 day"><span class="'+preAct+'" data-val="'+preDate+'">'+preWeekDate.getDate()+'</span></div>';
  128. //填充后一个星期的数据
  129. var nextWeekDate = new Date(curDate);
  130. nextWeekDate.setDate(curDate.getDate() - curDate.getDay() + 7 + i);
  131. var nextAct = (i==1)?"active":"",
  132. nextDate = nextWeekDate.format("yyyy-MM-dd");
  133. nextWeekHtml += '<div class="ui-col-1 c-t-center c-f14 c-333 day"><span class="'+nextAct+'" data-val="'+nextDate+'">'+nextWeekDate.getDate()+'</span></div>';
  134. }
  135. },
  136. showWeekDays = function(){
  137. getWeekHtml();
  138. $("[data-swiper-slide-index=0] .days").empty().append(curWeekHtml);
  139. $("[data-swiper-slide-index=1] .days").empty().append(nextWeekHtml);
  140. $("[data-swiper-slide-index=2] .days").empty().append(preWeekHtml);
  141. },
  142. //显示当前时间对应的月份和年
  143. showMonYear = function(){
  144. var month = (curDate.getMonth() + 1)+"月",
  145. year = curDate.getFullYear(),
  146. showMonth = $("#month").find(".month").text(),
  147. showYear = $("#month").find(".year").text();
  148. if(month != showMonth){
  149. $("#month").find(".month").text(month);
  150. }
  151. if(year != showYear){
  152. $("#month").find(".year").text(year);
  153. }
  154. },
  155. initSwiper = function(){
  156. mySwiper = new Swiper('.swiper-container',{
  157. loop : true
  158. });
  159. mySwiper.on('slideChangeStart',function(swiper){
  160. swiper.lockSwipes();
  161. })
  162. mySwiper.on('slideChangeEnd',function(swiper){
  163. swiper.unlockSwipes();
  164. var activeIndex = swiper.activeIndex;
  165. var cur = $(swiper.slides[activeIndex]).find('.day span[class=active]').attr("data-val");
  166. curDate = new Date(cur);
  167. showMonYear();
  168. getPlanList();
  169. getWeekHtml();
  170. var nextIndex = (activeIndex == 4) ? 2 : (activeIndex +1), //当到达最后一页时,最后一页在循环中相当于index为1的页面
  171. preIndex = (activeIndex == 0)? 2 : (activeIndex - 1);//当到达第一页面时,在循环中相当于index为3的页面
  172. $(swiper.slides[nextIndex]).find(".days").empty().append(nextWeekHtml);
  173. $(swiper.slides[preIndex]).find('.days').empty().append(preWeekHtml);
  174. });
  175. },
  176. //初始化iscroll
  177. initScroll = function(){
  178. //阻尼系数
  179. var deceleration = mui.os.ios?0.003:0.0009;
  180. iscroller = mui('.mui-scroll-wrapper').scroll({
  181. bounce: false,
  182. indicators: true, //是否显示滚动条
  183. deceleration:deceleration
  184. });
  185. mui('.mui-scroll-wrapper').pullRefresh({
  186. down: {
  187. contentinit: '下拉显示上周信息',
  188. contentdown: '下拉显示上周信息',
  189. callback: function() {
  190. setTimeout(function() {
  191. mySwiper.slidePrev();
  192. mui('.mui-scroll-wrapper').pullRefresh().endPulldownToRefresh();
  193. }, 1000);
  194. }
  195. },
  196. up:{
  197. contentinit: '上拉显示下周信息',
  198. contentdown: '上拉显示下周信息',
  199. contentrefresh: '正在加载...',
  200. callback: function(){
  201. var self = this;
  202. setTimeout(function() {
  203. mui('.mui-scroll-wrapper').scroll().scrollTo(0,0);
  204. mySwiper.slideNext();
  205. mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh();
  206. mui('.mui-scroll-wrapper').scroll().reLayout();
  207. }, 1000);
  208. }
  209. }
  210. });
  211. },
  212. setSex = function(s) {
  213. if(s == 1) {
  214. return "男";
  215. } else if(s == 2) {
  216. return "女";
  217. }
  218. },
  219. setAge = function(str){
  220. var r = str.substr(0,10);
  221. var arr = r.split('-');
  222. var y = arr[0],
  223. m = arr[1],
  224. day = arr[2];
  225. var now = new Date(),
  226. Y = now.getFullYear(),
  227. M = now.getMonth(),
  228. DAY = now.getDate();
  229. if(y == Y){
  230. return '0岁';
  231. }else{
  232. var diff = Y - y; //年岁之差
  233. if(diff > 0){
  234. if(m == M){
  235. var dayDiff = DAY - day;
  236. if(dayDiff > 0){
  237. return diff + '岁';
  238. }else{
  239. return (diff -1) + '岁';
  240. }
  241. }else{
  242. var monDiff = M - m;
  243. if(monDiff > 0){
  244. return diff + '岁';
  245. }else{
  246. return (diff -1) + '岁';
  247. }
  248. }
  249. }else{
  250. return "未知";
  251. }
  252. }
  253. return "";
  254. },
  255. //绑定事件
  256. bindEvents = function(){
  257. initSwiper();
  258. $('#month').mobiscroll({
  259. preset: 'date',
  260. theme: 'ios',
  261. lang: 'zh',
  262. dateOrder: 'yy mm',
  263. dateFormat: 'yy/mm',
  264. showLabel: true,
  265. showOnFocus: true,
  266. onSelect: function(valueText, inst) {
  267. var dateStr = valueText+"/01";
  268. curDate = new Date(dateStr);
  269. var month = curDate.getMonth() + 1,
  270. year = curDate.getFullYear();
  271. $(this).find(".month").text(month+"月");
  272. $(this).find(".year").text(year);
  273. getPlanList();
  274. showWeekDays();
  275. if(mySwiper){
  276. mySwiper.slideTo(1, 300, false);
  277. }
  278. }
  279. });
  280. //新增随访
  281. $addPlan.on("tap", function(){
  282. openWebview("../../home/html/huanzhe.html", {follow_type : 1,origin:'suifang',chooseDate:chooseDate});
  283. mui('#sheet1').popover('toggle');
  284. });
  285. //临时随访
  286. $linshiSF.on("tap", function(){
  287. openWebview("../../home/html/huanzhe.html", {follow_type : 2,origin:'suifang'});
  288. mui('#sheet1').popover('toggle');
  289. });
  290. $planList.on('tap', '.mui-table-view-cell', function(){
  291. var value = this.id;
  292. var $day = $(".days").find("span[data-val="+value+"]");
  293. $day.closest(".days").find('span').removeClass("active");
  294. $day.addClass("active");
  295. });
  296. $planList.on("tap", "li.plan_li2", function(){
  297. var $this = $(this),
  298. status = $this.attr("data-status"),
  299. fv_id = $this.attr("data-id");
  300. //随访状态 1-已完成,2-未开始,3-进行中
  301. var jsonStr = $this.attr('data-json');
  302. var docMsg = JSON.stringify(docInfo);
  303. var datas = JSON.parse(jsonStr);
  304. if(datas.prescriptionCode && status!=2){
  305. openWebview("fvDetail.html", {followup_id: fv_id,status:status,prescriptionCode:datas.prescriptionCode});
  306. }else{
  307. if(datas.prescriptionCode){//长处方登记页面
  308. var patientInfo={}
  309. patientInfo.code = datas.patientCode
  310. mui.openWindow('follow_way.html', 'xf_follow_way', {
  311. extras: {
  312. followup_id:fv_id,
  313. followClass:datas.followupClass,
  314. patientInfo:patientInfo,
  315. prescriptionCode: datas.prescriptionCode
  316. }
  317. })
  318. }else{
  319. openWebview("suifang_detail.html", {data: jsonStr,docInfo:docMsg});
  320. }
  321. }
  322. })
  323. $(".days").on('tap','.day',function(e){
  324. var date = $(this).find('span').attr('data-val');
  325. $(this).closest(".days").find('span').removeClass("active");
  326. $(this).find('span').addClass("active");
  327. curDate = new Date(date);
  328. showMonYear();
  329. //滚动iscroll
  330. var $obj = $("#"+curDate.format("yyyy-MM-dd"));
  331. var height = $obj.offset().top;
  332. mui.scrollTo(-(parseFloat(height)-125), 300);
  333. //展开对应的日期数据
  334. var classList = document.getElementById(curDate.format("yyyy-MM-dd")).classList;
  335. if (!classList.contains("mui-active")) { //展开时,需要收缩其他同类
  336. var collapse = $obj.parent().find('.mui-collapse.mui-active');
  337. if (collapse) {
  338. collapse.removeClass("mui-active");
  339. }
  340. }
  341. classList.toggle("mui-active");
  342. });
  343. $("#today").on('tap',function(){
  344. curDate = new Date();
  345. showMonYear();
  346. getPlanList();
  347. showWeekDays();
  348. if(mySwiper){
  349. mySwiper.slideTo(1, 300, false);
  350. }
  351. });
  352. //每天新增随访
  353. $(document).on("tap", '.add_icon', function(){
  354. var $li = $(this).closest("li");
  355. chooseDate = $li.attr("id");
  356. mui('#sheet1').popover('toggle');
  357. })
  358. $('#add').on("tap", function(){
  359. chooseDate = $('.swiper-slide.swiper-slide-active').find('span.active').attr("data-val");
  360. })
  361. }
  362. template.helper("setSex", setSex);
  363. template.helper("setAge", setAge);
  364. mui.plusReady(function() {
  365. getBaseEnvPromise();
  366. baseInfo = getBaseInfo();
  367. showWeekDays();
  368. getPlanList();
  369. initScroll();
  370. // 绑定页面事件
  371. bindEvents();
  372. window.addEventListener("refresh", function(){
  373. showMonYear();
  374. getPlanList();
  375. });
  376. });
  377. template.helper("setPhoto", function(p) {
  378. return getImgUrl(p);
  379. });