add.js
5.4 KB
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
import React, { Component } from "react";
import { NavLink } from "react-router-dom";
import Questionnair from "@components/reactQuestionnair/src/Questionnair";
import Editor from "@components/reactQuestionnair/src/QuestionnairEditor";
import Answer from "@components/reactQuestionnair/src/QuestionnairAnswer";
import "@components/reactQuestionnair/assets/iconfonts/iconfont.less";
import { UserManageBar } from "@components/Common";
import { formatQuesData, switchEditor } from "@components/reactQuestionnair/utils/utils";
import axios from "@src/axios/index";
import "./health.less";
import { API_SURVEY_MANAGE, API_SURVEY_QURADIO, API_SURVEY_DELETE_BY_ID } from "@src/Api";
import { message } from "antd";
Questionnair.Editor = Editor;
Questionnair.Answer = Answer;
class HealthNoticeAdd extends React.Component {
state = {
menuName: "新增告知",
spinStatus: false,// 是否显示加载中
editors: [], //可编辑的题目
surveyId: '',
};
componentDidMount() {
let originInfo = this.props.location;
console.log(this.props.match.params)
const { params } = this.props.match.params
let id = this.props.match.params.id
if (params === 'update') {
this.setState({ menuName: "修改告知", surveyId: id });
this.buildSurvey(id)
} else {
this.buildSurvey(id)
this.setState({ menuName: "新增告知", surveyId: id });
}
}
//获取数据,设计健康告知数据buildSurvey
buildSurvey = (id) => {
axios.ajax({
url: API_SURVEY_MANAGE.buildSurvey, //只是修改 发布/保存 的状态
data: {
surveyId: id
}
}).then(res => {
console.log(res);
let editors = formatQuesData(res)
this.setState({
questionnairTitle:res.surveyName,
editors
})
})
}
onConfirm = (newItem, index, newEditors) => {
const belongId = this.props.match.params.id
const { editors } = this.state
let data = {}
console.log('newItem', newItem);
let { type, url } = switchEditor(newItem.type)
console.log('type', type)
axios.ajax({
url,
data: type === 'input' ? {
belongId,
hv: 2,
completionBackwards: newItem.completionBackwards,
completionForwards: newItem.completionForwards,
isRequired: newItem.required ? 1 : 0, //是否必答
orderById: newItem.orderById, //排序
otherOption: newItem.otherOption ? 1 : 0,
otherOptionBackwards: newItem.otherOptionBackwards,
otherOptionForwards: newItem.otherOptionForwards,
quId: newItem.quId,
quTag: 1, //是否是大小题
quTitle: newItem.title,
randOrder: 0, //选项随机排序
tag: 2 //标记
} : {
[type]: newItem.type,
belongId, //健康告知id
hv: 2, //控制性属性
isRequired: newItem.required ? 1 : 0, //是否必答
orderById: newItem.orderById, //排序
otherOption: newItem.otherOption ? 1 : 0,
otherOptionBackwards: newItem.otherOptionBackwards,
otherOptionForwards: newItem.otherOptionForwards,
quId: newItem.quId,
[type]: [ //单选题/多选/填空
{
id: newItem.id,
isNote: newItem.remark ? 1 : 0,
optionName: newItem.remarkText,
orderById: newItem.orderById, //排序
optionTitle: JSON.stringify(newItem.options),
}
],
quTag: 1, //是否是大小题
quTitle: newItem.title,
randOrder: 0, //选项随机排序
tag: 2 //标记
}
}).then(res => {
newEditors[index].quId = res.quId
newEditors[index].id = type !== 'input' ? res[type][0].id : null
this.setState({
editors: newEditors
})
console.log('this.editors', newEditors)
})
}
//onRemove根据id删除问题
onRemove = (questionId) => {
console.log('questionId', questionId)
axios.ajax({
url: API_SURVEY_DELETE_BY_ID.deleteQuestionById,
data: {
quId: questionId
}
}).then(res => {
console.log('删除成功', res)
})
}
//保存标题
// onSaveTitle = (qTitle) => {
// console.log('tt', qTitle)
// this.setState({
// surveyName: qTitle
// })
// }
updateStateById =(surveyName,state)=>{
console.log('state',state)
axios.ajax({
url: API_SURVEY_MANAGE.updateStateById, //只是修改 发布/保存 的状态
data: {
surveyId:this.props.match.params.id,
surveyName,
state:state ? 1:0
}
}).then(res => {
message.success(state ?'发布成功!': '保存成功!')
})
}
render() {
const { menuName, surveyId ,questionnairTitle} = this.state;
let originInfo = this.props.location.state;
return (
<div className="roleAdd">
<div className="nav">
<NavLink to="/home/healthNotice/manage">健康告知 > </NavLink>
<span>{menuName}</span>
</div>
<Questionnair
updateStateById= {this.updateStateById}
surveyId={surveyId}
questionnairTitle = { questionnairTitle }
onConfirm={this.onConfirm}
onRemove={this.onRemove}
// onSaveTitle={this.onSaveTitle}
editors={this.state.editors} />
{/* <Questionnair.Editor editor={editor} activeAnswer = {true}/> */}
</div>
);
}
}
export default HealthNoticeAdd;