// index.js
var app = getApp()
Page({
  data: {
    userId : '',
    userInfo: {},
    phone:'',
    orderList:{
      label:'我的采购订单',
      summary:"全部",
      state:"",
      icon:"icon-left",
      data:[
        {
          label:"待付款",
          state:"1",
          icon:"icon-icon-test",
          num:0,
        },
        {
          label: "待发货",
          state: "3",
          icon: "icon-daifahuo1",
          num: 0,
        },
        {
          label: "待收货",
          state: "4",
          icon: "icon-daishouhuo",
          num: 0,
        }
      ]
    },
    madeList: {
      label: '我的定制订单',
      summary: "全部",
      state: "",
      icon: "icon-left",
      data: [
        {
          label: "待付款",
          state: "",
          icon: "icon-icon-test",
          num: 0,
        },
        {
          label: "待发货",
          state: "",
          icon: "icon-daifahuo1",
          num: 0,
        },
        {
          label: "待收货",
          state: "",
          icon: "icon-daishouhuo",
          num: 0,
        }
      ]
    },
  },

  onLoad: function () {
    var that = this;
    var openid = getApp().globalData.openid;
    var un_id = getApp().globalData.un_id;
    var host = getApp().globalData.servsers;
    wx.showNavigationBarLoading();

    wx.request({
      url: host + "phoneapi/phoneall",
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        'Accept': 'application/json'
      },
      success: function (res) {
        that.setData({
          phone: res.data.rows[0].phone,
        });
        if (res == null || res.data == null) {
          console.error('网络请求失败');
          return;
        }
        wx:wx.hideNavigationBarLoading(
          that.setData({
            hidden : ''
          })
        )
      }
    });

    that.setData({
      userInfo: getApp().globalData.userInfo,
      userId: getApp().globalData.un_id
    })
 
  },

  //重新加载
  onShow: function () {
    var that = this;
    var host = getApp().globalData.servsers;
    var un_id = getApp().globalData.un_id;
    var openid = getApp().globalData.openid;
    var userInfo = getApp().globalData.userInfo;
    var userRole = getApp().globalData.userRole;

    // if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
    //   wx.navigateTo({
    //     url: '/pages/authorize/authorize?link=mine',
    //   })
    // } else {

      userInfo = getApp().globalData.userInfo;
      
      //查询用户身份
    //   getApp().getUserRole(un_id);//获取用户角色
    //   userRole = getApp().globalData.userRole;
    // }
    that.setData({
      userInfo: userInfo,
      userId: un_id,
      userRole: userRole
    })
  },
  orderList(e){
    console.log(e,"orderList")
    let state = e.currentTarget.dataset.state
    wx.navigateTo({
      url: '/newsShop/pages/orderList/orderList?state' + state,
    })
  }

})