xufangdingdan.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. var page = 1,
  2. pagesize = 10;
  3. var $tabs = $('#tabs'),
  4. $unassignedLink = $('#unassignedLink'), // 待分配配送员链接
  5. $unassignedNum = $('#unassigned_num'), // 待分配配送员数
  6. $panels = $('.c-panels'),//切换选项卡
  7. $list = $('#dest_list'),//选项卡内容
  8. $teamGroups = $('.lin-sel-group'),//团队数
  9. $notext = $('#no_result_wrap'),//没有样式
  10. $scroll = $('#iScroll');//内容展示
  11. var teamInfo,
  12. docInfo,
  13. teamCode,//团队code
  14. state="",
  15. dispensaryType="",
  16. startDate="",
  17. endDate="";
  18. function setCurTeamName(){
  19. teamCode = $('.lin-sel-group li.checked').attr('data-code');
  20. $('.demo-comtop h1').html(($('.lin-sel-group li.checked').attr('data-name'))+'续方订单 <label class="lin-down-arrow"></label>');
  21. }
  22. /**
  23. * 显示团队选择
  24. */
  25. var showGroupSel = function(e, isShow){
  26. isShow = isShow || $('.lin-mask:hidden').length != 0;
  27. $('.lin-mask').toggle(isShow);
  28. $('.lin-sel-group').toggle(isShow);
  29. }
  30. function queryHeaderData(){
  31. sendPost("doctor/prescriptionInfo/getPrescriptionExpressageAsdoctorFilter",{}, null, function(res){
  32. if(res.status == 200){
  33. var html = template('tag_tmpl',{data:res.data})
  34. $('#showHeader').html(html)
  35. }
  36. },'get')
  37. }
  38. function queryListData(fun,text){
  39. var params ={
  40. teamCode:teamCode,
  41. state:state,
  42. dispensaryType:dispensaryType,
  43. startDate:startDate,
  44. endDate:endDate,
  45. page:page,
  46. size:pagesize
  47. }
  48. sendPost("/doctor/prescriptionInfo/getDoctorPrescriptionExpressage",params, function(){
  49. plus.nativeUI.closeWaiting();
  50. fun&&fun.call(this,false)
  51. mui.toast("获取数据失败!");
  52. }, function(res){
  53. plus.nativeUI.closeWaiting();
  54. if(res.status == 200){
  55. var html = template('li_tmpl',{list:_.map(res.data,function(o){
  56. o.jsonStr = JSON.stringify(o);
  57. return o;})
  58. })
  59. if(page == 1 && res.data.length==0){
  60. $notext.show();
  61. $scroll.hide();
  62. }else{
  63. $notext.hide();
  64. $scroll.show();
  65. if(text == 'down'){
  66. // $('#dest_list').empty();
  67. // fun&&fun.call(this);
  68. }else{
  69. if(res.data.length < pagesize){
  70. fun&&fun.call(this,true)
  71. }else{
  72. fun&&fun.call(this,false)
  73. }
  74. }
  75. $('#dest_list').append(html);
  76. }
  77. }else{
  78. fun&&fun.call(this,false)
  79. mui.toast("获取数据失败!");
  80. }
  81. },'get')
  82. }
  83. template.helper('setSex',function(item){
  84. if(item == 1){
  85. return '男'
  86. }else{
  87. return '女'
  88. }
  89. })
  90. template.helper('dispensaryTypeName',function(type){
  91. if(type == 1){
  92. return '自取'
  93. } else if(type == 2){
  94. return '快递配送'
  95. } else if(type == 3){
  96. return '健管师配送'
  97. }
  98. return ''
  99. })
  100. //该上月份最后一天
  101. function lastDate(date){
  102. var arr = date.split('-');
  103. var year = arr[0];
  104. var month = arr[1]*1-1;
  105. if(month<1){
  106. month = 12;
  107. year = year - 1;
  108. }
  109. var day = new Date(year,month,0).getDate();
  110. return day;
  111. }
  112. //近一周
  113. function beforeWeek(date,num){
  114. var arr = date.split('-');
  115. var reduce = arr[2]*1-num;
  116. if(reduce>0){
  117. var sDate = arr[0]*1+'-'+arr[1]*1+'-'+reduce;
  118. return sDate;
  119. }else if(arr[1]*1 > 1){
  120. var sDate = arr[0]*1+'-'+(arr[1]*1-1)+'-'+(lastDate(date)+reduce);
  121. return sDate;
  122. }else{
  123. var sDate = (arr[0]*1-1)+'-12-'+(lastDate(date)+reduce);
  124. return sDate;
  125. }
  126. }
  127. //近几个月前
  128. function beforeMonth(date,num){
  129. var arr = date.split('-');
  130. var reduce = arr[1]*1-num;
  131. if(reduce>0){
  132. var sDate = arr[0]+'-'+reduce+'-'+arr[2];
  133. return sDate;
  134. }else{
  135. var sDate = (arr[0]*1-1)+'-'+(12+reduce*1)+'-'+arr[2];
  136. return sDate;
  137. }
  138. }
  139. // 显示待分配配送员链接
  140. function showUnssignedLink() {
  141. showUnssignedNum();
  142. var teamCode = $('.lin-sel-group li.checked').attr('data-code');
  143. if(docInfo.adminTeamCode == teamCode && docInfo.isLeader == "1") {
  144. $unassignedLink.show();
  145. $scroll.css('top','135px')
  146. } else {
  147. $unassignedLink.hide();
  148. $scroll.css('top','80px')
  149. }
  150. }
  151. // 显示待分配配送员数
  152. function showUnssignedNum() {
  153. var teamCode = $('.lin-sel-group li.checked').attr('data-code');
  154. sendPost("/doctor/prescriptionInfo/getCountExpressage",{
  155. teamCode: teamCode
  156. }, function(){
  157. mui.toast("获取数据失败!");
  158. }, function(res){
  159. if(res.status == 200){
  160. $unassignedNum.text(res.data.count)
  161. }else{
  162. mui.toast("获取数据失败!");
  163. }
  164. },'get')
  165. }
  166. function bindEvents() {
  167. $tabs.on('click','.sanp-flex',function() {
  168. var index = $(this).index(),
  169. $panel = $panels.find('.c-panel').eq(index);
  170. $panel.siblings().hide();
  171. if($panel.css('display')=='none') {
  172. $panel.show();
  173. } else {
  174. $panel.hide();
  175. }
  176. })
  177. $panels.on('click','li',function() {
  178. var $panel = $(this).closest('.c-panel');
  179. $(this).siblings().removeClass('list-selected');
  180. $(this).addClass('list-selected');
  181. $panel.hide();
  182. $('.j-tag').eq($panel.index()).text($(this).find('a').text())
  183. if($panel.index() ==0){ state = $(this).attr('data-id') }
  184. if($panel.index() ==1){ dispensaryType = $(this).attr('data-id') }
  185. if($panel.index() ==2){
  186. var num = $(this).attr('data-id'),
  187. now = new Date();
  188. var day = now.getDate();
  189. var month = now.getMonth() + 1;
  190. var year = now.getFullYear();
  191. var date = year+'-'+month+'-'+day
  192. endDate = date;
  193. if(num == 1){
  194. startDate = beforeWeek(date,6);
  195. }else if(num == 2){
  196. startDate = beforeMonth(date,1);
  197. }else if(num == 3){
  198. startDate = beforeMonth(date,6);
  199. }else if(num == 4){
  200. startDate = beforeMonth(date,12);
  201. }else{
  202. startDate = '';
  203. }
  204. }
  205. reloadLessData()
  206. })
  207. //点击跳转
  208. $('#dest_list').on('tap','li',function(){
  209. var data = JSON.parse($(this).attr('data-json')),
  210. prescriptionCode = data.code;
  211. mui.openWindow({
  212. id: "dingdangenzong",
  213. url: "dingdangenzong.html",
  214. extras: {
  215. teamCode: teamCode,
  216. prescriptionCode: prescriptionCode
  217. }
  218. })
  219. })
  220. $unassignedLink.on('tap', function() {
  221. mui.openWindow({
  222. id: "daifenpei",
  223. url: "daifenpei.html",
  224. extras: {
  225. teamCode: teamCode
  226. }
  227. })
  228. });
  229. $('.demo-comtop h1').on('tap', showGroupSel);
  230. $('.lin-mask').on('tap', showGroupSel);
  231. $teamGroups.on('click', 'li', function(){
  232. showGroupSel(undefined, false);
  233. if(!$(this).hasClass('checked')){
  234. $(this).addClass('checked').siblings().removeClass('checked');
  235. setCurTeamName();
  236. showUnssignedLink();
  237. }
  238. reloadPageData()//重新加载数据
  239. })
  240. $('#search_btn').click(function(){
  241. mui.openWindow({
  242. id: "searchxufangdingdan",
  243. url: "searchxufangdingdan.html",
  244. extras: {
  245. teamCode:teamCode
  246. }
  247. })
  248. })
  249. }
  250. //局部刷新
  251. function reloadLessData(){
  252. plus.nativeUI.showWaiting();
  253. page = 1;
  254. $('#dest_list').empty();
  255. mui('.mui-scroll-wrapper').pullRefresh().refresh(true);//重置
  256. queryListData();
  257. }
  258. //整体刷新
  259. function reloadPageData(){
  260. plus.nativeUI.showWaiting();
  261. page = 1;
  262. recoverTag()
  263. $('#dest_list').empty();
  264. queryListData();
  265. }
  266. function paramReset(){
  267. state='';dispensaryType='';startDate='';endDate='';
  268. }
  269. //恢复选项卡
  270. function recoverTag(){
  271. $('.c-panel').find('li').removeClass('list-selected');
  272. $.map($('.c-panel'),function(o,i){
  273. var $li = $('.c-panel').eq(i).find('li').eq(0);
  274. $li.addClass('list-selected');
  275. $('.j-tag').eq(i).text($li.find('a').text())
  276. })
  277. paramReset()
  278. }
  279. new Promise(function(resolve, reject) {
  280. mui.plusReady(function() {
  281. resolve(true);
  282. })
  283. }).then(function() {
  284. plus.nativeUI.showWaiting();
  285. //设置团队
  286. teamInfo = JSON.parse(plus.storage.getItem("teamInfo"));
  287. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  288. $('.lin-sel-group').html(template('teams_tmpl', teamInfo));
  289. var index = 0;
  290. for(var i=0;i<teamInfo.data.length;i++){
  291. // 默认显示其担任团队长的团队列表
  292. if(teamInfo.data[i].leaderCode == docInfo.adminTeamCode){
  293. index = i;
  294. }
  295. }
  296. $('.lin-sel-group li').eq(index).addClass('checked');
  297. setCurTeamName();
  298. showUnssignedLink();
  299. //请求头部数据
  300. queryHeaderData();
  301. }).then(function() {
  302. mui.init({
  303. pullRefresh : {
  304. container:'.mui-scroll-wrapper',
  305. // down : {
  306. // height:50,
  307. // auto: false,
  308. // contentdown : "下拉可以刷新",
  309. // contentover : "释放立即刷新",
  310. // contentrefresh : "正在刷新...",
  311. // callback: function() {
  312. // var self = this;
  313. // page = 1;
  314. // queryListData(function(value){
  315. // setTimeout(function(){
  316. // self.endPulldownToRefresh(false);
  317. // mui('.mui-scroll-wrapper').pullRefresh().enablePullupToRefresh();
  318. // },500)
  319. // },'down')
  320. // }
  321. // },
  322. up : {
  323. height:50,
  324. contentrefresh : "正在加载...",
  325. contentnomore:'没有更多数据了',
  326. callback: function() {
  327. var self = this;
  328. page++;
  329. queryListData(function(value){
  330. setTimeout(function(){
  331. self.endPullupToRefresh(value);
  332. },500)
  333. },'up')
  334. }
  335. }
  336. }
  337. })
  338. queryListData();
  339. bindEvents()
  340. })
  341. window.addEventListener("refreshPage", function(e) {
  342. plus.webview.getWebviewById("xufangdingdan").reload(true);
  343. });