index.js 2.24 KB
Newer Older
xuzhenghua committed
1 2
import React, { Component } from 'react'
import './index.scss'
xuzhenghua committed
3
import { http, getParam } from '@/utils';
xuzhenghua committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

export default class RecordPopup extends Component {
  constructor(props) {
    super(props);
    this.state = {
      recordList: [],
    }
  }

  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
24 25 26
  handleToTestRecord = (e, id) => {
    e.preventDefault();
    const { history } = this.props;
wangshuo committed
27 28
    if(!getParam('version')) {
      location.href = `${API.m}/levelTest/report?id=${id}`;
xuzhenghua committed
29 30 31 32 33
    } else {
      location.href = `${API.m}/levelTest/report?id=${id}&version=${getParam('version')}`;
    }
  }

xuzhenghua committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

  render() {
    let {recordList} = this.state;
    const { handleToHide } = this.props;
    return (
      <div className='record__mark'>
      <div className="gift__record">
        <div className="close__button" onClick={handleToHide}>
          <i className="icon iconfont iconiconfront-77"></i>
        </div>
        <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 ? (
xuzhenghua committed
62
                    <a onClick={(e) => this.handleToTestRecord(e, item.id)}>测试记录</a>
xuzhenghua committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                  ) : (null)
                }
              </span>
            </div>
              )
            }):
                <div className={'notdata'}>暂无测试记录</div>
          }
          </div>
        </div>
      </div>

      </div>
    )
  }
}