123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- var page = 1,
- pagesize = 10;
- var $tabs = $('#tabs'),
- $unassignedLink = $('#unassignedLink'), // 待分配配送员链接
- $unassignedNum = $('#unassigned_num'), // 待分配配送员数
- $panels = $('.c-panels'),//切换选项卡
- $list = $('#dest_list'),//选项卡内容
- $teamGroups = $('.lin-sel-group'),//团队数
- $notext = $('#no_result_wrap'),//没有样式
- $scroll = $('#iScroll');//内容展示
-
- var lastTeamId,//读取缓存
- teamInfo,
- docInfo,
- teamCode,//团队code
- state="",
- type = '', // type: 1 需跟踪; 2已接受
- hospital="",
- startDate="",
- endDate="",
- dispensaryType = ""; // 配送方式
- // 控制“订单跟踪页面”取药码的显示
- var isShowQuYaoCode = false;
- var isTeam = false; // 是否选择的是团队
- var expressageUrl = "/doctor/prescriptionInfo/getHDoctorPrescriptionExpressage"
- var filterUrl = "doctor/prescriptionInfo/getPrescriptionExpressageFilter"
- function setCurTeamName(){
- var $checked = $('.lin-sel-group li.checked');
-
- if($checked.attr('data-code')) {
- isTeam = true;
- isShowQuYaoCode = false;
- $tabs.html(template('tagTeamBar',{}))
- expressageUrl = "/doctor/prescriptionInfo/getDoctorPrescriptionExpressage";
- filterUrl = "doctor/prescriptionInfo/getPrescriptionExpressageAsdoctorFilter";
- teamCode = $checked.attr('data-code');
- type = '';
- $('.demo-comtop h1').html($checked.attr('data-name')+'续方订单 <label class="lin-down-arrow"></label>')
- } else {
- isTeam = false;
- isShowQuYaoCode = $checked.attr('data-type') == 1;
- $tabs.html(template('tagBar',{}))
- expressageUrl = "/doctor/prescriptionInfo/getHDoctorPrescriptionExpressage";
- filterUrl = "doctor/prescriptionInfo/getPrescriptionExpressageFilter";
- type = $checked.attr('data-type');
- teamCode = '';
- $('.demo-comtop h1').html($checked.attr('data-name')+' <label class="lin-down-arrow"></label>')
- }
-
- queryHeaderData(isTeam)
- }
- /**
- * 显示团队选择
- */
- var showGroupSel = function(e, isShow){
- isShow = isShow || $('.lin-mask:hidden').length != 0;
- $('.lin-mask').toggle(isShow);
- $('.lin-sel-group').toggle(isShow);
- }
- function queryHeaderData(isTeam){
- plus.nativeUI.showWaiting()
- sendPost(filterUrl,{}, null, function(res){
- if(res.status == 200){
- plus.nativeUI.closeWaiting()
- res.data.isTeam = isTeam;
- var html = template('tag_tmpl',{data:res.data})
- $('#showHeader').html(html)
- }
- },'get')
- }
- function queryListData(fun,text){
- var params ={
- type: type,
- teamCode:teamCode,
- state:state,
- hospital:hospital,
- dispensaryType: dispensaryType,
- startDate:startDate,
- endDate:endDate,
- page:page,
- size:pagesize
- }
- sendPost(expressageUrl,params, function(){
- plus.nativeUI.closeWaiting();
- fun&&fun.call(this,false)
- mui.toast("获取数据失败!");
- }, function(res){
- plus.nativeUI.closeWaiting();
- if(res.status == 200){
- var html = template('li_tmpl',{list:_.map(res.data,function(o){
- o.jsonStr = JSON.stringify(o);
- return o;})
- })
- if(page == 1 && res.data.length==0){
- $notext.show();
- $scroll.hide();
- }else{
- $notext.hide();
- $scroll.show();
- if(text == 'down'){
- // $('#dest_list').empty();
- // fun&&fun.call(this);
- }else{
- if(res.data.length < pagesize){
- fun&&fun.call(this,true)
- }else{
- fun&&fun.call(this,false)
- }
- }
- $('#dest_list').append(html);
- }
- }else{
- fun&&fun.call(this,false)
- mui.toast("获取数据失败!");
- }
- },'get')
- }
- template.helper('setSex',function(item){
- if(item == 1){
- return '男'
- }else{
- return '女'
- }
- })
- template.helper('dispensaryTypeName',function(type){
- if(type == 1){
- return '自取'
- } else if(type == 2){
- return '快递配送'
- } else if(type == 3){
- return '健管师配送'
- }
- return ''
- })
- //该上月份最后一天
- function lastDate(date){
- var arr = date.split('-');
- var year = arr[0];
- var month = arr[1]*1-1;
- if(month<1){
- month = 12;
- year = year - 1;
- }
- var day = new Date(year,month,0).getDate();
- return day;
- }
- //近一周
- function beforeWeek(date,num){
- var arr = date.split('-');
- var reduce = arr[2]*1-num;
- if(reduce>0){
- var sDate = arr[0]*1+'-'+arr[1]*1+'-'+reduce;
- return sDate;
- }else if(arr[1]*1 > 1){
- var sDate = arr[0]*1+'-'+(arr[1]*1-1)+'-'+(lastDate(date)+reduce);
- return sDate;
- }else{
- var sDate = (arr[0]*1-1)+'-12-'+(lastDate(date)+reduce);
- return sDate;
- }
- }
- //近几个月前
- function beforeMonth(date,num){
- var arr = date.split('-');
- var reduce = arr[1]*1-num;
- if(reduce>0){
- var sDate = arr[0]+'-'+reduce+'-'+arr[2];
- return sDate;
- }else{
- var sDate = (arr[0]*1-1)+'-'+(12+reduce*1)+'-'+arr[2];
- return sDate;
- }
- }
- // 显示待分配配送员链接
- function showUnssignedLink() {
- showUnssignedNum();
- var teamCode = $('.lin-sel-group li[data-code].checked').attr('data-code');
- if(docInfo.adminTeamCode == teamCode && docInfo.isLeader == "1") {
- $unassignedLink.show();
- } else {
- $unassignedLink.hide();
- }
- }
- // 显示待分配配送员数
- function showUnssignedNum() {
- var teamCode = $('.lin-sel-group li.checked').attr('data-code');
- sendPost("/doctor/prescriptionInfo/getCountExpressage",{
- teamCode: teamCode || ''
- }, function(){
- mui.toast("获取数据失败!");
- }, function(res){
- if(res.status == 200){
- $unassignedNum.text(res.data.count)
- }else{
- mui.toast("获取数据失败!");
- }
- },'get')
- }
- function bindEvents() {
- $tabs.on('click','.sanp-flex',function() {
- var index = $(this).index(),
- $panel = $panels.find('.c-panel').eq(index);
- $panel.siblings().hide();
- if($panel.css('display')=='none') {
- $panel.show();
- } else {
- $panel.hide();
- }
- })
-
- $panels.on('click','li',function() {
- var $panel = $(this).closest('.c-panel');
- $(this).siblings().removeClass('list-selected');
- $(this).addClass('list-selected');
- $panel.hide();
- $('.j-tag').eq($panel.index()).text($(this).find('a').text())
-
- if($panel.index() ==0){ state = $(this).attr('data-id') }
- if($panel.index() ==1){
- if(isTeam) {
- dispensaryType = $(this).attr('data-id');
- } else {
- hospital = $(this).attr('data-id');
- }
- }
- if($panel.index() ==2){
- var num = $(this).attr('data-id'),
- now = new Date();
- var day = now.getDate();
- var month = now.getMonth() + 1;
- var year = now.getFullYear();
- var date = year+'-'+month+'-'+day
- endDate = date;
- if(num == 1){
- startDate = beforeWeek(date,6);
- }else if(num == 2){
- startDate = beforeMonth(date,1);
- }else if(num == 3){
- startDate = beforeMonth(date,6);
- }else if(num == 4){
- startDate = beforeMonth(date,12);
- }else{
- startDate = '';
- }
- }
- reloadLessData()
- })
-
- //点击跳转
- $('#dest_list').on('tap','li',function(){
- var data = JSON.parse($(this).attr('data-json')),
- prescriptionCode = data.code;
-
- mui.openWindow({
- id: "dingdangenzong",
- url: "dingdangenzong.html",
- extras: {
- teamCode: teamCode?teamCode:$(this).attr('data-team'),
- prescriptionCode: prescriptionCode,
- isShowQuYaoCode: isShowQuYaoCode,
- selectType: isTeam?"team":""
- }
- })
- })
-
- $('.demo-comtop h1').on('tap', showGroupSel);
-
- $('.lin-mask').on('tap', showGroupSel);
-
- $teamGroups.on('click', 'li', function(){
- showGroupSel(undefined, false);
- if(!$(this).hasClass('checked')){
- $(this).addClass('checked').siblings().removeClass('checked');
- showUnssignedLink();
- }
- setCurTeamName();
- reloadPageData()//重新加载数据
- })
-
- $('#search_btn').click(function(){
- mui.openWindow({
- id: "searchxufangdingdan",
- url: "searchxufangdingdan.html",
- extras: {
- teamCode:teamCode,
- type:type
- }
- })
- })
- }
- //局部刷新
- function reloadLessData(){
- plus.nativeUI.showWaiting();
- page = 1;
- $('#dest_list').empty();
- queryListData();
- }
- //整体刷新
- function reloadPageData(){
- plus.nativeUI.showWaiting();
- page = 1;
- $('#dest_list').empty();
- queryListData();
- }
- function paramReset(){
- state='';hospital='';startDate='';endDate='';
- }
- new Promise(function(resolve, reject) {
- mui.plusReady(function() {
- var cur = plus.webview.currentWebview(),
- opener = cur.opener();
- if(opener.id == "querenjieshou") {
- mui.back = backToWebviewById("home2.html")
- }
- resolve(true);
- })
- }).then(function() {
- plus.nativeUI.showWaiting();
- //设置团队
- lastTeamId = plus.storage.getItem("selectedTeamId");
- teamInfo = JSON.parse(plus.storage.getItem("teamInfo"));
- docInfo = JSON.parse(plus.storage.getItem("docInfo"));
- $('.lin-sel-group').html(template('teams_tmpl', teamInfo));
-
- var index = 0;
- for(var i=0;i<teamInfo.data.length;i++){
- if(teamInfo.data[i].id == lastTeamId){
- index = i;
- }
- }
- $('.lin-sel-group li').eq(index).addClass('checked');
- setCurTeamName();
- showUnssignedLink();
- //请求头部数据
- queryHeaderData();
- }).then(function() {
- mui.init({
- pullRefresh : {
- container:'.mui-scroll-wrapper',
- // down : {
- // height:50,
- // auto: false,
- // contentdown : "下拉可以刷新",
- // contentover : "释放立即刷新",
- // contentrefresh : "正在刷新...",
- // callback: function() {
- // var self = this;
- // page = 1;
- // queryListData(function(value){
- // setTimeout(function(){
- // self.endPulldownToRefresh(false);
- // mui('.mui-scroll-wrapper').pullRefresh().enablePullupToRefresh();
- // },500)
- // },'down')
- // }
- // },
- up : {
- height:50,
- contentrefresh : "正在加载...",
- contentnomore:'没有更多数据了',
- callback: function() {
- var self = this;
- page++;
- queryListData(function(value){
- setTimeout(function(){
- self.endPullupToRefresh(value);
- },500)
- },'up')
- }
- }
- }
- })
- queryListData();
- bindEvents()
- })
|