exerciseDetail.vue 8.17 KB
<!--
 * @Description: AI对练记录
 * @Author: huyue
 * @Date: 2024-04-15 16:26:57
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2024-11-04 17:29:09
-->
<template>
  <d2-container class="m-t-40">
    <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" style="position: positive">
      <d2-table-header>
        <auth-button
          category="Button"
          style="
             {
              display: inline-block;
            }
          "
          :show-btn-ids="['9120802']"
        />
      </d2-table-header>
      <d2-table
        ref="exerciseTable"
        :has-num="true"
        :search-form="searchFormSearch"
        :table-params="tableParams"
        :get-list-api="getListApi"
        :before-search-fn="beforeSearchFn"
      >
        <div slot="result" slot-scope="scope">
          <div class="online-status">
            <span
              :class="[
                scope.scope.sparringResult === 0 ? 'dot gray' : 'dot blue'
              ]"
            ></span
            >{{ statusObj[scope.scope.sparringResult] }}
          </div>
        </div>
      </d2-table>
    </div>
  </d2-container>
</template>

<script>
import { mapActions, mapState } from "vuex"
import { Util, deepClone } from "@/common/util"
import { staffBehaviorPage, updateTaskPromptStatus } from "@api/exercise"
export default {
  name: "exerciseRecord",
  data() {
    return {
      title: "查看结果",
      isQualityVisible: false,
      searchForm: {},
      showFormData: [
        {
          label: "员工名称",
          name: "staffName",
          type: "input",
          isclear: true
        },
        {
          label: "手机号",
          name: "staffPhone",
          type: "input",
          isclear: true
        },
        {
          label: "分类",
          name: "sparringType",
          type: "select",
          isclear: true,
          optionList: [
            {
              value: null,
              label: "全部"
            },
            {
              value: "1",
              label: "话术演练"
            },
            {
              value: "2",
              label: "攻防演练"
            }
          ],
          optionId: "value",
          optionLabel: "label"
        },
        {
          label: "练习结果",
          name: "sparringResult",
          type: "select",
          isclear: true,
          optionList: [
            {
              value: null,
              label: "全部"
            },
            {
              value: "0",
              label: "未完成"
            },
            {
              value: "1",
              label: "已完成"
            }
          ],
          optionId: "value",
          optionLabel: "label"
        },
        {
          label: "进入页面时间",
          name: "EntryTime",
          type: "datePicker",
          isclear: true
        },
        {
          label: "离开页面时间",
          name: "LeaveTime",
          type: "datePicker",
          isclear: true
        }
      ],
      statusObj: { 0: "未完成", 1: "已完成" },
      activeName: "all",
      // table相关
      getListApi: staffBehaviorPage,
      searchFormSearch: {},
      tableParams: {
        listName: "list",
        tableOption: false,
        tableColumns: [
          {
            label: "员工名称",
            prop: "staffName"
          },
          {
            label: "手机号",
            prop: "staffPhone"
          },
          {
            label: "分类",
            prop: "sparringType",
            formatter: (cellValue) => {
              return cellValue.sparringType == 1 ? "话术演练" : "攻防演练"
            }
          },

          {
            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: "sparringResult",
            addHtml: "result"
          },
          {
            label: "进入页面时间",
            prop: "pageEntryTime",
            formatter: (cellValue) => {
              return Util.dateFormate(
                cellValue.pageEntryTime,
                "YYYY-MM-DD HH:mm:ss"
              )
            }
          },
          {
            label: "离开页面时间",
            prop: "pageLeaveTime",
            formatter: (cellValue) => {
              return Util.dateFormate(
                cellValue.pageLeaveTime,
                "YYYY-MM-DD HH:mm:ss"
              )
            }
          }
        ]
      }
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  methods: {
    ...mapActions({
      get: "d2admin/base/get",
      close: "d2admin/page/close"
    }),
    ...mapActions("d2admin/user", ["actionSetDownloadList"]),
    handleSearch() {
      this.$refs.exerciseTable.refreshTable(true, true)
    },
    /*************  ✨ Codeium Command ⭐  *************/
    /**
     * Called before search button is clicked.
     * @returns {Promise} A promise that resolves with the modified search form.
     */
    /******  e51793b8-956c-4eaf-98d6-36489bc9fc04  *******/
    beforeSearchFn() {
      console.log(this.searchForm)
      return new Promise((resolve) => {
        this.searchFormSearch = this.getParams()
        resolve()
      })
    },
    getParams() {
      var params = deepClone(this.searchForm)
      const { activeName } = this
      // params.taskId = this.taskInfo.id
      if (params.LeaveTime && params.LeaveTime.length) {
        params.leaveStartTime = Util.dateFormate(
          params.LeaveTime[0],
          "YYYY-MM-DD HH:mm:ss"
        )
        params.leaveEndTime =
          Util.dateFormate(params.LeaveTime[1], "YYYY-MM-DD") + " 23:59:59"
        delete params.LeaveTime
      }
      if (params.EntryTime && params.EntryTime.length) {
        params.entryStartTime = Util.dateFormate(
          params.EntryTime[0],
          "YYYY-MM-DD HH:mm:ss"
        )
        params.entryEndTime =
          Util.dateFormate(params.EntryTime[1], "YYYY-MM-DD") + " 23:59:59"
        delete params.EntryTime
      }
      return params
    },
    handleReset() {
      console.log("handleReset")
      this.searchForm = {}
      // this.activeName = "all"
      this.searchFormSearch = {}
      this.$refs.exerciseTable.refreshTable(true, true)
    },
    // 导出
    handleExport() {
      console.log("导出", this.searchFormSearch, this.getParams())
      var params = this.getParams()
      params.method =
        "dj.api.smartcarlife.ai.sparring.staff.behavior.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">
.m-t-40 {
  margin-top: 40px;
}
.online-status {
  display: flex;
  justify-content: center;
  align-items: center;
  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
  }
  .gray {
    background-color: #c5c5c5;
  }
  .orange {
    background-color: #fdb757;
  }
  .blue {
    background-color: #2cca74;
  }
}
</style>