mathDate(search){
console.log(search,"时间");
var date = new Date(),
m = '';
if(search.month === 0 && search.year.getFullYear() === date.getFullYear()){
this.result = [];
if(date.getMonth() === 0){
for(var j=0;j<12;j++){
m = (date.getFullYear()-1)+'-'+(12-j);
this.result.push(m);
}
}else{
for (var i=0;i<date.getMonth()+1;i++){
m = date.getFullYear()+'-'+(date.getMonth()+1-i);
this.result.push(m);
}
if(this.result.length != 12){
for(var j=0;j<12;j++){
m = (date.getFullYear()-1)+'-'+(12-j);
this.result.push(m);
}
}
}
console.log(this.result,"自动日期");
this.myChartTrend.setOption({
xAxis:[{data:this.result.slice(0,12).reverse()}]
});
}else if(search.month === 0 && search.year.getFullYear() !== date.getFullYear()){
this.result = [];
for(var k=0;k<12;k++){
m = (search.year.getFullYear())+'-'+(12-k);
this.result.push(m)
}
console.log(this.result,"未输入月份的日期");
this.myChartTrend.setOption({
xAxis:[{data:this.result.slice(0,12).reverse()}]
});
}else {
this.result = [];
for (var i=0;i<Number(search.month);i++){
m = search.year.getFullYear()+'-'+(Number(search.month)-i);
this.result.push(m);
}
if(this.result.length != 12){
for(var j=0;j<12;j++){
m = (search.year.getFullYear()-1)+'-'+(12-j);
this.result.push(m);
}
}
console.log(this.result,"年月都有的日期");
this.myChartTrend.setOption({
xAxis:[{data:this.result.slice(0,12).reverse()}]
});
}
},
配合echart趋势柱状图使用