b_index.js 5.67 KB
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
var bookOrder=require('../../utils/bookCommon.js')
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({
    data:{
        isloading:false,
        pagex:1,
        pagey:10,
        sort:null,
        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' }
        ],
        keywords:'',
        sort:'',
        form:{
            time:-1,
        }
    },
    sellerid:0,
    indexOpt:null,
    onLoad:function(opt){
        let d=new Date()/1000;
        let dateStr=util.unixtoTime(d,'MM-DD DAY');
        var radio=750/util.getsystem().windowWidth;
        var contentHeight=util.getsystem().windowHeight-Math.ceil(120/radio)
        if(opt.seller_id){
            this.sellerid=opt.seller_id;
            util.cache('sellerid',opt.seller_id)
            util.cache('enter_params',opt)
            App.Reserve.SellerInfo(opt).then(res=>{
                util.cache('sellerInfo',res.data)
            })
        }else{
            this.sellerid=util.cache('sellerid');
        }
        //this.sellerid=opt.seller_id ? opt.seller_id : util.cache('sellerid');
        this.setData({
            sellerid:this.sellerid,
            listHeight:contentHeight-Math.ceil(210/radio),
            dateStr:dateStr,
        })
        //util.setBarTitle('预定本');
        this.indexOpt=opt;
    },
    onShow:function(){
      this.setData({
          isloading:false,
      })
      this.getbooklist();
      this.selectComponent('#nav').init();
      setTimeout(()=>{
        this.setData({
          calendarMaskLoad:true,
        })
        let openid=getApp().openid;
        if(openid && this.indexOpt.seller_id){
          App.Reserve.SellerForOpenid({openid:openid,sedata:JSON.stringify(this.indexOpt)})
          //客户经理
          if(this.indexOpt.manager_id){
            App.Reserve.UpdateSellerUser({seat_openid:openid,kid:this.indexOpt.manager_id});
          }
        }else{
          console.log('index-opt',openid,this.indexOpt);
        }

      },1000);
    },
    async getbooklist(){
      let time=0;
      if(this.data.form.time<0){
        time=await bookOrder.getTimeSpaceIndex();
      }else{
        time=this.data.form.time;
      }
        var formdata={};
        if(this.data.sort!=''){
             formdata.sort=this.data.sort
        }
        if(this.data.keywords!=''){
            formdata.keywords=this.data.keywords
        }
        formdata.sid=this.sellerid;
        formdata.x=1;
        formdata.y=200;
        let rdate=await bookOrder.getTimeSpace(this.data.dateStr,time);
        formdata.rdate=rdate;
        var that=this;
        App.Reserve.GetReserveList(formdata).then(function(json){
                console.log(json)
                if(json.ret==200){
                    that.setData({
                        isloading:true,
                        bookList:json.data.length==0 ? null : json.data,
                        form:{time:time},
                    })
                    that.boolists=that.selectAllComponents('.orderbook');
                    that.boolists.forEach(function(v,i){
                        v.changeitem();
                    })
                }
        })
    },
    timeorder:function(){
        if(this.data.sort==''){
            this.data.sort=1;
        }else{
            this.data.sort='';
        }

        this.setData({
            sort:this.data.sort
        })
        this.getbooklist();
    },
    searchinput:function(e){
        this.data.keywords=e.detail.value;
        this.setData({
            keywords:this.data.keywords
        })
        if(e.detail.value==''){
            this.getbooklist();
        }
    },
    calendarShow(){
        console.log('xxxxx')
        this.setData({
            calendarMask:true
        })
        console.log(this.data.calendarMask)
    },
    dateChange(event){
      let cktime=util.timetouUnix(event.detail.year+'/'+event.detail.month+'/'+event.detail.day)
      let clickDay = event.detail.day;
      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
        })
    },
    selectedValue:function (e) {
        this.setData({
            form:{time:e.currentTarget.dataset.value}
        })
        this.getbooklist();
    },
    searchbook:function(e){
        console.log(this.data.form)
        this.getbooklist();
    },
  exportFile(){
    App.Reserve.ExportReserve().then(res=>{
      let url=res.data;
      wx.downloadFile({
        url: url,
        success: function(res) {
          const filePath = res.tempFilePath;
          console.log('filePath',filePath);
          wx.saveFile({
            tempFilePath: filePath,
            success (res) {
              const savedFilePath = res.savedFilePath;
              console.log('savedFilePath',savedFilePath);
              wx.openDocument({
                filePath: savedFilePath,
                fileType:'pdf',
                success: function(res) {
                  console.log('打开文档成功')
                },
                fail(e){
                  console.log('打开文档失败',e)
                },
              })
            }
          })

        }
      })
    });

  },
})