forked from nsjcy/frontEnd/nsjcy

1
liuwh
2020-05-26 aba05ff402b2b6a7ed9e3eedee43addc1b7eee44
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
/**
 * 徐祥健<xuxj@hugeinfo.com.cn>
 * 2018年8月28日 10:41
 *
 */
 
 
import React from 'react';
 
import HeadView from '../view/HeadView';
import TableBtnView from '../view/TableBtnView';
import LinkView from '../view/LinkView';
import { Input, Button, DatePicker, Divider, Row, Col, message, Modal, Popconfirm, Badge, Tabs, Form, Table } from 'antd';
import moment from 'moment';
import Fetch from '../fetch';
import TableView from '../view/TableView';
 
const { TabPane } = Tabs;
class QuestionnaireTable extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      formdata: {},
      userId: "",
      tableData: [],
      totalElements: 1,
      pageSize: 10,
      page: 1,
      currItem: {},
      auditVisible: false //审核弹窗
    };
  }
 
  componentDidMount() {
    document.title = '问卷管理';
    this.loadData(1, this.state.pageSize);
  }
 
  loadData = (page, pageSize) => {
    let _this = this;
    _this.setState({
      loading: true
    })
    _this.props.form.validateFields((err, values) => {
      _this.setState({ formdata: values });
      Fetch.questionQuery({
        ...values,
        page: page,
        size: pageSize,
      })
        .then(res => {
          console.log('res', res);
          this.setState({
            loading: false
          })
          if (res.code == 0) {
            for (var i = 0; i < res.data.content.length; i++) {
              res.data.content[i]['index'] = i + 1;
              res.data.content[i]['key'] = i;
            }
            this.setState({
              tableData: res.data.content,
              loading: false,
              totalElements: res.data.totalElements,
              page
            });
 
          }
        });
    })
  }
 
  onShowSizeChange = (current, pageSize) => {
    this.setState({ pageSize, page: 1 })
    this.loadData(1, pageSize);
  }
  pageChange = (page, pageSize) => {
    this.loadData(page, pageSize);
  }
 
  audit = (data) => {
    Fetch.questionAudit({
      id: this.state.currItem.id,
      ...data,
    }).then(res => {
      console.log('res', res);
      if (res) {
        message.success('操作完成');
      } else {
        message.warn('操作失败,请稍后重试!')
      }
      this.setState({
        auditVisible: false,
      }, ()=> {
        this.loadData(this.state.page, this.state.pageSize)
      })
    })
  }
 
  callback(key) {
    console.log(key);
  }
 
  render() {
    const columns = [{
      title: '编号',
      dataIndex: 'index',
      key: 'index',
    }, {
      title: '主题',
      dataIndex: 'title',
      key: 'title',
      ellipsis: true,
      render: (cur, item) => {
        return cur || '暂无'
      }
    }, {
      title: '描述',
      dataIndex: 'content',
      key: 'content',
      ellipsis: true,
      render: (cur, item) => {
        return cur || '暂无'
      }
    }, {
      title: '发布时间',
      dataIndex: 'publicTime',
      key: 'publicTime',
      render: (cur, item) => {
        return cur ? moment(cur).format("YYYY-MM-DD HH:mm") : '暂无'
      }
    }, {
      title: '创建人',
      dataIndex: 'createrName',
      key: 'createrName',
      render: (cur, item) => {
        return cur || '暂无'
      }
    }, {
      title: '创建时间',
      dataIndex: 'createTime',
      key: 'createTime',
      render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
    }, {
      title: '状态',
      dataIndex: 'status',
      key: 'status',
      render: cur => (
        renderStatus(cur)
      )
    }, {
      title: '操作',
      key: 'action',
      render: (cur, item) => {
        return <React.Fragment>
          <a onClick={() => {
            console.log(item.id);
            this.props.history.push(`/questionnaire/detail/${item.id}`)
          }}>查看</a>
          {
            item.status == 0 &&
            <React.Fragment>
              <Divider type="vertical" />
              <a onClick={() => {
                console.log(item.id);
                this.props.history.push(`/questionnaire/newly/${item.id}`)
              }}>编辑</a>
              <br />
            </React.Fragment>
          }
          {
            item.status == 1 &&
            <React.Fragment>
              <Divider type="vertical" />
              <a onClick={() => {
                this.setState({
                  auditVisible: true,
                  currItem: cur
                })
              }}>审核</a>
              <br/>
              <a onClick={() => {
                console.log(item.id);
                this.props.history.push(`/questionnaire/newly/${item.id}`)
              }}>编辑</a>
            </React.Fragment>
          }
          {
            item.status == 2 &&
            <React.Fragment>
              <Divider type="vertical" />
              <a onClick={() => {
                this.audit({
                  status: 3,
                  id: item.id
                })
              }}>发布</a>
              
            </React.Fragment>
          }
          {
            item.status == 3 &&
            <React.Fragment>
              <Divider type="vertical" />
              <a onClick={() => {
                this.audit({
                  status: 4,
                  id: item.id
                })
              }}>回收</a>
            </React.Fragment>
          }
        </React.Fragment>
 
      },
    }];
    const { data, loading, auditVisible } = this.state;
    const { title, local, type, total, notRead, contact, sed } = this.props;
    return (
      <div className="app-page">
        {/* <div style={{ background: '#fff', margin: '0 20px' }} >
          <Tabs type="card" style={{ margin: 0 }} onChange={this.callback}>
            <TabPane tab="全部" key="1">
            </TabPane>
            <TabPane tab="派送中" key="2">
            </TabPane>
            <TabPane tab="已回收" key="3">
            </TabPane>
          </Tabs>
        </div> */}
        {/* <TableView columns={columns} data={data} pageSize='10' size='default' loading={loading} /> */}
        <div style={{
          padding: '8px',
          margin: '0px 20px',
          backgroundColor: '#fff'
        }}>
          <Table
            size="middle"
            dataSource={this.state.tableData}
            loading={{ spinning: this.state.loading }}
            columns={columns}
            pagination={{
              pageSize: this.state.pageSize,
              onChange: this.pageChange,
              total: this.state.totalElements,
              showSizeChanger: true,
              onShowSizeChange: this.onShowSizeChange,
              showTotal: (total, range) => `共${total}条记录 `,
              // itemRender: this.itemRender,
              showQuickJumper: true,
              defaultCurrent: 1,
              current: this.state.page
            }}
          />
        </div>
 
        <Modal
          title="调查问卷审核"
          visible={this.state.auditVisible}
          footer={null}
          onCancel={() => {
            this.setState({
              auditVisible: false
            })
          }}
        >
          <Row type="flex" justify="end" gutter={20}>
            <Col>
              <Button onClick={() => {
                this.setState({
                  auditVisible: false
                })
              }}>取消</Button>
            </Col>
            <Col>
              <Button onClick={() => {
                this.audit({
                  status: 99
                });
              }}>不通过</Button>
            </Col>
            <Col>
              <Button type="primary" onClick={() => {
                this.audit({
                  status: 2
                });
              }}>通过</Button>
            </Col>
          </Row>
        </Modal>
      </div>
    );
  }
}
const QuestionnaireTableList = Form.create()(QuestionnaireTable);
export default QuestionnaireTableList;
 
function renderStatus(status) {
  switch (status) {
    case 0:
      return <Badge count={'草稿'} style={{ background: '#2db7f5' }} />
    case 1:
      return <Badge count={'待审核'} style={{ background: '#f50' }} />
    case 2:
      return <Badge count={'待发布'} style={{ background: '#f50' }} />
    case 3:
      return <Badge count={'已发布'} style={{ background: '#87d068' }} />
    case 4:
      return <Badge count={'已回收'} style={{ background: '#fadb14' }} />
    case 99:
      return <Badge count={'不通过'} style={{ background: '#fadb14' }} />
    default:
      return '暂无'
  }
}