dataView.vue 12 KB
<template>
  <div class="data-view">
    <div class="title">旅程看板</div>
    <div class="carousel-box">
      <template v-if="dataViewLoading">
        <template v-if="viewList.length">
          <el-carousel ref="carousel" :autoplay="false" :loop="false" indicator-position="none" height="100%" arrow="never" class="carousel" @change="viewIndex = $event">
            <template v-for="(i, index) in viewList">
              <template>
                <el-carousel-item :key="index" class="carousel-item">
                  <template v-for="(c, cindex) in i">
                    <template>
                      <div :key="cindex" class="group" v-loading="c.loading">
                        <div class="title">
                          <div class="text flex">
                            <div class="icon">
                              <img :src="`https://img01.glsx.com.cn/weapp/resource/saas/scrm/data-view-sop-${cindex}.png`" />
                            </div>
                            {{ c.title }}
                          </div>
                          <div class="line-box">
                            <div class="line" :style="[{ width: c.width }]"></div>
                          </div>
                        </div>
                        <div
                          class="content"
                          v-infinite-scroll="
                            () => {
                              infiniteLoad(cindex, index)
                            }
                          "
                        >
                          <template v-if="c.list.length">
                            <template v-for="(item, ind) in c.list">
                              <template>
                                <div :key="ind" class="item">
                                  <div class="top flex">
                                    <div class="icon">
                                      <template v-if="item.wechatAvatarUrl">
                                        <img :src="item.wechatAvatarUrl" />
                                      </template>
                                      <template v-else>
                                        <img src="@/assets/icon/default-avatar.png" />
                                      </template>
                                    </div>
                                    <div class="text">
                                      <div class="name">
                                        {{ item.customerName || '' }}
                                        <template v-if="item.wechatNickname">@{{ item.wechatNickname }}</template>
                                      </div>
                                      {{ item.customerPhone }}
                                    </div>
                                  </div>
                                  <div class="bottom flex">
                                    <div class="left text-hide">进入该阶段:第{{ item.day }}天</div>
                                    <div class="right text-hide">跟进人:{{ item.sopFollowUpPersonName || '--' }}</div>
                                  </div>
                                </div>
                              </template>
                            </template>
                          </template>
                          <template v-else>
                            <div class="nothing">
                              <img src="@/assets/icon/nodata.png" />
                            </div>
                          </template>
                        </div>
                      </div>
                    </template>
                  </template>
                </el-carousel-item>
              </template>
            </template>
          </el-carousel>
          <div class="arrow left" @click="$refs.carousel.prev()">
            <img :src="viewIndex == 0 ? leftIcon : leftActiveIcon" />
          </div>
          <div class="arrow right" @click="$refs.carousel.next()">
            <img :src="viewIndex < viewList.length - 1 ? rightActiveIcon : rightIcon" />
          </div>
        </template>
        <template v-else>
          <div class="nothing">
            <img :src="nothing" />
            暂无数据
          </div>
        </template>
      </template>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import * as dayjs from 'dayjs'
import nothing from '@/assets/icon/data-view-nothing.png'
export default {
  name: '',
  props: {
    params: {
      type: Object,
      default: () => { }
    },
    stageList: {
      type: Array,
      default: () => { }
    },
  },
  data () {
    return {
      dataViewLoading: true,
      viewList: [],
      viewIndex: 0,
      leftIcon: require('@/assets/icon/left.png'),
      leftActiveIcon: require('@/assets/icon/left-active.png'),
      rightIcon: require('@/assets/icon/right.png'),
      rightActiveIcon: require('@/assets/icon/right-active.png'),
      pageNumber: [11],
      pageCount: [],
      nothing,
    }
  },
  watch: {
    // stageList: {
    //   handler() {
    //     this.pageNumber = new Array(this.stageList.length).fill(1);
    //     this.pageCount = new Array(this.stageList.length).fill(0)
    //   },
    //   deep:true,
    //   immediate:true
    // }
  },
  mounted () {
    this.refreshTable()
  },
  methods: {
    // 下拉加载
    async infiniteLoad (cindex, index) {
      if (this.viewList[index][cindex].list.length == 0) return
      if (this.viewList[index][cindex].list.length == this.pageCount[cindex]) return
      this.pageNumber[cindex]++
      const params = {
        ...this.$common.utils.deepClone(this.params),
        pageSize: 10,
        pageNumber: this.pageNumber[cindex],
        sopJourneyStage: this.stageList[cindex+1].value
      }
      let { list } = await this.$apis.journey.getCustomersList(params)
      list.length &&
        list.forEach((e) => {
          e.day = dayjs().diff(dayjs(e.sopJourneyStageEnterTime).format('YYYY/MM/DD'), 'day')
        })
      this.viewList[index][cindex].list = this.viewList[index][cindex].list.concat(list)
    },
    async refreshTable () {
      function splitArrayIntoChunks (arr, chunkSize) {
        const weight = 1 / arr.length
        return arr.reduce((result, item, index) => {
          const chunkIndex = Math.floor(index / chunkSize)
          // console.log(index, chunkIndex)
          item.width = `${(weight * index + weight) * 100}%`
          result[chunkIndex] = result[chunkIndex] || []
          result[chunkIndex].push(item)
          return result
        }, [])
      }
      const params = {
        ...this.$common.utils.deepClone(this.params),
        pageSize: 10,
        pageNumber: 1
      }
      const stageList = this.stageList,
        arr = [],
        { sopJourneyStage } = params
      this.dataViewLoading = false
      for (let k in stageList) {
        if (stageList[k].value) {
          arr.push({
            title: stageList[k].label,
            list: [],
            loading: true
          })
          this.viewList = splitArrayIntoChunks(arr, 4)
          this.dataViewLoading = true
        }
      }
      for (let k in stageList) {
        if (stageList[k].value) {
          params.sopJourneyStage = stageList[k].value
          let list = []
          if (!sopJourneyStage || sopJourneyStage == stageList[k].value) {
            k != 0 && this.$set(this.pageNumber, k - 1, 1)

            const { list: apiList, total } = await this.$apis.journey.getCustomersList(params)
            console.log(total,'total')
            list = apiList
            k != 0 && this.$set(this.pageCount, k - 1, total)
          }
          list.length &&
            list.forEach((e) => {
              e.day = dayjs().diff(dayjs(e.sopJourneyStageEnterTime).format('YYYY/MM/DD'), 'day')
            })
          this.viewList.forEach(item => {
            item.forEach(e => {
              if (!e.list.length && e.title === stageList[k].label) {
                e.list = list || []
                e.loading = false
              }
            })
          })
        }
      }
    },
  }
}
</script>

