scene.js 5.38 KB
/*
 * @Description: 
 * @Author: huyue
 * @Date: 2024-06-14 13:57:29
 * @LastEditors: huyue
 * @LastEditTime: 2024-10-22 15:33:21
 */
// packageEquity/pages/aiCheck/scene/scene.js
import carLifeApi from '../../../carEquityApi'
import {
  setConfigInfo
} from "~/store/index";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    selectedIndex: 0,
    customeTypeList: [],
    navBarHeight: 0,
    footerHeight: 0,
    text: '好胜心强,容易固执已见,建议多以<span class="blue">肯定、迎合</span>的话进行对练!',
    step: 'reception',
    stepName: '接待',
    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: '此环节模拟驻店专员已完成了延保产品的介绍,即将根据客户是否展示购买意愿进行话术演练,建议对明显展示不想购买意愿的客户使用逼单话术进行进一步沟通!'
      }
    ],
    key: Date.now()
  },
  // 设置音频
  setAudio() {
    this.aiAudio = wx.createInnerAudioContext({
      useWebAudioImplement: true
    })
    // console.log(this.aiAudio)
  },
  selectCustomerType(e) {
    this.setData({
      selectedIndex: e.currentTarget.dataset.index
    })
    const {
      isDemo
    } = this.data
    this.aiAudio.src = isDemo ? this.data.customeTypeList[e.currentTarget.dataset.index].roleVoiceHs : this.data.customeTypeList[e.currentTarget.dataset.index].roleVoice
    const {
      paused
    } = this.aiAudio
    console.log(paused)
    this.aiAudio.play()
    this.setData({
      key: Date.now()
    })
  },
  selectStepType(e) {
    const {
      name,
      type
    } = e.currentTarget.dataset
    this.setData({
      step: type,
      stepName: name
    })
  },
  // 头部返回上一级
  back() {
    wx.$router.back()
  },
  // 开始练习
  startPractice() {
    this.setData({
      show: !this.data.show
    })
  },
  jump() {
    const {selectedIndex,customeTypeList,stepName, step, linkChainList,isDemo,entry} = this.data
    const { roleType } = customeTypeList[selectedIndex]
    const { suggest } = linkChainList.find(item => item.type == step)
    console.log(roleType, stepName, suggest,isDemo)
    wx.navigateTo({
      url: `/packageEquity/pages/aiCheck/chat/chat?roleType=${roleType}&stage=${stepName}&suggest=${suggest}&isDemo=${isDemo}&entry=${entry}`
    })
    this.setData({
      show: false
    })
  },
  navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
    wx.createSelectorQuery().select('#footer').boundingClientRect(rect => {
      this.setData({
        footerHeight: rect.height
      }) 
    }).exec()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    const {stage} = options;
    if(stage) {
      await 1
      const {linkChainList} = this.data;
      const findChain = linkChainList.find((link) => link.name == stage);
      this.setData({
        stepName: findChain.name,
        step: findChain.type,
        show:true,
        entry:'other'
      })
    }
    const {
      aiPhone
    } = await setConfigInfo({});
    const {
      phone
    } = wx.$util.getUserInfo()
      this.setData({
        isDemo: aiPhone.includes(phone)
      })
    this.getRole()
  },
  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
      })
      this.setAudio()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      step: 'reception',
      selectedIndex: 0
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})