o_list.js 7.03 KB
//logs.js
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
import App from '../../utils/api.js'
Page({
    data: {
        statuslist:[
			{
				name:'已下单',
				status:1,
			},
			{
				name:'配送中',
				status:2,
			},
			{
				name:'已完成',
				status:3,
			},
			{
				name:'已退款',
				status:4,
			},
		],
		statusidx:0,
		
    },
    onLoad:function(opt){
        console.log(opt);
		let systeminfo=util.cache('system.info');
		let ratio=750/systeminfo.windowWidth;
		this.setData({
			contentHeight:systeminfo.windowHeight-util.cache('headerHeight')-130/ratio,
			headerHeight:util.cache('headerHeight')
		})
    },
    onShow:function(){
		this.hasmore=true;
        this.page=0;
		this.setData({
			orderlist:[]
		})
        this.getlist(this.page);
    },
    typelink:function(e){
        var _id = e.target.dataset.id
        var typelistData = this.data.typelistData
        typelistData.map(function(r,n){
            if(r.id==_id){
                r.style="active"
            }else{
                r.style=""
            }
        })
        this.setData({
            classid:_id,
            order:_id,
            typelistData:typelistData,
            type:_id,
            bill:null,
            reduce:null,
            time:1
        })
        this.orderlist();
    },
    //反结账
    moreTypeCount:function(e){
        if(util.powercontro('反结账')==false){
            this.alert.show('您暂没有权限进行反结账')
        }else{
            this.setData({
                atn_ishidden:false,
                moreHidden:true,
                currentid:e.currentTarget.dataset.id,
                auto_focus:true,
            })
        }
    },
    //反结账输入原因
    ModalInput:function(e){
        var inputval=''
        if(e.detail.keyCode==32){
            inputval=e.detail.value.slice(0,-1)
        }else{
            inputval=e.detail.value;
        }
        this.setData({
            reasonInput:inputval
        })
    },
    //确定反结账
    ConfirmModel:function(){
        if(this.data.reasonInput!=''){
            util.post(uri.CGI__USER_BACKORDERPAY,{orderid:this.data.currentid,back_desc:this.data.reasonInput},uri.CGI__USER_BACKORDERPAY__CODE)
        }else{
            wx.showModal({
                content:'请输入反结账原因',
                showCancel:false,
                confirmColor:'#199095',
                success:function(){

                }
            })
        }

    },
    //取消反结账
    CancelModel:function(){
        this.setData({
            atn_ishidden:true,
            reasonInput:''
        })
    },
    orderlist:function () {
        util.post(uri.CGI__USER_ORDERLISTS,{sellerid:this.data.sellerid,type:this.data.order,time:this.data.time},uri.CGI__USER_ORDERLISTS__CODE)
    },
    timeSearch:function(e){
        this.setData({
            time:e.currentTarget.dataset.time,
            typelistData:this.data.typelistData
        })
        this.orderlist();
    },
    formSubmit:function(e){
        var formdata=e.detail.value;
        console.log(e.detail.value)
        var type=this.data.order;
        formdata.type=type;
        console.log(formdata)
        util.post(uri.CGI__USER_ORDERSERCH,{sellerid:this.data.sellerid,type:formdata.type,keyword:e.detail.value.keyword},uri.CGI__USER_ORDERSERCH__CODE)
    },
    bindPickerChange:function(e){
        console.log(e)
        console.log(this.data.order)
        var _id=e.currentTarget.dataset.id;
        var typelistData = this.data.typelistData;
        var keyword=parseInt(e.detail.value)+1;
        console.log(keyword)
        typelistData.map(function(r,n){
            if(r.id==_id){
                r.style="active"
            }else{
                r.style=""
            }
        })
        this.setData({
            order:3,
            typelistData:typelistData,
            time:4,
            keyword:keyword
        })
        util.post(uri.CGI__USER_ORDERSERCH,{sellerid:this.data.sellerid,type:3,keyword:keyword},uri.CGI__USER_ORDERSERCH__CODE)
     },
//  退菜
    reduceCook:function(e){
       if(util.powercontro('退菜')==false){
          this.alert.show('您暂没有权限退菜')
       }else{
           wx.navigateTo({
               url:'o_detail?id='+e.currentTarget.dataset.id+'&status='+e.currentTarget.dataset.status+'&reduce=1'
           })
       }
    },
    moreAction:function(e){
        console.log(e)
        var target=e.currentTarget.dataset
        this.setData({
            currentStatus:target.status,
            currentId:target.id,
            currentTableid:target.tableid,
            moreHidden:false,
            currentBack:target.back
        })
    },
    closeMore:function(){
        this.setData({
            moreHidden:true
        })
    },
    //订单详情
    orderDetail:function(e){
        wx.navigateTo({
            url:'o_detail?id='+e.currentTarget.dataset.id+'&status='+e.currentTarget.dataset.status
        })
    },
    netchange:function(){
        this.onShow();
    },
	getlist(page){
		App.Orders.GetOrderBySellerid({openid:util.cache('openid'),page:page,size:10,sellerid:util.cache('sellerid'),status:this.data.statusidx+1}).then((json)=>{
			console.log(json)
			if(json.ret==200 && json.data){
				json.data.forEach((v,i)=>{
					v.showdate=util.unixtoTime(v.cdate,'YYYY/MM/DD HH:II');
					v.sdate=util.unixtoTime(v.sd_time.split('-')[0],'YYYY/MM/DD HH:II')
					v.edate=util.unixtoTime(v.sd_time.split('-')[1],'YYYY/MM/DD HH:II');
				})
				let orderlist=this.data.orderlist ? this.data.orderlist.concat(json.data) : json.data;
				if(json.data.length<10){
					console.log('yyyyy')
					this.hasmore=false;
				}
				this.setData({
					orderlist:orderlist
				})
			}
		})
	},
	getnext(){
		console.log('rrrrr');
		if(this.hasmore){
			this.page+=1;
			this.getlist(this.page);
		}
		
	},
	selectstatus(e){
		let statusidx=e.currentTarget.dataset.index;
		this.setData({
			statusidx:statusidx,
			orderlist:[]
		})
		this.hasmore=true;
		this.page=0;
		this.getlist(this.page);
	},
	lookdetail(e){
		let orderidx=e.currentTarget.dataset.index;
		let id=e.currentTarget.dataset.id;
		wx.navigateTo({
			url:'./o_detail?id='+id+'&orderidx='+orderidx
		})
	},
	setorder(e){
		let status=e.currentTarget.dataset.status;
		let id=e.currentTarget.dataset.id;
		let idx=e.currentTarget.dataset.index;
		wx.showModal({
			content:'订单是否'+(status==2 ? '开始配送' : '配送完成')+',一旦修改不可撤回',
			confirmColor:'#199095',
			cancelColor:'#999999',
			success:(res)=>{
				if(res.confirm){
					App.Orders.SetOrderById({orderid:id,status:status}).then((json)=>{
						if(json.ret==200){
							 wx.showToast({
								 title:'订单'+this.data.orderlist[idx].row_num+(status==2 ? '已开始配送' : '已完成配送'),
								 duration:1500,
								 mask:true,
								 icon:'none'
							 })
							 let orderlist=this.data.orderlist.slice(0,Math.floor(idx/10)*10);
							 this.setData({
								orderlist:orderlist 
							 })
							 this.getlist(Math.floor(idx/10)); 
							// this.getorderinfo();
						}
					})
				}
			}
		})
		
	},
})