Page({
    data: {
        active: 0,
        ops: [{
            title: '销售数据',
            name: '0',
        }, {
            title: '',
            name: '',
        }, {
            title: '',
            name: '',
        }],
        tabsList: [{
            label: "销售面板",
            model: "#Panel"
        }, {
            label: "客户账户余额分析",
            model: "#CustomerBlance"
        }, {
            label: "销售TOP10",
            model: "#Top10"
        }, {
            label: "报价分析",
            model: "#BiddingAnalysis"
        }, {
            label: "订单趋势分析",
            model: "#OrderTrendAnalysis"
        }, {
            label: "订单类型占比分析",
            model: "#AnalysisOfOrderTypeDistribution"
        }, {
            label: "订单产品类别占比分析",
            model: "#AnalysisOfTheProportionOfProductCategoriesInOrders"
        }, {
            label: "出货趋势分析",
            model: "#ClearisTrendAnalysis"
        }, {
            label: "近12月延期出货情况分析",
            model: "#ShipmentAnalysis2"
        }, {
            label: "未出货已延期情况分析",
            model: "#ShipmentAnalysis3"
        }, {
            label: "开票金额趋势分析",
            model: "#InvoiceTrendAnalysis"
        }, {
            label: "近12月出货未开票金额趋势分析",
            model: "#GoodsDispatchedButInvoiceNotIssued"
        }, {
            label: "已下单未出货分析",
            model: "#ShipmentAnalysis1"
        }, {
            label: "出货未开票分析",
            model: "#AnalysisOfUninvoicedShipments"
        }, {
            label: "财务回款分析",
            model: "#FinancialCollectionAnalysis"
        }],
        tabsActive: 0,
        showFiltrate: false,
        type: 0,
        isleave: 1,
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '销售数据');
        let organization = this.selectComponent("#organization");
        organization.initDepAndUser()
        this.partialRenewal();
        this.setData({
            dataid: wx.getStorageSync('userMsg').userid,
            username: wx.getStorageSync('userMsg').name,
        });
    }, //tabs 切换
    tabsChange({
        detail
    }) {
        this.setData({
            tabsActive: detail
        });
        this.partialRenewal();
    },
    //局部数据更新 tabs
    partialRenewal() {
        const model = this.data.tabsList[this.data.tabsActive].model;
        if (model) {
            const Component = this.selectComponent(model);
            Component.getList(true);
        }
    },
    openFiltrate() {
        this.setData({
            showFiltrate: true
        })
    },
    handleFilter({
        detail
    }) {
        if (detail.name == "close") return;
        if (detail.name == 'reset') {
            this.selectComponent("#organization").setData({
                isleave: 1
            })
            this.selectComponent("#organization").initDepAndUser()
            this.setData({
                dataid: wx.getStorageSync('userMsg').userid,
                'type': 0,
                isleave: 1,
                username: wx.getStorageSync('userMsg').name
            })
        } else {
            let active = this.selectComponent("#organization").data.result,
                isleave = this.selectComponent("#organization").data.isleave;
            let type = active.userid ? 0 : 1,
                dataid = type == 0 ? active.userid : active.sa_saleareaid
            this.setData({
                isleave,
                dataid,
                type,
                username: active.name
            })
        }
        this.partialRenewal(true)
    },
})