美文网首页
处理数据,按月份划分

处理数据,按月份划分

作者: 八妹sss | 来源:发表于2023-08-07 11:34 被阅读0次

    数据处理代码:

    // 获取客户跟进记录
        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 = {};
                // 遍历数据数组,将数据按月份分组
                list.forEach(item => {
                  const month = item.month
                  if (!groupedData[month]) {
                    groupedData[month] = []; // 如果该月份还没有分组,则创建一个新的分组数组
                  }
                  groupedData[month].push(item); // 将数据添加到对应的分组数组中
                })
                
                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)
            }
          })
        },
    
    效果图: image.png

    相关文章

      网友评论

          本文标题:处理数据,按月份划分

          本文链接:https://www.haomeiwen.com/subject/jergpdtx.html