b_desk.js 2.27 KB
import util from '../../utils/util';
import comm from '../../utils/bookCommon';
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({
    data:{
      menu_active_id:''
    },
    checked_tids:[],
    onLoad:function(opt){
        console.log('onLoad',opt)
        util.setBarTitle('选择桌位');
        var radio=750/util.getsystem().windowWidth;
        var contentHeight=util.getsystem().windowHeight-Math.ceil(350/radio);
        if(opt.tid==0){
            delete opt.tid
        }
        if(opt.checked_tids){
            this.checked_tids=opt.checked_tids.split(',')
            util.cache('tableid',this.checked_tids)
        }
        this.setData({
            sellerid:util.cache('sellerid'),
            opt:opt,
            hasCheckedTable:this.checked_tids.length>0
        })
        this.getdesklist();
    },
    onShow:function(){
        this.setData({
          height:getApp().system.windowHeight-55
        })
    },
    changedesk:function(e){
        let tableid=util.cache('tableid');
        this.checked_tids= tableid && tableid.length>0?tableid:[];
        this.setData({
           hasCheckedTable:this.checked_tids.length>0
        })
    },
    back:function(){
        this.setData({
            buttonClick:true
        })
        //wx.removeStorage({key:'tableid'})
        wx.navigateBack();
    },
    getdesklist:function(){
        var formdata=this.data.opt;
        formdata.sid=this.data.sellerid;
        var that=this;
        App.Reserve.GetTableList(formdata).then(function (json) {
            if(json.ret==200){
                console.log('this.checked_tids',that.checked_tids);
                if(json.data.length>0){
                    json.data.forEach(function(v,i){
                        v.list.forEach(function(r,n){
                            r.isselect=false
                            if(that.checked_tids._indexOf(r.id)>-1){
                                r.isselect=true;
                            }
                        })
                    })
                }
                that.setData({
                    desklist:json.data,
                  menu_active_id:json.data[0].name
                })
            }
        })
    },
  switchMenu(e){
    this.setData({
      menu_active_id:util.attr(e,'id')
    })
  },
})