qualityInspectionAnalyse.vue 10.4 KB
<template>
  <div class="analyse">
    <div class="statistics">
      <div class="s-item" v-for="(item, index) in sList" :key="index">
        <div class="title">{{ item.text }}</div>
        <div
          class="content"
          v-html="item.formatter && item.formatter(detailObjData)"
        ></div>
      </div>
    </div>
    <d2-search
      ref="showSearch"
      class="show-search"
      :search-form="searchForm"
      :form-data="showFormData"
    >
      <div slot="firstClassify">
        <el-select
          v-model="searchForm.firstClassify"
          clearable
          placeholder="请选择"
          @change="changeClassify"
        >
          <el-option
            v-for="item in baseData.firstClassifyList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </div>
      <div slot="secondClassify">
        <el-select
          v-model="searchForm.secondClassify"
          clearable
          placeholder="请选择"
        >
          <el-option
            v-for="item in baseData.secondClassifyList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </div>
      <template slot="score">
        <el-input-range
          start-placeholder="请输入"
          end-placeholder="请输入"
          :display-value="searchForm.qualityTestScore"
        ></el-input-range>
      </template>
    </d2-search>
    <div class="up-btns">
      <el-button @click="handleSearch" size="small" type="primary">
        查询
      </el-button>
      <el-button size="small" @click="handleReset"> 重置 </el-button>
    </div>
    <div class="theader">
      <div class="title">话术列表</div>
      <el-radio-group v-model="searchForm.hitResult">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button label="1">命中</el-radio-button>
        <el-radio-button label="0">未命中</el-radio-button>
      </el-radio-group>
    </div>
    <d2-table
      ref="analyseTable"
      :get-list-api="getListApi"
      :search-form="searchFormSearch"
      :table-params="tableParams"
      :before-search-fn="beforeSearchFn"
      :has-page="false"
    >
      <div slot="scoreHtml" slot-scope="scope">
        <template v-if="scope.scope.score || scope.scope.score === 0">
          {{ scope.scope.score }}
        </template>
        <template v-else>--</template>
      </div>
      <!-- hitTextHtml -->
      <template slot="hitTextHtml" slot-scope="scope">
        <div v-html="formatSrt(scope.scope.hitText)"></div>
      </template>
      <template slot="suggestions" slot-scope="scope">
        <div v-html="formatSrt(scope.scope.suggestions)"></div>
      </template>
      <template slot="hitResult" slot-scope="scope">
        <div :class="['tag', scope.scope.hitResult == 1 ? 'gre' : 'red']">
          {{ scope.scope.hitResult == 1 ? "是" : "否" }}
        </div>
      </template>
    </d2-table>
  </div>
