Quality.vue 9.5 KB
<template>
  <div class="div">
    <div class="classify-container">
      <div class="scroll-arrow left" v-show="showLeftArrow" @click="handleScroll('left')">
        <i class="el-icon-arrow-left"></i>
      </div>
      <div class="classify-wrap" ref="classifyWrap">
        <template v-for="(item,index) in classifyList">
          <div
            :class="['classify-item flex',{active: index == activeIndex}]"
            :key="index"
            @click="activeIndex = index"
          >
            <div class="title">{{item.tagGroupName}}</div>
            <div class="score"><span>{{item.score||item.score===0?item.score:'-'}}</span>/{{item.sumScore||item.sumScore===0?item.sumScore :'-'}}</div>
          </div>
        </template>
      </div>
      <div class="scroll-arrow right" v-show="showRightArrow" @click="handleScroll('right')">
        <i class="el-icon-arrow-right"></i>
      </div>
    </div>
    <div
      class="scroll-view"
      :style="{ height: `${dialogueBoxHeight - 56}px` }"
    >
      <template v-if="qualityData[activeIndex]">
        <div style="height: 10px; background: #fff;width: 100%;"></div>
        <div class="quality-block" >
          <div class="title flex">
            {{qualityData[activeIndex].tagGroupName}}
            <div :class="['matched-btn flex', qualityData[activeIndex].matchedClass]">{{qualityData[activeIndex].matchedText}}</div>
          </div>
          <template v-for="(item,index) in qualityData[activeIndex].conversationDetailDTOList">
            <div :key="index">
              <div
                v-if="item.text_id"
                :id="item.text_id"
                :class="['quality-item flex',{active:item.text_id == activeId}]"
                @click="seekPlay(item)"
              >
                <div class="avatar-box">
                  <img :src="require(`@/assets/role-${item.role}.png`)" class="sprite-icon" />
                  <div class="time">{{item.time}}</div>
                </div>
                <div class="text flex">{{item.content}}</div>
              </div>
              <template v-if="item.scriptRec">
                <div class="script-rec">
                  <div class="suggestions-box">
                    <div class="suggestions-title">
                      <div class="sprite-icon icon-suggestions-icon"></div>
                      话术推荐
                    </div>
                    <div class="text">
                      <div v-html="item.scriptRec"></div>
                    </div>
                  </div>
                </div>
              </template>
            </div>
          </template>
        </div>
      </template>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
