|
|
|
@ -5,6 +5,8 @@ import {
|
|
|
|
|
times2
|
|
|
|
|
} from "../../../components/option/text"
|
|
|
|
|
import moment from "moment";
|
|
|
|
|
let iPageIndex = 1 // 当前第几页,0代表第一页
|
|
|
|
|
let iPageSize = 20 //每页显示多少数据
|
|
|
|
|
Page({
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
@ -19,7 +21,8 @@ Page({
|
|
|
|
|
ranking: [],
|
|
|
|
|
carName: "",
|
|
|
|
|
showDialog: false,
|
|
|
|
|
loadMore: false
|
|
|
|
|
loadMore: false, //"上拉加载"的变量,默认false,隐藏
|
|
|
|
|
loadAll: false, //“没有数据”的变量,默认false,隐藏
|
|
|
|
|
},
|
|
|
|
|
dropdownSel(e) {
|
|
|
|
|
this.setData({
|
|
|
|
@ -27,50 +30,75 @@ Page({
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getData() {
|
|
|
|
|
app.globalData.request({
|
|
|
|
|
action: 'getCheZhuCarSeriesListHome',
|
|
|
|
|
let obj = {
|
|
|
|
|
action: 'getCheZhuCarBrandTimeRankingHome',
|
|
|
|
|
sType: 'Marketing',
|
|
|
|
|
sBrand: this.data.carName || '',
|
|
|
|
|
sStartTime: this.data.date || "",
|
|
|
|
|
sEndTime: this.data.date2 || '',
|
|
|
|
|
}).then(res => {
|
|
|
|
|
const arr = []
|
|
|
|
|
const time = []
|
|
|
|
|
const obj = {}
|
|
|
|
|
var totalSum = 0
|
|
|
|
|
var num = 0
|
|
|
|
|
|
|
|
|
|
res.forEach(i => {
|
|
|
|
|
totalSum += parseInt(i.salescount)
|
|
|
|
|
// console.log(i.salescount)
|
|
|
|
|
if (!obj[i.sourcetime]) {
|
|
|
|
|
obj[i.sourcetime] = []
|
|
|
|
|
time.push(i.sourcetime)
|
|
|
|
|
num++
|
|
|
|
|
}
|
|
|
|
|
obj[i.sourcetime].push(i)
|
|
|
|
|
iPageIndex: iPageIndex,
|
|
|
|
|
iPageSize: iPageSize,
|
|
|
|
|
}
|
|
|
|
|
//第一次加载数据
|
|
|
|
|
if (iPageIndex == 1) {
|
|
|
|
|
this.setData({
|
|
|
|
|
loadMore: true, //把"上拉加载"的变量设为true,显示
|
|
|
|
|
loadAll: false //把“没有数据”设为false,隐藏
|
|
|
|
|
})
|
|
|
|
|
for (let j = 0; j < num; j++) {
|
|
|
|
|
var sum = 0
|
|
|
|
|
for (let a = 0; a < obj[time[j]].length; a++) {
|
|
|
|
|
sum += parseInt(obj[time[j]][a].salescount)
|
|
|
|
|
}
|
|
|
|
|
arr.push({
|
|
|
|
|
times: time[j],
|
|
|
|
|
sales: sum,
|
|
|
|
|
share: ((sum / totalSum) * 100).toFixed(2),
|
|
|
|
|
brand: this.data.carName
|
|
|
|
|
}
|
|
|
|
|
app.globalData.request(obj).then(res => {
|
|
|
|
|
if (res && res.length > 0) {
|
|
|
|
|
iPageIndex++;
|
|
|
|
|
// const arr = []
|
|
|
|
|
// const time = []
|
|
|
|
|
// const obj = {}
|
|
|
|
|
// var totalSum = 0
|
|
|
|
|
// var num = 0
|
|
|
|
|
|
|
|
|
|
// res.forEach(i => {
|
|
|
|
|
// totalSum += parseInt(i.salescount)
|
|
|
|
|
// // console.log(i.salescount)
|
|
|
|
|
// if (!obj[i.sourcetime]) {
|
|
|
|
|
// obj[i.sourcetime] = []
|
|
|
|
|
// time.push(i.sourcetime)
|
|
|
|
|
// num++
|
|
|
|
|
// }
|
|
|
|
|
// obj[i.sourcetime].push(i)
|
|
|
|
|
// })
|
|
|
|
|
// for (let j = 0; j < num; j++) {
|
|
|
|
|
// var sum = 0
|
|
|
|
|
// for (let a = 0; a < obj[time[j]].length; a++) {
|
|
|
|
|
// sum += parseInt(obj[time[j]][a].salescount)
|
|
|
|
|
// }
|
|
|
|
|
// arr.push({
|
|
|
|
|
// times: time[j],
|
|
|
|
|
// sales: sum,
|
|
|
|
|
// share: ((sum / totalSum) * 100).toFixed(2),
|
|
|
|
|
// brand: this.data.carName
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// if (arr.length == 0) {
|
|
|
|
|
// this.data.loadMore = true
|
|
|
|
|
// } else {
|
|
|
|
|
// this.data.loadMore = false
|
|
|
|
|
// }
|
|
|
|
|
let arr = this.data.ranking.concat(res);
|
|
|
|
|
this.setData({
|
|
|
|
|
ranking: arr,
|
|
|
|
|
loadMore: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (arr.length == 0) {
|
|
|
|
|
this.data.loadMore = true
|
|
|
|
|
if (res.length < iPageSize) {
|
|
|
|
|
this.setData({
|
|
|
|
|
loadMore: false, //隐藏加载中。。
|
|
|
|
|
loadAll: true //所有数据都加载完了
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.data.loadMore = false
|
|
|
|
|
this.setData({
|
|
|
|
|
loadAll: true, //把“没有数据”设为true,显示
|
|
|
|
|
loadMore: false //把"上拉加载"的变量设为false,隐藏
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
ranking: arr,
|
|
|
|
|
loadMore: this.data.loadMore
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -81,7 +109,6 @@ Page({
|
|
|
|
|
},
|
|
|
|
|
//详情跳转
|
|
|
|
|
detail(e) {
|
|
|
|
|
console.log(e)
|
|
|
|
|
const carBrand = e.currentTarget.dataset.carbrand
|
|
|
|
|
const carTime = e.currentTarget.dataset.cartime
|
|
|
|
|
// console.log(carbrand,carTime)
|
|
|
|
@ -109,8 +136,11 @@ Page({
|
|
|
|
|
let isBefore = moment(this.data.date2).isBefore(this.data.date)
|
|
|
|
|
// console.log(isBefore)
|
|
|
|
|
if (!isBefore) {
|
|
|
|
|
iPageIndex = 1
|
|
|
|
|
iPageSize = 20
|
|
|
|
|
this.setData({
|
|
|
|
|
date: e.detail.value
|
|
|
|
|
date: e.detail.value,
|
|
|
|
|
ranking: [],
|
|
|
|
|
})
|
|
|
|
|
this.getData()
|
|
|
|
|
} else {
|
|
|
|
@ -123,8 +153,11 @@ Page({
|
|
|
|
|
this.data.date2 = e.detail.value
|
|
|
|
|
let isBefore = moment(this.data.date2).isBefore(this.data.date)
|
|
|
|
|
if (!isBefore) {
|
|
|
|
|
iPageIndex = 1
|
|
|
|
|
iPageSize = 20
|
|
|
|
|
this.setData({
|
|
|
|
|
date2: e.detail.value
|
|
|
|
|
date2: e.detail.value,
|
|
|
|
|
ranking: [],
|
|
|
|
|
})
|
|
|
|
|
this.getData()
|
|
|
|
|
} else {
|
|
|
|
@ -145,6 +178,7 @@ Page({
|
|
|
|
|
this.data.date = options.date
|
|
|
|
|
this.data.date2 = options.date2
|
|
|
|
|
}
|
|
|
|
|
iPageIndex = 1;
|
|
|
|
|
this.getData()
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
@ -163,7 +197,16 @@ Page({
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
console.log("触发刷行")
|
|
|
|
|
console.log("上拉触底事件")
|
|
|
|
|
let that = this
|
|
|
|
|
if (!that.data.loadMore) {
|
|
|
|
|
that.setData({
|
|
|
|
|
loadMore: true, //加载中
|
|
|
|
|
loadAll: false //是否加载完所有数据
|
|
|
|
|
});
|
|
|
|
|
//加载更多,这里做下延时加载
|
|
|
|
|
that.getData();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onShow: function (options) {}
|
|
|
|
|
})
|