defense.js 5.58 KB
// packageEquity/pages/aiCheck/defense/defense.js
// import { defenseData, typeList } from './constants/data'
import carLifeApi from '../../../carEquityApi'
import {
  setConfigInfo
} from "~/store/index";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navBarHeight: 0,
    tabList: [],
    currentTab: 0,
    customeTypeList:[],
    linkChainList: [{
        id: 1,
        name: '接待',
        iconUrl: 'icon-reception',
        type: 'reception',
        suggest: '此环节模拟交付专员把客户介绍给驻店专员,建议使用敬语,尊称客户,恭喜客户提车,主动向客户介绍工作环节并进行自我介绍!'
      },
      {
        id: 2,
        name: '车辆交付',
        iconUrl: 'icon-car',
        type: 'delivery',
        suggest: '此环节模拟驻店专员已完成对于客户的接待,即将向客户介绍新车使用注意事项、保养要求和基础质保政策,建议在介绍过程中主动了解客户的用车周期,用车环境,给介绍延保产品时进行铺垫!'
      },
      {
        id: 3,
        name: '需求挖掘',
        iconUrl: 'icon-demand',
        type: 'defense',
        suggest: '此环节模拟驻店专员已完成了新车使用、保养要求和基础质保政策的介绍,即将向客户介绍延保产品,此环节容易触发攻防,建议多以延保相对基础质保的优势,当天购买价格有优惠,大部分客户均选择购买等为主进行推荐!'
      },
      {
        id: 4,
        name: '促成交',
        iconUrl: 'icon-dear',
        type: 'referral',
        suggest: '此环节模拟驻店专员已完成了延保产品的介绍,即将根据客户是否展示购买意愿进行话术演练,建议对明显展示不想购买意愿的客户使用逼单话术进行进一步沟通!'
      }
    ],
    scrollIntoView: 0,
    list: [],
    id: '',
    scrollTop: 0,
    defenseData: [],
    typeList: []
  },
  // 头部返回上一级
  back() {
    wx.$router.back()
  },
  navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
  },

  switchTab(e) {
    const { index, type } = e.currentTarget.dataset
    const { defenseData } = this.data
    const { id } = this.data
    console.log(index,type, id)
    if (index) {
      this.setData({
        currentTab: index,
        scrollLeft: index > 2 ? index * 60 : 0,
        list: defenseData[id].filter(item => item.type == type),
        scrollTop: 0
      })
    } else {
      this.setData({
        currentTab: index,
        scrollLeft: index > 2 ? index * 60 : 0,
        list: defenseData[id],
        scrollTop: 0
      })
    }
  },
  toChat(e) {
    const { id,title } = e.currentTarget.dataset
    const objection_id = id.split('-').pop()
    const type_id = id.split('-')[1]
    const {customeTypeList,isDemo,linkChainList,recordName, typeList} = this.data
    console.log(customeTypeList)
    const selectedIndex = Math.floor(Math.random()*customeTypeList.length)
    const linkIndex =  Math.floor(Math.random()*linkChainList.length)
    const { roleType } = customeTypeList[selectedIndex]
    const { name: stage, suggest } = linkChainList[linkIndex]
    const product_name = typeList.find(item => item.id == type_id)?.name
    wx.navigateTo({
      url: `/packageEquity/pages/aiCheck/chat/chat?roleType=${roleType}&stage=${stage}&suggest=${suggest}&isDemo=${isDemo}&isInspiration=1&objection_id=${objection_id}&recordName=${recordName}&title=${title}&product_name=${product_name}`
    })
    // wx.navigateTo({
    //   url: `/packageEquity/pages/aiCheck/chat/chat?id=${id}`
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initData().then(r => {
      const { id } = options
      const recordName = `攻防演练 · ${id==2?'延保':'安心包'}`
      const { typeList, defenseData } = this.data
      const result = typeList.filter(item => item.ids.includes(+id))
      console.log(result, 'result')
      this.setData({
        list: defenseData[id],
        id,
        recordName,
        tabList: result
      })
    })
  },
  initData() {
    return new Promise(async(resolve, reject) => {
      const {
        aiPhone,
        defenseData,
        typeList
        } = await setConfigInfo({});
        this.setData({
          defenseData,
          typeList
        })
      const {
        phone
      } = wx.$util.getUserInfo()
        this.setData({
          isDemo: aiPhone.includes(phone)
        })
      this.getRole()
      resolve()
    })
},
getRole() {
  carLifeApi.sparringRole({
    currentPage: 1,
    pageSize: 100,
  }).then(res => {
    const customeTypeList = res.data.list
    customeTypeList.forEach(item => {
      if (item.roleName.includes('客户'))
        item.roleName = item.roleName.slice(0, -2)
    })
    this.setData({
      customeTypeList
    })
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})