const {
  api,
  imgName,
  getUserInfo,
  wxLogin,
  alertTip,
  authAgainByUser,
  userLocation
} = require('../../lib/util.js')
const qrcode = require('../../lib/qrcode.js')
Page({
  data: {
    orderList: [],
    current:'all',
    states:{
      '0':'未支付',
      '1':'已支付',
      '2':'交易关闭',
      '3':'已退款',
      '4':'退款中',
    },

    tip:'无更多数据',
    loading:false,
  },
  onLoad: function() {
    this.getOrder()
  },
  onShow: function() {},
  tabChange(e) {
    const current = e.detail.key
    this.getOrder(current)
    .then(()=>{
      this.setData({ current})
    })
  },
  toOrderDeatil(e){
    console.log(e)
    wx.navigateTo({
      url: `/pages/orderDetail/index?orderId=${e.currentTarget.id}`,
    })
  },
  getOrder(state) {
    return new Promise((resolve,reject)=>{
      let data={}
      if (state&&state !== 'all'){
        data = { state}
      }
      api.get('order/getOrder', data)
        .then(res => {
          console.log('res:', res)
          this.setData({
            orderList: res.items
          })
          resolve()
        })
        .catch(err => {
          alertTip(err)
          reject()
        })
    })
    
  },
  removeUser(mobile) {
    let that = this
    wx.showModal({
      title: '警告',
      content: '确定删除副账号？',
      success: function(res) {
        if (res.confirm) {
          api.post('user/delAssistantUser', {
              mobile
            })
            .then(res => {
              that.getUserList()
            })
            .catch(err => {
              alertTip(err, () => {
                that.getUserList()
              })
            })
        }
      }
    })
  },
  onPageScroll(event) {
  console.log(event)
  }
})