// pages/user/user.js
let method = require("../../utils/reuqest.js")
Page({
  data: {
    userData: '',
    vip: '',
    orderList: [{
      url: '/images/05-01/moban.png',
      text: '待付款'
    }, {
      url: '/images/05-01/daipeisong.png',
      text: '待发货'
    }, {
      url: '/images/05-01/peisong.png',
      text: '待收货'
    }, {
      url: '/images/05-01/daipingjia.png',
      text: '待评价'
    }],
    serveList: [{
      url: '/images/05-01/huiyuan.png',
      text: '我的会员'
    }, {
      url: '/images/05-01/address.png',
      text: '收货地址'
    }, {
      url: '/images/05-01/cart.png',
      text: '优惠券'
    }, {
      url: '/images/05-01/shouhou.png',
      text: '退款售后'
    }, {
      url: '/images/05-01/kefu.png',
      text: '在线客服'
    }, {
      url: '/images/05-01/shoucang.png',
      text: '我的收藏'
    }, {
      url: '/images/05-01/user.png',
      text: '关于我们'
    }]
  },
  //用户信息
  getUserInfo() {
    method.getRequest("/myUser/queryUserInfo", data => {
      if (data.statusCode == 0) {
        this.setData({
          userData: data.data
        })
      }
    })
  },
  //全部订单
  mainOrder() {
    wx.navigateTo({
      url: '/pages/all-order/all-order',
    })
  },
  //订单状态
  orderEvent(e) {
    let index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/all-order/all-order?index=' + index,
    })
  },
  //我的服务
  myServeEvent(e) {
    let index = e.currentTarget.dataset.index;
    switch (index) {
      case 0:
        this.myMember();
        break;
      case 1:
        this.myAddress()
        break;
      case 2:
        this.mydiscountCard()
        break;
      case 3:
        this.myRefund()
        break;
      case 4:
        this.myKefu()
        break;
      case 5:
        this.myCollect()
        break;
      case 6:
        this.relatedOur()
        break;
    }
  },
  //我的会员
  myMember() {
    method.getRequest("/myUser/queryUserInfo", data => {
      if (data.statusCode == 0) {
        this.setData({
          vip: data.data.vip
        })
        wx.setStorageSync('vip', this.data.vip)
      }
    })
    wx.navigateTo({
      url: '/pages/my-member/my-member',
    })
  },
  //收货地址
  myAddress() {
    wx.navigateTo({
      url: '/pages/select-address/select-address',
    })
  },
  //优惠券
  mydiscountCard() {
    wx.navigateTo({
      url: '/pages/discount-card/discount-card',
    })
  },
  //退款售后
  myRefund() {
    wx.navigateTo({
      url: '/pages/refund-after/refund-after',
    })
  },
  //在线客服
  myKefu() {
    wx.makePhoneCall({
      phoneNumber: '111111111000',
      success() {
        console.log('拨打电话成功')
      },
      fail() {
        console.log('拨打电话失败')
      }
    })
  },
  //我的收藏
  myCollect() {
    wx.navigateTo({
      url: '/pages/my-collect/my-collect',
    })
  },
  //关于我们
  relatedOur() {
    wx.navigateTo({
      url: '/pages/related-our/related',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.getUserInfo()
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})