updateChannel.js
7.69 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import './index.less'
import React from "react";
import axios from '@src/axios'
import Utils from '@utils/utils'
import { API_CHANNEL_MANAGE } from '@src/Api'
import { UserManageBar } from '@components/Common'
import { NavLink, withRouter } from 'react-router-dom'
import storage from '@src/utils/localStorage'
import { Row, Col, Table, Form, Button, Input, Icon, message, Spin ,Select, } from 'antd'
const FormItem = Form.Item;
const TextArea = Input.TextArea
const Option = Select.Option;
class updateChannel extends React.Component {
state = {
loading: false,
btnAuth: null,
isShowOpt: true,
expandStatus: false,
titName: "新增渠道",
channelInfo: {},
spinStatus: false,
}
params = {
page: 1,
pageSize: 10
}
componentWillMount() {
document.getElementById('root').scrollIntoView(true);//为ture返回顶部,false为底部
}
componentDidMount() {
this.getRouterParams()
//获取渠道信息
//await this.getChannelById()
}
/*数据获取区域*/
//获取多条件查询历史状态
getChannelById = (searchInfo) => {
return new Promise((resolve, reject) => {
const { optTag,id } = this.props.match.params
if (!id) {
message.warn('请重新选择,或者刷新页面')
this.props.history.push({
pathname: '/home/Channel/manage',
});
return
}else {
axios.ajax({
url: API_CHANNEL_MANAGE.getChannelById,
data: {
id:id
}
}).then(res => {
console.log('res',res)
if (res && Object.keys(res).length > 0) {
//根据修改还是新增下级机构来渲染上级机构显示数据
if (optTag === 'updateItem') {
this.props.form.setFieldsValue({ 'name': res.name })
this.props.form.setFieldsValue({ 'channelId': res.channelId })
this.props.form.setFieldsValue({ 'remark': res.remark })
}
resolve(this.setState({
channelInfo: res,
}))
}
})
}
})
}
//渠道增加
handleOperator = (e) => {
e && e.preventDefault();
let data = Utils.trim(this.props.form.getFieldsValue());
const { optTag } = this.props.match.params
const { channelInfo } = this.state
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.setState({
spinStatus: true,
})
axios.optAjax({
url: optTag && optTag === 'updateItem' ? API_CHANNEL_MANAGE.updChannel:API_CHANNEL_MANAGE.addChannel,
data: {
...data,
id: optTag && optTag === 'updateItem' ? channelInfo.id:""
}
}).then(res=>{
if(res && res.code && res.code !== 0){
this.setState({
spinStatus: false,
})
return
}
message.success(optTag && optTag === 'updateItem' ? '修改成功' : '新增成功')
this.props.history.push({
pathname: '/home/Channel/manage',
});
})
}
});
}
//获取跳转过来的传参判断是新增、修改渠道
getRouterParams = () => {
const params = this.props.match.params
if (!params || !params.optTag) {
message.warn('请重新选择,或者刷新页面')
this.props.history.push({
pathname: '/home/Channel/manage',
});
return
}
if (params.optTag === 'addItem') {
this.setState({
titName: '新增渠道'
})
} else if (params.optTag === 'updateItem') {
this.setState({
titName: '修改渠道',
})
this.getChannelById()
}
}
// 展开查询条件
expandMenu = ()=> {
this.setState({
expandStatus: !this.state.expandStatus,
})
}
render() {
const { getFieldDecorator } = this.props.form;
const { channelInfo } = this.state;
const { optTag } = this.props.match.params
const isUpdChannel = (field) => optTag && optTag === 'updateItem' ? (channelInfo[field] ? channelInfo[field] : 1) : 1
const formItemLayout = {
labelCol: {
md: { span: 12 },
lg: { span: 6 },
},
wrapperCol: {
md: { span: 24 },
lg: { span: 18 },
},
}
const formItemLayout2 = {
labelCol: {
md: { span: 12 },
lg: { span: 3 },
},
wrapperCol: {
md: { span: 24 },
lg: { span: 21 },
},
}
return (
<div className="channelManage searchWrap">
<Spin tip="加载中..." spinning = {this.state.spinStatus}>
<div className="nav">
<NavLink to='/home/Channel/manage' > 渠道管理 </NavLink> ><span>{this.state.titName}</span>
</div>
<UserManageBar title="基本信息" />
<div className="channelInfo">
<Form layout="horizontal">
<Row gutter={24}>
<Col span="8">
<FormItem label="渠道名称:"{...formItemLayout} >
{
getFieldDecorator('name', {
rules: [
{ required: true, message: '请输入渠道名称', },
{ max: 50, whitespace: true, message: '渠道名称最长为50位字符' },
]
})(
<Input placeholder="渠道名称" />
)
}
</FormItem>
</Col>
<Col span="8" >
<FormItem label="渠道编号:"{...formItemLayout} >
{
getFieldDecorator('channelId', {
rules: [
{required: true, message: '请输入渠道编号' },
{pattern: /^(\s)*([0-9]{1,3})(\s)*$/, message: '渠道编号必须为正整数,最长为3位字符'},
]
})(
<Input placeholder="渠道编号" />
)
}
</FormItem>
</Col>
<Col span="8">
<FormItem label="状  态:"{...formItemLayout} >
{
getFieldDecorator('status', {
initialValue: isUpdChannel('status'),
})(
<Select placeholder="状态" className="formInput" >
<Option value={1}>正常</Option>
<Option value={2}>停用</Option>
</Select>
)
}
</FormItem>
</Col>
</Row>
<Row gutter={24} style={{ marginTop: 20 }}>
<Col span="16">
<FormItem label="备   注" {...formItemLayout2}>
{
getFieldDecorator('remark', {
rules: [{ max: 300, message: '备注最长为300位字符' },]
})(
<TextArea placeholder="备注" rows={8} columns={10} />
)
}
</FormItem>
</Col>
</Row>
</Form>
</div>
<div className="submitBtn" >
<Button type="primary" disabled = {this.state.spinStatus} onClick={this.handleOperator} >保存</Button>
<NavLink to='/home/Channel/manage'> <Button>返回 </Button></NavLink>
</div>
</Spin>
</div>
)
}
}
export default Form.create()(updateChannel);