forked from nsjcy/frontEnd/nsjcy

Mr Ke
2020-03-31 09b4797fb18e2971434c8cfc217f706628e0126e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import React from 'react';
import { Input, Button, DatePicker, Divider, message, Popconfirm, Select, Badge, Spin, Breadcrumb, Table } from 'antd';
import Questionnair from './Questionnair'
import Fetch from '../fetch'
import TableView from '../view/TableView';
import HeadView from '../view/HeadView';
import moment from 'moment';
 
export default class QuestionPersonDetail extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      data: [],
      initData: null,
      btnLoading: false,
      dateSource: null
    };
  }
 
  componentDidMount() {
 
    document.title = '问卷详情';
    const { id } = this.props.match.params;
    const { userId } = this.props.match.params;
    console.log(id)
    console.log(userId)
    this.setState({
      loading: true
    });
    Fetch.getAnswer({ id, userId }).then(res => {
      console.log('res', res);
      console.log('res', res);
      this.setState({
        loading: false,
        dataSoure: res
      })
    })
  }
 
 
  showModal = (id) => {
    this.props.history.push("/activeManageEdit/" + id);
  }
 
  submitQuestionTemp = (questionDtos, extraData) => {
    const { initData } = this.state;
    console.log('questionDtos', questionDtos);
    console.log('initData', initData);
    if (!extraData.questionnairTitle) {
      return message.error('请填写问卷标题');
    }
    questionDtos = questionDtos.map(({ type, title, required, remarkText, options, scores, warnFlag }) => ({
      type, title, required, remarkText, options, scores, warnFlag
    }));
    this.setState({
      btnLoading: true
    })
    Fetch.saveQuestionTemp({
      ...initData,
      title: extraData.questionnairTitle,
      content: extraData.questionnairDescription,
      businessType: extraData.questionnairBusinessType,
      questionDtos
    }).then(res => {
      console.log('res', res);
      this.setState({
        btnLoading: false
      })
      if (res.code == 0) {
        message.success('问卷提交成功');
      }
    })
  }
 
  getData = () => {
 
  }
 
  switchByType = (type) => {
    switch (type) {
      case 'radio':
        return '单选题';
      case 'checkbox':
        return '多选题'
    }
  }
 
  columns = () => {
    return [
      {
        title: '问题',
        dataIndex: 'questionTitle',
        key: 'questionTitle',
      },
      {
        title: '问题类型',
        dataIndex: 'type',
        key: 'type',
        render: (cur, item) => {
          return this.switchByType(cur)
        }
      },
      {
        title: '问题选项',
        dataIndex: 'options',
        key: 'options',
        render: (cur) => {
          return cur.map((a, idx) => {
            return <div>
              {idx + 1}、{a};
            </div>
          })
        }
      },
      {
        title: '答题情况',
        dataIndex: 'itemDesc',
        key: 'itemDesc',
        render: (cur, item) => {
          return cur || '未提供答案'
        }
      },
      {
        title: '得分',
        dataIndex: 'score',
        key: 'score',
        render: (cur) => {
          return cur + '分'
        }
      },
    ];
  }
 
  render() {
 
    const { loading, dataSoure } = this.state;
    return (
      <div className="app-page">
        <HeadView history={this.props.history} />
        <div style={{
          margin: 10
        }}>
          <Breadcrumb>
            <Breadcrumb.Item>
              <a onClick={() => {
                this.props.history.goBack();
              }}>返回</a>
            </Breadcrumb.Item>
            <Breadcrumb.Item>
              问卷答题详情
            </Breadcrumb.Item>
          </Breadcrumb>
        </div>
        {
          loading ?
            <div style={{ height: 200, width: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
              <Spin spinning={loading} />
            </div> :
            <React.Fragment>
              {/* <Questionnair submitQuestionTemp={this.submitQuestionTemp} btnLoading={btnLoading} /> */}
              {
                dataSoure &&
                <div style={{ background: '#fff', marginTop: 10 }}>
                  <div style={{ width: 600, margin: '0 auto', padding: '20px 0 0 0 ' }}>
                    <h3>
                      问卷标题:{dataSoure[0].title || '暂无'}
                    </h3>
                    <h4 style={{ marginBottom: 0 }}>
                      答题人:{dataSoure[0].userName || '暂无'}
                    </h4>
                    <h4 style={{ marginBottom: 0 }}>
                      答题时间:{dataSoure[0].createTime ? moment(dataSoure[0].createTime).format("YYYY-MM-DD HH:mm") : '暂无'}
                    </h4>
                    <h4 style={{ marginBottom: 0 }}>
                      答题总得分:{dataSoure.map(({ score }) => score).reduce(function (prev, cur, index, array) {
                      return prev + cur
                    })}分
                    </h4>
                  </div>
                </div>
              }
 
              {/* {initData && initData.questionDtos.map((item, index) => (
                <React.Fragment>
                  <Questionnair.Editor editor={item} acitveAnswer={true} data={initData} key={item.questionId} index={index} disabled={true}/>
                  <Questionnair.Answer answer={item} index={index} />
                </React.Fragment>
              ))} */}
 
              {
                dataSoure &&
                <div style={{ background: '#fff', padding: 40 }}>
                  <Table columns={this.columns()} dataSource={dataSoure} style={{ width: '80%', margin: '0 auto' }} pagination={false}></Table>
                </div>
              }
 
            </React.Fragment>
        }
 
      </div>
    );
  }
 
}
 
function typeStatus(type) {
  switch (type) {
    case 1:
      return "企业体检";
    case 2:
      return "培训活动";
    case 3:
      return "未检调查";
    case 4:
      return "刑执监督";
  }
}