juminxufangjilu.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. var page = 1,
  2. pagesize = 10;
  3. var $tabs = $('#tabs'),
  4. $panels = $('.c-panels'),//切换选项卡
  5. $list = $('#dest_list'),//选项卡内容
  6. $notext = $('#no_result_wrap'),//没有样式
  7. $scroll = $('#iScroll');//内容展示
  8. var teamCode,//团队code
  9. state="",
  10. diseases="",
  11. startDate="",
  12. endDate="",
  13. docInfo,
  14. self;
  15. function queryHeaderData(){
  16. sendPost("doctor/prescriptionInfo/getPrescriptionFilter",{teamCode:teamCode,patient:self.patiCode}, null, function(res){
  17. if(res.status == 200){
  18. var html = template('tag_tmpl',{data:res.data})
  19. $('#showHeader').html(html)
  20. var stateVal=0;
  21. $.map(res.data.states,function(o,index){
  22. stateVal += o.count;
  23. })
  24. $('#allStateVal').text(stateVal);
  25. seledtedOne();//取消优选审核中
  26. }
  27. },'get')
  28. }
  29. function queryListData(fun,text){
  30. var params ={
  31. teamCode:teamCode,
  32. patient:self.patiCode,
  33. state:state,
  34. diseases:diseases,
  35. startDate:startDate,
  36. endDate:endDate,
  37. page:page,
  38. size:pagesize
  39. }
  40. sendPost("/doctor/prescriptionInfo/getDoctorPrescription",params, function(){
  41. plus.nativeUI.closeWaiting();
  42. fun&&fun.call(this,false)
  43. mui.toast("获取数据失败!");
  44. }, function(res){
  45. plus.nativeUI.closeWaiting();
  46. if(res.status == 200){
  47. var html = template('li_tmpl',{list:_.map(res.data,function(o){
  48. o.jsonStr = JSON.stringify(o);
  49. return o;})
  50. })
  51. if(page == 1 && res.data.length==0){
  52. $notext.show();
  53. $scroll.hide();
  54. }else{
  55. $notext.hide();
  56. $scroll.show();
  57. if(res.data.length < pagesize){
  58. fun&&fun.call(this,true)
  59. }else{
  60. fun&&fun.call(this,false)
  61. }
  62. $list.append(html);
  63. }
  64. }else{
  65. fun&&fun.call(this,false)
  66. mui.toast("获取数据失败!");
  67. }
  68. },'get')
  69. }
  70. template.helper('setSex',function(item){
  71. if(item == 1){
  72. return '男'
  73. }else{
  74. return '女'
  75. }
  76. })
  77. template.helper('setPrescription',function(array){
  78. var arr=[];
  79. $.map(array,function(item,index){
  80. arr.push(item.name)
  81. })
  82. return arr.join(',')
  83. })
  84. template.helper('setRestTime',function(minDate,sDate){
  85. var now = getNowDate();
  86. var createDate = sDate.split(' ');
  87. var diff = getDays(createDate[0],now);
  88. if(diff<minDate){
  89. return '<span style="color:#17b3ec">'+(minDate-diff)+'</span>'
  90. }else{
  91. return '<span style="color:#ff4c4c">已用完</span>'
  92. }
  93. })
  94. //相隔几天
  95. function getDays(sDate,eDate){
  96. var oDate1;
  97. var oDate2;
  98. var iDays;
  99. oDate1= sDate.split("-");
  100. oDate2= eDate.split("-");
  101. var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
  102. var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
  103. iDays = parseInt(Math.abs(strDateE - strDateS ) / 1000 / 60 / 60 /24)
  104. return iDays ;
  105. }
  106. //现在时间
  107. function getNowDate() {
  108. var date = new Date();
  109. var year = date.getFullYear();
  110. var month = date.getMonth() + 1;
  111. var day = date.getDate();
  112. var hour = date.getHours();
  113. var minute = date.getMinutes();
  114. var second = date.getSeconds();
  115. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  116. }
  117. //该上月份最后一天
  118. function lastDate(date){
  119. var arr = date.split('-');
  120. var year = arr[0];
  121. var month = arr[1]*1-1;
  122. if(month<1){
  123. month = 12;
  124. year = year - 1;
  125. }
  126. var day = new Date(year,month,0).getDate();
  127. return day;
  128. }
  129. //近一周
  130. function beforeWeek(date,num){
  131. var arr = date.split('-');
  132. var reduce = arr[2]*1-num;
  133. if(reduce>0){
  134. var sDate = arr[0]*1+'-'+arr[1]*1+'-'+reduce;
  135. return sDate;
  136. }else if(arr[1]*1 > 1){
  137. var sDate = arr[0]*1+'-'+(arr[1]*1-1)+'-'+(lastDate(date)+reduce);
  138. return sDate;
  139. }else{
  140. var sDate = (arr[0]*1-1)+'-12-'+(lastDate(date)+reduce);
  141. return sDate;
  142. }
  143. }
  144. //近几个月前
  145. function beforeMonth(date,num){
  146. var arr = date.split('-');
  147. var reduce = arr[1]*1-num;
  148. if(reduce>0){
  149. var sDate = arr[0]+'-'+reduce+'-'+arr[2];
  150. return sDate;
  151. }else{
  152. var sDate = (arr[0]*1-1)+'-'+(12+reduce*1)+'-'+arr[2];
  153. return sDate;
  154. }
  155. }
  156. function bindEvents() {
  157. $tabs.on('click','.sanp-flex',function() {
  158. var index = $(this).index(),
  159. $panel = $panels.find('.c-panel').eq(index);
  160. $panel.siblings().hide();
  161. if($panel.css('display')=='none') {
  162. $panel.show();
  163. } else {
  164. $panel.hide();
  165. }
  166. })
  167. $panels.on('click','li',function() {
  168. var $panel = $(this).closest('.c-panel');
  169. $(this).siblings().removeClass('list-selected');
  170. $(this).addClass('list-selected');
  171. $panel.hide();
  172. $('.j-tag').eq($panel.index()).text($(this).find('a').text())
  173. if($panel.index() ==0){ state = $(this).attr('data-id') }
  174. if($panel.index() ==1){ diseases = $(this).attr('data-id') }
  175. if($panel.index() ==2){
  176. var num = $(this).attr('data-id'),
  177. now = new Date();
  178. var day = now.getDate();
  179. var month = now.getMonth() + 1;
  180. var year = now.getFullYear();
  181. var date = year+'-'+month+'-'+day
  182. endDate = date;
  183. if(num == 1){
  184. startDate = beforeWeek(date,6);
  185. }else if(num == 2){
  186. startDate = beforeMonth(date,1);
  187. }else if(num == 3){
  188. startDate = beforeMonth(date,6);
  189. }else if(num == 4){
  190. startDate = beforeMonth(date,12);
  191. }else{
  192. startDate = '';
  193. }
  194. }
  195. reloadLessData()
  196. })
  197. //点击跳转
  198. $list.on('tap','.j-detail',function(){
  199. mui.openWindow({
  200. id: "juminxufangxiangqing",
  201. url: "juminxufangxiangqing.html",
  202. extras: {
  203. teamCode:teamCode,
  204. infoStr:$(this).attr('data-json')
  205. }
  206. })
  207. })
  208. }
  209. //局部刷新
  210. function reloadLessData(){
  211. plus.nativeUI.showWaiting();
  212. page = 1;
  213. $list.empty();
  214. mui('.mui-scroll-wrapper').pullRefresh().refresh(true);//重置
  215. queryListData();
  216. }
  217. //整体刷新
  218. function reloadPageData(){
  219. plus.nativeUI.showWaiting();
  220. page = 1;
  221. recoverTag()
  222. $list.empty();
  223. queryHeaderData();
  224. }
  225. function paramReset(){
  226. state="";diseases='';startDate='';endDate='';
  227. }
  228. //取消优选审核中
  229. function seledtedOne(){
  230. $one = $('.c-panel').eq(0).find('li');
  231. $one.removeClass('list-selected');
  232. $one.eq(0).addClass('list-selected');
  233. $('.j-tag').eq(0).text($one.eq(0).find('a').text())
  234. }
  235. //恢复选项卡
  236. function recoverTag(){
  237. $('.c-panel').find('li').removeClass('list-selected');
  238. $.map($('.c-panel'),function(o,i){
  239. var $li = $('.c-panel').eq(i).find('li').eq(0);
  240. $li.addClass('list-selected');
  241. $('.j-tag').eq(i).text($li.find('a').text())
  242. })
  243. seledtedOne()
  244. paramReset()
  245. }
  246. new Promise(function(resolve, reject) {
  247. mui.plusReady(function() {
  248. resolve(true);
  249. })
  250. }).then(function() {
  251. plus.nativeUI.showWaiting();
  252. //设置团队
  253. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  254. self = plus.webview.currentWebview();
  255. teamCode = self.teamCode?self.teamCode:'';//可以为空
  256. //展示头部标题
  257. $('#header_title').html(self.patiName+'续方记录');
  258. //请求头部标签数据
  259. queryHeaderData();
  260. }).then(function() {
  261. mui.init({
  262. pullRefresh : {
  263. container:'.mui-scroll-wrapper',
  264. up : {
  265. height:50,
  266. contentrefresh : "正在加载...",
  267. contentnomore:'没有更多数据了',
  268. callback: function() {
  269. var self = this;
  270. page++;
  271. queryListData(function(value){
  272. setTimeout(function(){
  273. self.endPullupToRefresh(value);
  274. },500)
  275. },'up')
  276. }
  277. }
  278. }
  279. })
  280. queryListData();
  281. bindEvents()
  282. })
  283. window.addEventListener("refreshXufang", function(){
  284. reloadPageData()
  285. });
  286. template.helper("setPhoto", function(p) {
  287. return getImgUrl(p);
  288. });