import { getQualityList } from '@/api/resident'
export default {
  name: '',
  props: {
    batchId: [String, Number],
    qualityData: {
      type: Array,
      default: () => []
    },
    qualityAudio: {
      type: [Object, HTMLElement],
      required: true
    },
    dialogueBoxHeight: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      classifyList: [],
      activeIndex: 0,
      showLeftArrow: false,
      showRightArrow: true,
      activeId: ''
    }
  },
  mounted () {
    this.getQualityList()
    this.$nextTick(() => {
      this.checkScrollArrows()
      window.addEventListener('resize', this.checkScrollArrows)
    })
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.checkScrollArrows)
  },
  methods: {
    async getQualityList() {
      this.classifyList = await getQualityList({
        batchId: this.batchId
      })
      this.$nextTick(() => {
        this.checkScrollArrows()
      })
    },
    checkScrollArrows() {
      const wrap = this.$refs.classifyWrap
      if (!wrap) return
      this.showLeftArrow = wrap.scrollLeft > 0
      this.showRightArrow = wrap.scrollLeft < (wrap.scrollWidth - wrap.clientWidth)
    },
    handleScroll(direction) {
      const wrap = this.$refs.classifyWrap
      if (!wrap) return
      
      const scrollAmount = 100 // 每次滚动的距离
      const newScrollLeft = direction === 'left' 
        ? wrap.scrollLeft - scrollAmount 
        : wrap.scrollLeft + scrollAmount
      
      wrap.scrollTo({
        left: newScrollLeft,
        behavior: 'smooth'
      })
      
      // 滚动结束后检查箭头状态
      setTimeout(() => {
        this.checkScrollArrows()
      }, 300)
    },
    onTimeUpdate () {
      const {
        mergedOffset
      } = this.setProgress()
      this.activeId = `text_${mergedOffset}`
    },
    setProgress () {
      const {
        currentTime
      } = this.qualityAudio,
        mergedOffset = Math.ceil(currentTime)
      return {
        currentTime,
        mergedOffset
      }
    },
    seekPlay (item) {
      let { activeId } = this
      this.$emit('seek', item.mergedOffset)
      if (item.text_id == activeId) {
        const {
          paused
        } = this.qualityAudio
        if (paused) this.$emit('onPlay')
        else this.$emit('onPause')
        this.$emit('changeOperate', !paused)
      } else {
        this.$emit('onPlay')
        this.$emit('changeOperate', false)
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.flex {
  display: flex;
  align-items: center;
}
.div {
  height: 100%;
  width: 100%;
  position: relative;
  .classify-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 56px;
    background: #F7F9FA;
    border-radius: 4px;
  }
  .classify-wrap {
    width: 100%;
    height: 48px;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 0 4px;
    &::-webkit-scrollbar {
      display: none;
    }
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
    
    .classify-item {
      box-sizing: border-box;
      min-width: 80px;
      height: 100%;
      padding: 6px 12px;
      flex-shrink: 0;
      justify-content: center;
      flex-direction: column;
      line-height: 20px;
      font-size: 14px;
      transition: all .15s;
      background: #F7F9FA;
      text-align: center;
      .title {
        color: #666;
      }
      .score {
        color: #999;
      }
    }
    .active {
      border-radius: 8px;
      background: #ffffff;
      .title {
        color: #2A58AD;
        font-weight: 500;
      }
    }
  }
  .scroll-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F7F9FA;
    // box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    z-index: 1;
    
    &.left {
      left: 0;
    }
    
    &.right {
      right: 0;
    }
    
    i {
      font-size: 16px;
      color: #808285;
    }
  }
  .scroll-view {
    height: 100%;
    width: 100%;
    background: #F0F3F8;
    overflow-y: auto;
    border-radius: 0 0 4px 4px ;
  }
  .quality-block {
    border-radius: 4px 4px 0 0;
    .title {
      height: 36px;
      background: linear-gradient(119.9deg, #e1f7fc 0%, #f3f7ff 27%, #f7f2ff 41%, #e8f1ff 66%, #f7f2ff 100%);
      font-size: 14px;
      font-weight: 600;
      padding: 0 10px;
      border-radius: 4px 4px 0 0;
      &::before {
        content: '';
        width: 4px;
        height: 4px;
        background: #000000;
        border-radius: 100%;
        display: block;
        margin-right: 8px;
      }

      .matched-btn {
        margin-left: auto;
        height: 28px;
        border-radius: 14px;
        background: #ffffff;
        padding: 0 18px;
        color: #eb4e4e;
        font-size: 12px;
        font-weight: 600;
      }
      .hit {
        color: #35c376;
      }
    }
    .quality-item {
      padding: 10px 12px;
      background: #fff;
      .avatar-box {
        position: relative;
        width: 34px;
        width: 34px;
        height: 48px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        flex-direction: column;

        .sprite-icon {
          width: 34px;
          height: 34px;
          border-radius: 100%;
          overflow: hidden;
          flex-shrink: 0;
        }
        .time {
          width: 35px;
          height: 14px;
          background: #ffffff;
          border: 1px solid #f0f6ff;
          border-radius: 14px;
          font-size: 10px;
          color: #999ea8;
          display: flex;
          align-items: center;
          justify-content: center;
          box-sizing: border-box;
        }
      }
      .text {
        width: 361px;
        min-height: 40px;
        color: #292d33;
        font-size: 13px;
        margin-left: 8px;
        line-height: 22px;
      }
    }
    .active {
      background: #f0f6ff;
      .text {
        font-weight: 500;
      }
    }
    .script-rec {
      padding: 12px;
      .suggestions-box {
        background: #ffffff;
        border-radius: 8px;
        padding: 12px 14px;
        box-sizing: border-box;

        .suggestions-title {
          display: flex;
          align-items: center;
          font-weight: 500;
          font-size: 14px;
          color: #333333;
          margin-bottom: 10px;

          .sprite-icon {
            margin-right: 6px;
          }
        }

        .text {
          color: #292d33;
          font-size: 13px;
          line-height: 22px;
        }

        .suggestions-text {
          padding-bottom: 11px;
          border-bottom: 1px solid #f0f6ff;
          margin-bottom: 12px;
        }
      }
    }
    .active {
      background: #f0f6ff;
      .text {
        font-weight: 500;
      }
    }
  }
}
</style>