<style scoped lang="scss">
.flex {
  display: flex;
  align-items: center;
}
.data-view {
  height: 100%;
  .title {
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    padding: 8px 0 16px;
  }
  .carousel-box {
    height: calc(100% - 40px);
    position: relative;
    .carousel {
      height: 100%;
      &-item {
        display: flex;
        gap: 8px;
        .group {
          width: 25%;
          height: 100%;
          background: #f9f9fe;
          border-radius: 4px;
          .title {
            height: 60px;
            background: #f0efff;
            border-radius: 4px 4px 0 0;
            box-sizing: border-box;
            padding: 10px 16px;
            .text {
              font-weight: 500;
              font-size: 16px;
              color: #5850ff;
              .icon {
                width: 30px;
                height: 30px;
                margin-right: 8px;
              }
            }
            .line-box {
              height: 2px;
              background: #d6d4f8;
              border-radius: 1px;
              margin-top: 8px;
              .line {
                height: 100%;
                background-color: #5850ff;
                border-radius: 1px;
                transition: all 0.25s;
              }
            }
          }
          .content {
            height: calc(100% - 60px);
            overflow-y: auto;
            box-sizing: border-box;
            padding: 16px 16px 8px;
            position: relative;
            /deep/.el-scrollbar__wrap {
              width: 100%;
              &::-webkit-scrollbar {
                width: 0;
                height: 0;
                color: transparent;
              }
            }
            &::-webkit-scrollbar {
              width: 0;
              height: 0;
              color: transparent;
            }
            .item {
              height: 91px;
              background: #ffffff;
              border-radius: 4px;
              margin-bottom: 8px;
              .top {
                border-bottom: 1px solid #f0efff;
                padding: 8px;
                .icon {
                  width: 40px;
                  height: 40px;
                  margin-right: 8px;
                  overflow: hidden;
                  border-radius: 100%;
                }
                .text {
                  font-size: 12px;
                  color: #666666;
                  .name {
                    font-weight: 500;
                    font-size: 14px;
                    color: #333333;
                    margin-bottom: 4px;
                  }
                }
              }
              .bottom {
                height: 33px;
                line-height: 33px;
                justify-content: space-between;
                padding: 0 8px;
                font-size: 12px;
                color: #666666;
                .text-hide {
                  flex: 1;
                }
                .right {
                  text-align: right;
                }
              }
            }
            .nothing {
              position: absolute;
              left: 50%;
              top: 50%;
              transform: translate(-50%, -50%);
              width: 270px;
              height: 112px;
            }
          }
        }
      }
    }
    &:hover {
      .arrow {
        display: block;
      }
    }
    .arrow {
      display: none;
      position: absolute;
      width: 36px;
      height: 36px;
      top: 50%;
      transform: translateY(-50%) scale(1.15);
      z-index: 2;
      cursor: pointer;
      opacity: 0;
      animation: show-arrow 0.25s forwards;
    }
    .left {
      left: -12px;
    }
    .right {
      right: -12px;
    }
    @keyframes show-arrow {
      to {
        opacity: 1;
        transform: translateY(-50%) scale(1);
      }
    }
    .nothing {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      font-size: 16px;
      color: #999999;
      img {
        width: 270px;
        height: 112px;
      }
    }
  }
}
</style>