detail.vue 9.86 KB
<!--
 * @Description: 明细
 * @Author: huyue
 * @Date: 2024-04-16 17:54:27
 * @LastEditors: huyue
 * @LastEditTime: 2024-05-07 11:00:31
-->
<template>
  <div>
    <div class="title-box">
      <div class="title-tag">{{ scenarioType[taskInfo.businessScenario] }}</div>
      <div class="title">{{ taskInfo.taskName }}</div>
      <div class="title-time">创建时间:{{ taskInfo.createdDate }}</div>
      <div class="title-time">
        任务时间:{{ taskInfo.startTime }} - {{ taskInfo.endTime }}
      </div>
    </div>
    <d2-container style="margin-top: 50px">
      <div class="header" slot="header" style="padding: 10px 20px">
        <d2-search
          ref="showSearch"
          class="show-search"
          label-width="110px"
          :search-form="searchForm"
          :form-data="showFormData"
        >
          <div class="up-btns">
            <el-button size="small" type="primary" @click="handleSearch">
              查询
            </el-button>
            <el-button size="small" @click="handleReset"> 重置 </el-button>
          </div>
        </d2-search>
      </div>
      <div class="d2-container-content">
        <d2-table-header>
          <el-button @click="handleExport" size="small" type="primary">
            导出
          </el-button>
        </d2-table-header>
        <d2-table
          ref="exerciseDetailTable"
          :has-num="true"
          :search-form="searchFormSearch"
          :table-params="tableParams"
          :get-list-api="getListApi"
          :before-search-fn="beforeSearchFn"
        >
          <template slot="auth-button-other" slot-scope="scope">
            <!-- <el-button type="text" @click="btnClick(scope)">{{ scope.scope.sparringStatus == 1 ? '查看结果' : '提醒' }}</el-button> -->
            <!-- <el-button
              v-if="scope.scope.taskState == 1"
              type="text"
              @click="btnClickEnd(scope)"
              >结束</el-button
            > -->
            <el-button
              v-if="isEndTimePassed && scope.scope.sparringStatus !== 1"
              type="text"
              @click="btnClick(scope)"
              >提醒</el-button
            >
            <el-button
              v-if="scope.scope.sparringStatus === 1"
              type="text"
              @click="btnClick(scope)"
              >查看结果</el-button
            >
          </template>
          <div slot="sparringStatus" slot-scope="scope">
            <div class="online-status">
              <span
                :class="[
                  scope.scope.sparringStatus === 0
                    ? 'dot blue'
                    : scope.scope.sparringStatus === 1
                    ? 'dot green'
                    : 'dot orange'
                ]"
              ></span
              >{{ scope.scope.sparringStatus ? "已完成" : "未完成" }}
            </div>
          </div>
        </d2-table>
      </div>
    </d2-container>
    <quality-detail
      :is-quality-visible="isQualityVisible"
      v-if="isQualityVisible"
      :detail-obj="detailObj"
      @closeDialog="closeDialog"
    ></quality-detail>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex"
