index.js
10.6 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
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, Modal ,DatePicker,Select,Message } from 'antd'
const FormItem = Form.Item;
const Option = Select.Option;
class Channel extends React.Component {
state = {
loading: false,
btnAuth: null,
isShowOpt: true,
expandStatus: false,
statusBtn:"启用",
page: 1,
pageSize: 10
}
componentWillMount() {
let btnAuth = localStorage.btnAuth
console.log('btnAuth',btnAuth)
this.setState({btnAuth,})
if(
btnAuth.indexOf('channel-edit') === -1 &&
btnAuth.indexOf('channel-delete') === -1 &&
btnAuth.indexOf('channel-stopOrStart') === -1){
this.setState({isShowOpt: false})
}
}
componentDidMount() {
this.getParamQuery()
}
//根据条件查询table数据
queryList = () => {
let searchInfo = Utils.trim(this.props.form.getFieldsValue());
console.log(searchInfo);
// 校验日期选择
if (searchInfo.beginTime && !searchInfo.endTime) {
Message.warn('请选择结束时间');
return;
} else if (!searchInfo.beginTime && searchInfo.endTime) {
Message.warn('请选择开始时间');
return;
}
// 判断日期并转换时间格式
if (searchInfo.beginTime && searchInfo.endTime) {
if (new Date(searchInfo.endTime._d) < new Date(searchInfo.beginTime._d)) {
Message.warn('选择结束时间要大于选择开始时间');
return;
}
else {
searchInfo.beginTime = Utils.formatTimeStamp(searchInfo.beginTime);
searchInfo.endTime = Utils.formatTimeStamp(searchInfo.endTime);
}
}
this.setState({page:1})
this.getParamQuery(searchInfo)
}
//重置表单
reset = () => {
this.props.form.resetFields();
let searchInfo = Utils.trim(this.props.form.getFieldsValue());
this.setState({searchInfo},() => {
this.getParamQuery()
})
}
//获取多条件查询定时任务
getParamQuery = (searchInfo) => {
let _this = this
this.setState({
loading: true
})
axios.ajax({
url: API_CHANNEL_MANAGE.getParamChannel,
data: {
...searchInfo,
pageNum: this.state.page,
pageSize: this.state.pageSize
}
}).then(res => {
let list =res.records.map((item, index) => {
item.key = index
return item
})
this.setState({
list,
loading: false,
pagination: Utils.pagination(res, (current) => {
_this.state.page = current;
_this.queryList();
}),
})
})
}
//停用
stop = (item, id ,statusBtn,status) => {
if (id) {
Modal.confirm({
title: '注意',
content: `是否确认${statusBtn}?`,
okText:"确认",
cancelText:"取消",
onOk: () => {
axios.ajax({
url: API_CHANNEL_MANAGE.enableOrDisableById,
data: {
id: id,
status:status
}
}).then(res => {
if (res) {
message.success(`${statusBtn}成功`)
this.queryList()
} else {
message.error('请刷新重新操作')
}
})
}
})
}
}
//编辑
edit = (item, id,name) => {
this.props.history.push({
pathname: `/home/channel/updateChannel/updateItem/${id}`,
});
}
// 展开查询条件
expandMenu = ()=> {
this.setState({
expandStatus: !this.state.expandStatus,
})
}
deleteChannel= (item, id,name) => {
if (id) {
Modal.confirm({
title: '删除',
content: `您要删除的渠道为 : ${name} ?`,
okText:"确认",
cancelText:"取消",
onOk: () => {
axios.ajax({
url: API_CHANNEL_MANAGE.deleteChannel,
data: { id: id }
}).then(res => {
if (res) {
console.log(res);
message.success('删除成功')
this.queryList();
} else {
message.error('请刷新重新操作')
}
})
}
})
}
}
// 展开查询条件
expandMenu = ()=> {
this.setState({
expandStatus: !this.state.expandStatus,
})
}
//选择一行数据
onRowClick = (record, index) => {
let selectKey = [index];
this.setState({
selectedRowKeys: selectKey,
selectedItem: record
})
}
render() {
const { getFieldDecorator } = this.props.form;
const { selectedRowKeys, selectedRows, loading } = this.state;
const columns = [
{
title: '编号',
align: 'left',
className:'pLeft',
dataIndex: 'channelId',
},
{
title: '名称',
dataIndex: 'name',
align: 'center',
className:'tdWidth',
width: '200px',
render(name) {
return Utils.formatTableColumn(name)
}
},
{
title: '状态',
dataIndex: 'status',
align: 'center',
render(status) {
return {
1: '正常',
2: '停用',
}[status]
}
},
{
title: '创建时间',
dataIndex: 'createTime',
align: 'center',
render(createTime) {
return Utils.formateDateToYMD(createTime)
}
},
];
if (this.state.isShowOpt) {
columns.push(
{
title: '操作',
key: 'opereate',
className:'pRight',
width: '250px',
align: 'right',
render: (record) => {
let id = record.id, name = record.name, item= record,statusBtn='启用' ,status=1
if(record.status===1){
statusBtn='禁用'
status=2
}
return (
<div>
{
this.state.btnAuth.indexOf('channel-stopOrStart') !== -1 ?
<Button size="small" style={{ marginLeft: 15 }} onClick={()=> {this.stop(item, id,statusBtn,status)}} >{statusBtn}</Button>
: ''
}
{
this.state.btnAuth.indexOf('channel-edit') !== -1 ?
<Button size="small" style={{ marginLeft: 15 }} onClick={(item) => { this.edit(item, id, name) }}>修改</Button>
: ''
}
{
this.state.btnAuth.indexOf('channel-delete') !== -1 ?
<Button size="small" style={{ marginLeft: 15 }} onClick={(item) => { this.deleteChannel(item, id ,name) }} >删除</Button>
: ''
}
</div>
)
}
}
)
}
return (
<div className="channelManage searchWrap">
<UserManageBar title="渠道管理" />
<div className='expandMenu iconfont icon-chazhaobiaodanliebiao' onClick={this.expandMenu} ></div>
{
this.state.expandStatus ?
<div className="taskForm">
<Form >
<Row gutter={10}>
<Col span={4}>
<FormItem>
<label htmlFor="添加时间">添加时间</label>
{
getFieldDecorator('beginTime',{
rules: []
})(
<DatePicker
style={{width:'100%'}}
showTime
format="YYYY-MM-DD HH:mm:ss"
placeholder="开始时间" />
)
}
</FormItem>
</Col>
<Col span={1} style={{paddingTop: 46,width: 30}}>
<span style={{marginTop: 29}}>至</span>
</Col>
<Col span={4}>
<FormItem style={{marginTop: 39}}>
{
getFieldDecorator('endTime',{
rules: []
})(
<DatePicker
style={{width: '100%'}}
showTime
format="YYYY-MM-DD HH:mm:ss"
placeholder="结束时间" />
)
}
</FormItem>
</Col>
<Col span="4">
<FormItem >
<label htmlFor="名称">名称</label>
{
getFieldDecorator('name', {
})(
<Input placeholder="名称" />
)
}
</FormItem>
</Col>
<Col span="4">
<FormItem >
<label htmlFor="状态">状态</label>
{
getFieldDecorator('status', {
})(
<Select placeholder="状态" className="formInput" >
<Option value=''>全部</Option>
<Option value={1}>正常</Option>
<Option value={2}>停用</Option>
</Select>
)
}
</FormItem>
</Col>
<Col span="7">
<FormItem style={{ marginTop: 38, }} >
<Button onClick={(item) => { this.queryList(item) }} style={{ background: '#00BB29', color: "#fff", marginRight: 4 }} >查询</Button>
<Button onClick={this.reset} style={{ background: '#ED1719', color: "#fff" }} type="danger">重置</Button>
</FormItem>
</Col>
</Row>
</Form>
</div>
: ''
}
<div className="operate">
{
this.state.btnAuth.indexOf('channel-add') !== -1 ?
<NavLink to={'/home/Channel/updateChannel/addItem'} ><Button>新增</Button></NavLink>
: ''
}
</div>
<UserManageBar title="详细数据" />
<div className="detData">
<Table
selections={false}
bordered={false}
loading={loading}
pagination={this.state.pagination}
onRow={(record, index) => {
return {
onClick: () => {
this.onRowClick(record, index);
}
};
}}
dataSource={this.state.list}
columns={columns}
/>
</div>
</div>
)
}
}
export default Form.create()(Channel);