// order.js
const app = getApp(),
  { hostname, business_id } = app.globalData,
  users_id = wx.getStorageSync('users_id')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    empty_box: {
      tips_img: 'https://ypx.shenmikj.com/canyin/Uploads/canyin/box_green.png',
      tips_word: '暂无订单',
      tips_btn: '返回首页'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

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

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '餐饮行业展示案例',
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
      },
    }
  },

  // 获取订单列表
  getOrderList() {
    let that = this
    wx.request({
      url: hostname + 'Order/get_order_list',
      data: {
        business_id,
        users_id,
        page: this.data.page
      },
      header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' },
      method: 'POST',
      dataType: 'JSON',
      success: (res) => {
        let orderList = JSON.parse(res.data).data
        that.setData({ orderList: orderList ? orderList:[] })
      },
      fail: (res) => { },
      complete: (res) => { },
    })
  },

  __emptyAction(){
    wx.switchTab({
      url: '../index/index',
    })
  }
})