dataView.vue 10.6 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"
                      >
                        <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>
                        <el-scrollbar class="content">
                          <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>
                        </el-scrollbar>
                      </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: 1,
      nothing,
    }
  },
  mounted () {
    this.refreshTable()
  },
  methods: {
    async refreshTable () {
      function splitArrayIntoChunks (arr, chunkSize) {
        const weight = 1 / arr.length
        return arr.reduce((result, item, index) => {
          const chunkIndex = Math.floor(index / chunkSize)
          item.width = `${(weight * index + weight) * 100}%`
          result[chunkIndex] = result[chunkIndex] || []
          result[chunkIndex].push(item)
          return result
        }, [])
      }
      const params = {
        ...JSON.parse(JSON.stringify(this.params)),
        pageSize: 9999,
        pageNumber: this.pageNumber
      }
      const stageList = this.stageList,
        arr = [],
        { sopJourneyStage } = params
      for (let k of stageList) {
        if (k.value) {
          params.sopJourneyStage = k.value
          let list = []

          if (!sopJourneyStage || sopJourneyStage == k.value) {
            this.dataViewLoading = false
            const { list: apiList } = await this.$apis.journey.getCustomersList(params)
            list = apiList
          }
          list.length &&
            list.forEach((e) => {
              e.day = dayjs().diff(dayjs(e.sopJourneyStageEnterTime).format('YYYY/MM/DD'), 'day')
            })
          arr.push({
            title: k.label,
            list
          })
        }
      }
      this.viewList = splitArrayIntoChunks(arr, 4)
      this.dataViewLoading = true
    },
  }
}
</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: scroll;
            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;
                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>