b_setting.js 5.84 KB
// pages/book/b_setting.js
var util = require('../../utils/util.js')
var bookOrder=require('../../utils/bookCommon.js')
import App from '../../utils/api';
const {regeneratorRuntime} = global

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dateStr:'',
    calendarMaskLoad:false,
    calendarMask:false,
    dayStyle:[
      { month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5' },
      { month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5' }
    ],
    regions:[],
    regions_active:'',
    time:-1,
    speciallist:[],
    calendar:{
      nextNum:0,
    },
    rdate:'',
  },
  regions:[],
  sellerid:0,
  timePickerArray:[
    [],
    [],
    [],
  ],
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    let d=new Date()/1000;
    let dateStr=util.unixtoTime(d,'MM-DD DAY');
    let timePickerArray= await bookOrder.getDayTimeSpace();
    let speciallist=[
      { date: util.unixtoTime(d,'YYYY-MM-DD'), background: '', text:'今 天' },
      { date: util.unixtoTime(d+86400,'YYYY-MM-DD'), background: '', text: '明 天'  },
      { date: util.unixtoTime(d+86400*2,'YYYY-MM-DD'), background: '', text: '后 天' },
    ];
    this.setData({
      dateStr:dateStr,
      timePickerArray:timePickerArray,
      speciallist:speciallist,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
   onShow: async function () {
    this.setData({
      height:getApp().system.windowHeight-170,
    })
    setTimeout(()=>{
      this.setData({
        calendarMaskLoad:true,
      })
    },1000);
    this.selectComponent('#nav').init();
    this.sellerid=util.cache('sellerid');
    App.Tables.GetTableListsBySellerId({
      sellerid:this.sellerid
    }).then((res)=>{
      this.regions=res.data[0];
      this.getbooklist();
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  calendarShow(){
    console.log('xxxxx')
    this.setData({
      calendarMask:true
    })
    console.log(this.data.calendarMask)
  },
  dateChange(event){
    let cktime=util.timetouUnix(event.detail.date)
    let day0=parseInt(new Date(new Date().setHours(0, 0, 0, 0)) / 1000);
    // if(cktime<day0){
    //   util.toast('请选择今天之后的日期','none');
    //   return;
    // }
    let clickDay = event.detail.date.substr(8,2);
    let changeDay = `dayStyle[1].day`;
    let changeBg = `dayStyle[1].background`;
    this.setData({
      dateStr:util.unixtoTime(cktime,'MM-DD `DAY/周WW`'),
      [changeDay]: clickDay,
      [changeBg]: "#84e7d0",
    })

    this.getbooklist();
    this.calendarClose();
  },
  calendarClose(){
    this.setData({
      calendarMask:false
    })
  },
  async getbooklist(){
    let obj={};

    let formdata={};
    formdata.sid=this.sellerid;
    formdata.x=1;
    formdata.y=200;
    let time=0;
    if(this.data.time<0){
      let sid=await bookOrder.getTimeSpaceIndexData();
      time=sid.timeIndex
      obj.time=time;
    }else{
      time=this.data.time;
    }
    let rdate=await bookOrder.getTimeSpace(this.data.dateStr,time);
    formdata.rdate=rdate;
    formdata.status='1,2';
    obj.rdate=rdate;
    let tids={};
    let reserves=await App.Reserve.GetReserveList(formdata);
    if(reserves.data.length>0){
      reserves.data.forEach(r=>{
        let ts=r.tid.split(',');
        ts.forEach(tid=>{
          let rname='';
          if(r.sex==3){
            rname=r.rname.substr(0,10)
          }else{
            rname=r.rname.substr(0,1)+(r.sex==1?'先生':'女士')
          }
          tids[tid]={
            rdate:r.rdate,
            id:r.id,
            status:r.status,
            rname:rname,
          }
        })
      })
    }
    console.log('tids',tids);
    let regions=[];
    this.regions.forEach(region=>{
      if(region.list.length>0){
        let list_num=0;
        region.list.forEach(tb=>{
          tb.status_str='';
          tb.status_classname='enabled'
          tb.reserve_name=''
          tb.reserve_id=''
          if(tb.status!=0 && tb.status!=""){
            tb.status_str='用餐中';
            tb.status_classname='highlight';
            tb.reserve_name=tb.spell==1?'拼桌':'堂食';
          }else if(tids[tb.id]){
            console.log('tids',region.name,tb.name);
            tb.status_str=tids[tb.id].status==2?'用餐中':'已预订';
            tb.status_classname='highlight';
            tb.reserve_id=tids[tb.id].id;
            tb.reserve_name=tids[tb.id].rname;
          }
          if(tb.enable!=1){
            if(tb.status_str){
              tb.status_classname='disabled-highlight';
            }else{
              tb.status_str='已停用';
              tb.status_classname='disabled';
            }
          }
          if(!tb.status_str){
            list_num++;
          }
          region.list_num=list_num;
        })
        regions.push(region);
      }
    })
    obj.regions=regions
    if(!this.data.regions_active){
      obj.regions_active=this.regions[0].name
    }
    this.setData(obj)
  },
  chooseRegion(e){
    this.setData({
      regions_active:util.attr(e,'name')
    })
  },
  selectedValue(e){
    this.setData({
      time:util.attr(e,'value')
    })
    this.getbooklist();
  },
  boardEvent(e){
    console.log(e);
    App.Tables.GetTableListsBySellerId({
      sellerid:this.sellerid
    },true).then((res)=>{
      this.regions=res.data[0];
      this.getbooklist();
    })
  },
  gotoday(e){
    this.setData({
      [`calendar.nextNum`]:0
    })
  },
  nextMonth(e){
    this.setData({
      [`calendar.nextNum`]:this.data.calendar.nextNum+1
    })
  },
  prevMonth(e){
    this.setData({
      [`calendar.nextNum`]:this.data.calendar.nextNum-1
    })
  },
})