xufangdingdan-jg.js 9.5 KB

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