statistic.vue 10.8 KB
<template>
  <div class="statisic-container">
    <van-tabs v-model="tabIndex" sticky @change="tabChange">
      <van-tab :title="'未送达(' + deliveredData.undelivered + ')'">
        <scroll-view @ReachBottom="onReachBottom" ref="scrollView">
          <div class="reason">
            <div>未送达可能原因:</div>
            <div>1. 客户开启消息免打扰,消息发送失败;</div>
            <div>2. 群发次数达到上限,上限次数为每个客户每天仅可接收1条群发消息。(系统将连续重试3天)</div>
          </div>
          <customer-card v-if="customerInfo1.length > 0" :customerInfo="customerInfo1" @showFollowPop="showFollowPop" @showInfoPop="showInfoPop" @showAction="showAction"></customer-card>
          <empty v-else></empty>
        </scroll-view>
      </van-tab>
      <van-tab :title="'已送达(' + deliveredData.delivered + ')'">
        <div class="statistic-pic flex">
          <div class="funnel-logo">
            <img v-if="activityGroupType" src="@/assets/images/funnel.png" alt="" />
            <img v-else src="@/assets/images/funnel2.png" alt="" />
          </div>
          <div class="statistic-list">
            <template v-for="(status, index) in reachStatus">
              <div class="font-12 color-2f flex m-b-14" :key="index">
                <div class="circle" :style="{ background: status.color }"></div>
                {{ status.text }}
                <span class="font-16 color-3 m-l-8 bold">{{ status.value(deliveredData) }}</span>
                <span class="font-10 color39 m-l-4 fw5">
                  ({{ Number(status.proportion(deliveredData)) == 0 ? '0' : parseInt((Number(status.value(deliveredData)) / Number(status.proportion(deliveredData))) * 100) }}%)
                </span>
              </div>
            </template>
          </div>
        </div>
        <select-bar :index="alreadyIndex" :list="selectBarList" @change="changeSelectTab"></select-bar>
        <customer-card v-if="customerInfo2.length > 0" :customerInfo="customerInfo2" @showFollowPop="showFollowPop" @showInfoPop="showInfoPop" @showAction="showAction"></customer-card>
        <empty v-else></empty>
      </van-tab>
    </van-tabs>
    <!-- 跟进弹窗 -->
    <customer-follow-popup ref="customerFollowRef" :info="followCustomerData" @changeIndexEvent="changeIndexEvent"></customer-follow-popup>
    <!-- 客户信息弹窗 -->
    <customer-info-popup ref="customerInfoRef"></customer-info-popup>
    <van-action-sheet v-model:show="show" :actions="actions" @select="onSelect" cancel-text="取消" close-on-click-action @cancel="onCancel" />
  </div>
</template>

