const Http = require('../../../../utils/http.js')
const config = require('../../../../config/config.js')
const format = require('../../../../utils/util.js')
const app = getApp()
Page({
  data: {
    money:'',
    timer:'',
    oldTradeAmt:'',
    newTradeAmt:'0'
  },
  onLoad(e){
    console.log(e);
    if (e.money==""){
      this.setData({
        newTradeAmt:0
      })
    }else{
      this.setData({
        newTradeAmt: e.money
      })
    }
    Http.getRequest(config.api.getVolume, app.globalData.token, '解单中', {},(res)=>{
      console.log(res);
      this.setData({
        oldTradeAmt: res.data.tradeAmt,
        timer: format.formatTime(res.data.updateDate, 'yyyy-MM-dddd hh:mm:ss')
      })
    })
  },
  subList() {
    //提交解单
    Http.getRequest(config.api.reportDailyVolume, app.globalData.token, '解单中', {
      volume: this.data.newTradeAmt*100
    }, (res) => {
      if (res.code == 200) {
        wx.redirectTo({
          url: `../success/success?money=${res.data.tradeAmt}&timer=${res.data.reportDate}`
        })
        // })
      } else {
        wx.redirectTo({
          url: '/pages/main/solution/fail/fail',
        })
        wx.showToast({
          title: res.message,
          image: './../../../../static/images/fail.png'
        })
      }
    })
  },
  cancel(){
    wx.switchTab({
      url: '/pages/main/main',
    })
  }
})