import QualityDetail from "./components/dialogResult.vue"
import { Util, deepClone } from "@/common/util"
import { staffRecordPage } from "@api/exercise"
import { scenarioType } from "./contant"
export default {
  components: { QualityDetail },
  data() {
    return {
      scenarioType,
      activeName: "all",
      searchForm: { sparringStatus: 1 },
      showFormData: [
        {
          label: "手机号",
          name: "staffPhone",
          type: "input",
          isclear: true
        },
        {
          label: "员工名称",
          name: "staffName",
          type: "input",
          isclear: true
        },
        {
          label: "完成时间",
          name: "completionTime",
          type: "datePicker",
          isclear: true
        }
      ],
      // table 相关
      // getListApi: getTaskStaffList,
      getListApi: staffRecordPage,
      searchFormSearch: { sparringStatus: 1 },
      tableParams: {
        listName: "list",
        tableOption: true,
        tableColumns: [
          {
            label: "手机号",
            prop: "staffInfo.staffPhone",
            formatter: (cellValue) => {
              return cellValue.staffInfo.staffPhone
            }
          },
          {
            label: "员工名称",
            prop: "staffInfo.staffName",
            formatter: (cellValue) => {
              return cellValue.staffInfo.staffName
            }
          },
          {
            label: "客户类型",
            prop: "roleTypeDesc"
          },
          {
            label: "得分",
            prop: "score"
          },
          {
            label: "对练时长",
            prop: "sparringDuration",
            formatter: (cellValue) => {
              let timeInMs = cellValue.sparringDuration
              const totalSeconds = Math.floor(timeInMs / 1000)
              const hours = Math.floor(totalSeconds / 3600)
              const minutes = Math.floor((totalSeconds % 3600) / 60)
              const seconds = totalSeconds % 60

              if (hours > 0) {
                return `${hours}时${minutes}分${seconds}秒`
              } else {
                return `${minutes}分${seconds}秒`
              }
            }
          },
          {
            label: "完成时间",
            prop: "completionTime"
          }
        ]
      },
      isQualityVisible: false,
      detailObj: {},
      taskInfo: {}
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    }),
    isEndTimePassed() {
      const currentTime = new Date()
      const endTime = new Date(this.taskInfo.endTime)
      return currentTime < endTime
    }
  },
  mounted() {
    console.log(this.$route.query, "===")
    this.taskInfo = JSON.parse(this.$route.query.detail)
    this.searchFormSearch.taskId = this.taskInfo.id
  },
  methods: {
    ...mapActions({
      get: "d2admin/base/get",
      close: "d2admin/page/close"
    }),
    ...mapActions("d2admin/user", ["actionSetDownloadList"]),
    handleSearch() {
      console.log("search", this.searchFormSearch)
      this.$refs.exerciseDetailTable.refreshTable(true, true)
    },

    handleReset() {
      console.log("handleReset")
      const { activeName } = this
      this.searchForm = {}
      // this.searchForm.sparringStatus = activeName != "all" ? activeName : ""
      this.searchForm.sparringStatus = "1"
      this.searchFormSearch = {}
      this.$refs.exerciseDetailTable.refreshTable(true, true)
    },
    // 查询和导出的参数
    getParams() {
      var params = deepClone(this.searchForm)
      const { activeName } = this
      params.taskId = this.taskInfo.id
      if (params.completionTime && params.completionTime.length) {
        params.startTime = Util.dateFormate(
          params.completionTime[0],
          "YYYY-MM-DD HH:mm:ss"
        )
        params.endTime =
          Util.dateFormate(params.completionTime[1], "YYYY-MM-DD") + " 23:59:59"
        delete params.completionTime
      }
      // params.sparringStatus = activeName != "all" ? activeName : ""
      params.sparringStatus = 1
      return params
    },
    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = this.getParams()
        resolve()
      })
    },
    // tab 列表切换
    handleTabChange(tab, event) {
      console.log(tab, event)
      this.activeName = tab.name
      this.handleSearch()
    },
    // 查看结果和提醒
    btnClick(scope) {
      console.log(scope, "2222222")
      const _row = scope.scope
      if (_row.sparringStatus == "1") {
        // 查看结果
        this.detailObj = _row
        this.isQualityVisible = true
      } else {
        this.$confirm("是否确认发送提醒给驻店员工?", "发送提醒", {
          confirmButtonText: "确定",
          type: "warning"
        }).then(() => {
          console.log("dia关闭")
          const params = {
            id: _row.id
          }
          remindTaskStaff(params).then((res) => {
            console.log(res)
            this.$message.success("提醒成功")
          })
        })
      }
    },
    closeDialog() {
      this.isQualityVisible = false
    },
    // 导出
    handleExport() {
      var params = this.getParams()
      params.method =
        "dj.api.smartcarlife.ai.sparring.task.staff.record.list.export"
      const list = [
        ...this.dowloadList,
        {
          name: "明细列表",
          exportParam: JSON.stringify(params),
          status: "waiting",
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: "dowloadList" })
    }
  }
}
</script>

<style scoped lang="scss">
.title-box {
  display: flex;
  align-items: center;
  margin-left: 24px;
  .title-tag {
    font-size: 14px;
    color: #1d1d1d;
    padding: 6px 16px;
    background: #ffffff;
    border: 1px solid #e8e8ea;
    border-radius: 16px;
  }
  .title {
    font-weight: 500;
    font-size: 16px;
    color: #1d1d1d;
    margin-left: 12px;
    line-height: 24px;
  }
  .title-time {
    font-size: 14px;
    color: #666666;
    margin-left: 20px;
  }
}
.online-status {
  display: flex;
  justify-content: center;
  align-items: center;
  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
  }
  .green {
    background-color: #27cd5a;
  }
  .orange {
    background-color: #fdb757;
  }
  .blue {
    background-color: #2a58ad;
  }
}
</style>