export default {
    data() {
        return {
            tableData: [],
            ethTopAddrListLoading: false,
            totalPage: 0,
            currentPage4: 1,

            params: {
                req: "ethTopAddrList",
                radius: "eth",
                page: 1,
                limit: 50,
            },
            value: "",
            valueList: [
                {
                    value: 50000,
                    label: "value > 5W",
                },
                {
                    value: 100000,
                    label: "value > 10W",
                },
                {
                    value: 150000,
                    label: "value > 15W",
                },
                {
                    value: 250000,
                    label: "value > 25W",
                },
                {
                    value: 500000,
                    label: "value > 50W",
                },
                {
                    value: 1000000,
                    label: "value > 100W",
                },
            ],
            state: ""
        }
    },
    // watch:{
    //     page(val){
    //         this.currentPage4 = val
    //     }
    // },
    mounted() {

        this.fetchTabelData(this.params.req, this.params.radius, this.params.page, this.params.limit)
    },
    methods: {
        //页数及条数
        async fetchTabelData(req, radius, page, limit) {
            this.ethTopAddrListLoading = true
            const { data } = await this.$API.getBtctags(req, radius, page, limit);
            this.tableData = data.data.data
            this.tableData.forEach(item => {
                item.balance = Number(item.balance).toFixed(2)
            });
            this.totalPage = data.data.totalPage
            if (page) {
                this.currentPage4 = page
            } else {
                this.currentPage4 = 1
            }
            this.ethTopAddrListLoading = false
        },

        //搜索框查询
        async fetchEthTopAddrList(type, page, limit) {
            this.ethTopAddrListLoading = true
            const { data } = await this.$API.getTopAddrList(type, page, limit);
            this.tableData = data.data.data
            this.tableData.forEach(item => {
                item.balance = Number(item.balance).toFixed(2)
                if (item.abbr) {
                    item.tag = `${item.tag}(${item.abbr})`
                }
            });

            if (page) {
                this.currentPage4 = page
            } else {
                this.currentPage4 = 1
            }
            this.totalPage = data.data.totalPage
            this.ethTopAddrListLoading = false
        },
        //点击的改变页数
        handleCurrentChange(value) {
            this.params.page = value
            this.fetchTabelData(this.params.req, this.params.radius, this.params.page, this.params.limit)
            this.params.page = 1
            this.currentPage4 = this.params.page

        },
        //改变每页条数
        handleSizeChange(val) {
            this.params.limit = val
            this.fetchTabelData(this.params.req, this.params.radius, this.params.page, val)

        },
        //下拉框选择
        handelChang(e) {
            // this.searchParams.search = e
            this.fetchEthTopAddrList(this.value, this.params.page, this.params.limit)
            this.state = ""
        },
        //搜索框输入参数     
        handelSearch() {
            this.fetchEthTopAddrList(this.state, this.params.page, this.params.limit)

            this.value = ""
        },
        //双击表格单元格复制
        cellDblclick(row, column, cell, event) {
            if (event.type === "dblclick") {
                var save = (e) => {
                    e.clipboardData.setData("text/plain", event.target.innerText);
                    e.preventDefault(); //阻止默认行为
                };
                document.addEventListener("copy", save);
                document.execCommand("copy");
                document.removeEventListener("copy", save);
            }
            this.$message({ message: this.$t(`home.copy`), type: "success" }); //加提示
        },

    }
}