You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

500 lines
14 KiB

3 years ago
// pages/index/Salesranking/Salesranking.js
3 years ago
const app = getApp()
import brokenLine from "../../../components/option/singleLineOption"
3 years ago
import histogram from "../../../components/option/columnarOption"
import {
3 years ago
times
3 years ago
} from "../../../components/option/text"
3 years ago
import moment from "moment"
3 years ago
let iPageIndex = 1 // 当前第几页,0代表第一页
3 years ago
let iPageSize = 20 //每页显示多少数据
3 years ago
Page({
3 years ago
data: {
3 years ago
nengtitle1: '全部级别',
nengtitle2: '全部价格',
nengtitle3: '全部能源',
3 years ago
active: 0,
end: moment().format("YYYY-MM"),
showChart: true,
// select: false,
grade_value2: "",
grade_value4: 0,
grades4: [{
text: '列表展示',
value: 0
},
{
text: '图表展示',
value: 1
}
],
num: 0,
num1: false,
//弹出框
show: false,
duration: 300,
position: 'bottom',
// round: true,
overlay: true,
showChart: true,
//图表
// positiveOption:brokenLine(dName,dValue,dColor,data),
imageUrl: getApp().globalData.imageUrl,
accountIndex: 0,
ranking: [],
accountIndex: 0,
sSpec: '',
sPriceType: '',
sEnergyType: '',
imageUrl: getApp().globalData.imageUrl,
mockData: [],
3 years ago
mainActiveIndex: 0,
3 years ago
mainActiveIndex2: 0,
3 years ago
activeId: '',
3 years ago
activeId2: '',
3 years ago
//
ec: {
lazyLoad: true // 设置图表懒加载
3 years ago
},
3 years ago
dateList: [], //日期列表
currentDate: '',
startDate: '',
endDate: ''
},
onLoad() {
app.globalData.request({
action: 'getCheZhuLatestTimeHome',
sType: 'Marketing',
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
}).then(res => {
let dateArr = [];
for(let i=0; i<6;i++) {
let date = this.getLastMonth(res, i);
dateArr.push(date);
};
3 years ago
this.setData({dateList: dateArr, currentDate: dateArr[0]});
3 years ago
})
},
getLastMonth(dt, number = 0) {
if(number >= 12) {return}
let year = new Date(dt).getFullYear(); //get年份
let month = new Date(dt).getMonth() + 1; //get月份
let m = month - number;
let y = year;
if(m < 0) {
y = y - 1; m = 12 + m;
};
if(m < 10) {
m = '0' + m;
}
return y+'-'+m;
},
changeDate(option) {
iPageIndex = 1
iPageSize = 20
let value = option.currentTarget.dataset.value;
this.setData({ranking: [], currentDate: value, startDate: value, endDate: value});
this.getTrend();
},
changePast(option) {
iPageIndex = 1
iPageSize = 20
let value = option.currentTarget.dataset.value;
if(value == 'past3') {
this.setData({ranking: [], endDate: this.data.dateList[0], startDate: this.data.dateList[2], currentDate: '近3个月'})
} else if(value == 'past6') {
this.setData({ranking: [], endDate: this.data.dateList[0], startDate: this.data.dateList[5], currentDate: '近6个月'})
}
this.getTrend();
3 years ago
},
// 标签切换点击事件
onChange(val) {
let n = val.detail.index;
3 years ago
this.setData({
3 years ago
active: n
})
// wx.showToast({
// // title: `切换到标签 ${event.detail.name}`,
// icon: 'none',
// });
},
getData() {
wx.showToast({
title: '加载中',
icon: 'loading',
duration: 3000
})
// 下拉列表
this.getAmount();
// 车型
this.getTrend();
// 品牌
app.globalData.request({
action: 'getUserBrand',
3 years ago
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
3 years ago
}).then(res => {
let arr = []
for (let i = 65; i <= 90; i++) {
arr.push({
name: String.fromCharCode(i),
data: []
});
}
for (let i of res) {
for (let j of arr) {
if (i.firstword == j.name) {
j.data.push(i)
}
}
}
this.setData({
mockData: arr
})
setTimeout(() => {
wx.hideToast();
}, 2000)
})
setTimeout(() => {
wx.hideToast();
}, 500)
},
// 排行榜数据
getTrend() {
wx.showToast({
title: '加载中',
icon: 'loading',
duration: 300000
})
let obj = {
action: 'getCheZhuCarSeriesRankingHome',
sType: 'Marketing',
3 years ago
sStartTime: this.data.startDate,
sEndTime: this.data.endDate,
3 years ago
iPageIndex: iPageIndex,
iPageSize: iPageSize,
sSpec: this.data.sSpec,
sPriceType: this.data.sPriceType,
sEnergyType: this.data.sEnergyType
3 years ago
}
3 years ago
//第一次加载数据
if (iPageIndex == 1) {
this.setData({
loadMore: true, //把"上拉加载"的变量设为true显示
loadAll: false //把“没有数据”设为false隐藏
})
}
app.globalData.request(obj, (database) => {}).then(res => {
const carName = []
const carValue = []
// console.log("这是数据",res)
if (res && res.length > 0) {
iPageIndex++;
//把新请求到的数据添加到列表里
let list = this.data.ranking.concat(res);
list.forEach(e => {
carName.push(e.seriesname)
carValue.push(e.salescount)
})
// length=(carName.length/carName.length)*100
// console.log(carName.length)
this.setData({
ranking: list, //获取数据数组
loadMore: false, //把"上拉加载"的变量设为false显示
brandOption: histogram(carName, carValue, '#0084FF', false, (20 / list.length) * 100)
});
if (res.length < iPageSize) {
this.setData({
loadMore: false, //隐藏加载中。。
loadAll: true //所有数据都加载完了
});
}
} else {
this.setData({
loadAll: true, //把“没有数据”设为true显示
loadMore: false //把"上拉加载"的变量设为false隐藏
3 years ago
3 years ago
});
}
setTimeout(() => {
wx.hideToast();
}, 500)
})
},
//页面上拉触底事件的处理函数
onReachBottom: function () {
let that = this
if (!that.data.loadMore) {
that.setData({
loadMore: true, //加载中
loadAll: false //是否加载完所有数据
});
//加载更多,这里做下延时加载
that.getTrend();
3 years ago
}
3 years ago
},
// 筛选列表
getAmount() {
//能源
app.globalData.request({
action: 'getEnergyJson2',
}).then(res => {
let arr = []
res.forEach(ele => {
3 years ago
let data = ele.data || []
let obj = {
text: ele.value,
id: ele.key,
}
if (data.length > 0) {
obj.children = [];
3 years ago
data.forEach(e => {
let ol = {
text: e.value,
3 years ago
id: e.key
3 years ago
}
3 years ago
obj.children.push(ol)
3 years ago
})
3 years ago
}
3 years ago
arr.push(obj)
3 years ago
})
this.setData({
grades3: arr
})
})
//价格
app.globalData.request({
action: 'getPriceRangeS',
}).then(res => {
let arr = []
res.forEach(ele => {
let obj = {
text: ele.value,
value: ele.key
}
arr.push(obj)
})
this.setData({
grades2: arr
})
})
//级别
app.globalData.request({
action: 'getSpecName1',
}).then(res => {
let arr = []
res.forEach(ele => {
3 years ago
let data = ele.data || []
let obj = {
text: ele.value,
id: ele.key,
}
if (data.length > 0) {
obj.children = [];
3 years ago
data.forEach(e => {
let ol = {
text: e.value,
3 years ago
id: e.key
3 years ago
}
3 years ago
obj.children.push(ol)
3 years ago
})
3 years ago
}
3 years ago
arr.push(obj)
3 years ago
})
this.setData({
grades1: arr,
})
})
},
bindValue(e) {
let type = e.detail.type
if (type == 0) {
this.data.roomLevel = e.detail.val
} else {
this.data.builds = e.detail.val
3 years ago
}
3 years ago
},
// 按价格
3 years ago
mySelect2({ detail }) {
3 years ago
iPageIndex = 1
iPageSize = 20
3 years ago
let n = 0;
if(detail) {
n = detail * 1;
}
3 years ago
this.setData({
ranking: [],
3 years ago
sPriceType: this.data.grades2[n].value,
nengtitle2:this.data.grades2[n].text,
3 years ago
})
this.getTrend()
},
// 列表展示
mySelect4(e) {
iPageIndex = 1
iPageSize = 20
this.setData({
ranking: [],
3 years ago
a: e.detail != 0,
3 years ago
showvalue: false
3 years ago
})
this.getTrend()
},
// 全部
all() {
iPageIndex = 1
iPageSize = 20
this.data.num++
let dj = this.data.num % 2 == 0
this.setData({
ranking: [],
3 years ago
nengtitle1: '全部级别',
nengtitle2: '全部价格',
nengtitle3: '全部能源',
3 years ago
sSpec: '',
sPriceType: '',
sEnergyType: '',
boxSize: dj ? 'noall' : 'all1'
})
this.getTrend()
},
priceSel(e) {
this.setData({
intervalSel: e.currentTarget.dataset.index
})
},
//弹出框
popup(e) {
let duration = this.data.duration
let models = e.currentTarget.dataset.car
app.globalData.request({
action: "getCheZhuCarSeriesListHome",
sType: "Marketing",
sSeriesName: models,
3 years ago
sStartTime: times(this.data.startDate),
sEndTime: this.data.endDate,
3 years ago
}).then(res => {
// console.log(res)
const dataTime = []
const dataCar = []
res.forEach(e => {
if ((e.sourcetime).substring(5, 6) == "0") {
dataTime.push((e.sourcetime).substring((e.sourcetime).length - 1, (e.sourcetime).length) + '月')
} else {
dataTime.push((e.sourcetime).substring((e.sourcetime).length - 2, (e.sourcetime).length) + "月")
}
dataCar.push(e.salescount)
});
this.setData({
show: true,
duration,
positiveOption: brokenLine(dataCar, dataTime),
models
})
})
},
3 years ago
onClose(){
this.setData({
show: false
})
},
3 years ago
exit() {
this.setData({
show: false
})
},
onShow() {
iPageIndex = 1;
3 years ago
this.setData({
3 years ago
startDate: wx.getStorageSync('newTime'),
endDate: wx.getStorageSync('newTime')
3 years ago
})
3 years ago
// this.getTabBar().init();
this.getData()
},
changeTab(val) {
let n = val.detail.index;
// console.log(n)
this.setData({
active: n
})
},
3 years ago
// 树形结构父级点击
3 years ago
// 按能源
onClickNav({
detail = {}
}) {
3 years ago
this.setData({
3 years ago
mainActiveIndex: detail.index || 0,
3 years ago
});
3 years ago
let {
grades3
} = this.data;
if (!grades3[detail.index].children) {
3 years ago
this.setData({
ranking: [],
3 years ago
sEnergyType: grades3[detail.index].id || "",
nengtitle3: grades3[detail.index].text,
3 years ago
})
3 years ago
this.selectComponent('#menuitem2').toggle(false);
3 years ago
this.getTrend()
3 years ago
}
3 years ago
},
3 years ago
// 按级别
onClickNav2({
detail = {}
}) {
3 years ago
this.setData({
3 years ago
mainActiveIndex2: detail.index || 0,
3 years ago
});
3 years ago
let {
grades1
} = this.data;
if (!grades1[detail.index].children) {
3 years ago
this.setData({
ranking: [],
sSpec: grades1[detail.index].id || "",
3 years ago
nengtitle1: grades1[detail.index].text,
3 years ago
})
3 years ago
this.selectComponent('#menuitem1').toggle(false);
3 years ago
this.getTrend()
}
},
3 years ago
// 树形结构子级点击
// 按能源
onClickItem({
detail = {}
}) {
const activeId = this.data.activeId === detail.id ? null : detail.id;
3 years ago
// let {
// mainActiveIndex
// } = this.data;
3 years ago
this.setData({
ranking: [],
activeId,
nengtitle3: detail.text,
3 years ago
// sEnergyType: mainActiveIndex + "," + activeId,
sEnergyType:activeId,
3 years ago
3 years ago
});
3 years ago
this.selectComponent('#menuitem2').toggle(false);
3 years ago
this.getTrend()
},
// 按级别
onClickItem2({
detail = {}
}) {
const activeId2 = this.data.activeId2 === detail.id ? null : detail.id;
let {
mainActiveIndex2
} = this.data;
this.setData({
ranking: [],
activeId2,
nengtitle1: detail.text,
3 years ago
// sSpec: mainActiveIndex2 + "," + activeId2,
sSpec:activeId2,
3 years ago
});
3 years ago
this.selectComponent('#menuitem1').toggle(false);
3 years ago
this.getTrend()
},
3 years ago
})