r_index.js 12.2 KB
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
var bookOrder=require('../../utils/bookCommon.js')
Page({
    data:{
       selectList:[
           {
               type:'days',
               title:'日报',
               isactive:true
           },
           {
               type:'week',
               title:'周报',
               isactive:false
           },
           {
               type:'month',
               title:'月报',
               isactive:false
           },
           {
               type:'',
               title:'更多',
               isactive:false
           }
       ],
        selectdim:'days',
        page:1,
        success:false
    },
    onLoad:function(){
        util.setBarTitle('经营报表');
        var currentTime=Date.parse(new Date());
        var beforeTime=currentTime-24*60*60*1000;
        var todayobj=bookOrder.changedate(currentTime);
        var yesterobj=bookOrder.changedate(beforeTime);
        var radio=750/util.getsystem().windowWidth;
        this.setData({
            sellerid:util.cache('sellerid'),
            todayobj:todayobj,
            yesterobj:yesterobj,
            contentHeight:util.getsystem().windowHeight-Math.ceil(100/radio),
            radio:radio
        })
        this.getreportlist();
    },
    onShow:function(){
        if(util.cache('date')){
            wx.removeStorage({
                key:'date',
            })
        }
        if(util.cache('time')){
            wx.removeStorage({
                key:'time',
            })
        }
        var that=this;
        util.postSuccessFun=function(json,uri_code) {
            switch (uri_code) {
                case uri.CGI_USER_GETOPERDATEBYDAY__CODE:
                     console.log(json)
                    if(json.ret==200 && json.data){
                         var list=json.data;
                         var reportlist=[];
                         var date,dd;
                         var i=0;
                         for(var key in list){
                             var daymask='';
                             i++;
                             if(that.data.selectdim=='days'){
                                 date=bookOrder.getdate_num(key.split('-')[1]+'-'+key.split('-')[2]);
                                 var thisdate=key+' 12:00:00';
                                 var timestamp=bookOrder.gettimestamp(thisdate);
                                 var myDate = new Date(timestamp*1000);
                                 dd=bookOrder.changedate(timestamp*1000);
                                 if(dd.day==that.data.todayobj.day){
                                     daymask='今天'
                                 }
                                 if(dd.day==that.data.yesterobj.day){
                                     daymask='昨天'
                                 }else if(dd.day!=that.data.todayobj.day && dd.day!=that.data.yesterobj.day){
                                     daymask=bookOrder.getweek(myDate.getDay());
                                 }
                             }
                             if(that.data.selectdim=='week'){
                                 // if(!that.data.reportlist){
                                 //     if(i==1){
                                 //         daymask='本周'
                                 //     }
                                 //     if(i==2){
                                 //         daymask='上周'
                                 //     }
                                 // }
                                 date=key;
                             }
                             if(that.data.selectdim=='month'){
                                 var arr=key.split('.');
                                 date=arr[0]+'年'+arr[1]+'月';
                             }
                             if(list[key]!=''){
                                 reportlist.push({
                                     date:date,
                                     total_order:list[key].total_order,
                                     unit_price:Number(list[key].unit_price).toFixed(2),
                                     total_pnum:list[key].total_pnum,
                                     total_price:list[key].total_price,
                                     daymask:daymask!='' ? daymask : null,
                                     dateall:key,
                                     totaldate:that.data.selectdim=='days' ? dd.year+'年'+date : null
                                 })
                             }else{
                                 reportlist.push({
                                     date:date,
                                     daymask:daymask,
                                     dateall:key,
                                     totaldate:dd.year+'年'+date
                                 })
                             }
                         }
                        var len=reportlist.length;
                        var node;
                        if(that.data.selectdim=='days'){
                            var arr=reportlist[len-1].dateall.split('-');
                            node=arr[0]+arr[1]+arr[2]
                        }else{
                            if(that.data.selectdim=='week'){
                                var arr=reportlist[len-2].dateall.split('-');
                                var begin=arr[0].split('.');
                                node='';
                                if(begin[1][0]==0){
                                    if(begin[1][1]==1){
                                       node=Number(begin[0])-1+'-'+12
                                    }else{
                                        node=begin[0]+'-'+'0'+(Number(begin[1][1])-1)
                                    }
                                }else{
                                    if(begin[1][1]==0){
                                        node=begin[0]+'-'+'0'+9
                                    }else{
                                        node=begin[0]+'-'+(Number(begin[1])-1)
                                    }
                                }
                            }else{
                                var arr=reportlist[len-1].dateall.split('.');
                                node='';
                                if(arr[1][0]==0){
                                    if(arr[1][1]==1){
                                        node=Number(arr[0])-1+''+12
                                    }else{
                                        node=arr[0]+'0'+(Number(arr[1][1])-1)
                                    }
                                }else{
                                    if(arr[1][1]==0){
                                        node=arr[0]+'0'+9
                                    }else{
                                        node=arr[0]+''+(Number(arr[1])-1)
                                    }
                                }
                            }
                        }

                        console.log(node)
                        that.setData({
                            reportlist:that.data.reportlist ? that.data.reportlist.concat(reportlist) : reportlist,
                            node:node,
                            ifnode:reportlist[len-1].dateall,
                            page:that.data.page+1,
                            success:true
                        })
                    }
                break;
            }
        }
    },
    getreportlist:function () {
        console.log('xxxxx')
       util.post(uri.CGI_USER_GETOPERDATEBYDAY,{sid:this.data.sellerid,dim:this.data.selectdim},uri.CGI_USER_GETOPERDATEBYDAY__CODE)
    },
    selectdate:function(e){
        var type=e.currentTarget.dataset.type;
        var selectList=this.data.selectList;
        selectList.forEach(function (v,i) {
            v.isactive=false
            if(v.type==type){
                v.isactive=true
            }
        })
        this.setData({
            selectList:selectList,
            selectdim:type,
            reportlist:null,
            page:1,
            complete:null
        })
        this.getreportlist();
    },
    morelist:function(e){
        if(this.data.selectdim=='days'){
            var thistime=this.data.ifnode+' 23:59:59';
            var thisstamp=bookOrder.gettimestamp(thistime);
            var singlebroll=Math.ceil(1800/this.data.radio);
            if(this.data.success==true){
                if(e.detail.scrollTop>singlebroll*this.data.page){
                    if(thisstamp>Number(util.cache('cdate'))) {
                        util.post(uri.CGI_USER_GETOPERDATEBYDAY, {
                            sid: this.data.sellerid,
                            dim: this.data.selectdim,
                            node: this.data.node
                        }, uri.CGI_USER_GETOPERDATEBYDAY__CODE)
                        this.setData({
                            success: false
                        })
                    }else{
                        this.setData({
                            complete:true
                        })
                    }
                }
            }
        }else{
            if(this.data.selectdim=='week') {
                var singlebroll = Math.ceil(800/ this.data.radio);
                var loginobj=bookOrder.changedate(Number(util.cache('cdate')*1000));
                var node=this.data.node;
                var nodearr=node.split('-');
                if (this.data.success == true) {
                    if (e.detail.scrollTop > singlebroll * this.data.page) {
                        if(loginobj.year<=nodearr[0]) {
                            var nodemonth=nodearr[1][0]==0 ? Number(nodearr[1][1]) : Number(nodearr[1])
                            if(loginobj.month<=nodemonth){
                                util.post(uri.CGI_USER_GETOPERDATEBYDAY, {
                                    sid: this.data.sellerid,
                                    dim: this.data.selectdim,
                                    node: this.data.node
                                }, uri.CGI_USER_GETOPERDATEBYDAY__CODE)
                                this.setData({
                                    success: false
                                })
                            }else{
                                this.setData({
                                    complete:true
                                })
                            }

                        }
                    }else{
                        this.setData({
                            complete:true
                        })
                    }

                }
            }else{
                var singlebroll = Math.ceil(600/ this.data.radio);
                var loginobj=bookOrder.changedate(Number(util.cache('cdate')*1000));
                var node=this.data.node;
                console.log(e.detail.scrollTop,singlebroll * this.data.page)
                if (this.data.success == true) {
                    if (e.detail.scrollTop > singlebroll * this.data.page) {
                        var logintime=loginobj.year+''+(loginobj.month<10 ? '0'+loginobj.month : loginobj.month);
                        if(logintime<=node){
                            util.post(uri.CGI_USER_GETOPERDATEBYDAY, {
                                sid: this.data.sellerid,
                                dim: this.data.selectdim,
                                node: this.data.node
                            }, uri.CGI_USER_GETOPERDATEBYDAY__CODE)
                            this.setData({
                                success: false
                            })
                        }else{
                            this.setData({
                                complete:true
                            })
                        }

                    }
                }
            }
        }


    },
    lookdetail:function(e){
        var item=e.currentTarget.dataset.item;
        var path='/pages/report/r_detail?selectdim='+this.data.selectdim;
        for(var key in item){
            if(item[key]){
                path+='&'+key+'='+item[key]
            }
        }
        console.log(path)
        wx.navigateTo({
            url:path
        })
    },
    netchange:function(){
        this.onShow();
    }
})