
/**
 * 
 * @param type bar柱状图 line曲线图
 * @param data 处理数据
 * @param swiData 当前的swi为按月true，按年false
 */

export default function findDataFun(type:any,data:any,swiData:any){
    if(type=='bar'){
        return barFun(data,swiData)
    }else{
        return lineFun(data,swiData)
    }
}

//筛选bar
function barFun(data:any,swiData:any) {
    const paramData:any = {
        titles:'',//标题
        xAxisArr:[],//x轴
        seriesDiscount:[], //合同总金额
        seriesRecoveries:[] //合同已回款金额
    }
    if(swiData){//按月
        if(data.ContractMoneyByMonth){
            data.ContractMoneyByMonth.forEach((item:any) => {
                paramData.titles = '月度合同金额统计(元)'
                paramData.xAxisArr.push(item.T_date + '月')
                paramData.seriesDiscount.push(item.T_discount)
                paramData.seriesRecoveries.push(item.T_recoveries_money)
            });
        }else{
            paramData.titles = '月度合同金额统计(元)'
            paramData.xAxisArr = []
            paramData.seriesDiscount = []
            paramData.seriesRecoveries = []

        }
       
    }else{//按年
        if(data.ContractMoneyByYear){
            data.ContractMoneyByYear.forEach((item:any) => {
                paramData.titles = '年度合同金额统计(元)'
                paramData.xAxisArr.push(item.T_date + '年')
                paramData.seriesDiscount.push(item.T_discount)
                paramData.seriesRecoveries.push(item.T_recoveries_money)
            });
        }else{
            paramData.titles = '年度合同金额统计(元)'
                paramData.xAxisArr = []
                paramData.seriesDiscount = []
                paramData.seriesRecoveries = []
        }
        
    }
    return paramData
}

//筛选line
function lineFun(data:any,swiData:any) {
    const paramData:any = {
        tooltip:'',
        titles:'',//标题
        xAxisArr:[],//x轴
        seriesArr:[], //合同数量
    }
    if(swiData){//按月
        if(data.ContractNumByMonth){
            data.ContractNumByMonth.forEach((item:any) => {
                paramData.tooltip = '月度(份)'
                paramData.titles = '月度合同数量(份)'
                paramData.xAxisArr.push(item.T_date + '月')
                paramData.seriesArr.push(item.T_num)
            });
        }else{
            paramData.tooltip = '月度(份)'
            paramData.titles = '月度合同数量(份)'
            paramData.xAxisArr = []
            paramData.seriesArr = []
        }
        
    }else{//按年
        if(data.ContractNumByYear){
            data.ContractNumByYear.forEach((item:any) => {
                paramData.tooltip = '年度(份)'
                paramData.titles = '年度合同数量(份)'
                paramData.xAxisArr.push(item.T_date + '年')
                paramData.seriesArr.push(item.T_num)
            });
        }else{
            paramData.tooltip = '年度(份)'
            paramData.titles = '年度合同数量(份)'
            paramData.xAxisArr = []
            paramData.seriesArr = []
        }
        
    }
    return paramData
}