數(shù)據(jù)處理代碼:
// 獲取客戶跟進記錄
fetchFollowList () {
let url = `/agent/guest/follow/list`
let params = {
customer_id: this.clientId,
page: this.page,
per_page: 10
}
this.loading = true
this.$_load.show()
this.$post(url, params).then(res => {
this.loading = false
this.$_load.hide()
if (res.code === 200) {
let data = res.data
if (data) {
let list = data.data || []
const groupedData = {};
// 遍歷數(shù)據(jù)數(shù)組撮奏,將數(shù)據(jù)按月份分組
list.forEach(item => {
const month = item.month
if (!groupedData[month]) {
groupedData[month] = []; // 如果該月份還沒有分組魔眨,則創(chuàng)建一個新的分組數(shù)組
}
groupedData[month].push(item); // 將數(shù)據(jù)添加到對應(yīng)的分組數(shù)組中
})
let followList = []
let keys = Object.keys(groupedData)
keys.forEach(item => {
let obj = {
month: item,
dataList: groupedData[item]
}
followList.push(obj)
})
if (!this.followList || !this.followList.length) {
this.followList = followList
} else {
let lastInfo = this.followList[this.followList.length - 1]
let lastMonth = lastInfo.month
followList.forEach(item => {
if (item.month === lastMonth) {
lastInfo.dataList = lastInfo.dataList.concat(item.dataList)
} else {
this.followList.push(item)
}
})
}
}
if (this.page < data.last_page) {
this.isEnd = false
} else {
this.isEnd = true
}
this.refreshScroll()
} else {
this.$toast(res.message)
}
})
},
效果圖: