prescription-records.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. mui.init();
  2. var CITY_CODE = "350200";
  3. var self,
  4. userRole,
  5. areaCode,
  6. areaTitle,
  7. initLevel,
  8. level,
  9. initDate,//记录从前一个页面跳转过来的日期
  10. dateType,//记录前一个页面跳转时柱状图的日期类型 1-日期,2-周,3-月
  11. disease, //记录从前一个页面跳转过来的疾病
  12. status, //从前一个页面跳转过来的状态
  13. expressType, //从前一个页面跳转过来的配送状态
  14. selectedArea, //从前一个页面带过来的区域信息
  15. startDate,
  16. endDate,
  17. currentYear,
  18. minYear = '2017', //长处方功能开始的时间2017才有这个功能
  19. page = 1,
  20. pageSize = 10,
  21. filterSelectedData = {
  22. area: {
  23. town: '',
  24. hospital: ''
  25. },
  26. filter: {
  27. disease: '',
  28. status: '',
  29. type: ''
  30. },
  31. date:{
  32. sDate: '',
  33. eData: '',
  34. year: '',
  35. month: ''
  36. }
  37. };
  38. var now = new Date();
  39. currentYear = now.getFullYear();
  40. mui.plusReady(function(){
  41. //获得权限
  42. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  43. areaCode = userRole.code;
  44. self = plus.webview.currentWebview();
  45. initDate = self.date;
  46. dateType = self.dateType;
  47. disease = self.disease;
  48. status = self.status;
  49. expressType = self.expressType;
  50. areaCode = self.area + '';
  51. level = areaCode == CITY_CODE ? 4 : areaCode.length==6 ? 3 : 2;
  52. areaTitle = self.areaTitle;
  53. $("#area").text(self.areaTitle);
  54. //填充帅选条件
  55. if(disease){
  56. var val = 0;
  57. if(disease == 'HP0047'){ //糖尿病
  58. val = 2;
  59. }else if(disease == 'HP0093'){ //高血压
  60. val = 1;
  61. }
  62. $(".disease[data-val="+val+"]").addClass("active");
  63. }
  64. if(status){
  65. $(".status[data-val="+status+"]").addClass("active");
  66. }
  67. if(expressType){
  68. $(".express-type[data-val="+expressType+"]").addClass("active");
  69. }
  70. getStartEndDate(initDate, dateType);
  71. //填充时间筛选数据
  72. if(dateType == 1 || dateType == 3){
  73. $("#date").text(initDate);
  74. }else if(dateType == 2){
  75. var str = startDate.substr(5, 5) + "~"+endDate.substr(5, 5);
  76. $("#date").text(str);
  77. //处理选中的时间
  78. var $inputs = $(".date-input");
  79. $($inputs[0]).val(startDate);
  80. $($inputs[1]).val(endDate);
  81. }
  82. getFilterData();
  83. getList(true);
  84. initListPanelScroller();
  85. initComminityScroller();
  86. initYearScroller();
  87. bindEvents();
  88. })
  89. function getFilterData(){
  90. initLevel = userRole.code == CITY_CODE ? 4 : userRole.code.length==6 ? 3 : 2;
  91. var areaTitle = userRole.name;
  92. if(initLevel == 4){
  93. getTown();
  94. filterSelectedData.area.town = CITY_CODE;
  95. }else if(initLevel == 3){
  96. $("#districtPanel").hide();
  97. filterSelectedData.area.town = userRole.code;
  98. //TODO 获取社区列表
  99. getHospital(userRole.code, userRole.name);
  100. }else if(initLevel == 2){
  101. filterSelectedData.area.hospital = userRole.code;
  102. $("#districtPanel").hide();
  103. var html = "<li data-code='"+areaCode+"' class='active'>"+areaTitle+"</li>";
  104. $(".community-panel").empty().append(html);
  105. }
  106. var dateHtml = "";
  107. for(i=currentYear; i>=minYear; i--){
  108. dateHtml += '<span class="tag mr20" data-type="date" data-val="'+i+'">'+i+'年</span>';
  109. }
  110. $("#yearPanel").empty().append(dateHtml);
  111. }
  112. //获得列表数据
  113. function getList(isInit){
  114. if(isInit){
  115. page = 1;
  116. }
  117. var url = "/doctor/prescriptionInfo/getPrescriptionByCondition",
  118. $disease = $(".disease.active"),
  119. disease = $disease.length > 0 ? $disease.attr("data-val") : '',
  120. $status = $(".status.active"),
  121. status = $status.length > 0 ? $status.attr("data-val") : 1,
  122. $type = $(".express-type.active"),
  123. type = $type.length > 0 ? $type.attr("data-val") : '',
  124. params = {
  125. level: level,
  126. area: areaCode,
  127. disease: disease,
  128. status: status,
  129. type: type,
  130. startTime: startDate,
  131. endTime: endDate,
  132. pageNo: page,
  133. pageSize: pageSize
  134. };
  135. plus.nativeUI.showWaiting();
  136. sendGet(url, params, null, function(res){
  137. if(res.status == 200){
  138. if(isInit){
  139. mui('#listPanel').scroll().scrollTo(0,0);
  140. if(res.data.length == 0){
  141. $("#listPanel").hide();
  142. $("#no_result_wrap").show();
  143. }else{
  144. $("#listPanel").show();
  145. $("#no_result_wrap").hide();
  146. $("#totalCount").text(res.data.count);
  147. $("#totalAmount").text(res.data.totalAmount);
  148. var html = template("list-tmp", res.data);
  149. $("#listPanel .list-panel").empty().append(html);
  150. if(res.data.length < pageSize){
  151. mui('#listPanel').pullRefresh().endPullupToRefresh(true);
  152. }else{
  153. mui('#listPanel').pullRefresh().refresh(true);
  154. page ++;
  155. }
  156. }
  157. }else{
  158. var html = template("list-tmp", res.data);
  159. $("#listPanel .list-panel").append(html);
  160. if(res.data.length < pageSize){
  161. mui('#listPanel').pullRefresh().endPullupToRefresh(true);
  162. }else{
  163. mui('#listPanel').pullRefresh().endPullupToRefresh();
  164. page ++;
  165. }
  166. }
  167. }else{
  168. mui.toast(res.msg);
  169. }
  170. plus.nativeUI.closeWaiting();
  171. }, true);
  172. }
  173. //获得市区信息
  174. function getTown(){
  175. var url = "/area/"+CITY_CODE+"/towns";
  176. sendGet(url, {city: CITY_CODE}, null, function(res){
  177. if(res.status == 200){
  178. console.log(res);
  179. var html = template("town-tmp", {list: res.data, cityCode: CITY_CODE, cityName: userRole.name});
  180. $("#districtPanel").empty().append(html);
  181. //判断前一个页面带过来的区域是否在此页显示
  182. if(level == 3){
  183. $(".district").removeClass("active");
  184. var $node = $(".district[data-code="+areaCode+"]");
  185. $node.addClass("active");
  186. getHospital(areaCode, $node.attr("data-name"));
  187. }else if(level == 2){
  188. var parentCode = areaCode.substr(0,6);
  189. $(".district").removeClass("active");
  190. var $node = $(".district[data-code="+parentCode+"]");
  191. $node.addClass("active");
  192. getHospital(parentCode, $node.attr("data-name"));
  193. }
  194. }
  195. }, true);
  196. }
  197. //获得服务中心的数据
  198. function getHospital(code, name){
  199. var url = "/area/getHospitals",
  200. params = {
  201. town: code
  202. };
  203. $(".mui-loading").show();
  204. $(".community-panel").hide();
  205. sendGet(url, params, null, function(res){
  206. if(res.status = 200){
  207. var html = template("community-temp", {townCode: code, townName: name, list: res.data});
  208. $(".community-panel").empty().append(html);
  209. $(".mui-loading").hide();
  210. $(".community-panel").show();
  211. //判断前一个页面带过来的区域是否在此页显示
  212. if(level == 2){
  213. $("li[data-level=2]").removeClass("active");
  214. $("li[data-code="+areaCode+"]").addClass("active");
  215. }
  216. }else{
  217. $(".mui-loading").hide();
  218. mui.toast(res.msg);
  219. }
  220. }, true);
  221. }
  222. function getStartEndDate(str, type){
  223. //type 1-日,2-周,3-月, 4-年
  224. switch(parseInt(type)){
  225. case 1:
  226. startDate = str;
  227. endDate = str;
  228. break;
  229. case 2:
  230. startDate = str;
  231. var d = new Date(str),
  232. end = new Date(str);
  233. end.setDate(d.getDate() + 6);
  234. endDate = end.format("yyyy-MM-dd");
  235. break;
  236. case 3:
  237. var month = str.substr(5,2);
  238. if(month == '12'){
  239. startDate = str+"-01";
  240. endDate = str+"-31";
  241. }else{
  242. var d = new Date(str);
  243. startDate = d.format("yyyy-MM-dd");
  244. d.setMonth(d.getMonth() + 1);
  245. d.setDate(d.getDate()-1);
  246. endDate = d.format("yyyy-MM-dd");
  247. }
  248. break;
  249. case 4:
  250. startDate = str+"-01-01";
  251. endDate = str+"-12-31";
  252. break;
  253. }
  254. }
  255. function bindEvents(){
  256. $("#area").on('click', function(){
  257. if($(this).hasClass("active")){
  258. $(this).removeClass("active");
  259. $("#showHeader").removeClass("show");
  260. $("#showHeader").hide();
  261. return false;
  262. }
  263. $("#tabs .j-tag").removeClass("active");
  264. $(this).addClass("active");
  265. $("#areaPanel").show();
  266. $("#filterPanel").hide();
  267. $("#datePanel").hide();
  268. $("#showHeader").show();
  269. $("#showHeader").addClass("show");
  270. });
  271. $("#filter").on('click', function(){
  272. if($(this).hasClass("active")){
  273. $(this).removeClass("active");
  274. $("#showHeader").removeClass("show");
  275. $("#showHeader").hide();
  276. return false;
  277. }
  278. $("#tabs .j-tag").removeClass("active");
  279. $(this).addClass("active");
  280. $("#areaPanel").hide();
  281. $("#filterPanel").show();
  282. $("#datePanel").hide();
  283. $("#showHeader").show();
  284. $("#showHeader").addClass("show")
  285. });
  286. $("#date").on('click', function(){
  287. if($(this).hasClass("active")){
  288. $(this).removeClass("active");
  289. $("#showHeader").removeClass("show");
  290. $("#showHeader").hide();
  291. return false;
  292. }
  293. $("#tabs .j-tag").removeClass("active");
  294. $(this).addClass("active");
  295. $("#areaPanel").hide();
  296. $("#filterPanel").hide();
  297. $("#datePanel").show();
  298. $("#showHeader").show();
  299. $("#showHeader").addClass("show")
  300. });
  301. $("#showHeader").on('tap', '.tag', function(){
  302. var $this = $(this);
  303. if($this.hasClass("active")){
  304. return false;
  305. }
  306. $this.siblings().removeClass("active");
  307. $this.addClass("active");
  308. //如果是日期选项,则清空输入框的内容
  309. var type = $this.attr("data-type");
  310. if(type == 'year'){
  311. $(".date-input").val("");
  312. }
  313. });
  314. $("#districtPanel").on('click', '.district', function(){
  315. var $this = $(this),
  316. code = $this.attr("data-code"),
  317. name = $this.attr("data-name");
  318. if($this.hasClass("active")){
  319. return false;
  320. }
  321. $this.siblings().removeClass("active");
  322. $this.addClass("active");
  323. if(code == CITY_CODE){
  324. $("#communityPanel .mui-loading").hide();
  325. $("#communityPanel .community-panel").hide();
  326. }
  327. // $("#area").text(name);
  328. // $("#area").attr("data-code", code);
  329. //TODO 获得社区服务中心列表
  330. getHospital(code, name);
  331. });
  332. $("#communityPanel").on('tap', "li", function(){
  333. var $this = $(this),
  334. code = $this.attr("data-code"),
  335. name = $this.attr("data-name");
  336. if($this.hasClass("active")){
  337. return false;
  338. }
  339. $this.siblings().removeClass("active");
  340. $this.addClass("active");
  341. // $("#area").text(name);
  342. // $("#area").attr("data-code", code);
  343. })
  344. $(".date-input").on('click', function(){
  345. var picker = new mui.DtPicker({
  346. "type": 'date',
  347. "beginYear": minYear,
  348. "endYear": currentYear
  349. });
  350. var $this = $(this);
  351. picker.show(function(rs){
  352. $this.val(rs.text);
  353. //将不选中选中的月份和年份
  354. $("#datePanel .tag").removeClass("active");
  355. picker.dispose();
  356. })
  357. });
  358. //重置按钮绑定事件
  359. $("#showHeader").on('click', ".reset-btn", function(){
  360. var activeTab = $("#tabs .j-tag.active").attr("id");
  361. if(activeTab == "area"){
  362. //位置的重置,直接使用默认初始的
  363. var areaTitle = userRole.name;
  364. $("#area").text(areaTitle);
  365. if(initLevel == 4){
  366. $("#districtPanel .district").removeClass("active");
  367. $("#districtPanel .district").eq(0).addClass("active");
  368. $(".community-panel").hide();
  369. }else if(initLevel == 3){
  370. $(".community-panel .district").removeClass("active");
  371. $(".community-panel .district").eq(0).addClass("active");
  372. }else if(initLevel == 2){
  373. }
  374. }else if(activeTab == "filter"){
  375. $("#filterPanel").find(".tag").removeClass("active");
  376. }else{
  377. $("#datePanel").find(".tag").removeClass("active");
  378. $("#datePanel").find(".date-input").val("");
  379. }
  380. });
  381. //确定按钮绑定事件
  382. $("#showHeader").on('click', ".confirm-btn", function(){
  383. //先处理地区选中的值
  384. if(initLevel == 4){
  385. var $selectTown = $("#districtPanel .district.active");
  386. filterSelectedData.area.town = $selectTown.attr("data-code");
  387. if($selectTown.attr("data-code") != CITY_CODE){
  388. var $hospital = $("#communityPanel li.active");
  389. filterSelectedData.area.hospital = $hospital.attr("data-code");
  390. $("#area").text($hospital.attr("data-name"));
  391. $("#area").attr("data-code", $hospital.attr("data-code"));
  392. areaCode = $hospital.attr("data-code");
  393. level = $hospital.attr("data-code").length > 6 ? 2 : 3;
  394. }else{
  395. $("#area").text(userRole.name);
  396. $("#area").attr("data-code", userRole.code);
  397. areaCode = userRole.code;
  398. level = 4;
  399. }
  400. }else if(initLevel == 3){
  401. var $hospital = $("#communityPanel li.active");
  402. filterSelectedData.area.hospital = $hospital.attr("data-code");
  403. $("#area").text($hospital.attr("data-name"));
  404. $("#area").attr("data-code", $hospital.attr("data-code"));
  405. areaCode = $hospital.attr("data-code");
  406. level = $hospital.attr("data-code").length > 6 ? 2 : 3;
  407. }
  408. //处理选中的时间
  409. var $inputs = $(".date-input"),
  410. sd = $($inputs[0]).val(),
  411. ed = $($inputs[1]).val();
  412. if(sd && ed){
  413. startDate = sd;
  414. endDate = ed;
  415. $("#date").text("自定义时间");
  416. }else if(sd || ed){
  417. //不改变时间值
  418. }else{
  419. var year = $("#yearPanel .tag.active").attr("data-val"),
  420. month = $(".month.active").attr("data-val");
  421. if(year && month){
  422. getStartEndDate(year+"-"+month, 3);
  423. $("#date").text(year+"年"+month+"月");
  424. }else if(year && !month){
  425. getStartEndDate(year, 4);
  426. $("#date").text(year+"年");
  427. }else if(!year && month){
  428. mui.toast("请选择年份");
  429. return false;
  430. }
  431. }
  432. getList(true);
  433. $("#showHeader").hide();
  434. });
  435. $("#listPanel").on('tap', ".order", function(){
  436. var code = $(this).attr("data-code");
  437. openWebview("xufangxiangqing2.html", {prescriptionCode: code});
  438. });
  439. $(".search-input").on('click', function(){
  440. openWebview("search-xufang-order.html");
  441. });
  442. template.helper("getStatusName", function(status){
  443. status = parseInt(status);
  444. if(status == 100){
  445. return "已完成";
  446. }else if(status == -2){
  447. return "居民取消";
  448. }else if(status == -1){
  449. return "审核不通过";
  450. }else if(status <= -3){
  451. return "其他原因取消";
  452. }else if(status >=0 && status<100){
  453. return "进行中";
  454. }
  455. });
  456. template.helper("getExpressName", function(type){
  457. switch(type){
  458. case 1:
  459. return '自取';
  460. break;
  461. case 3:
  462. return "健管师配送";
  463. break;
  464. case 2:
  465. return "快递配送";
  466. break;
  467. default:
  468. return "";
  469. break;
  470. }
  471. })
  472. template.helper("formatDate", function(str){
  473. if(!str){
  474. return "";
  475. }
  476. var timeStm = parseInt(str),
  477. d = new Date(timeStm);
  478. return d.format("yyyy-MM-dd hh:mm")
  479. })
  480. }
  481. function initListPanelScroller(){
  482. //阻尼系数
  483. var deceleration = mui.os.ios?0.003:0.0009;
  484. mui('.mui-scroll-wrapper').scroll({
  485. bounce: false,
  486. indicators: true, //是否显示滚动条
  487. deceleration:deceleration
  488. });
  489. mui("#listPanel").pullRefresh({
  490. up: {
  491. callback: function(){
  492. var self = this;
  493. setTimeout(function(){
  494. getList(false);
  495. // self.endPullupToRefresh();
  496. }, 500);
  497. }
  498. }
  499. })
  500. }
  501. function initComminityScroller(){
  502. mui("#communityPanel .mui-scroll-wrapper").pullRefresh();
  503. }
  504. function initYearScroller(){
  505. mui("#year-panel").scroll({
  506. scrollY: false, //是否竖向滚动
  507. scrollX: true, //是否横向滚动
  508. startX: 0, //初始化时滚动至x
  509. startY: 0, //初始化时滚动至y
  510. indicators: true, //是否显示滚动条
  511. deceleration:0.0006, //阻尼系数,系数越小滑动越灵敏
  512. bounce: true
  513. });
  514. }