aiInspectionDetail.js 3.93 KB
// packageEquity/pages/aiInspectionDetail/aiInspectionDetail.js
import carLifeApi from '../../carEquityApi'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    overviewList: [{
      title: '话术评分',
      key: 'score'
    },
    {
      title: '预计营销结果',
      key: 'estimatedResult',
      fontSize: 'var(--fontSize28)'
    },
    {
      title: '开始录音时间',
      key: 'startTime'
    },
    {
      title: '对话时长',
      key: '_duration'
    }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.$router.getData(res => {
      if (!res.estimatedResult) res.estimatedResult = '未知'
      if (res.startTime) res.startTime = res.startTime.match(/\b\d{2}:\d{2}:\d{2}\b/)[0]
      if (res.duration) res._duration = this.formatTime(res.duration)
      this.setData({
        detailInfo: res
      })
      this.getInspectionDetail(res.id)
    })
  },

  setCopyData(e) {
    console.log(e)
    // let {
    //   content
    // } = e.currentTarget.dataset
    const { detailInfo } = this.data,
      receptionStatus = {
        1: '成交',
        0: '战败'
      }[detailInfo.receptionStatus],
      { customerName, startTime, duration, fileUrl, createdDate } = detailInfo
    // 客户姓名 - 接待开始时间 - 接待时长 - 员工标记的接待结果 - 接待录音mp3地址
    let text = [customerName, wx.$util.tsFormatTime(createdDate, 'Y年M月D日'), startTime, this.formatTime(duration), receptionStatus, fileUrl].join(' - ')
    wx.$util.setCopyData(text)
    // wx.$util.showToast('复制成功')
  },
  async getInspectionDetail(batchId) {

    try {
      wx.$util.showLoading()
      const {
        code,
        data: {
          list
        },
        message
      } = await carLifeApi.getInspectionDetail({
        batchId,
        pageSize: 99999
      })
      if (code == 0 && list) {
        let titleList = Array.from(new Set([...list.map(e => e.firstClassify)]))

        const classifyList = titleList.map(i => {
          let arr = [],
            rawScore = 0,
            score = 0
          list.map(e => {
            if (i == e.firstClassify) {
              arr.push(e)
              rawScore += e.rawScore
              score += e.score
            }
            e.suggestions = e.suggestions.replace(/<\/br>/g, '\n')
            e.hitText = e.hitText && e.hitText.replace(/<\/br>/g, '\n')
          })
          return {
            list: arr,
            title: i,
            rawScore,
            score,
          }
        })


        console.log(classifyList)
        this.setData({
          list: classifyList
        })
        wx.hideLoading()
      } else throw message
    } catch (error) {
      wx.hideLoading()
      wx.$util.showToast(error)
    }
  },
  formatTime(seconds) {
    seconds = Math.floor(seconds / 1000)
    let formattedTime = ''
    if (seconds < 60) return seconds + '秒'
    else {
      let hours = Math.floor(seconds / 3600),
        minutes = Math.floor((seconds % 3600) / 60),
        remainingSeconds = seconds % 60
      if (hours > 0) formattedTime += hours + '小时'
      if (minutes > 0 || hours > 0) formattedTime += minutes + '分'
      if (remainingSeconds > 0) formattedTime += remainingSeconds + '秒'
      return formattedTime
    }
  },
  jump(e) {
    const {
      item
    } = e.currentTarget.dataset
    wx.$router.go('aiInspectionReception', item)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})