export default {
    data() {
        return {
            params: {
                req: "",
                radius: "btc",
                address: "",
                value: "",
                type: ""
            },
            page: 1,
            tableData: [],
            totalPage: 0,
            currentPage4: 1,//当前页数
            value: "",
            valueList: [
                {
                    value: 500,
                    label: "value > 500",
                },
                {
                    value: 1500,
                    label: "value > 1500",
                },
                {
                    value: 5000,
                    label: "value > 5000",
                },
                {
                    value: 10000,
                    label: "value > 10000",
                },
                {
                    value: 15000,
                    label: "value > 15000",
                },
            ],
            state: "",
            type: "",
            topListLoading: false,
            date: "",
            tabelShow: "true",
            introduce: "",
            start: "",
            end: "",
            limit: 50,
            search: "",

        }
    },

    mounted() {
          //禁用时间框
          this.$addStorageEvent(1, "timeDisable", true);
       
        let menuObj = localStorage.getItem("params");
        this.params.req = JSON.parse(menuObj).componentReq;
        this.introduce = JSON.parse(menuObj).introduce;
        //监听localstorage变化
        window.addEventListener("setItem", () => {
            let menuObj = localStorage.getItem("params");
            this.params.req = JSON.parse(menuObj).componentReq;
            this.introduce = JSON.parse(menuObj).introduce;

        });


    },
    watch: {
        params: {
            handler(val) {
                if (val.req == "getTopList" || val.req == "getTopListWatch") {
                    // console.log(val,333333);
                    this.value = ""
                    this.state = ""

                    this.fetchTopList(this.params.req, this.params.radius, this.search, this.start, this.end, this.page, this.limit)

                }

                if (val.req == "getTopList") {
                    this.tabelShow = "true"
                } else if (val.req == "getTopListWatch") {
                    this.tabelShow = "false"
                }
            },
            deep: true,
            Immutable: true

        }
    },
    methods: {
        async fetchTopList(req, radius, search, start, end, page, limit) {
            this.topListLoading = true

            // const { data } = await this.$API.getTopList(req, radius, type)   
            const { data } = await this.$API.getBigDeals(req, radius, search, start, end, page, limit)
            this.tableData = data.data.list
            if (!this.tableData[0]) {
                this.$message({
                    message: this.$t(`home.NoData`),
                    type: 'warning'
                  });
                  this.topListLoading = false
                  return
            }
            this.totalPage = data.data.totalPage
            this.tableData.forEach(item => {
                item.value = Number(item.value).toFixed(2)
                item.outValue = Number(item.outValue).toFixed(2)
            })
            if (this.params.req == "getTopList") {

                this.date =data.data.date
            }
            this.$nextTick(() => {
                if (page) {
                    this.currentPage4 = page
                } else {
                    this.currentPage4 = 1
                }
            })


            this.topListLoading = false
        },
        //点击的改变页数
        handleCurrentChange(a) {
            this.page = a
            let search
            if (this.value) {
                search = this.value
            } else if (this.state) {
                search = this.state
            }
            this.fetchTopList(this.params.req, this.params.radius, search, this.start, this.end, this.page, this.limit)
            this.currentPage4 = this.page

        },
         //接收Home传的时间handelParmesTime
         handelSonTime(start, end) {
            this.start = start;
            this.end = end;
            // this.fetchTopList(this.params.req, this.params.radius, this.search, this.start, this.end, this.page, this.limit)

        },
        //下拉框选择
        handelChang(e) {
            this.page = 1;
            this.search = e
            this.fetchTopList(this.params.req, this.params.radius, this.value, this.start, this.end, this.page, this.limit)

           
            this.state = "";


        },
        //点击搜索处理搜索内容
        handelSearch(e) {
            this.page = 1;
            this.search = e
            this.fetchTopList(this.params.req, this.params.radius, this.state, this.start, this.end, this.page, this.limit)
            this.value = ""
            // this.state=""


        },
        //改变每页条数
        handleSizeChange(val) {

            this.page = 1;
            this.limit = val;
            this.fetchTopList(this.params.req, this.params.radius, this.search, this.start, this.end, this.page, this.limit)


        },
        //双击表格单元格复制
        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" }); //加提示
        },

    }
}