<script>
import Empty from '../../components/Empty.vue'
import ScrollView from '../../components/ScrollView.vue'
import SelectBar from '../../components/SelectBar.vue'
import { solicitApi } from '@/api'
import { mapState } from 'vuex'
import { Notify } from 'vant'
export default {
  components: { SelectBar, Empty, ScrollView },
  data() {
    return {
      // 电话营销弹窗
      show: false,
      actions: [{ name: '呼叫' }, { name: '复制' }],
      phoneNumber: '',
      tabIndex: 0,
      alreadyIndex: 0,
      deliveredNum: 0,
      selectBarList: [
        {
          text: '已送达',
          value: 0
        },
        { text: '已查看', value: 1 },
        {
          text: '已领取',
          value: 2
        },
        {
          text: '已到店',
          value: 3
        }
      ],
      // 未送达客户列表
      customerInfo1: [],
      // 已送达客户列表
      customerInfo2: [],
      followCustomerData: {},
      customerIndex: 0,
      // 客户送达分层
      deliveredData: {},
      // 套餐类型是否不是权益套餐或秒杀活动
      activityGroupType: true,
      reachStatus: [
        {
          text: '已送达',
          value: obj => {
            return obj.delivered
          },
          proportion: obj => {
            return obj.delivered
          },
          color: '#3975C6'
        },
        {
          text: '已查看',
          value: obj => {
            return obj.viewed
          },
          proportion: obj => {
            return obj.delivered
          },
          color: '#59BCFF'
        },
        {
          text: '已领取',
          value: obj => {
            return obj.received
          },
          proportion: obj => {
            return obj.delivered
          },
          color: '#33C1B9'
        },
        {
          text: '已到店',
          value: obj => {
            return obj.arrived
          },
          proportion: obj => {
            return obj.delivered
          },
          color: '#82D876'
        }
      ]
    }
  },
  computed: {
    ...mapState({
      activityId: state => state.solicit.activityId,
      staffId: state => state.solicit.staffId
    })
  },
  created() {
    this.groupId = this.getQuery().groupId
  },
  mounted() {
    this.showLoading()
    //一键营销状态回收
    this.ocmarketingRecovery()
    //员工发送状态判断
    this.staffSendStatus()
    // 触达统计-客户送达分层
    this.deliveredStatistics()
    this.getSendCustomerList(0) // 未送达
    this.getSendCustomerList(1) // 已送达
  },
  methods: {
    // 初始化微信接口
    initWx() {
      window.$wx = wxConfig
      window.$wx.init(['setClipboardData', 'navigateToAddCustomer', 'openEnterpriseChat', 'makePhoneCall']).then(() => {})
    },
    // 电话招揽弹窗关闭
    onCancel() {
      this.show = false
    },
    // 选择电话营销方式
    onSelect(e) {
      // 呼叫
      if (e.name === '呼叫') {
        // window.location.href = 'tel://' + this.telNumber
        this.makePhoneCall(this.phoneNumber)
        return
      }
      // 复制
      this.setClipboardData(this.phoneNumber)
    },
    showAction(data) {
      this.show = true
      this.phoneNumber = data.phoneNumber
    },
    ocmarketingRecovery() {
      let params = {
        id: this.activityId,
        staffId: this.staffId,
        groupId: this.groupId
      }
      solicitApi.ocmarketingRecovery(params).then(({ code, data, message }) => {})
    },
    staffSendStatus() {
      let params = {
        // id: 65,
        // staffId: 67,
        // groupId: 26816
        id: this.activityId,
        staffId: this.staffId,
        groupId: this.groupId
      }
      solicitApi.staffSendStatus(params).then(({ code, data, message }) => {
        if (code == 0) {
          if (data.createFlag == 0) {
            Notify('营销活动尚未创建,请创建一键营销后重试')
          }
          if (data.massStatus == 1 && data.createFlag == 1 && data.status == 0) {
            Notify('请前往“群发助手”确认群发消息')
          }
        }
      })
    },
    showFollowPop(data) {
      this.$refs.customerFollowRef.init()
      this.customerIndex = data.customerIndex
      this.followCustomerData = data.followCustomerData
    },
    showInfoPop(data) {
      this.$refs.customerInfoRef.getCustomerDetail(data.followCustomerData)
    },
    changeIndexEvent() {
      let params = {
        customerId: this.followCustomerData.actCutId
      }
      let target = ['customerInfo1', 'customerInfo2']
      solicitApi.getCustomerDetail(params).then(({ code, data, message }) => {
        if (code == 0) {
          data.solicitTime = data.solicitTime ? data.solicitTime.slice(0, 11) : data.solicitTime
          data.updatedTime = data.updatedTime ? data.updatedTime.slice(0, 11) : data.updatedTime
          this[target[this.tabIndex]][this.customerIndex] = data

          this.$set(this[target[this.tabIndex]], this.customerIndex, data)
          // if (data.followFlag == 2) {
          //   this[target[this.tabIndex]].splice(this.customerIndex, 1)
          // } else {
          //   this.$set(this[target[this.tabIndex]], this.customerIndex, data)
          // }
        } else {
          Notify(message)
        }
      })
    },
    // tab栏切换
    tabChange(e) {
      this.tabIndex = e
    },
    // 已送达Tab四种状态
    changeSelectTab(e) {
      this.alreadyIndex = e
      this.getSendCustomerList(1)
    },
    // 获取送达客户信息
    getSendCustomerList(index) {
      this.hideLoading()
      let target = ['customerInfo1', 'customerInfo2']
      let { alreadyIndex } = this
      let params = {
        customerGroupType: 2,
        id: this.activityId,
        staffId: this.staffId,
        groupId: this.groupId,
        sendStatus: index // 发送状态 0-未发送 1-已发送
      }
      if (index === 1) {
        // 0-未查看 1-已查看
        if (alreadyIndex === 1) params.checkStatus = 1
        // 0-未领取 1-已领取
        if (alreadyIndex === 2) params.receiveStatus = 1
        // 0.未到店 1.已到店
        if (alreadyIndex === 3) params.retFacFlag = 1
      }
      solicitApi.getCustomerList(params).then(({ code, data, message }) => {
        if (code == 0) {
          data.map(item => {
            item.solicitTime = item.solicitTime ? item.solicitTime.slice(0, 11) : item.solicitTime
            item.updatedTime = item.updatedTime ? item.updatedTime.slice(0, 11) : item.updatedTime
          })
          this[target[index]] = data
        } else {
          Notify(message)
        }
      })
    },
    // 客户送达分层
    deliveredStatistics() {
      let params = {
        id: this.activityId,
        staffId: this.staffId,
        groupId: this.groupId
      }
      solicitApi.deliveredStatistics(params).then(({ code, data, message }) => {
        if (code == 0) {
          this.deliveredData = data
          // 判断发送方式是否为权益套餐或秒杀活动
          if ((data.activityGroupType && data.activityGroupType == 4) || (data.activityGroupType && data.activityGroupType == 5)) {
            this.activityGroupType = false
            this.reachStatus.splice(2, 1)
            this.selectBarList.splice(2, 1)
          }
        }
      })
    },
    // 下拉触底刷新
    onReachBottom() {
      this.$refs.scrollView.loading = false
      this.$refs.scrollView.finished = true
    }
  }
}
</script>

<style lang="scss" scoped>
.statisic-container {
  /deep/ .van-list {
    background: #f7f7f7;
  }
}
.reason {
  padding: 16px;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(47, 64, 86, 0.7);
  line-height: 18px;
}
.statistic-pic {
  width: 100%;
  height: 172px;
  background: #ffffff;
  box-shadow: 0px 1px 0px 0px rgba(233, 233, 233, 1);
  padding: 16px 40px;
  box-sizing: border-box;
  .funnel-logo {
    width: 144px;
    height: 140px;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .statistic-list {
    white-space: nowrap;
    // width: calc(100% - 190px);
    .circle {
      width: 8px;
      height: 8px;
      background: #3975c6;
      border-radius: 2px;
      margin-right: 6px;
    }
  }
  .statistic-list div:nth-child(4) {
    margin-bottom: 0;
  }
}

/deep/ .van-tabs__line {
  background-color: #3975c6;
}
</style>