king
2020-01-07 ec3cc73f8deaf0b83b0b517e65f949a5a5c496dc
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Tabs, Row, Col, Radio, Button, Table, Popconfirm, Icon, notification, Modal, message, InputNumber } from 'antd'
import Utils from '@/utils/utils.js'
import UniqueForm from './uniqueform'
import CustomForm from './customform'
import BillcodeForm from './billcodeform'
import Api from '@/api'
import './index.scss'
 
const { TabPane } = Tabs
 
class VerifyCard extends Component {
  static propTpyes = {
    dict: PropTypes.object,   // 字典项
    card: PropTypes.object,
    columns: PropTypes.array
  }
 
  state = {
    verify: {},
    fields: []
  }
 
  UNSAFE_componentWillMount() {
    let _verify = this.props.card.verify || {}
 
    this.setState({
      verify: {
        invalid: _verify.invalid || 'false',
        uniques: _verify.uniques || [],
        accountdate: _verify.accountdate || 'false',
        customverifys: _verify.customverifys || [],
        billCode: _verify.billCode || {}
      }
    })
 
    if (this.props.card.OpenType === 'pop') {
      Api.getSystemConfig({
        func: 'sPC_Get_LongParam',
        MenuID: this.props.card.uuid
      }).then(res => {
        if (res.status) {
          let _LongParam = ''
          if (res.LongParam) {
            _LongParam = window.decodeURIComponent(window.atob(res.LongParam))
            try {
              _LongParam = JSON.parse(_LongParam)
            } catch (e) {
              _LongParam = ''
            }
          }
  
          if (!_LongParam) return
          
          let _fields = []
          if (_LongParam.groups.length > 0) {
            _LongParam.groups.forEach(group => {
              group.sublist.forEach(field => {
                _fields.push(field)
              })
            })
          } else {
            _fields = _LongParam.fields
          }
 
          this.setState({
            fields: _fields
          })
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 10
          })
        }
      })
    }
  }
 
  uniqueChange = (values) => {
    let verify = JSON.parse(JSON.stringify(this.state.verify))
 
    if (values.uuid) {
      verify.uniques = verify.uniques.map(item => {
        if (item.uuid === values.uuid) {
          return values
        } else {
          return item
        }
      })
    } else {
      values.uuid = Utils.getuuid()
      verify.uniques.push(values)
    }
 
    this.setState({
      verify: verify
    })
  }
 
  customChange = (values) => {
    let verify = JSON.parse(JSON.stringify(this.state.verify))
 
    if (values.uuid) {
      verify.customverifys = verify.customverifys.map(item => {
        if (item.uuid === values.uuid) {
          return values
        } else {
          return item
        }
      })
    } else {
      values.uuid = Utils.getuuid()
      verify.customverifys.push(values)
    }
 
    this.setState({
      verify: verify
    })
  }
 
  onOptionChange = (e, key) => {
    const { verify } = this.state
    let value = e.target.value
 
    this.setState({
      verify: {...verify, [key]: value}
    })
  }
 
  handleDelete = (record, type) => {
    const { verify } = this.state
 
    if (type === 'customverify') {
      verify.customverifys = verify.customverifys.filter(item => item.uuid !== record.uuid)
    } else if (type === 'unique') {
      verify.uniques = verify.uniques.filter(item => item.uuid !== record.uuid)
    }
 
    this.setState({ verify: verify })
  }
 
  handleEdit = (record, type) => {
    if (type === 'customverify') {
      this.customForm.edit(record)
    } else if (type === 'unique') {
      this.uniqueForm.edit(record)
    }
  }
 
  handleUpDown = (record, type, direction) => {
    let verify = JSON.parse(JSON.stringify(this.state.verify))
    let index = 0
 
    if (type === 'customverify') {
      verify.customverifys = verify.customverifys.filter((item, i) => {
        if (item.uuid === record.uuid) {
          index = i
        }
 
        return item.uuid !== record.uuid
      })
      if ((index === 0 && direction === 'up') || (index === verify.customverifys.length && direction === 'down')) {
        return
      }
 
      if (direction === 'up') {
        verify.customverifys.splice(index - 1, 0, record)
      } else {
        verify.customverifys.splice(index + 1, 0, record)
      }
  
      this.setState({
        verify: verify
      })
    } else if (type === 'unique') {
      verify.uniques = verify.uniques.filter((item, i) => {
        if (item.uuid === record.uuid) {
          index = i
        }
 
        return item.uuid !== record.uuid
      })
      if ((index === 0 && direction === 'up') || (index === verify.uniques.length && direction === 'down')) {
        return
      }
 
      if (direction === 'up') {
        verify.uniques.splice(index - 1, 0, record)
      } else {
        verify.uniques.splice(index + 1, 0, record)
      }
  
      this.setState({
        verify: verify
      })
    }
  }
 
  showError = (errorType) => {
    if (errorType === 'S') {
      notification.success({
        top: 92,
        message: '执行成功!',
        duration: 2
      })
    } else if (errorType === 'F') {
      notification.error({
        className: 'notification-custom-error',
        top: 92,
        message: '执行失败!',
        duration: 15
      })
    } else if (errorType === 'N') {
      notification.error({
        top: 92,
        message: '执行失败!',
        duration: 15
      })
    } else if (errorType === 'E') {
      Modal.error({
        title: '执行失败!'
      })
    } else if (errorType === 'NM') {
      message.error('执行失败!')
    }
  }
 
  timeChange = (val, type) => {
    const { verify } = this.state
 
    this.setState({
      verify: {...verify, [type]: val}
    })
  }
 
  render() {
    // const { getFieldDecorator } = this.props.form
    const { verify, fields } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
    let uniqueColumns = [
      {
        title: '字段名',
        dataIndex: 'field',
        width: '50%'
      },
      {
        title: 'ErrorMessage',
        dataIndex: 'errmsg',
        width: '25%'
      },
      {
        title: 'ErrorCode',
        dataIndex: 'errorCode',
        width: '10%'
      },
      {
        title: '操作',
        align: 'center',
        width: '15%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <Popconfirm title="确定删除吗?" onConfirm={() => this.handleDelete(record, 'unique')}>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
            </Popconfirm>
            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'unique', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'unique', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
          </div>)
      }
    ]
 
    let columns = [
      {
        title: 'SQL',
        dataIndex: 'sql',
        width: '50%'
      },
      {
        title: 'ErrorMessage',
        dataIndex: 'errmsg',
        width: '25%'
      },
      {
        title: 'ErrorCode',
        dataIndex: 'errorCode',
        width: '10%'
      },
      {
        title: '操作',
        align: 'center',
        width: '15%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" onClick={() => this.handleEdit(record, 'customverify')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <Popconfirm title="确定删除吗?" onConfirm={() => this.handleDelete(record, 'customverify')}>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
            </Popconfirm>
            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'customverify', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'customverify', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
          </div>)
      }
    ]
 
    return (
      <Tabs defaultActiveKey="1" className="verify-card-box" onChange={this.tabchange}>
        <TabPane tab="基础验证" key="1">
          <Form {...formItemLayout}>
            <Row gutter={24}>
              <Col span={12}>
                <Form.Item label={'账期验证'}>
                  <Radio.Group value={verify.accountdate} onChange={(e) => {this.onOptionChange(e, 'accountdate')}}>
                    <Radio value="true">开启</Radio>
                    <Radio value="false">不开启</Radio>
                  </Radio.Group>
                </Form.Item>
              </Col>
              <Col span={12}>
                <Form.Item label={'失效验证'}>
                  <Radio.Group value={verify.invalid} onChange={(e) => {this.onOptionChange(e, 'invalid')}}>
                    <Radio value="true">开启</Radio>
                    <Radio value="false">不开启</Radio>
                  </Radio.Group>
                </Form.Item>
              </Col>
            </Row>
          </Form>
        </TabPane>
        <TabPane tab="唯一性验证" key="2">
          <UniqueForm
            fields={fields}
            dict={this.props.dict}
            uniqueChange={this.uniqueChange}
            wrappedComponentRef={(inst) => this.uniqueForm = inst}
          />
          <Table
            bordered
            rowKey="uuid"
            className="custom-table"
            dataSource={verify.uniques}
            columns={uniqueColumns}
            pagination={false}
          />
        </TabPane>
        <TabPane tab="自定义验证" key="3">
          <CustomForm
            dict={this.props.dict}
            customChange={this.customChange}
            wrappedComponentRef={(inst) => this.customForm = inst}
          />
          <Table
            bordered
            rowKey="uuid"
            className="custom-table"
            dataSource={verify.customverifys}
            columns={columns}
            pagination={false}
          />
        </TabPane>
        <TabPane tab="单号生成" key="4">
          {verify.billCode ? <BillcodeForm dict={this.props.dict} billCode={verify.billCode} /> : null}
        </TabPane>
        <TabPane tab="信息提示" key="5">
          <Form {...formItemLayout}>
            <Row gutter={24}>
              <Col offset={6} span={6}>
                <Form.Item label={'提示编码'}>
                  <span className="errorval"> S </span>
                  <Button onClick={() => {this.showError('S')}} type="primary" size="small">
                    查看
                  </Button>
                </Form.Item>
              </Col>
              <Col span={8}>
                <Form.Item label={'停留时间'}>
                  <InputNumber defaultValue={2} min={1} max={10000} precision={0} onChange={(val) => {this.timeChange(val, 'stime')}} />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={24}>
              <Col offset={6} span={6}>
                <Form.Item label={'提示编码'}>
                  <span className="errorval"> -1 </span>
                  不提示
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={24}>
              <Col offset={6} span={6}>
                <Form.Item label={'提示编码'}>
                  <span className="errorval"> N </span>
                  <Button onClick={() => {this.showError('N')}} type="primary" size="small">
                    查看
                  </Button>
                </Form.Item>
              </Col>
              <Col span={8}>
                <Form.Item label={'停留时间'}>
                  <InputNumber defaultValue={15} min={1} max={10000} precision={0} onChange={(val) => {this.timeChange(val, 'ntime')}} />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={24}>
              <Col offset={6} span={6}>
                <Form.Item label={'提示编码'}>
                  <span className="errorval"> F </span>
                  <Button onClick={() => {this.showError('F')}} type="primary" size="small">
                    查看
                  </Button>
                </Form.Item>
              </Col>
              <Col span={8}>
                <Form.Item label={'停留时间'}>
                  <InputNumber defaultValue={15} min={1} max={10000} precision={0} onChange={(val) => {this.timeChange(val, 'ftime')}} />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={24}>
              <Col offset={6} span={6}>
                <Form.Item label={'提示编码'}>
                  <span className="errorval"> E </span>
                  <Button onClick={() => {this.showError('E')}} type="primary" size="small">
                    查看
                  </Button>
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={24}>
              <Col offset={6} span={6}>
                <Form.Item label={'提示编码'}>
                  <span className="errorval"> NM </span>
                  <Button onClick={() => {this.showError('NM')}} type="primary" size="small">
                    查看
                  </Button>
                </Form.Item>
              </Col>
            </Row>
          </Form>
        </TabPane>
      </Tabs>
    )
  }
}
 
export default Form.create()(VerifyCard)