king
2020-09-04 b987be8dd8b6bc1fa01810daa1e1a60e58a3c921
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Tabs, Row, Col, Button, notification, Modal, message, InputNumber, Input, Select, Radio } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import CodeMirror from '@/templates/zshare/codemirror'
import EditTable from './editable'
 
import './index.scss'
 
const { TabPane } = Tabs
 
class VerifyCard extends Component {
  static propTpyes = {
    floor: PropTypes.any,      // 是否为子表
    btnTab: PropTypes.any,     // 表单标签页(按钮)参数
    config: PropTypes.any,     // 表单标签页参数
    dict: PropTypes.object,    // 字典项
    card: PropTypes.object,
    columns: PropTypes.array
  }
 
  state = {
    verify: {},
    templates: [],
    selectimg: '',
    printMode: 'normal'
  }
 
  UNSAFE_componentWillMount() {
    let _verify = this.props.card.verify || {}
 
    _verify.Template = _verify.Template || ''
    _verify.printerTypeList = _verify.printerTypeList || []
    _verify.linkType = _verify.linkType || 'system'
    _verify.printMode = _verify.printMode || 'normal'
 
    this.setState({
      verify: _verify,
      linkType: _verify.linkType,
      printMode: _verify.printMode,
      printFunc: _verify.printFunc || '// Function(data, form, printer, notification) data-打印数据列表,form-表单信息(不存在时为{}),printer-打印设置,notification-信息提示控件'
    })
  }
 
  componentDidMount() {
    let _sql = `select PrintTempNO,Images,PrintTempNO+PrintTempName as PN from sPrintTemplate 
    where appkey= @appkey@ and Deleted=0 
    union select ID,Images,a.PrintTempNO+PrintTempName as PN 
    from (select * from sPrintTemplate where appkey= '' and Deleted=0 ) a 
    left join (select PrintTempNO from sPrintTemplate where appkey= @appkey@ and Deleted=0 ) b 
    on a.PrintTempNO=b.PrintTempNO 
    left join (select Srcid from sPrintTemplate_Log where appkey='' and apicode= @appkey@ and Deleted=0 ) c 
    on a.ID=c.Srcid where b.PrintTempNO is null and c.Srcid is null`
 
    let param = {
      func: 'sPC_Get_SelectedList',
      LText: Utils.formatOptions(_sql),
      obj_name: 'data',
      arr_field: 'PN,PrintTempNO,Images'
    }
 
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
 
    Api.getSystemConfig(param).then(res => {
      if (res.status) {
        let temps = res.data.map(temp => {
          return {
            value: temp.PrintTempNO,
            text: temp.PN,
            img: temp.Images
          }
        })
 
        let Template = this.state.verify.Template
        let selectimg = ''
        let selectTemp = temps.filter(temp => temp.value === Template)[0]
 
        if (!selectTemp) {
          Template = ''
        } else {
          selectimg = selectTemp.img
        }
 
        this.setState({
          selectimg: selectimg,
          templates: temps,
          verify: {
            ...this.state.verify,
            Template: Template
          }
        })
      } else {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      }
    })
  }
 
