
import * as echarts from "echarts";
import {getPageInfo,getProfitInfo,getMinerAccountPower,getAccountPowerDistribution,getMinerList,getHistoryIncome,getHistoryOutcome,getMinerPower} from "../../api/readOnlyDisplay"
import { Debounce,throttle }from "../../utils/publicMethods";

export default {
  data() {
    return {
      activeName: "power",
      option: {
        legend: {
          right: 100,
          show: true,
          formatter: function (name) {
            return name;
          },
        },
        // grid: {//解决Y轴显示不全
        //   left: "2%",
        //   containLabel: true
        // },
        tooltip: {
          trigger: "axis",
          textStyle: {
            align: "left",
          },
          animation: false,
          formatter: function (params) {
            var res
            res = params[0].axisValueLabel;

         
            for (let i = 0; i <= params.length - 1; i++) {

              if (params[i].seriesName == "Rejection rate" || params[i].seriesName == "拒绝率") {
                res += `</br>${params[i].marker} ${params[i].seriesName} &nbsp&nbsp&nbsp&nbsp <span style="font-weight: bold">${params[i].value}%</span>`
              }else{
                  res += `</br>${params[i].marker} ${params[i].seriesName} &nbsp&nbsp&nbsp&nbsp <span style="font-weight: bold">${params[i].value}</span>`
              }

          }



            return res;
          },
          axisPointer: {
            animation: false,
            snap: true,
            label: {
              precision: 2, //坐标轴保留的位数
            },
            type: "cross", //cross shadow
            crossStyle: {
              //十字轴横线
              // opacity: "0",
              width: 0.5,
            },
            lineStyle: {
              // opacity: 0,
            },
          },
        },

        xAxis: {
          // type: "time",
          boundaryGap: false,

          axisTick: {
            //去除刻度
            show: false,
          },
          axisLine: {
            //去除轴线
            show: false,
          },
          data: []
        },
        yAxis: [
          {
            position: "left",
            type: "value",
            name:"GH/s",
            nameTextStyle:{                           
              padding: [0, 0, 0,-40],
          }
            // min: `dataMin`,
            // max: `dataMax`,
        
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: true,
            min:0,
            max:100,
            splitLine:{//不显示右侧Y轴横线
              show: false
          }
          },
    
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
            maxSpan: 100,
            minSpan: 2,
            // animation: false,
          },
          {
            type: "inside",//slider
            start: 0,
            end: 100,
            // showDetail: false,
          },
        ],
        series: [
          {
            name: "总算力",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#5721E4",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#5721E4",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(210,195,234)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [],
          },
          {
            name: "Refusal rate",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#FE2E74",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#FE2E74",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(252,220,233)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [],
            yAxisIndex: 1,
          },



        ],
      },
      barOption: {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            name:"MH/s",
            type: 'category', 
            data: [],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            show: true,
            name:"Pcs",
            nameTextStyle:{                           
              padding: [0, 0, 0,-25],
          }

          }
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 80,
            maxSpan: 100,
            minSpan: 2,
            animation: false,
          },
          {
            type: "inside",//slider
            start: 0,
            end: 100,
            // showDetail: false,
          },
        ],
        series: [
          {
            name: 'count',
            type: 'bar',
            barWidth: '60%',
            data: [],
            itemStyle: {
              borderRadius: [100, 100, 0, 0],
              color: "#7645EE",
            }
          }
        ]
      },
      miniOption: {
        legend: {
          right: 100,
          show:false,
          formatter: function (name) {
            return name;
          },
        },
        grid: {//解决Y轴显示不全
          left: "5%",
          containLabel: true
        },
        tooltip: {
          trigger: "axis",
          textStyle: {
            align: "left",
          },
          animation: false,
          formatter: function (params) {
            var res
            res = params[0].axisValueLabel;

         
            for (let i = 0; i <= params.length - 1; i++) {

              if (params[i].seriesName == "Rejection rate" || params[i].seriesName == "拒绝率") {
                res += `</br>${params[i].marker} ${params[i].seriesName} &nbsp&nbsp&nbsp&nbsp <span style="font-weight: bold">${params[i].value}%</span>`
              }else{
                  res += `</br>${params[i].marker} ${params[i].seriesName} &nbsp&nbsp&nbsp&nbsp <span style="font-weight: bold">${params[i].value}</span>`
              }

          }



            return res;
          },
          axisPointer: {
            animation: false,
            snap: true,
            label: {
              precision: 2, //坐标轴保留的位数
            },
            type: "cross", //cross shadow
            crossStyle: {
              //十字轴横线
              // opacity: "0",
              width: 0.5,
            },
            lineStyle: {
              // opacity: 0,
            },
          },
        },

        xAxis: {
          // type: "time",
          boundaryGap: false,

          axisTick: {
            //去除刻度
            show: false,
          },
          axisLine: {
            //去除轴线
            show: false,
          },
          data: ["07-1","07-1","07-1","07-1","07-1","07-1","07-1","07-1","07-1"]
        },
        yAxis: [
          {
            position: "left",
            type: "value",
            name:"MH/s",
             nameTextStyle:{
                           
              padding: [0, 0, 0,-40],
             } 
            // min: `dataMin`,
            // max: `dataMax`,
            // axisLabel: {
            //     formatter: function (value) {
            //         let data
            //         if (value > 10000000) {
            //             data = `${(value / 10000000)} KW`
            //         } else if (value > 1000000) {
            //             data = `${(value / 1000000)} M`
            //         } else if (value / 10000) {
            //             data = `${(value / 10000)} W`
            //         }
            //         return data
            //     }
            // }
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: true,
            splitLine:{//不显示右侧Y轴横线
              show: false
          }
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: false,
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: false,
          },
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
            maxSpan: 100,
            minSpan: 2,
            animation: false,
          },
          {
            type: "inside",//slider
            start: 0,
            end: 100,
            // showDetail: false,
          },
        ],
        series: [
          {
            name: "Computational power",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#5721E4",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#5721E4",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(210,195,234)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [12,15,8,3,6,9,78,12,63],
          },
          {
            name: "Refusal rate",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#FE2E74",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#FE2E74",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(252,220,233)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [12,15,8,3,6,9,78,12,63],
            yAxisIndex: 1,
          },



        ],
      },
      onLineOption: {
        legend: {
          right: 100,
          show:false,
          formatter: function (name) {
            return name;
          },
        },
        grid: {//解决Y轴显示不全
          left: "5%",
          containLabel: true
        },
        tooltip: {
          trigger: "axis",
          textStyle: {
            align: "left",
          },
          animation: false,
          formatter: function (params) {
            var res
            res = params[0].axisValueLabel;
            res += `</br>${params[0].marker} <span style="font-weight: bold">${params[0].seriesName}</span>\u00A0\u00A0\u00A0\u00A0 ${params[0].value}
                </br>${params[1].marker} <span style="font-weight: bold">${params[1].seriesName}</span>\u00A0\u00A0\u00A0\u00A0 ${params[1].value}%  
                `;
            return res;
          },
          axisPointer: {
            animation: false,
            snap: true,
            label: {
              precision: 2, //坐标轴保留的位数
            },
            type: "cross", //cross shadow
            crossStyle: {
              //十字轴横线
              // opacity: "0",
              width: 0.5,
            },
            lineStyle: {
              // opacity: 0,
            },
          },
        },

        xAxis: {
          // type: "time",
          boundaryGap: false,

          axisTick: {
            //去除刻度
            show: false,
          },
          axisLine: {
            //去除轴线
            show: false,
          },
          data: ["07-1","07-1","07-1","07-1","07-1","07-1","07-1","07-1","07-1"]
        },
        yAxis: [
          {
            position: "left",
            type: "value",
            name:"MH/s",
            nameTextStyle:{
                          
             padding: [0, 0, 0,-40],
            } 
            // min: `dataMin`,
            // max: `dataMax`,
            // axisLabel: {
            //     formatter: function (value) {
            //         let data
            //         if (value > 10000000) {
            //             data = `${(value / 10000000)} KW`
            //         } else if (value > 1000000) {
            //             data = `${(value / 1000000)} M`
            //         } else if (value / 10000) {
            //             data = `${(value / 10000)} W`
            //         }
            //         return data
            //     }
            // }
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: true,
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: false,
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: false,
          },
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
            maxSpan: 100,
            minSpan: 2,
            animation: false,
          },
          {
            type: "inside",//slider
            start: 0,
            end: 100,
            // showDetail: false,
          },
        ],
        series: [
          {
            name: "Computational power",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#5721E4",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#5721E4",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(210,195,234)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [12,15,8,3,6,9,78,12,63],
          },
          {
            name: "Refusal rate",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#FE2E74",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#FE2E74",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(252,220,233)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [12,15,8,3,6,9,78,12,63],
            yAxisIndex: 1,
          },



        ],
      },
      OffLineOption: {
        legend: {
          right: 100,
          show:false,
          formatter: function (name) {
            return name;
          },
        },
        grid: {//解决Y轴显示不全
          left: "5%",
          containLabel: true
        },
        tooltip: {
          trigger: "axis",
          textStyle: {
            align: "left",
          },
          animation: false,
          formatter: function (params) {
            var res
            res = params[0].axisValueLabel;
            res += `</br>${params[0].marker} <span style="font-weight: bold">${params[0].seriesName}</span>\u00A0\u00A0\u00A0\u00A0 ${params[0].value}
                </br>${params[1].marker} <span style="font-weight: bold">${params[1].seriesName}</span>\u00A0\u00A0\u00A0\u00A0 ${params[1].value}%  
                `;
            return res;
          },
          axisPointer: {
            animation: false,
            snap: true,
            label: {
              precision: 2, //坐标轴保留的位数
            },
            type: "cross", //cross shadow
            crossStyle: {
              //十字轴横线
              // opacity: "0",
              width: 0.5,
            },
            lineStyle: {
              // opacity: 0,
            },
          },
        },

        xAxis: {
          // type: "time",
          boundaryGap: false,

          axisTick: {
            //去除刻度
            show: false,
          },
          axisLine: {
            //去除轴线
            show: false,
          },
          data: ["07-1","07-1","07-1","07-1","07-1","07-1","07-1","07-1","07-1"]
        },
        yAxis: [
          {
            position: "left",
            type: "value",
            name:"MH/s",
            nameTextStyle:{
                          
             padding: [0, 0, 0,-40],
            } 
            // min: `dataMin`,
            // max: `dataMax`,
            // axisLabel: {
            //     formatter: function (value) {
            //         let data
            //         if (value > 10000000) {
            //             data = `${(value / 10000000)} KW`
            //         } else if (value > 1000000) {
            //             data = `${(value / 1000000)} M`
            //         } else if (value / 10000) {
            //             data = `${(value / 10000)} W`
            //         }
            //         return data
            //     }
            // }
          },
          {
            position: "right",
            // type: "log",
            splitNumber: "5",
            show: true,
            splitLine:{//不显示右侧Y轴横线
              show: false
          }
          },
         
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
            maxSpan: 100,
            minSpan: 2,
            animation: false,
          },
          {
            type: "inside",//slider
            start: 0,
            end: 100,
            // showDetail: false,
          },
        ],
        series: [
          {
            name: "Computational power",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#5721E4",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#5721E4",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(210,195,234)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [12,15,8,3,6,9,78,12,63],
          },
          {
            name: "Refusal rate",
            type: "line",
            smooth: false, //线条是否圆滑
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            itemStyle: {
              color: "#FE2E74",
              borderColor: "rgba(221,220,107,0.1)",
              borderWidth: 12,
            },
            lineStyle: {
              //线条样式
              color: "#FE2E74",
              width: "2",
            },
            areaStyle: {
              origin: 'start',//颜色始终显示在线条下
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(252,220,233)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 255, 255)'
                }
              ])
            },
            data: [12,15,8,3,6,9,78,12,63],
            yAxisIndex: 1,
          },



        ],
      },
      sunTabActiveName: "all",
      Accordion: "",
      currentPage: 1,
      params: {
        // account: "lx888",
        // coin: "nexa",
        key:"",
      },
      PowerParams: {
        // account: "lx888",
        // coin: "nexa",
        interval: "rt",
        key:"",
      },
      PowerDistribution: {
        // account: "lx888",
        // coin: "nexa",
        interval: "rt",
        key:"",
      },
      MinerListParams: {
        // account: "lx888",
        // coin: "nexa",
        type: "0",
        filter: "",
        limit: 50,
        page: 1,
        key:"",
        sort:"30m",
        collation:"asc",
      },
      activeName2: "power",
      IncomeParams: {
        // account: "lx888",
        // coin: "nexa",
        limit: 10,
        page: 1,
        key:"",
      },
      OutcomeParams: {
        // account: "lx888",
        // coin: "grs",
        limit: 10,
        page: 1,
        key:"",
      },
      MinerAccountData: {
        // totalProfit: "78678862.96791889",
        // expend: "78678862.96791889",
        // preProfit: "78678862.96791889",
        // todayPorfit: "78678862.96791889",
        // balance: "78678862.96791889",
      },
      MinerListData: {
        // all: "100",
        // online: "99",
        // offline: "1",
        // miner: "",
        // rate: "",
        // dailyRate: "",
        // reject: "",
      },
      intervalList: [
        {
          value: "rt",
          label: "home.realTime",
        },
        // {
        //   value: "1h",
        //   label: "home.hour",
        // },
        {
          value: "1d",
          label: "home.day",
        },
      ],
      HistoryIncomeData: [
        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "565S656",
        //   comment: "挖矿收益",

        // },
        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "56G5656",
        //   comment: "挖矿收益",

        // },
        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "565Y656",
        //   comment: "挖矿收益",

        // },
        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },
        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },

        // {
        //   date: "2021-09-21",
        //   coin: "ETH",
        //   amount: "5645656",
        //   comment: "挖矿收益",

        // },





      ],
      HistoryOutcomeData: [
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56D5656",
        //   txid: "12345678d90",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56G5656",
        //   txid: "123456f7890",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "565T656",
        //   txid: "123sf4567890",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56D5656",
        //   txid: "12345678d90",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56G5656",
        //   txid: "123456f7890",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "565T656",
        //   txid: "123sf4567890",
        // },

        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56D5656",
        //   txid: "12345678d90",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56G5656",
        //   txid: "123456f7890",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "565T656",
        //   txid: "123sf4567890",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56D5656",
        //   txid: "12345678d90",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "56G5656",
        //   txid: "123456f7890",
        // },
        // {
        //   date: "2021-09-21",
        //   address: "0x1234567890",
        //   comment: "mona",
        //   amount: "565T656",
        //   txid: "123sf4567890",
        // },




      ],
      currentPageIncome: 1,
      MinerListTableData: [
      //  {
      //     miner: "107fx61",
      //     rate: "0.0066666 ",
      //     dailyRate: "0.019999 ",
      //     reject: "0.01 TH/s",
      //     offline:1442,
      //     status:2
      //   },
      //   {
      //     miner: "107dfx62",
      //     rate: "0.407777 ",
      //     dailyRate: "0.016666 ",
      //     reject: "0.01 TH/s",
      //     offline:82,
      //     status:2
      //   },
      //   {
      //     miner: "107dfsx63",
      //     rate: "0.9635656 ",
      //     dailyRate: "0.018888",
      //     reject: "0.01 TH/s",
      //     offline:78,
      //     status:1
      //   },
      //   {
      //     miner: "107xsf6",
      //     rate: "0.00 H/s",
      //     dailyRate: "0.01 TH/s",
      //     reject: "0.01 TH/s",
      //     offline:61,
      //     status:1
      //   },
        // {
        //   miner: "107xsf666",
        //   rate: "0.00 H/s",
        //   dailyRate: "0.01 TH/s",
        //   reject: "0.01 TH/s",
        //   offline:61,
        //   status:2
        // },
        // {
        //   miner: "107xsf6",
        //   rate: "0.00 H/s",
        //   dailyRate: "0.01 TH/s",
        //   reject: "0.01 TH/s",
        //   offline:61,
        //   status:2
        // },

      ],
      AccountPowerDistributionintervalList: [
        {
          value: "rt",
          label: "home.realTime",
        },
        {
          value: "1d",
          label: "home.day",
        },
      ],
      miniLoading:false,
      search: "",
      input2: "",
      timeActive: "rt",
      barActive: "rt",
      powerChartLoading: false,
      barChartLoading: false,
      miniChartParams: {
        miner: "",
        coin: "grs",
        key:"",
      },
      ids: "smallChart107fx61",
      activeMiner:"",
      miniId:"",
      MinerListLoading:false,
      miner:"miner",
      accountId:"",
      currentPageMiner: 1,
      minerTotal:0,
      accountItem:{},
      HistoryIncomeTotal:0,
      HistoryOutcomeTotal:0,
      jurisdiction:[],
      minerShow:false,
      profitShow:false,
      paymentShow:false,
      jurisdictionLoading:false,
      stateList:[{
        value: "1", 
        label: "mining.onLine"
      },{
        value: "2",
        label: "mining.offLine"
      },
      ],
      loadingText:"personal.loadingText",
      directives: {
        // 定义节流函数
        throttle: {
          bind(el, binding) {
            let throttleTime;
            el.addEventListener('click', (e) => {
              if (!throttleTime || Date.now() - throttleTime >= binding.value) {
                throttleTime = Date.now();
                binding.value.apply(e.target, [e]);
              }
            });
          }
        }
      },
      paymentStatusList:[
        {
          value: 0,
          label: "mining.paymentInProgress"
        },
        {
          value: 1,
          label: "mining.paymentCompleted"
        }
        

      ]

    } 
  },
  watch: {
    '$route' (to, from) {
  
      this.loadingText = this.$t("personal.loadingText")
    
      this.fetchPageInfo({key:this.params.key})
    
      this.getMinerListData(this.MinerListParams)
      this.getMinerAccountPowerData(this.PowerParams)
      this.getAccountPowerDistributionData(this.PowerDistribution)
      
     

    },
    "$i18n.locale":(val)=>{
      location.reload();//刷新页面 刷新echarts
   }
  },

  computed: {
    sortedMinerListTableData() { //离线旷工靠前
      if (!this.MinerListTableData) return [];
      
      return [...this.MinerListTableData].sort((a, b) => {
        // 确保 status 是字符串类型
        const statusA = String(a.status);
        const statusB = String(b.status);
        
        // 离线（status='2'）的排在前面
        if (statusA === '2' && statusB !== '2') return -1;
        if (statusA !== '2' && statusB === '2') return 1;
        
        // status 相同时保持原有顺序
        return 0;
      });
    }
  },
  mounted() {

    this.loadingText = this.$t("personal.loadingText")
    const urlParams = new URLSearchParams(window.location.search);
    this.params.key = urlParams.get('key'); // 获取order_key参数的值
    this.PowerParams.key = urlParams.get('key'); 
    this.PowerDistribution.key = urlParams.get('key');
    this.MinerListParams.key = urlParams.get('key'); 
    this.IncomeParams.key = urlParams.get('key'); 
    this.OutcomeParams.key = urlParams.get('key'); 

  
    this.fetchPageInfo({key:this.params.key})

    this.getMinerListData(this.MinerListParams)
    this.getMinerAccountPowerData(this.PowerParams)
    this.getAccountPowerDistributionData(this.PowerDistribution)


    this.registerRecoveryMethod('getMinerListData', this.MinerListParams);
    this.registerRecoveryMethod('getMinerAccountPowerData', this.PowerParams);
    this.registerRecoveryMethod('getAccountPowerDistributionData', this.PowerDistribution);
    this.registerRecoveryMethod('fetchPageInfo', {key:this.params.key});
    
  
  },
  methods: {

    //初始化图表
    inCharts() {
      // if (this.myChart == null) {
      //   this.myChart = echarts.init(document.getElementById("powerChart"));
      // }
      this.myChart = echarts.init(document.getElementById("powerChart"));
      this.option.series[0].name= this.$t(`home.finallyPower`)
      this.option.series[1].name= this.$t(`home.rejectionRate`)
      this.myChart.setOption(this.option);
      // window.addEventListener("resize", () => {
      //   if (this.myChart) this.myChart.resize();
      // });

      window.addEventListener('resize', throttle(() => {
        if (this.myChart) this.myChart.resize();
      }, 200));
    },
    //初始化小图表
    smallInCharts(option) {
    
      // if (this.miniChart == null) {
      //   this.miniChart = echarts.init(document.getElementById("smallChart"));
      // }
      // this.miniChart.setOption(this.miniOption,true);
      option.series[0].name= this.$t(`home.minerSComputingPower`)
      option.series[1].name= this.$t(`home.rejectionRate`)
      this.miniChart.setOption(option,true);


      window.addEventListener('resize', throttle(() => {
        if (this.miniChart) this.miniChart.resize();
      }, 200));
    },
    barInCharts() {
      if (this.barChart == null) {
        this.barChart = echarts.init(document.getElementById("barChart"));
      }
      this.barOption.series[0].name = this.$t(`home.numberOfMiningMachines`);
      this.barChart.setOption(this.barOption);
     
      window.addEventListener('resize', throttle(() => {
        if (this.barChart) this.barChart.resize();
      }, 200));
    },
    //返回权限 1矿工 2收益 3支付
    async fetchPageInfo(params){
      this.setLoading('jurisdictionLoading', true);
      const data = await getPageInfo(params)
      console.log(data);
      if (data && data.code == 200) {
        this.jurisdiction =data.data
      
        if (this.jurisdiction.config.includes(`3`)) {
            this.paymentShow =true
        }

        if (this.jurisdiction.config.includes(`2`)) {
           this.profitShow =true
        }
        
        if (this.jurisdiction.config.includes(`1`)) {
            this.minerShow =true
        }

           
      // if (this.minerShow) {
      //   this.getMinerListData(this.MinerListParams)
      // }
      if (this.profitShow) {
        this.getHistoryIncomeData(this.IncomeParams)
        this.getMinerAccountInfoData(this.params)
      }
      if (this.paymentShow) {
        this.getHistoryOutcomeData(this.OutcomeParams)
      }
        

        
      }
     
      this.setLoading('jurisdictionLoading', false);
    },
    //获取当前挖矿账号信息(包含收益、余额)
    async getMinerAccountInfoData(params) {
      const data = await getProfitInfo(params)
      this.MinerAccountData = data.data
    },
    async getMinerAccountPowerData(params) {
      this.setLoading('powerChartLoading', true);
      const data = await getMinerAccountPower(params)

      if (!data) {
        this.setLoading('powerChartLoading', false);
        if (this.myChart) {
          this.myChart.dispose()//销毁图表实列
        }
        return
      }
      let chartData = data.data
      let xData = []
      let pvData = []
      let rejectRate = []
      chartData.forEach(item => {

        if (item.date.includes(`T`) && params.interval == `rt`) {                
            item.date= `${item.date.split("T")[0]} ${item.date.split("T")[1].split(`.`)[0]}` 
        } else if(item.date.includes(`T`) && params.interval == `1d`){
            item.date= item.date.split("T")[0]
        }
        xData.push(item.date)
        pvData.push(item.pv.toFixed(2))
        rejectRate.push((item.rejectRate * 100).toFixed(4))
      });
      let maxValue = Math.max(...rejectRate)
      maxValue= Math.round(maxValue*3) 
      if (maxValue>0) {
     
        this.option.yAxis[1].max=maxValue
      }
    
      this.option.xAxis.data = xData
      this.option.series[0].data = pvData
      this.option.series[1].data = rejectRate

      this.inCharts()
      this.setLoading('powerChartLoading', false);



    },
    async getAccountPowerDistributionData(params) {
      this.setLoading('barChartLoading', true);
      const data = await getAccountPowerDistribution(params)
      let barData = data.data
      let xData = []
      let barValueList = []
      barData.forEach(item => {
        xData.push(`${item.low}-${item.high}`)
        barValueList.push(item.count)
      })
      this.barOption.xAxis[0].data = xData
      this.barOption.series[0].data = barValueList
      this.barInCharts()
      this.setLoading('barChartLoading', false);
    },
    formatNumber(num) {//保留两位小数并补0
      const intPart = Math.floor(num);
      const decimalPart = Math.floor((num - intPart) * 100);
      return `${intPart}.${String(decimalPart).padStart(2, '0')}`;
  },
    async getMinerListData(params) {
      this.setLoading('MinerListLoading', true);
      const data = await getMinerList(params)
      if (data && data.code == 200) {
        this.MinerListData = data.data
        if (this.MinerListData.submit && this.MinerListData.submit.includes(`T`)) {
          this.MinerListData.submit =`${this.MinerListData.submit.split(`T`)[0]} ${this.MinerListData.submit.split(`T`)[1].split(`.`)[0]}` 
        }
        this.MinerListData.rate =  this.formatNumber(this.MinerListData.rate)
        this.MinerListData.dailyRate =  this.formatNumber(this.MinerListData.dailyRate)


        this.MinerListTableData = data.data.rows
        this.MinerListTableData.forEach(item=>{
          if (item.submit.includes(`T`)) {
            item.submit =  `${item.submit.split(`T`)[0]} ${item.submit.split(`T`)[1].split(`.`)[0]}` 
           
          }
          item.rate= this.formatNumber(item.rate)
          item.dailyRate= this.formatNumber(item.dailyRate)
         
        
        })
        this.minerTotal= data.data.total
           
      }

      this.setLoading('MinerListLoading', false);

    },

    //小图
    async getMinerPowerData(params) {
      this.setLoading('miniLoading', true);
      const data = await getMinerPower(params)
   
    if (!data) {
      this.setLoading('miniLoading', false);
      return
    }
      let miniData = data.data
      let xData = []
      let pv = []
      let rejectRate = []

      miniData.forEach(item => {

        if (item.date.includes(`T`) && params.interval == `rt`) {                
          item.date= `${item.date.split("T")[0]} ${item.date.split("T")[1].split(`.`)[0]}` 
      } else if(item.date.includes(`T`) && params.interval == `1d`){
          item.date= item.date.split("T")[0]
      }
      item.date= `${item.date.split("T")[0]} ${item.date.split("T")[1].split(`.`)[0]}` 
      xData.push(item.date)


    

        pv.push(item.pv.toFixed(2))
        rejectRate.push((item.rejectRate * 100).toFixed(4))
      })

      this.miniOption.xAxis.data = xData
      this.miniOption.series[0].data = pv
      this.miniOption.series[1].data = rejectRate

      this.miniOption.series[0].name= this.$t(`home.finallyPower`)
      this.miniOption.series[1].name= this.$t(`home.rejectionRate`)
     
      this.ids = `SmallChart${this.miniId}`
      this.miniChart = echarts.init(document.getElementById(this.ids))
      let maxValue = Math.max(...rejectRate)
      maxValue= Math.round(maxValue*3) 
      if (maxValue>0) {
        this.miniOption.yAxis[1].max=maxValue
      }
    
      this.$nextTick(() => {
        this.smallInCharts(this.miniOption)
      });
     
   

      this.setLoading('miniLoading', false);
    },
     //小图
     async getMinerPowerOnLine(params) {
      this.setLoading('miniLoading', true);
      const data = await getMinerPower(params)
   
    if (!data) {
      this.setLoading('miniLoading', false);
      return
    }
      let miniData = data.data
      let xData = []
      let pv = []
      let rejectRate = []

      miniData.forEach(item => {
        if (item.date.includes(`T`)) {
          xData.push(`${item.date.split("T")[0]} ${item.date.split("T")[1].split(".")[0]}` )

        } else {
          xData.push(item.date)
        }

        pv.push(item.pv.toFixed(2))
        rejectRate.push((item.rejectRate * 100).toFixed(4))
      })

    
      this.onLineOption.xAxis.data = xData
      this.onLineOption.series[0].data = pv
      this.onLineOption.series[1].data = rejectRate
      this.onLineOption.series[0].name= this.$t(`home.finallyPower`)
      this.onLineOption.series[1].name= this.$t(`home.rejectionRate`)
     
      this.ids = `Small${this.miniId}`
      this.miniChartOnLine = echarts.init(document.getElementById(this.ids))
    
      this.$nextTick(() => {
        this.miniChartOnLine.setOption(this.onLineOption,true);
        

          window.addEventListener('resize', throttle(() => {
            if (this.miniChartOnLine) this.miniChartOnLine.resize();
          }, 200));
      });
    
   

      this.setLoading('miniLoading', false);
    },
    //小图
    async getMinerPowerOffLine(params) {
      this.setLoading('miniLoading', true);
      const data = await getMinerPower(params)
    if (!data) {
      this.setLoading('miniLoading', false);
      return
    }
      let miniData = data.data
      let xData = []
      let pv = []
      let rejectRate = []

      miniData.forEach(item => {
        if (item.date.includes(`T`)) {
          xData.push(`${item.date.split("T")[0]} ${item.date.split("T")[1].split(".")[0]}` )

        } else {
          xData.push(item.date)
        }

        pv.push(item.pv.toFixed(2))
        rejectRate.push((item.rejectRate * 100).toFixed(4))
      })

    
      this.OffLineOption.xAxis.data = xData
      this.OffLineOption.series[0].data = pv
      this.OffLineOption.series[1].data = rejectRate
      this.OffLineOption.series[0].name= this.$t(`home.finallyPower`)
      this.OffLineOption.series[1].name= this.$t(`home.rejectionRate`)
     
     
      this.ids = `SmallOff${this.miniId}`
      this.miniChartOff = echarts.init(document.getElementById(this.ids))
    
      this.$nextTick(() => {
        this.miniChartOff.setOption(this.OffLineOption,true);
         

          window.addEventListener('resize', throttle(() => {
            if (this.miniChartOff) this.miniChartOff.resize();
          }, 200));
      });
    
   

      this.setLoading('miniLoading', false);
    },
    async getHistoryIncomeData(params) {
      const data = await getHistoryIncome(params)

      if (data && data.code == 200) {
        this.HistoryIncomeData = data.rows
        this.HistoryIncomeTotal=data.total
        this.HistoryIncomeData.forEach(item=>{
          if (item.date.includes(`T`)) {
            item.date =item.date.split(`T`)[0]
          }
        })


      }
     
    },
    async getHistoryOutcomeData(params) {
      const data = await getHistoryOutcome(params)
      if (data && data.code == 200) {
        this.HistoryOutcomeData = data.rows
        this.HistoryOutcomeTotal=data.total

        this.HistoryOutcomeData.forEach(item=>{
          if (item.date.includes(`T`)) {
            item.date =`${item.date.split(`T`)[0]} ` 
          }
        })
      }
        
     
     
    },



    handelMiniChart: throttle(function(id, miner) {
      if (!this.Accordion) return
      this.miniId = id
      this.miner = miner
      this.$nextTick(() => {
        // this.getMinerPowerData({ miner:miner, coin: this.params.coin, account: this.params.account })
        this.getMinerPowerData({key:this.params.key, account: miner })
      });
 

    }, 1000),
   
    
    handelOnLineMiniChart: throttle(function(id, miner) {
      if (!this.Accordion) return
      this.miniId = id
      this.$nextTick(() => {
        // this.getMinerPowerOnLine({ miner:miner, coin: this.params.coin, account: this.params.account })
        this.getMinerPowerOnLine({key:this.params.key, account:miner })
      });

    }, 1000),


    handelMiniOffLine: throttle(function(id, miner) {
      if (!this.Accordion) return
      this.miniId = id
      this.$nextTick(() => {
        this.getMinerPowerOffLine({key:this.params.key, account: miner })
      });
    }, 1000),
   


    handleClick() {
      switch (this.activeName) {
        case "power":
          this.inCharts()
          // this.getMinerAccountPowerData(this.PowerParams)
          break;
        case "miningMachineDistribution":
          this.distributionInCharts()
          // this.getAccountPowerDistributionData(this.PowerDistribution)
          break;



        default:
          break;
      }
    },
    handleClick2(activeName2) {
      this.search=""
      this.MinerListParams.filter=""
        this.Accordion=""
        this.IncomeParams.limit=10
        this.MinerListParams.limit=50
        this.OutcomeParams.limit =10
      switch (activeName2) {
        case "power":
          // if (!this.minerShow) {
          //   return
          // }
          this.activeName2 = activeName2;
          this.getMinerListData(this.MinerListParams)
          break;
        case "miningMachine":
          if (!this.profitShow) {
            

            return
          }
          this.activeName2 = activeName2;
       
          
          this.getHistoryIncomeData(this.IncomeParams)
          break;
        case "payment":
          if (!this.paymentShow) {
            return
          }
          this.activeName2 = activeName2;
          this.getHistoryOutcomeData(this.OutcomeParams)
          break;


        default:
          break;
      }
      
  

    },
    onlineStatus(sunTabActiveName) {
      this.Accordion=""
      this.search=""
      this.MinerListParams.filter=""
      this.sunTabActiveName = sunTabActiveName
      switch (this.sunTabActiveName) {
        case "all":
          this.MinerListParams.type = 0
          break;
        case "onLine":
          this.MinerListParams.type = 1
          break;
        case "off-line":
          this.MinerListParams.type = 2
          break;

        default:
          break;
      }
      this.getMinerListData(this.MinerListParams)
    },
    handleInterval(value) {
      this.PowerParams.interval = value
      this.timeActive = value
      this.getMinerAccountPowerData(this.PowerParams)
    },
    distributionInterval(value) {
      this.PowerDistribution.interval = value
      this.barActive = value
      this.getAccountPowerDistributionData(this.PowerDistribution)
    },
   
    handelSearch() {
      this.MinerListParams.filter = this.search
      this.getMinerListData(this.MinerListParams)
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.OutcomeParams.limit = val
      this.OutcomeParams.page = 1
      this.getHistoryOutcomeData(this.OutcomeParams)
      this.currentPage = 1
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);  
      this.OutcomeParams.page = val
      this.getHistoryOutcomeData(this.OutcomeParams)
    },
    handleSizeChangeIncome(val) {
      console.log(`每页 ${val} 条`);
      this.IncomeParams.limit = val
      this.IncomeParams.page = 1
      this.getHistoryIncomeData(this.IncomeParams)
      this.currentPageIncome = 1
    },
    handleCurrentChangeIncome(val) {
      console.log(`当前页: ${val}`);
      this.IncomeParams.page = val
      this.getHistoryIncomeData(this.IncomeParams)
    },
    handleSizeMiner(val) {
      console.log(`每页 ${val} 条`);
      this.MinerListParams.limit = val
      this.MinerListParams.page = 1
      this.getMinerListData(this.MinerListParams)
      this.currentPageMiner = 1
    },
    handleCurrentMiner(val) {
      console.log(`当前页: ${val}`);
      this.MinerListParams.page = val
      this.getMinerListData(this.MinerListParams)
    },
    
    handelStateList(value ){
      return this.stateList.find(item => item.value == value).label || ""
   },

   handleSort(sort){
    this.MinerListParams.sort = sort
    if ( this.MinerListParams.collation == "asc") {
      this.MinerListParams.collation = "desc"
   }else{
      this.MinerListParams.collation = "asc"
   }
   this.getMinerListData(this.MinerListParams)
  },

   handleSort30(){
    if ( this.MinerListParams.collation[0] == "asc") {
       this.MinerListParams.collation[0] = "desc"
    }else{
       this.MinerListParams.collation[0] = "asc"
    }
    this.getMinerListData(this.MinerListParams)
  },
  handleSort1h(){
    if ( this.MinerListParams.collation[1] == "asc") {
      this.MinerListParams.collation[1] = "desc"
   }else{
      this.MinerListParams.collation[1] = "asc"
   }
    this.getMinerListData(this.MinerListParams)
  },
  handelTimeInterval(time){
    if (time) {
      
      var seconds = time * 60;
      var days = Math.floor(seconds / (3600 * 24));
      var hours = Math.floor((seconds % (3600 * 24)) / 3600);
      var minutes = Math.floor((seconds % 3600) / 60);
      var secs = seconds % 60;
 
      if (days) {
        return `(${days}${this.$t(`personal.day`)} ${hours}${this.$t(`personal.hour`)} ${minutes}${this.$t(`personal.minute`)} ${this.$t(`personal.front`)})`
    }else if (hours) {
        return `(${hours}${this.$t(`personal.hour`)} ${minutes}${this.$t(`personal.minute`)} ${this.$t(`personal.front`)})`
    }else if(minutes){
      return `( ${minutes}${this.$t(`personal.minute`)} ${this.$t(`personal.front`)})`
    }
  }
  },

  async copyTxid(ID) {

    let id = `id${ID}`
  let d= document.getElementById(id)

    // d.select() //选中
          // document.execCommand("copy") //直接复制
          try {
              await navigator.clipboard.writeText(d.textContent);
              this.$message({
                  showClose: true,
                  message: this.$t(`personal.copySuccessful`),
                  type: 'success'
              });
          } catch (err) {
              console.log(err);
              this.$message({
                  showClose: true,
                  message: this.$t(`personal.copyFailed`),
                  type: 'error'
              });
          }
  },
  handelPayment(val){
    if (val || val == 0) {
      let obj=  this.paymentStatusList.find(item=>item.value ==val)
      
      return obj.label
    }else{
      return ''
    }
  },
  handelTxid(txid){
    if (this.jurisdiction.coin.includes(`dgb`)) {
      window.open(`https://chainz.cryptoid.info/dgb/tx.dws?${txid}.htm`)
        
    }else{
      switch (this.jurisdiction.coin) {
        case `nexa`:
          window.open(`https://explorer.nexa.org/tx/${txid}`)
          break;
          case `mona`:
            window.open(`https://mona.insight.monaco-ex.org/insight/tx/${txid}`)
          break;
          case `grs`:
            window.open(`https://chainz.cryptoid.info/grs/tx.dws?${txid}.htm`)
          break;
          case `rxd`:
            window.open(`https://explorer.radiantblockchain.org/tx/${txid}`)
          break;
          case `enx`:
            window.open(`https://explorer.entropyx.org/txs/${txid}`)
          break;
          case `alph`:
            window.open(`https://explorer.alephium.org/transactions/${txid}`)
          break;
          case `xmr`:
            window.open(`https://localmonero.co/blocks/tx/${txid}`)
          break;
          case `sha3x`:
            window.open(`https://explore.tari.com/txs/${txid}`)
          break;
      
        default:
          break;
      }
    }
 
  // 
}
  




 


    // jumpPage() {

    //   this.$router.push({path:`/personalCenter/personalMining`,query:{id:this.accountId,coin:this.params.coin,ma:this.params.account}})

    // }
  }
}