sopApi.js 3.4 KB
import api from '~/utils/request/request'
import {
  getScene,
  sopTrackPage,
  sopTrackPageType
} from '~/utils/constantData'
const getDuration = page_show_time => (Date.now() - page_show_time) / 1e3
const reportClick = ({
  thisPage,
  options
}) => {
  thisPage.options = {
    ...options,
    ...thisPage.options
  }
  reportSopCustomer(thisPage, 'PAGE_CLICK')
}
const reportHide = ({
  thisPage
}) => {
  reportSopCustomer(thisPage, 'PAGE_STOP')
}
const reportSopCustomer = async (thisPage, event_type) => {
  const {
    options,
    route
  } = thisPage
  if (sopTrackPage.includes(route)) {
    if (!sopTrackPage.includes(wx.$router.getPageInstance().route)) return
    if (options && options.scene) {
      const data = await getScene(options.scene)
      thisPage.options = data
      reportSopFun(thisPage, event_type)
    } else reportSopFun(thisPage, event_type)
  }
}
const reportSopFun = async (thisPage, event_type) => {
  const {
    options,
    route
  } = thisPage
  if (!options.sopId) return
  const userInfo = wx.$storage.get('srcm_shopmall_user_info') || wx.$storage.get("userInfo") || {},
    pageType = sopTrackPageType[route] || '',
    activityId = pageType == 4 ? options.couponId || '' : options.id || '', //商城券取couponId
    merchantId = options.merchantId || '',
    unionId = userInfo.unionId || wx.$storage.get('wx_user_info').unionId,
    sopId = options.sopId || '',
    extra = {
      pageType,
      activityId,
      unionId,
      merchantId,
      sopId,
    }
  if (event_type == 'PAGE_STOP') extra.time = getDuration(thisPage.page_show_time)
  const buryingPointList = [{
    customer_phone: userInfo.phone,
    add_way: 'SOP',
    sopId,
    // id_number: '',
    // org_user_id: '',
    // wechat_id: '',
    wechat_union_id: unionId,
    org_id: merchantId,
    system_source: 'scrm',
    platform: 'MimiProgram',
    event_type,
    event_time: new Date().format('yyyy-MM-dd hh:mm:ss'),
    extra: JSON.stringify(extra)
  }]
  api.post({
    method: 'marketing.api.sop.buryingPoint',
    projectName: 'marketing',
    buryingPointList
  }, true)
}

module.exports = {
  /**
   * sop客户埋点上报
   */
  reportSopCustomer,
  reportClick,
  reportHide,
  /** sop用户行为记录(埋点调用)
   */
  customerbehavior(data) {
    return api.post({
      method: 'scrm.api.sop.task.customerbehavior.add',
      flag: 1,
      ...data
    })
  },
  customerbehaviorByEventId(data) {
    return api.post({
      method: 'scrm.api.sop.event.customerbehavior.add',
      ...data
    })
  },
  //sop概览
  getSopOverview(data) {
    return api.post({
      method: 'scrm.api.marketing.sop.overview',
      projectName: 'stoassistant',
      ...data
    })
  },
  // sop任务客户列表
  getSopTaskCustomer(data) {
    return api.post({
      method: 'scrm.api.sop.task.customer.page',
      projectName: 'stoassistant',
      ...data
    })
  },
  // sop客户智能档案
  getSopArchives(data) {
    return api.post({
      method: 'scrm.api.sop.task.customer.archives',
      projectName: 'stoassistant',
      ...data
    })
  },
  // sop任务列表
  getSopList(data) {
    return api.post({
        method: 'scrm.api.marketing.sop.list',
        projectName: 'stoassistant',
        ...data
      },
      true)
  },
  // sop客户-更改旅程阶段
  updateStage(data) {
    return api.post({
      method: 'scrm.api.sop.task.customer.stage.update',
      projectName: 'stoassistant',
      ...data
    })
  },
}