index.js 9.4 KB
// packageEquity/pages/receptionDetail/components/quality/index.js
import api from "../../../../carEquityApi";
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import watchScrollMixin from '../watchScrollMixin'
Component({
  behaviors: [watchScrollMixin],
  /**
   * 组件的属性列表
   */
  properties: {
    batchId: Number
  },
  lifetimes: {
    ready() {
      let thisPage = wx.$router.getPageInstance()
      this.innerAudioContext = thisPage.qualityAudio
      this.getReceptionResult()
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    scrollTop: '',
    IMG_URL,
    isShow: false,
    activeIndex: 0,
    secondIndex: 0,
    activeids: [],
    tempData: [],
    list: [{
        stage: '接待环节',
        totalScore: 4
      }, {
        stage: '车辆交付',
        totalScore: 50
      },
      {
        stage: '需求挖掘',
        totalScore: 40
      }, {
        stage: '促成交',
        totalScore: 6
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onTimeUpdate() {
      let {
        list,
        activeIndex,
        secondIndex,
        activeids,
        tempData
      } = this.data, {
        mergedOffset
      } = this.setProgress();
      let data = list[activeIndex].conversationCheckDetailDTOList[secondIndex]?.conversationDetailDTOList
      if (list[activeIndex].conversationCheckDetailDTOList[secondIndex]?.isPlay) {
        if (tempData && tempData.length) {
          tempData.find((e, index) => {
            if (e && e.id) {
              // if (!activeids.includes(e.id)) {
              if (e.mergedOffset == mergedOffset) {
                tempData.splice(index--, 1)
                wx.nextTick(() => this.setData({
                  [`activeids[${secondIndex}]`]: e.id
                }, () => {
                  this.handleData()
                }))
              }

              // }
            }

          })
        }
      }

      if (data && data.every(item => !item.active)) {
        data[0].active = true
      }
      if (data[data.length - 1].active) {
        if ((data[data.length - 1].duration + data[data.length - 1].offset) / 1000 <= mergedOffset) {
          data[data.length - 1].active = false
          list[activeIndex].conversationCheckDetailDTOList[secondIndex].isPlay = false
        }

      }
      this.setData({
        list
      })

    },
    //录音暂停时,播放按钮重置
    clearData() {
      let {
        list
      } = this.data;
      list.forEach(item => {
        if (item.conversationCheckDetailDTOList) {
          item.conversationCheckDetailDTOList.forEach(sitem => {
            sitem.isPlay = false
            sitem.conversationDetailDTOList && sitem.conversationDetailDTOList.forEach((third, index) => {
              third.active = false
              if (index === 0) third.active = true
            })
          })
        }


      })
      this.setData({
        list
      })
    },
    handleData() {
      let {
        list,
        activeids,
        activeIndex,
        secondIndex
      } = this.data;

      if (list[activeIndex].conversationCheckDetailDTOList[secondIndex].conversationDetailDTOList) {
        list[activeIndex].conversationCheckDetailDTOList[secondIndex].conversationDetailDTOList.forEach(item => {
          item.active = false
          if (activeids[secondIndex] == item.id) {
            item.active = true
          }
        })
      }

      this.setData({
        list
      })
    },
    setProgress() {
      const {
        duration,
        currentTime
      } = this.innerAudioContext,
        mergedOffset = Math.ceil(currentTime)
      this.setData({
        progress: mergedOffset / duration * 100
      })
      return {
        currentTime,
        mergedOffset
      }
    },
    handleShow(e) {
      let {
        findex,
        sindex
      } = e.currentTarget.dataset;
      let {
        activeIndex,
        list,
        batchId
      } = this.data;
      this.setTrackData('quality_inspection_matching')
      list[activeIndex].conversationCheckDetailDTOList[findex].conversationDetailDTOList[sindex].isdown = !list[activeIndex].conversationCheckDetailDTOList[findex].conversationDetailDTOList[sindex].isdown
      this.setData({
        list
      })


    },
    changeClassifyType(e) {
      let {
        index
      } = e.currentTarget.dataset, {
        list,
        activeIndex
      } = this.data;
      this.setTrackData( {
        0: 'reception_link',
        1: 'vehicle_interaction',
        2: 'demand_mining',
        3: 'make_deal'
      } [index])
      let thisPage = wx.$router.getPageInstance()
      thisPage.onPause()
      this.setData({
        activeIndex: index,
        scrollTop: 0
      }, () => {
        if (list[index].conversationCheckDetailDTOList) {
          list[index].conversationCheckDetailDTOList.forEach((item, sIndex) => {
            this.setData({
              [`activeids[${sIndex}]`]: item.id
            })
          })
        }

      })
    },
    getReceptionResult() {
      let {
        list,
        batchId,
        activeId
      } = this.data;
      let params = {
        batchId
      }
      api.getReceptionResultData(params).then(res => {
        res.data.forEach(first => {
          first.conversationCheckDetailDTOList.forEach((second, sIndex) => {
            second.firstClassify = second.firstClassify.slice(0, 4);
            if (second.firstClassify === '结束环节') second.firstClassify = '促成交'
            second.isPlay = false
            this.setData({
              [`activeids[${sIndex}]`]: second.id
            })
            second.suggestions = second.suggestions ? second.suggestions.replace(/<\/br>/g, '\n') : ''
            if (second.suggestions == '-') second.suggestions = ''
            second.conversationDetailDTOList && second.conversationDetailDTOList.forEach((third, index) => {
              if (index === 0) third.active = true
              third.appealClass = third.id ? 'appeal-disabled' : ''
              third.time = this.formatTime(third.mergedOffset)
              if (third.id === second.inspectionConversationDetailId) {
                third.hit = true
                third.isdown = false
              }
            })

          })
        })
        list.forEach(item => {
          res.data.forEach(row => {
            if (row.stage.indexOf(item.stage) != -1) {
              Object.assign(item, row, {
                stage: item.stage
              })
            } else if (row.stage === '结束环节' && item.stage === '促成交') {
              Object.assign(item, row, {
                stage: '促成交'
              })
            }
          })
        })
        this.setData({
          list: list,
          isShow: true,
          activeId
        })
        console.log(list)


      })
    },
    lookMore(e) {
      let thisPage = wx.$router.getPageInstance();
      let {
        findex
      } = e.currentTarget.dataset;
      let {
        activeIndex,
        list
      } = this.data;
      this.setTrackData('go_to_dialogue_view')
      let item = list[activeIndex].conversationCheckDetailDTOList[findex].conversationDetailDTOList[0];
      item.text_id = `text_${item.id}`
      thisPage.onPause()
      thisPage.setData({
        activeIndex: 0
      }, () => {
        setTimeout(() => {
          thisPage.dialogueRef().setTopId(item, true)
        }, 200)
      })

    },
    handleStatus(activeIndex) {
      let {
        list
      } = this.data;
      //切换时清空之前的状态
      list.forEach(item => {
        item.conversationCheckDetailDTOList.forEach(sitem => {
          sitem.isPlay = false
          sitem.conversationDetailDTOList && sitem.conversationDetailDTOList.forEach((third, index) => {
            third.active = false
            if (index === 0) third.active = true
          })
        })
      })
      this.setData({
        list
      })
    },
    seek(e) {
      let {
        findex,
        sindex
      } = e.currentTarget.dataset;
      let {
        activeIndex,
        list
      } = this.data;
      this.setTrackData('play_verbal')
      let time = list[activeIndex].conversationCheckDetailDTOList[findex].conversationDetailDTOList[sindex].mergedOffset;
      let thisPage = wx.$router.getPageInstance()
      list[activeIndex].conversationCheckDetailDTOList.forEach(sitem => {
        sitem.isPlay = false
        sitem.conversationDetailDTOList && sitem.conversationDetailDTOList.forEach((third, index) => {
          third.active = false
          if (index === 0) third.active = true
        })
      })
      list[activeIndex].conversationCheckDetailDTOList[findex].isPlay = true
      this.setData({
        secondIndex: findex,
        list
      }, () => {
        this.data.tempData = [...list[activeIndex].conversationCheckDetailDTOList[findex]?.conversationDetailDTOList]
        console.log(this.data.tempData)
        thisPage.seek(time)
        thisPage.play()
      })



    },
    formatTime(num) {
      let minutes = Math.floor(num / 60) || '0',
        seconds = num % 60 || '0'
      seconds = seconds < 10 ? `0${seconds}` : seconds
      return `${minutes}:${seconds}`
    },
    practiceHandle(e) {
      const {
        stage
      } = e.currentTarget.dataset
      let thisPage = wx.$router.getPageInstance()
      thisPage.practiceHandle(stage)
    },
    /**设置埋点数据 */
    setTrackData(code) {
      let {
        batchId
      } = this.data
      wx.$track.setTrackData(0, code, {
        batchId
      })
    }
  }
})