  showError = (errorType) => {
    if (errorType === 'S') {
      notification.success({
        top: 92,
        message: '执行成功!',
        duration: 2
      })
    } else if (errorType === 'Y') {
      Modal.success({
        title: '执行成功!'
      })
    } else if (errorType === 'F') {
      notification.error({
        className: 'notification-custom-error',
        top: 92,
        message: '执行失败!',
        duration: 10
      })
    } else if (errorType === 'N') {
      notification.error({
        top: 92,
        message: '执行失败!',
        duration: 10
      })
    } 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}
    })
  }
 
  changeTemplate = (val) => {
    const { templates } = this.state
 
    let temp = templates.filter(temp => temp.value === val)[0]
 
    this.setState({
      selectimg: temp.img
    })
  }
 
  handleConfirm = () => {
    const { verify } = this.state
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          let _verify = {...verify, ...values}
 
          if (this.refs.editTable && this.refs.editTable.state) {
            let printTypes = this.refs.editTable.state.dataSource
  
            let emptys = printTypes.filter(item => !item.Value || !item.Text)
            let valMap = new Map()
            let isvalid = true
  
            printTypes.forEach(item => {
              if (valMap.has(item.Value)) {
                isvalid = false
              } else {
                valMap.set(item.Value, item.Text)
              }
            })
  
            if (emptys.length > 0) {
              notification.warning({
                top: 92,
                message: '打印类型表格中Value、Text字段不可为空!',
                duration: 5
              })
              return
            } else if (!isvalid) {
              notification.warning({
                top: 92,
                message: '打印类型表格中Value字段不可重复!',
                duration: 5
              })
              return
            }
  
            _verify.printerTypeList = printTypes
          }
 
          resolve(_verify)
        } else {
          notification.warning({
            top: 92,
            message: '链接地址与打印模板不可为空!',
            duration: 5
          })
        }
      })
    })
  }
 
  changePrintMode = (e) => {
    let value = e.target.value
 
    this.setState({
      printMode: value
    })
  }
 
  changeLinkType = (e) => {
    let value = e.target.value
 
    this.setState({
      linkType: value
    }, () => {
      if (value === 'system') {
        this.props.form.setFieldsValue({
          linkUrl: '127.0.0.1:13529'
        })
      }
    })
  }
 
  render() {
    const { getFieldDecorator } = this.props.form
 
    const { verify, linkType, printMode, printFunc } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
 
    return (
      <div id="verify-card-box-tab">
        <Tabs defaultActiveKey="1" className="verify-card-print-box" onChange={this.tabchange}>
          <TabPane tab="打印验证" key="1">
            <Form {...formItemLayout}>
              <Row gutter={24}>
                <Col span={8}>
                  <Form.Item label={'打印模式'}>
                    {getFieldDecorator('printMode', {
                      initialValue: printMode || 'normal'
                    })(
                      <Radio.Group onChange={this.changePrintMode}>
                        <Radio value="normal">标准</Radio>
                        <Radio value="custom">自定义</Radio>
                      </Radio.Group>
                    )}
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'链接类型'}>
                    {getFieldDecorator('linkType', {
                      initialValue: linkType || 'system'
                    })(
                      <Radio.Group onChange={this.changeLinkType}>
                        <Radio value="system">系统</Radio>
                        <Radio value="custom">自定义</Radio>
                      </Radio.Group>
                    )}
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'链接地址'}>
                    {getFieldDecorator('linkUrl', {
                      initialValue: verify.linkUrl || '127.0.0.1:13529',
                      rules: [
                        {
                          required: true,
                          message: this.props.dict['form.required.input'] + '链接地址!'
                        }
                      ]
                    })(<Input placeholder="" autoComplete="off" disabled={linkType === 'system'} />)}
                  </Form.Item>
                </Col>
                {printMode === 'custom' ? <Col span={24}>
                  <Form.Item label={'处理函数'} className="printFunc">
                    {getFieldDecorator('printFunc', {
                      initialValue: printFunc || '',
                      rules: [
                        {
                          required: true,
                          message: this.props.dict['form.required.input'] + '处理函数!'
                        }
                      ]
                    })(
                      <CodeMirror mode="text/javascript"/>
                    )} 
                  </Form.Item>
                </Col> : null}
                {printMode === 'normal' ? <Col span={8}>
                  <Form.Item label={'打印模板'}>
                    {getFieldDecorator('Template', {
                      initialValue: verify.Template || '',
                      rules: [
                        {
                          required: true,
                          message: this.props.dict['form.required.select'] + '打印模板!'
                        }
                      ]
                    })(
                      <Select dropdownClassName="print-template-setting" onChange={this.changeTemplate}>
                        {this.state.templates.map((option, key) =>
                          <Select.Option id={key} key={key} value={option.value}>
                            {option.text}
                          </Select.Option>
                        )}
                      </Select>
                    )}
                  </Form.Item>
                </Col> : null }
                {printMode === 'normal' ? <Col span={8} offset={8}>
                  <img className="legend" src={this.state.selectimg} alt=""/>
                </Col> : null }
              </Row>
            </Form>
          </TabPane>
          <TabPane tab={
            <span>
              打印类型
              {verify.printerTypeList.length ? <span className="count-tip">{verify.printerTypeList.length}</span> : null}
            </span>
          } key="2">
            <Form {...formItemLayout}>
              <Row gutter={24}>
                <Col span={24} className="print-tip">
                  <Form.Item label={'提示'}>
                    如果此按钮涉及多种数据类型的打印,需要设置不同的打印机时,请添加打印类型控制信息,用户在自定义设置中,可根据打印类型设置对应的打印机。
                    打印时,数据的打印类型取决于返回值(内部或外部接口)中的 printType 字段。
                    注:返回值中的 printCount、templateID 字段,可分别控制打印数量和打印模板。
                  </Form.Item>
                </Col>
                <Col span={24}>
                  <EditTable data={verify.printerTypeList} dict={this.props.dict} ref="editTable"/>
                </Col>
              </Row>
            </Form>
          </TabPane>
          <TabPane tab="信息提示" key="7">
            <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={verify.stime || 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"> Y </span>
                    <Button onClick={() => {this.showError('Y')}} type="primary" size="small">
                      查看
                    </Button>
                  </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={verify.ntime || 10} 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={verify.ftime || 10} 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>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                    <span className="errorval"> -1 </span>
                    不提示
                  </Form.Item>
                </Col>
              </Row>
            </Form>
          </TabPane>
        </Tabs>
      </div>
    )
  }
}
 
export default Form.create()(VerifyCard)