// components/mine/index.js
import { bootCoin } from "../../api/mine"
import { getNotifications } from "../../api/api"
import { formatTime } from "../../utils/util"

Component({
  /**
   * 组件的属性列表
   */
  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {
    btnTxt: "启动",
    history: [{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 1,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021-05-10",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021/05/10 15:50",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021/05/10 17:12",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021/05/10 15:50",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": 0,
    },{
      "symbol": "DOGE",
      "icon": "/images/one.png",
      "amount": 12.00034,
      "ts": "2021/05/10 17:12",
      "from": "abcde034345dd",
      "to": "aabde2343df34",
      "out": -1,
    }],
    symbol: "DOGE",
    icon: "/images/one.png",
    totals: 9999.9999,
    progress: 99.999, // 0 表示已停止
    
    timer: null,
    coinTimer: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tabIn: function() {
      this.getNotification();
      this.starTimer();

      console.log(formatTime(new Date(1620633003000)));
      this.setData({history: []});
    },

    tabOut: function() {
      clearInterval(this.data.timer);
      clearTimeout(this.data.coinTimer);
    },

    getNotification: function() {
      var that = this;
      getNotifications().then(res=>{
        console.log(res);
        that.setData({

        });
      }, err=>{
        console.log(err);
        that.setData({
          totals: 0,
          progress: 0
        });
      });

      that.data.coinTimer = setTimeout(()=>{
        that.getNotification();
      }, 30000);
    },

    starTimer: function() {
      var that = this;
      that.data.timer = setInterval(function(){
        var current = parseFloat(that.data.progress);
        that.setData({
          progress: (current + parseFloat(Math.random() * 0.001)).toFixed(4)
        });
      }, 1000);
    },

    onClickStart: function() {
      let that = this;
      that.setData({
        btnTxt: "挖矿中"
      });
    },

    goRule: function() {
      wx.navigateTo({
        url: '/pages/mine_rule/index',
      })
    },

    dateTime: function(time) {
      console.log(time);
      return formatTime(new Date(parseInt(time)));
    }
  }
})