</template>
<script>
import ElInputRange from "../../el-input-range"
import { Util, deepClone } from "@/common/util"
// import { conversationCheckList, getPointCategory } from "@api/resident"
import { getQualityResult } from "@api/exercise"
export default {
  name: "QualityInspectionAnalyse",
  components: {
    ElInputRange
  },
  props: {
    detailObj: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      detailObjData: {},
      sList: [
        {
          text: "话术评分",
          formatter: (data) => {
            return `<span style="font-weight:700;font-size:20px;">${
              data.score ? data.score : "0"
            }</span>分`
          }
        },
        {
          text: "预计营销结果",
          formatter: (data) => {
            const classStr =
              data.estimatedResult == "成交"
                ? data.estimatedResult == "战败"
                  ? "redStr"
                  : "greenStr"
                : "grayStr"
            return `<span  class="${classStr}" style="font-weight:700;font-size:20px;">${
              data.estimatedResult ? data.estimatedResult : "--"
            }</span>`
          }
        }
      ],
      searchForm: {
        // firstClassify: "",
        // secondClassify: "",
        qualityTestScore: [],
        hitResult: ""
      },
      searchFormSearch: {},
      showFormData: [
        // {
        //   label: "一级分类",
        //   name: "firstClassify",
        //   addHtml: "firstClassify"
        // },
        // {
        //   label: "二级分类",
        //   name: "secondClassify",
        //   addHtml: "secondClassify"
        // },
        {
          label: "质检评分",
          name: "qualityTestScore",
          addHtml: "score"
        }
      ],
      select: "全部",
      getListApi: getQualityResult,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "checkDetailList",
        tableOption: false,
        tableColumns: [
          {
            label: "一级分类",
            prop: "firstClassify",
            width: "120px"
          },
          {
            label: "二级分类",
            prop: "secondClassify",
            width: "140px"
          },
          {
            label: "质检评分",
            prop: "score",
            width: "100px",
            addHtml: "scoreHtml"
          },
          {
            label: "是否命中",
            prop: "hitResult",
            width: "100px",
            addHtml: "hitResult"
          },
          {
            label: "命中文本",
            prop: "hitText",
            addHtml: "hitTextHtml"
          },
          {
            label: "话术建议",
            prop: "suggestions",
            addHtml: "suggestions",
            align: "left"
          }
        ]
      },
      baseData: {
        firstClassifyList: [],
        secondClassifyList: []
      }
    }
  },
  watch: {
    "searchForm.hitResult"() {
      this.$refs.analyseTable.refreshTable(true, true)
    }
  },
  mounted() {
    this.getPointCategory()
  },
  methods: {
    formatSrt(str) {
      return str ? str.replace(/\n/g, "<br/>") : "--"
    },
    toMinutesAndSeconds(seconds) {
      seconds = Math.floor(seconds / 1000)
      let formattedTime = ""
      if (seconds < 60) return seconds + "秒"
      else if (seconds > 3600) {
        const hours = Math.floor(seconds / 3600)
        const minutes = Math.floor((seconds % 3600) / 60)
        if (hours > 0) formattedTime += hours + "小时"
        if (minutes > 0 || hours > 0) formattedTime += minutes + "分"
        return formattedTime
      } else {
        const hours = Math.floor(seconds / 3600)
        const minutes = Math.floor((seconds % 3600) / 60)
        const remainingSeconds = seconds % 60
        if (hours > 0) formattedTime += hours + "小时"
        if (minutes > 0 || hours > 0) formattedTime += minutes + "分"
        if (remainingSeconds > 0) formattedTime += remainingSeconds + "秒"
        return formattedTime
      }
    },
    // toMinutesAndSeconds(time) {
    //   const h = Math.floor(time / 3600)
    //   const m = parseInt((time % 3600) / 60)
    //   return {
    //     h,
    //     m
    //   }
    // },
    getPointCategory() {
      // this.classifyMap = new Map()
      getQualityResult({
        pageSize: 10,
        currentPage: 1,
        staffRecordId: this.detailObj.id
      }).then((res) => {
        console.log(res)
        this.detailObjData = {
          score: res.score,
          estimatedResult: this.detailObj.estimatedResult
        }
        // this.baseData.firstClassifyList = Object.keys(res)
        // for (const item in res) {
        //   this.classifyMap.set(item, res[item])
        // }
      })
    },
    changeClassify() {
      this.searchForm.secondClassify = ""
      this.baseData.secondClassifyList = this.classifyMap.get(
        this.searchForm.firstClassify
      )
    },
    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = deepClone(this.searchForm)
        this.searchFormSearch.staffRecordId = this.detailObj.id
        // this.searchFormSearch.pageSize = 99999
        if (this.searchFormSearch.qualityTestScore) {
          console.log(this.searchForm, "===")
          this.searchFormSearch.qualityTestScoreBegin =
            this.searchFormSearch.qualityTestScore[0]
          this.searchFormSearch.qualityTestScoreEnd =
            this.searchFormSearch.qualityTestScore[1]
        }
        delete this.searchFormSearch.qualityTestScore

        resolve()
      })
    },
    handleSearch() {
      this.$refs.analyseTable.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = {
        // firstClassify: "",
        // secondClassify: "",
        qualityTestScore: [],
        hitResult: ""
      }
      this.baseData.secondClassifyList = []
      this.$refs.analyseTable.refreshTable()
    }
  }
}
</script>
<style lang="scss" scoped>
.analyse {
  padding: 16px;
  .statistics {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .s-item {
      flex: 1;
      //   min-width: 248px;
      // height: 84px;
      background: #f7f9fa;
      border-radius: 4px;
      padding: 12px 20px;
      box-sizing: border-box;
      margin-right: 16px;
      .title {
        font-size: 14px;
        color: #333333;
        margin-bottom: 8px;
      }
      .content {
        color: #333333;
        line-height: 32px;
      }
    }
  }
  .theader {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    .title {
      font-size: 16px;
      color: #333333;
      font-weight: 600;
    }
  }
  .tag {
    width: 30px;
    height: 24px;
    border-radius: 2px;
    padding: 0 8px;
    line-height: 24px;
    box-sizing: border-box;
    font-size: 14px;
    margin: 0 auto;
  }
  .gre {
    color: #2cca74;
    background: #e9f9f1;
  }
  .red {
    color: #eb4e4e;
    background: #fdeded;
  }
}
</style>
<style>
.redStr {
  color: #eb4e4e;
}
.greenStr {
  color: #2cca74;
}
.grayStr {
  color: #999999;
}
</style>