index.js 2.53 KB
Newer Older
zhanghaozhe committed
1
/* eslint-disable jsx-a11y/anchor-is-valid */
zhanghaozhe committed
2 3 4
import React, { Component } from "react"
import "./index.scss"
import { http, getParam } from "src/utils"
xuzhenghua committed
5 6 7

export default class RecordPopup extends Component {
  constructor(props) {
zhanghaozhe committed
8
    super(props)
xuzhenghua committed
9 10 11 12 13
    this.state = {
      recordList: [],
    }
  }

zhanghaozhe committed
14 15 16 17 18 19 20 21 22 23 24 25
  componentDidMount() {
    http.get(`${API.home}/sys/ai_test/get_user_testinfo`).then((res) => {
      let {
        code,
        data: { user_test_record },
      } = res.data
      if (code === 200) {
        this.setState({
          recordList: user_test_record,
        })
      }
    })
xuzhenghua committed
26 27
  }

xuzhenghua committed
28
  handleToTestRecord = (e, id) => {
zhanghaozhe committed
29 30
    e.preventDefault()
    if (!getParam("version")) {
zhanghaozhe committed
31
      window.location.href = `${API.m}/levelTest/report?id=${id}`
xuzhenghua committed
32
    } else {
zhanghaozhe committed
33 34 35
      window.location.href = `${
        API.m
      }/levelTest/report?id=${id}&version=${getParam("version")}`
xuzhenghua committed
36 37 38
    }
  }

xuzhenghua committed
39
  render() {
zhanghaozhe committed
40 41
    let { recordList } = this.state
    const { handleToHide } = this.props
xuzhenghua committed
42
    return (
zhanghaozhe committed
43 44 45 46
      <div className="record__mark">
        <div className="gift__record">
          <div className="close__button" onClick={handleToHide}>
            <i className="icon iconfont iconiconfront-77"></i>
xuzhenghua committed
47
          </div>
zhanghaozhe committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
          <p className="mark__title">测试记录</p>
          <p className="mark__tip">
            多次测试保留最高分,可查看最近一次答题记录
          </p>
          <div>
            <div className="table__head">
              <span className="tr">测试时间</span>
              <span className="tr">分数</span>
              <span className="tr">操作</span>
            </div>
            <div className="table__body">
              {recordList.length > 0 ? (
                recordList.map((item, index) => {
                  return (
                    <div className="tr__container" key={index}>
                      <span className="tr">{item.submit_time}</span>
                      <span className="tr">{item.score}</span>
                      <span className="tr">
                        {index === 0 ? (
                          <a
                            onClick={(e) => this.handleToTestRecord(e, item.id)}
                          >
                            测试记录
                          </a>
                        ) : null}
                      </span>
                    </div>
                  )
                })
              ) : (
                <div className={"notdata"}>暂无测试记录</div>
              )}
xuzhenghua committed
80 81 82 83 84 85 86
            </div>
          </div>
        </div>
      </div>
    )
  }
}