success.js 2.99 KB
// pack-cookbook/pages/success.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({

  /**
   * 页面的初始数据
   */
  data: {
    moreDisplay:false,
    detail:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      options:options
    })
	console.log('success',options)
    this.initOrder()
    this.getDetail()
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let options={...this.data.options,hasOnlyShow:1};
    delete options.hasSuccess
    return {
      title:'菜品已点好,快来看看都点了什么~',
      path:util.http_build_query(options,'/pack-cookbook/pages/success'),
      imageUrl:'http://nosqn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148571.jpg',
    }
  },

  initOrder(){
    App.Advance.CreateOrder({
      rid: this.data.options.rid,
      identity:this.data.options.identity,
      status:1,
    }).then(res => {
      res.data.cdateStr=util.unixtoTime(res.data.cdate,'YYYY-MM-DD')
      let cookbooklist={};
      let i=0;
      let moreDisplay=true;
      res.data.cookbooklist.forEach(ck=>{
        if(!cookbooklist[ck.classid]){
          cookbooklist[ck.classid]={'name':ck.class_name,list:[],moreDisplay:moreDisplay}
        }
        ck.moreDisplay=moreDisplay
        cookbooklist[ck.classid].list.push(ck)
        i++;
        if(i>=4){
          moreDisplay=false;
        }
      })
      res.data.booklist=cookbooklist;
      this.setData({
        order: res.data,
      })
    })
  },
  moreDisplay(){
    this.setData({
      moreDisplay:!this.data.moreDisplay
    })
  },
  gotoEditor(){
    let options={...this.data.options,sid:this.data.order.sellerid};
    delete options.hasSuccess
    wx.redirectTo({
      url: util.http_build_query(options,'./index')
    })
  },
  getDetail(fouce=false){
    App.Reserve.Detail({
      rid: this.data.options.rid,
      openid: getApp().openid
    },fouce).then(res => {
      this.setData({
        detail:this.formatDatail(res.data)
      })
    })
  },
  formatDatail(detail){
    detail.rdateStr=util.unixtoTime(detail.ddate,'MM月DD日 WW HH:II');
    detail.tableSubInfo=[];
    detail.tables.forEach(t=>{
      detail.tableSubInfo.push(t.name);
    })
    detail.tableSubInfo=detail.tableSubInfo.join('、')
    return detail;
  },
  navEvent(){
    wx.navigateBack(2);
  },
})