xufangguanli.js 8.5 KB

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