// import * as echarts from "echarts";
// import { msgBoradTabel, msgBoradNum, responMsg } from "../../api/messageBoard"
import { getPrivateTicket } from "../../api/work"
// import { Debounce } from "../../util/processingData"
export default {
    data() {
        return {
            from2: [
            //     {
            //     id: 15656,
            //     type: "维修工单",
            //     date: "",
            //     model: "",
            //     serialNo: "56565",
            //     email: "",
            //     status: "",
            //     process: "",

            // }
        ],
            from0: [
            //     {
            //     id: 15656,
            //     type: "维修工单",
            //     date: "",
            //     model: "",
            //     serialNo: "56565",
            //     email: "",
            //     status: "待收货",
            //     process: "",

            // }
        ],
            from1: [
            //     {
            //     id: 15656,
            //     type: "维修工单",
            //     date: "",
            //     model: "",
            //     serialNo: "56565",
            //     email: "",
            //     status: "",
            //     process: "",

            // }
        ],
            params: {
                // page: 1,
                // limit: 300,
                status: 1,
                // cond: "",
                // start: "",
                // end: "",
            },
            PrivateConsume: false,
            activeName: "pending",
            WKRecordsLoading: false,
            value1: "",
            labelPosition: "top",
            currentPage: 1,
            msg: "",
            dialogVisible: false,
            rowId: "",
            faultList: [],         
            typeList: [],
            statusList:[
                {//待处理
                    value:1,
                    label:"work.pendingProcessing"
                },
                {//处理中
                    value:2,
                    label:"work.processed"
                },
                {//已完结
                    value:10,
                    label:"work.completeWK"
                }
                
            ]

        }
    },
    mounted() {


        localStorage.setItem("stateList",JSON.stringify(this.statusList) )

        this.activeName = sessionStorage.getItem('ActiveName')
        if (!this.activeName) {
            this.activeName = "pending"
        }

        switch (this.activeName) {
            case "pending":
                this.params.status = 1
                this.fetchPrivateConsume1(this.params)
                this.registerRecoveryMethod('fetchPrivateConsume1', this.params);
                break;
            case "success"://已完成工单
                this.params.status = 2
                this.fetchPrivateConsume2(this.params)
                this.registerRecoveryMethod('fetchPrivateConsume2', this.params);
                break;
            case "reply"://全部工单
                this.params.status = 0
                this.fetchPrivateConsume0(this.params)
                this.registerRecoveryMethod('fetchPrivateConsume0', this.params);
                break;

            default:
                break;
        }
    },
    methods: {
        //进行中工单记录
        async fetchPrivateConsume1(params) {
            this.WKRecordsLoading = true
            const res = await getPrivateTicket(params)
            if (res && res.code == 200) {
                this.from1 = res.data
            }
           
            this.WKRecordsLoading = false
        },
         //请求工单记录 全部
         async fetchPrivateConsume0(params) {
            this.WKRecordsLoading = true
            const res = await getPrivateTicket(params)
            if (res && res.code == 200) {

                this.from0 = res.data
            }
           
            this.WKRecordsLoading = false

        },
     
        //请求工单记录 已完成
        async fetchPrivateConsume2(params) {
            this.WKRecordsLoading = true
            const res = await getPrivateTicket(params)
            if (res && res.code == 200) {
                this.from2 = res.data
            }           
            this.WKRecordsLoading = false
        },



        
        async fetchTicketPayment(params) {
            const { data } = await getTicketPayment(params)
            if (data.url) {

                window.location.href = data.url
            }
        },

        handelType2(label) {
        //    console.log(label,66666);
            if (this.typeList && label) {
                const item = this.typeList.find(item => item.name == label);
                if (item) {
                    return item.label;
                }
            }
            return '';
        },
        handelStatus2(status) {

            if (this.statusList && status) {
                const item1 = this.statusList.find(item => item.value == status)

                
                if (item1) {
                    return this.$t(item1.label) 
                }
            }
            return '';
        },
        handelPhenomenon(id) {
            if (id) {
                return this.faultList.find(item => item.id == id).label
            }

        },
        //点击工单详情
        handelDetails(rows) {

            // this.$router.push({ name: 'UserWorkDetails', params: { workID: rows.id } })

            // localStorage.setItem("workOrderId", rows.id)

             // 获取当前语言
            const lang = this.$i18n.locale;
            
            // 添加语言参数的路由跳转
            this.$router.push({ 
                path: `/${lang}/UserWorkDetails`, 
                query: { workID: rows.id } 
            }).catch(err => {
                if(err.name !== 'NavigationDuplicated') {
                console.error('路由跳转失败:', err);
                }
            });

            // 保存ID到localStorage
            localStorage.setItem("workOrderId", rows.id);

        },
     

    
        //请求结束工单
        async fetchendTicket(params) {
            this.WKRecordsLoading = true
            let data = await getEndTicket(params)

            if (data && data.code == 200) {


                this.$message({
                    message: this.$t(`user.closeWK`),
                    type: 'success'
                })
                this.dialogVisible = false

                this.params.status = 0
                this.fetchPrivateConsume0(this.params)
                this.params.status = 1
                this.fetchPrivateConsume1(this.params)
                this.params.status = 2
                this.fetchPrivateConsume2(this.params)

            }
            this.WKRecordsLoading = false
        },
        handelTime(time) {
            if (time) {
                return `${time.split("T")[0]} ${time.split("T")[1].split(".")[0]}`
            }
        },
  
   

        handleClick() {
            // this.params.cond = ""
            switch (this.activeName) {
                case "pending":
                    this.params.status = 1
                    this.fetchPrivateConsume1(this.params)
                    break;
                case "success"://已完成工单
                    this.params.status = 2
                    this.fetchPrivateConsume2(this.params)
                    break;
                case "reply"://全部工单
                    this.params.status = 0
                    this.fetchPrivateConsume0(this.params)
                    break;

                default:
                    break;
            }
            sessionStorage.setItem("ActiveName", this.activeName)
        },


        determineInformation() {
            this.fetchendTicket({ id: this.rowId })
        }


    }
}