index.vue 9.64 KB
<!-- 录音标签管理 -->
<template>
  <d2-container class="customer-tags">
    <div class="header" slot="header">
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :label-width="'100px'"
        :form-data="showFormData"
      >
      </d2-search>
      <div class="up-btns">
        <el-button size="small" type="primary" @click="handleSearch">
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header title="录音标签管理列表">
        <el-button size="small" type="primary" @click="exportTable">
          导出
        </el-button>
      </d2-table-header>
      <d2-table
        ref="table"
        :get-list-api="getListApi"
        :search-form="searchFormSearch"
        :table-params="tableParams"
        :before-search-fn="beforeSearchFn"
      >
        <template slot="recordingUrl" slot-scope="scope">
          <div
            class="audio"
            @click="play(scope.scope.recordingUrl)"
            v-if="scope.scope.recordingUrl"
          >
            {{ scope.scope.recordingUrl }}
          </div>
        </template>
      </d2-table>
    </div>
  </d2-container>
</template>

<script>
import { receptionTagPage, receptionTagPageExport } from "@/api/resident.js"
import { listShop4sByRef } from "@api/merchant"
import { getBrandList } from "@/api/scene.js"
import { label_businessOpt } from "@/common/constants.js"
import { Util, deepClone } from "@/common/util"
export default {
  data() {
    return {
      getListApi: receptionTagPage,
      tableParams: {
        listName: "list",
        tableOption: false,
        tableColumns: [
          {
            label: "驻店名称",
            prop: "staffName"
          },
          {
            label: "门店名称",
            prop: "merchantName"
          },
          {
            label: "品牌",
            prop: "carBrand"
          },
          {
            label: "录音链接",
            addHtml: "recordingUrl",
            width: "150px"
          },
          {
            label: "质检日期",
            prop: "checkDate"
          },
          {
            label: "客户车型",
            prop: "carModel"
          },
          {
            label: "业务场景",
            prop: "bussinessType",
            formatter(row) {
              let result = { 1: "延保", 2: "轻改", 3: "权益" }[
                row.bussinessType
              ]
              return result || "-"
            }
          },
          {
            label: "APP接待结果",
            prop: "isOrderFinishFlagName"
          },
          {
            label: "质检得分",
            prop: "score"
          },
          {
            label: "身份介绍",
            prop: "sfjs"
          },
          {
            label: "服务意识",
            prop: "fwys"
          },
          {
            label: "话题介入",
            prop: "htjr"
          },
          {
            label: "需求分析",
            prop: "sqfx"
          },
          {
            label: "专业知识",
            prop: "zyzs"
          },
          {
            label: "场景塑造",
            prop: "cjsz"
          },
          {
            label: "案例展示",
            prop: "alzs"
          },
          {
            label: "攻防能力",
            prop: "gfnl"
          },
          {
            label: "逼单能力",
            prop: "bdnl"
          }
        ]
      },
      searchFormSearch: {},
      searchForm: {
        orderFinishFlag: "",
        staffName: "",
        merchantId: "",
        checkType: "",
        checkStart: [new Date(), new Date()],
        carBrandId: ""
      },
      showFormData: [
        {
          label: "驻店名称",
          name: "staffName",
          type: "input",
          isClear: true
        },
        {
          label: "业务场景",
          name: "checkType",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "businessTypeOpt"
        },
        {
          label: "门店",
          name: "merchantId",
          type: "select",
          optionList: [],
          optionId: "merchantId",
          optionLabel: "merchantName",
          optionsName: "storeIdList"
        },
        {
          label: "品牌",
          name: "carBrandId",
          type: "select",
          isClear: true,
          collapseTags: true,
          optionList: [],
          optionId: "id",
          optionLabel: "label",
          optionsName: "brandList"
        },

        {
          label: "质检时间",
          name: "checkStart",
          type: "datePicker",
          isClear: true,
          pickerOptions: "rangePickerOptions_30day2"
        },
        {
          label: "接待结果",
          name: "orderFinishFlag",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "receptionStatusOpt"
        }
      ],
      baseData: {
        businessTypeOpt: deepClone(label_businessOpt),
        receptionStatusOpt: [
          {
            confId: 0,
            confValue: "成交"
          },
          {
            confId: 1,
            confValue: "战败"
          }
        ],
        brandList: [],
        storeIdList: []
      }
    }
  },
  mounted() {
    this.initSelect()
  },
  methods: {
    play(url) {
      window.open(url)
    },
    handleDetail(data) {
      console.log("row", data)
      this.$router.push({
        path: "/inSceneConfigView",
        query: {
          id: data.id
        }
      })
    },
    beforeSearchFn(type = 1) {
      console.log(this.searchForm)
      return new Promise((resolve, reject) => {
        this.searchFormSearch = deepClone(this.searchForm)
        if (this.searchForm?.checkStart?.length) {
          let [startDate, endDate] = this.searchForm.checkStart
          this.searchFormSearch.checkStartTime = Util.dateFormate(
            startDate,
            "YYYY-MM-DD"
          )
          this.searchFormSearch.checkEndTime = Util.dateFormate(
            endDate,
            "YYYY-MM-DD"
          )
        }
        delete this.searchFormSearch.checkStart
        resolve()
      })
    },
    handleSearch() {
      this.page = this.$options.data.call(this).page
      this.$refs.table.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      this.handleSearch()
    },
    async exportTable() {
      try {
        await this.beforeSearchFn()
        const res = await receptionTagPageExport({
          ...this.searchFormSearch
        })
        if (res) window.open(res)
      } catch (error) {
        if (error) this.$message.error(error)
      }
    },
    initSelect() {
      // 使用 Promise.all 处理多个异步任务,并捕获所有可能的错误
      Promise.allSettled([this.getBrandList(), this.getServiceStore()])
        .then((results) => {
          // 检查每个任务的结果
          results.forEach((result, index) => {
            if (result.status === "rejected") {
              console.error(`Task ${index} failed:`, result.reason)
            }
          })
          // 统一调用 getOptionsList
          this.getOptionsList()
        })
        .catch((err) => {
          console.error("Unexpected error in initSelect:", err)
          this.getOptionsList() // 确保即使有意外错误也调用 getOptionsList
        })
    },

    getServiceStore() {
      return new Promise((resolve, reject) => {
        listShop4sByRef({})
          .then((res) => {
            this.baseData.storeIdList = res || []
            resolve(res) // 返回结果以便主流程感知
          })
          .catch((err) => {
            console.error("Error in getBusinessTypeList:", err)
            reject(err) // 捕获并传递错误
          })
      })
    },
    getBrandList() {
      const brandList = []
      return new Promise((resolve, reject) => {
        getBrandList({ containsChildren: true })
          .then((res) => {
            res.map((e) => {
              if (e && e.children && e.children.length) {
                e.children.map((i) => {
                  i.brandId = e.id
                  brandList.push(i)
                })
              }
            })
            this.baseData.brandList = brandList
            resolve(brandList) // 返回结果以便主流程感知
          })
          .catch((err) => {
            console.error("Error in getBrandList:", err)
            reject(err) // 捕获并传递错误
          })
      })
    },
    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === "select") {
          if (
            this.baseData[item.optionsName].length &&
            this.baseData[item.optionsName][0][
              this.showFormData[index].optionLabel
            ] !== "全部"
          ) {
            // if (item.optionsName != "brandList") {
            const temp = {}
            temp[this.showFormData[index].optionId] = ""
            temp[this.showFormData[index].optionLabel] = "全部"
            this.baseData[item.optionsName].unshift(temp)
            // }
          }
          this.$set(
            this.showFormData[index],
            "optionList",
            this.baseData[item.optionsName]
          )
        }
      })
    }
  }
}
</script>

<style scoped>
.audio {
  width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #2a58ad;
  font-size: 14px;
  cursor: pointer;
}
</style>