// import * as echarts from "echarts";
import messages from "@/i18n/messages"
import { getTicketList,getBKendTicket } from "../../api/work"
// import { Debounce } from "../../util/processingData"
export default {
    data() {
        return {
            from0: [
                //     {
                //     id: "",
                //     userDate: "",
                //     userName: "",
                //     msgPage: "",
                //     userMsg: ""


                // }
            ],
            from1: [
                //     {
                //     id: "",
                //     userDate: "",
                //     userName: "",
                //     msgPage: "",
                //     userMsg: ""


                // }
            ],
            from2: [
                //     {
                //     id: "",
                //     userDate: "",
                //     userName: "",
                //     msgPage: "",
                //     userMsg: ""


                // },
            ],
            from10: [
                //     {
                //     id: "",
                //     userDate: "",
                //     userName: "",
                //     msgPage: "",
                //     userMsg: ""


                // },
            ],
            params: {
                page: 1,
                limit: 10,
                status: 1,


            },
            rechargeRecord: false,
            activeName: "pendingProcessing",
            workBKLoading: false,
            options: [
                {
                    value: 1,
                    label: "待处理"
                },
                {
                    value: 3,
                    label: "等待收货中"
                },
                {
                    value: 5,
                    label: "已报价,等待付款"
                },
                {
                    value: 6,
                    label: "已付款"
                },
                {
                    value: 7,
                    label: "正在维修"
                },
                {
                    value: 8,
                    label: "维修完成,等待发回"
                },
                {
                    value: 9,
                    label: "已发回"
                },
                {
                    value: 10,
                    label: "已完结"
                },
                {
                    value: 20,
                    label: "确认收款中"
                },
                {
                    value: 21,
                    label: "待寄件"
                },
            ],
            value1: "",
            labelPosition: `top`,
            formLabelAlign: {
                name: '',
                region: '',
                type: ''
            },
            iconShow: false,
            totalLimit0: 0,
            totalLimit1: 0,
            totalLimit2: 0,
            totalLimit10:0,
            currentPage0: 1,
            currentPage1: 1,
            currentPage2: 1,
            currentPage10: 1,
            pageSizes: [10, 50, 100, 300],
            faultList: [
                {
                    id: 1,
                    name: "整机无算力",
                    label: "user.fault",
                },
                {
                    id: 2,
                    name: "某一块板无算力",
                    label: "user.fault2",
                },
                {
                    id: 3,
                    name: "整机算力过低",
                    label: "user.fault3",
                },
                {
                    id: 4,
                    name: "某一块板算力过低",
                    label: "user.fault4",
                },
                {
                    id: 5,
                    name: "其他故障",
                    label: "user.fault5",
                },
            ],
            typeList: [],
           
            statusList:[
                {//待处理
                    value:1,
                    label:"work.pendingProcessing"
                },
                {//处理中
                    value:2,
                    label:"work.processed"
                },
                {//已完结
                    value:10,
                    label:"work.completeWK"
                }
                
            ],
            lang: this.$i18n.locale,


        }
    },
    watch: {
        params: {
            handler(newVal) {
                if (newVal.low || newVal.high) {
                    this.iconShow = true
                } else {
                    this.iconShow = false
                }
            },
            deep: true,
        }

    },
    mounted() {
        // this.params.status = 0
        // this.fetchRechargeRecord0(this.params)
        // this.params.status = 1
        // this.fetchRechargeRecord1(this.params)
        // this.params.status = 2
        // this.fetchRechargeRecord2(this.params)

 
        this.activeName=sessionStorage.getItem('helpActiveName')
        if (!this.activeName) {
            this.activeName="pendingProcessing"
        }

        switch (this.activeName) {
            case `all`:
                this.params.status = 0
                this.fetchRechargeRecord0(this.params)
                this.registerRecoveryMethod('fetchRechargeRecord0', this.params);
                break;
            case `pending`:
                this.params.status = 2
                this.fetchRechargeRecord2(this.params)
                this.registerRecoveryMethod('fetchRechargeRecord2', this.params);
                break;
            case `Finished`:
                this.params.status = 10
                this.fetchRechargeRecord10(this.params)
                this.registerRecoveryMethod('fetchRechargeRecord10', this.params);
                break;
            case `pendingProcessing`:
                this.params.status = 1
                this.fetchRechargeRecord1(this.params)
                this.registerRecoveryMethod('fetchRechargeRecord1', this.params);
                break;

            default:
                break;
        }

    },
    methods: {

        async fetchBKendTicket(params){
            this.workBKLoading = true
            const data = await getBKendTicket(params)
            if (data && data.code == 200) {
                this.$message({
                    message: this.$t(`work.WKend`),
                    type: "success",
                  });
                  switch (this.activeName) {
                    case `all`:
                        this.params.status = 0
                        this.fetchRechargeRecord0(this.params)
                        break;
                    case `pending`:
                        this.params.status = 2
                        this.fetchRechargeRecord2(this.params)
                        break;
                    case `Finished`:
                        this.params.status = 10
                        this.fetchRechargeRecord10(this.params)
                        break;
                    case `pendingProcessing`:
                        this.params.status = 1
                        this.fetchRechargeRecord1(this.params)
                        break;
        
                    default:
                        break;
                }


            }
            this.workBKLoading = false
        },
        handelType2(label) {
            if (label) {
                return this.typeList.find(item => item.name == label).label
            }
        },
        handelStatus2(status) {

            if (this.statusList && status) {
                const item1 = this.statusList.find(item => item.value == status)
                if (item1) {
                    return item1.label;
                }
            }
            return '';
        },
        //请求工单列表 全部工单0
        async fetchRechargeRecord0(params) {
            this.workBKLoading = true
            const data = await getTicketList(params)
            this.totalLimit0 = data.total
            this.from0 = data.rows
            this.workBKLoading = false

        },
        //请求工单列表 待处理 1
        async fetchRechargeRecord1(params) {
            this.workBKLoading = true
            const data = await getTicketList(params)
            console.log(data,"哦客服");
            
            this.from1 = data.rows
            this.totalLimit1 = data.total
            this.workBKLoading = false

        },

        //请求工单列表  2 处理中
        async fetchRechargeRecord2(params) {
            this.workBKLoading = true
            const data = await getTicketList(params)
            this.from2 = data.rows
            this.totalLimit2 = data.total
            this.workBKLoading = false

        },

        //请求工单列表  已结束的工单10
        async fetchRechargeRecord10(params) {
            this.workBKLoading = true
            const data = await getTicketList(params)
            this.from10 = data.rows
            this.totalLimit10 = data.total
            this.workBKLoading = false

        },

      
        //点击详情
        handelDetails(row) {
            // this.$router.push({ path: `BKWorkDetails`, query: { totalID: row.id } })
            // localStorage.setItem("totalID", row.id)

             // 添加语言参数的路由跳转
            this.$router.push({ 
                path: `/${this.lang}/BKWorkDetails`, 
                query: { totalID: row.id } 
            }).catch(err => {
                if(err.name !== 'NavigationDuplicated') {
                console.error('路由跳转失败:', err);
                }
            });

            // 保存ID到localStorage
            localStorage.setItem("totalID", row.id);
        },
        handelPhenomenon(id) {
            if (id) {
                return this.faultList.find(item => item.id == id).label
            }

        },


        handelTime(time) {
            if (time) {
                return `${time.split("T")[0]} ${time.split("T")[1].split(".")[0]}`
            }
        },
        handleChange() {
            if (this.value1) {
                this.params.start = this.value1[0]
                this.params.end = this.value1[1]
            } else {
                this.params.start = ""
                this.params.end = ""
                switch (this.activeName) {
                    case `all`:
                        this.params.type = 2
                        this.fetchRechargeRecord2(this.params)
                        break;
                    case `support`:
                        this.params.type = 0
                        this.fetchRechargeRecord0(this.params)
                        break;
                    case `service`:
                        this.params.type = 1
                        this.fetchRechargeRecord1(this.params)
                        break;

                    default:
                        break;
                }


            }

        },


        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.params.limit = val
            this.params.page = 1
            switch (this.activeName) {
                case `all`:
                    this.params.status = 0
                    this.fetchRechargeRecord0(this.params)
                    break;
                case `pending`:
                    this.params.status = 2
                    this.fetchRechargeRecord2(this.params)
                    break;
                case `Finished`:
                    this.params.status = 10
                    this.fetchRechargeRecord10(this.params)
                    break;
                case `pendingProcessing`:
                    this.params.status = 1
                    this.fetchRechargeRecord1(this.params)
                    break;
    
                default:
                    break;
            }

            this.currentPage10 = 1,
                this.currentPage1 = 1,
                this.currentPage2 = 1,
                this.currentPage0 = 1
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.params.page = val
            switch (this.activeName) {
                case `all`:
                    this.params.status = 0
                    this.fetchRechargeRecord0(this.params)
                    break;
                case `pending`:
                    this.params.status = 2
                    this.fetchRechargeRecord2(this.params)
                    break;
                case `Finished`:
                    this.params.status = 10
                    this.fetchRechargeRecord10(this.params)
                    break;
                case `pendingProcessing`:
                    this.params.status = 1
                    this.fetchRechargeRecord1(this.params)
                    break;
    
                default:
                    break;
            }



        },
        handleElTabs(tab, event) {
            sessionStorage.setItem('helpActiveName', tab.name)
            // localStorage.setItem('activeName', tab.name)
            this.params.page = 1
            this.params.limit = 10
            switch (this.activeName) {
                case `all`:
                    this.params.status = 0
                    this.fetchRechargeRecord0(this.params)
                    break;
                case `pending`:
                    this.params.status = 2
                    this.fetchRechargeRecord2(this.params)
                    break;
                case `Finished`:
                    this.params.status = 10
                    this.fetchRechargeRecord10(this.params)
                    break;
                case `pendingProcessing`:
                    this.params.status = 1
                    this.fetchRechargeRecord1(this.params)
                    break;

                default:
                    break;
            }


        },

        handleClick() {
            this.params.address = ""
        },
        handelCloseWork(rows){
            this.fetchBKendTicket({id:rows.id})
        }
    },


}
