list.js 2.7 KB
const util = new window.publicMethod() ;

new Vue({
    el: '#app',
    data: {
        loginInfo: JSON.parse(localStorage.getItem('appLoginInfo') || '{}'),

        activeTab: 'tab1',
        searchQuery: '',

        todoData: [],
        completedData: []
    },
    computed: {
        currentData() {
            return this.activeTab === 'tab1' ? this.todoData : this.completedData;
        },
        filteredData() {
            if (!this.searchQuery.trim()) {
                return this.currentData;
            }

            let query = this.searchQuery.toLowerCase();
            let arr = this.currentData.filter(item =>
                item.accNbr.toLowerCase().includes(query)
            );
            console.log(arr)
            return arr;
        }
    },
    methods: {
        logout(){
            localStorage.removeItem('appLoginInfo');
            window.location.replace('login.html');
        },
        switchTab(tab) {
            this.activeTab = tab;
            this.searchQuery = ''; // 切换标签时清空搜索

            this.queryList()
        },

        handleItemClick(item) {
            sessionStorage.removeItem('huaiAnAppParam')
            sessionStorage.setItem('listInfoParam',JSON.stringify(item))

            window.location.href = 'index.html'
        },
        queryList(){
            if(this.activeTab==='tab1' && this.todoData.length>0){
                return
            }
            if(this.activeTab==='tab2' && this.completedData.length>0){
                return
            }

            util.httpRequest({
                url: '/zj/'+(this.activeTab==='tab1'?'pending':'completed'),
                middleUrl: '/zhijian-trial/api',
                data: {
                   campaignId: this.loginInfo.campaignId,
                   accNbr: this.searchQuery,
                },
            }).then(res=>{
                if(res.code == 200){
                    if(this.activeTab==='tab1'){
                        let arr = res.data.records || []
                        let tArr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
                        tArr.forEach(item=>{
                            arr.push({
                                accNbr: 'testAccount'+item,
                                fullAddress: 'test地址'+item,
                            })
                        })

                        this.todoData = arr
                    }
                    if(this.activeTab==='tab2'){
                        this.completedData = res.data.records || []
                    }
                }else{
                    util.toast(res.msg || '获取失败')
                }
            })
        },
    },

    mounted() {
        this.queryList()
    }
});