forked from nsjcy/frontEnd/nsjcy

1
liuwh
2020-03-05 c79f4fea5045445c40cd417c3bdcf78c843f87ae
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
219
220
221
import React from 'react';
import { Input, Button, DatePicker, Divider, message, Popconfirm, Select, Badge, Spin, Breadcrumb } from 'antd';
import Questionnair from '../page/Questionnair'
import Fetch from '../fetch'
 
export default class Newly extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      data: [
        {
          questionId: 'afaa9e6d672c56418199a8a62a4152c2d74f',
          type: 'radio',
          title: '单选题',
          required: true,
          remark: true,
          remarkText: '(此题关于一个很有深度的问题)',
          options: ['选项1', '选项2'],
          rows: 1,
          textareaHeight: 3,
          maxLength: 50,
          otherOption: true,
          otherOptionForwards: '其他',
          otherOptionBackwards: '22222',
          completionForwards: '题目:',
          completionBackwards: '',
          isEditor: false,
          isFirst: false,
          editorShake: ''
        },
        {
          questionId: '347a22645aa32d4f4a5a231fc98027e0b3c5',
          type: 'dropdown',
          title: '下拉',
          required: true,
          remark: false,
          remarkText: '',
          options: ['选项1', '选项2'],
          rows: 1,
          textareaHeight: 3,
          maxLength: 50,
          otherOption: false,
          otherOptionForwards: '其他',
          otherOptionBackwards: '',
          completionForwards: '题目:',
          completionBackwards: '',
          isEditor: false,
          isFirst: false,
          editorShake: ''
        },
        {
          questionId: '400eabd41ad9d846eca91abaf0a853670d38',
          type: 'checkbox',
          title: '多选题',
          required: true,
          remark: false,
          remarkText: '',
          options: ['选项1', '选项2'],
          rows: 1,
          textareaHeight: 3,
          maxLength: 50,
          otherOption: false,
          otherOptionForwards: '其他',
          otherOptionBackwards: '',
          completionForwards: '题目:',
          completionBackwards: '',
          isEditor: false,
          isFirst: false,
          editorShake: ''
        },
        {
          questionId: 'ea99f8009dc5c841504aaad62aab2ea2a7ee',
          type: 'text',
          title: '单行文本',
          required: true,
          remark: false,
          remarkText: '',
          options: ['选项', '选项'],
          rows: 1,
          textareaHeight: 3,
          maxLength: 50,
          otherOption: false,
          otherOptionForwards: '其他',
          otherOptionBackwards: '',
          completionForwards: '题目:',
          completionBackwards: '',
          isEditor: false,
          isFirst: false,
          editorShake: ''
        },
        {
          questionId: 'f0ca471ce2918043d5bad6f5b13b991bc5a6',
          type: 'textarea',
          title: '多行文本',
          required: true,
          remark: false,
          remarkText: '',
          options: ['选项', '选项'],
          rows: 1,
          textareaHeight: 3,
          maxLength: 50,
          otherOption: false,
          otherOptionForwards: '其他',
          otherOptionBackwards: '',
          completionForwards: '题目:',
          completionBackwards: '',
          isEditor: false,
          isFirst: false,
          editorShake: ''
        },
        {
          questionId: '0d0529163a79e749587888375a95a5045a0d',
          type: 'input',
          title: '',
          required: true,
          remark: false,
          remarkText: '',
          options: ['选项', '选项'],
          rows: 1,
          textareaHeight: 3,
          maxLength: 50,
          otherOption: false,
          otherOptionForwards: '其他',
          otherOptionBackwards: '',
          completionForwards: '题目:',
          completionBackwards: '下个路口见',
          isEditor: false,
          isFirst: false,
          editorShake: ''
        }
      ],
      initData: null,
      btnLoading: false
 
    };
  }
 
  componentDidMount() {
    const { id } = this.props.match.params;
    document.title = id == 'new' ? '新建问卷' : '编辑问卷';
    this.setState({
      loading: true
    });
    Fetch.questionFindById(id).then(res => {
      console.log('res', res);
      res.questionDtos = res.questionDtos && res.questionDtos.length ? res.questionDtos.map((item) => ({
        ...item,
        remark: true
      })) : [];
      this.setState({
        loading: false,
        initData: res
      })
    })
  }
 
  submitQuestionTemp = (questionDtos, extraData) => {
    const { initData } = this.state;
    console.log('questionDtos', questionDtos);
    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,
      questionDtos
    }).then(res => {
      console.log('res', res);
      this.setState({
        btnLoading: false
      })
      if (res.code == 0) {
        message.success('问卷提交成功');
      }
    })
  }
 
  getData = () => {
 
  }
 
  render() {
 
    const { data, loading, resetKey, initData, btnLoading } = this.state;
    const { id } = this.props.match.params;
    return (
      <div className="app-page">
        <div style={{
          margin: '10px 0 0 10px'
        }}>
          <Breadcrumb>
            <Breadcrumb.Item>
              <a onClick={()=>{
                this.props.history.goBack();
              }}>问卷管理</a>
            </Breadcrumb.Item>
            <Breadcrumb.Item>
              {id == 'new' ? '新建问卷' : '编辑问卷'}
            </Breadcrumb.Item>
          </Breadcrumb>
        </div>
        {
          loading ?
            <div style={{ height: 200, width: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
              <Spin spinning={loading} />
            </div> :
            initData && <Questionnair submitQuestionTemp={this.submitQuestionTemp} btnLoading={btnLoading} initData={initData} editors={initData.questionDtos || []} />
        }
      </div>
    );
  }
 
}