king
2023-02-10 49cd775392f5aa1da349703c9128cedf513d4317
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, Select, Input, Modal, DatePicker, notification, InputNumber } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const { confirm } = Modal
const { TextArea } = Input
const VoucherTable = asyncComponent(() => import('./voucherTable'))
 
class VoucherModule extends Component {
  static propTpyes = {
    config: PropTypes.object,        // 组件配置信息
  }
 
  state = {
    BID: '',
    type: 'createVoucher',
    config: null,
    loading: false,
    data: [],
    tbdata: [],
    typeOptions: [],
    charType: '',
    charName: '',
    charInt: '',
    vouDate: null,
    book: null,
    username: sessionStorage.getItem('User_Name'),
    remark: '',
    remarkVisible: false,
    attachments: 0,
    title: '',
    orgcode: '',
    orgname: '',
    status: '', // 新建时,empty、change、saved
    saved: false
  }
 
  UNSAFE_componentWillMount () {
    const { config } = this.props
 
    let BID = ''
    let BData = ''
 
    if (config.wrap.supModule) {
      BData = window.GLOB.CacheData.get(config.wrap.supModule)
    } else {
      BData = window.GLOB.CacheData.get(config.$pageId)
    }
    if (BData) {
      BID = BData.$BID || ''
    }
 
    let book = null
    let vouDate = null
    if (config.wrap.supBook) {
      book = window.GLOB.CacheData.get(config.wrap.supBook) || null
 
      if (book) {
        let month = book.months
        vouDate = moment()
  
        if (month && month < moment().format('YYYY-MM')) {
          vouDate = moment(month, 'YYYY-MM').endOf('month')
        }
      }
    }
 
    window.GLOB.CacheVoucher.delete(config.uuid)
    let type = config.wrap.type || 'createVoucher'
 
    // type = 'checkVoucher'
    // BID = '202302081418373862P8Q29OUD19CT1AVMU6'
 
    if (type === 'createVoucher' || type === 'createTemp') {
      BID = Utils.getguid()
    }
 
    this.setState({
      book: book,
      vouDate: vouDate,
      config: fromJS(config).toJS(),
      type: type,
      BID: BID || '',
      status: 'empty'
    }, () => {
      this.loadData()
      this.getVoucher()
    })
  }
 
  componentDidMount () {
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
 
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
  }
 
  resetParentParam = (MenuID, id, data) => {
    const { config, type } = this.state
 
    if (config.wrap.supBook === MenuID) {
      let month = data.months
      let vouDate = moment()
 
      if (month && month < moment().format('YYYY-MM')) {
        vouDate = moment(month, 'YYYY-MM').endOf('month')
      }
 
      this.setState({ book: data, vouDate }, () => {
        this.loadData()
        this.getVoucher()
      })
      return
    }
 
    if (!config.wrap.supModule || config.wrap.supModule !== MenuID || type === 'createVoucher' || type === 'createTemp') return
    if (id !== this.state.BID || id !== '') {
      this.setState({ BID: id }, () => {
        this.getVoucher()
      })
    }
  }
 
  loadData = () => {
    const { book, config, type } = this.state
 
    if (!book) return
 
    let param = {
      func: 's_get_fcc_account_data',
      // account_code: book.account_code || '',
      fcc_date: book.months ? book.months + '-01' : moment().format('YYYY-MM-DD'),
      account_year_code: book.account_year_code || '',
      months: book.months ? book.months : moment().format('YYYY-MM'),
      BID: book.id
    }
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
 
      let typeOptions = res.char || []
      if (type === 'createVoucher') {
        let charInt = typeOptions[0] ? typeOptions[0].voucher_char_int + 1 : 1
 
        this.setState({
          typeOptions: typeOptions,
          charType: typeOptions[0] ? typeOptions[0].voucher_class : '',
          charName: typeOptions[0] ? typeOptions[0].voucher_char : '',
          charInt: charInt,
          orgcode: res.orgcode,
          orgname: res.orgname,
        })
      } else {
        this.setState({
          typeOptions: typeOptions
        })
      }
 
      let names = {}
      let supplier = []
      let customer = []
      let department = []
      let project = []
      let inventory = []
      let employee = []
      let cash_flow = []
      let others = []
 
      res.sup && res.sup.forEach(item => {
        names[item.sup_type_code] = item.sup_type_name
      })
 
      res.supplier && res.supplier.forEach(item => {
        supplier.push({value: item.suppliercode, label: item.suppliername})
      })
 
      res.customer && res.customer.forEach(item => {
        customer.push({value: item.customercode, label: item.customername})
      })
      
      res.co_pro && res.co_pro.forEach(item => {
        department.push({value: item.co_pro_code, label: item.co_pro_name})
      })
        
      res.pm && res.pm.forEach(item => {
        project.push({value: item.projectcode, label: item.projectname})
      })
        
      res.materiel && res.materiel.forEach(item => {
        inventory.push({value: item.productcode, label: item.productname})
      })
        
      res.workers && res.workers.forEach(item => {
        employee.push({value: item.workercode, label: item.workername})
      })
        
      res.cash_flow && res.cash_flow.forEach(item => {
        cash_flow.push({value: item.cash_flow_code, label: item.cash_flow_name})
      })
 
      res.others && res.others.forEach(item => {
        others.push({value: item.sup_acc_code, label: item.sup_acc_name, parentId: item.sup_acc_type})
      })
 
      let message = {
        subjects: res.subjects || [],
        names: names,
        supplier: supplier,
        customer: customer,
        department: department,
        project: project,
        inventory: inventory,
        currency: res.currency || [],
        employee: employee,
        cash_flow: cash_flow,
        others: others,
        account_code: res.account_code,
        account_year_code: res.account_year_code
      }
 
      window.GLOB.CacheVoucher.set(config.uuid, message)
    })
  }
 
  getVoucher = () => {
    const { book, BID, type } = this.state
 
    if (!book || !BID || type === 'createVoucher' || type === 'createTemp') return
 
    let param = {
      func: 's_get_fcc_voucher',
      BID: book.id,
      ID: BID
    }
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
 
      let data = []
      if (res.voucher) {
        data = res.voucher.map(line => {
          line.uuid = line.subject_id || ''
 
          if (line.direction_type === 'credit') {
            line.credit = line.net_amount || 0
            line.debit = ''
          } else {
            line.debit = line.net_amount || 0
            line.credit = ''
          }
 
          line.unitratio = line.foreign_unitratio || 0
          line.exratecode = line.foreign_exratecode || ''
          line.exratename = line.foreign_exratename || ''
          line.local_currency = line.local_exratecode || ''
          line.foreign_currency_type = line.foreign_type || ''
 
          if (line.sup) {
            line.supAccounts = line.sup.map(cell => {
              cell.uuid = cell.sup_id
              return cell
            })
            delete line.sup
          }
 
          return line
        })
      }
 
      this.setState({
        data: data,
        vouDate: res.fibvoucherdate ? moment(res.fibvoucherdate, 'YYYY-MM-DD') : null,
        charType: res.voucher_class,
        charName: res.voucher_char,
        charInt: res.voucher_char_int,
        orgcode: res.orgcode,
        orgname: res.orgname,
        tbdata: fromJS(data).toJS(),
        status: 'saved'
      })
    })
  }
 
  triggersave = (t) => {
    const { tbdata } = this.state
 
    let err = ''
    let tip = ''
    let list = []
 
    tbdata.forEach((line, index) => {
      if (err) return
      if (line.type === 'total') {
        if (line.debit !== line.credit) {
          err = '借贷不平衡!'
        }
        return
      }
 
      let _index = index + 1
 
      if (!line.subject_voucher_text && !line.subject_code && !line.debit && line.debit !== 0 && !line.credit && line.credit !== 0) {
        if (_index === 1) {
          err = '第1行不可为空。'
        }
 
        return
      }
 
      if (!line.subject_voucher_text) {
        err = `第${_index}行,摘要不可为空。`
      } else if (!line.subject_code) {
        err = `第${_index}行,科目不可为空。`
      } else if (!line.debit && line.debit !== 0 && !line.credit && line.credit !== 0) {
        err = `第${_index}行,请输入金额。`
      } else if (line.debit === 0 || line.credit === 0) {
        err = `第${_index}行,金额不能为0。`
      } else if (line.foreign_currency_type === 'Y' && !line.foreign_amount) {
        err = `第${_index}行,原币不可为空或为0。`
      } else if (line.sup_accounting && !line.supAccounts) {
        err = `第${_index}行,请选择辅助核算。`
      } else if (line.sup_accounting && line.supAccounts) {
        line.supAccounts.forEach(item => {
          if (item.sup_acc_type === 'supplier') {
            if (!item.suppliercode || !item.suppliername) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (item.sup_acc_type === 'customer') {
            if (!item.customercode || !item.customername) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (item.sup_acc_type === 'department') {
            if (!item.co_pro_code || !item.co_pro_name) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (item.sup_acc_type === 'project') {
            if (!item.projectcode || !item.projectname) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (item.sup_acc_type === 'inventory') {
            if (!item.productcode || !item.productname) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (item.sup_acc_type === 'employee') {
            if (!item.workercode || !item.workername) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (item.sup_acc_type === 'cash_flow') {
            if (!item.cash_flow_code || !item.cash_flow_name) {
              err = `第${_index}行,请选择辅助核算。`
            }
          } else if (!item.sup_acc_type || !item.sup_acc_code || !item.sup_acc_name) {
            err = `第${_index}行,请选择辅助核算。`
          }
        })
      }
 
      if (line.count_type === 'Y' && !err) {
        if (!line.fcc_count) {
          tip += `第${_index}行,数量为空或为0!;`
        } else if (line.net_unitprice) {
          if (line.debit && line.debit !== line.fcc_count * line.net_unitprice) {
            tip += `第${_index}行,数量和金额不匹配!;`
          } else if (line.credit && line.credit !== line.fcc_count * line.net_unitprice) {
            tip += `第${_index}行,数量和金额不匹配!;`
          }
        }
      }
 
      list.push(line)
    })
 
    if (!err && list.length === 0) {
      err = '第1行不可为空。'
    }
 
    if (err) {
      notification.warning({
        top: 92,
        message: err,
        duration: 5
      })
      return
    }
 
    if (tip) {
      const _this = this
      confirm({
        content: tip + '确认要保存吗?',
        onOk() {
          _this.voucherSave(list, t)
        },
        onCancel() {}
      })
    } else {
      this.voucherSave(list, t)
    }
  }
 
  voucherSave = (list, t) => {
    const { type, data, config, charInt, charType, vouDate, book, remark, charName, attachments, title, orgcode, orgname } = this.state
 
    let err = ''
    if (!book) {
      err = '请选择账套!'
    } else if (!vouDate) {
      err = '请选择日期!'
    } else if (!charName || !charInt) {
      err = '请选择凭证号!'
    }
 
    if (err) {
      notification.warning({
        top: 92,
        message: err,
        duration: 5
      })
      return
    }
 
    let param = {
      func: 's_fcc_voucher_addupt',
      BID: book.id,
      ID: Utils.getguid(),
      voucher_code: '',
      voucher_text: title,
      remark: remark,
      account_year_code: book.account_year_code || '',
      voucher_type: config.wrap.voucherType || '',
      voucher_type_text: config.wrap.voucherTypeText || '',
      orgcode: orgcode || '',
      orgname: orgname || '',
      voucher_class: charType,
      years: book.years,
      months: moment(vouDate).format('YYYY-MM'),
      business_type: config.wrap.businessType || '',
      voucher_sign: config.wrap.voucherSign || '',
      voucher_char: charName,
      voucher_char_int: charInt,
      account_code: book.account_code || '',
      fibvoucherdate: moment(vouDate).format('YYYY-MM-DD'),
      UserName: sessionStorage.getItem('User_Name') || '',
      FullName: sessionStorage.getItem('Full_Name') || '',
      attachments_int: attachments,
      sup_data: '',
      subject_data: '',
      attachments_data: ''
    }
 
    // id,deleted
    // 附件列表
 
    // subject_id,subject_voucher_code,voucher_lp,subject_code,subject_name,subject_voucher_text,fcc_count,net_unitprice,unit,net_amount,direction_type
    // ,exratecode,exratename,unitratio,sup_accounting ,direction_type_count,src_amount,deleted,local_exratecode
 
    // sup_id,sup_voucher_code,sup_voucher_lp,voucher_sup_lp,sup_subject_code,sup_subject_name,sup_voucher_text,sup_direction_type,sup_net_amount,customercode,customername,suppliercode,suppliername,co_pro_code,co_pro_name,workercode,workername,project_code,project_name,productcode,productname,cash_flow_code,cash_flow_name,sup_acc_code,sup_acc_name,sup_acc_type,sup_bid,deleted
    // 辅助科目行id,新增时空,凭证行号空,辅助科目行号空,科目编码,科目名称,辅助科目摘要空,方向'debit'、'credit',行金额,客户编码,客户名称,供应商编码,供应商名称,部门编码,部门名称,职员编码,职员名称,项目编码,项目名称,产品编码,产品名称,现金编码,现金名称,自定义科目编码,自定义科目名称,辅助科目类型,凭证行ID,删除标记
    
    let sup_data = []
    let voucherMap = new Map()
    let supMap = new Map()
    let extract = localStorage.getItem(window.GLOB.host + '_voucher_extract')
    extract = extract ? JSON.parse(extract) : []
 
    data.forEach(item => {
      voucherMap.set(item.uuid, item)
 
      if (item.sup_accounting && item.supAccounts) {
        item.supAccounts.forEach(cell => {
          if (!cell.sup_acc_type) return
 
          let _cell = {...cell}
 
          _cell.sup_voucher_code = item.subject_voucher_code || ''
          _cell.sup_voucher_lp = item.voucher_lp || ''
          _cell.sup_subject_code = item.subject_code || ''
          _cell.sup_subject_name = item.subject_name || ''
          _cell.sup_bid = item.uuid || ''
          _cell.sup_direct = item.debit ? 'debit' : 'credit'
          _cell.sup_net_amount = item.debit || item.credit
 
          supMap.set(item.uuid + cell.sup_acc_type, _cell)
        })
      }
    })
    
    let subject_data = list.map(item => {
      let count = item.count_type === 'Y'
      let curr = item.foreign_currency_type === 'Y'
      let direct = item.debit ? 'debit' : 'credit'
      
      if (type === 'createVoucher' && item.subject_voucher_text && item.subject_voucher_text.length < 20) {
        extract.unshift(item.subject_voucher_text)
      }
 
      if (voucherMap.has(item.uuid)) {
        voucherMap.delete(item.uuid)
      }
      if (item.sup_accounting && item.supAccounts) {
        item.supAccounts.forEach(n => {
          if (supMap.has(item.uuid + n.sup_acc_type)) {
            supMap.delete(item.uuid + n.sup_acc_type)
          }
 
          sup_data.push(`'${n.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${n.voucher_sup_lp || ''}','${item.subject_code}','${item.subject_name}','${n.sup_voucher_text || ''}','${direct}',${item.debit || item.credit},'${n.customercode || ''}','${n.customername || ''}','${n.suppliercode || ''}','${n.suppliername || ''}','${n.co_pro_code || ''}','${n.co_pro_name || ''}','${n.workercode || ''}','${n.workername || ''}','${n.project_code || ''}','${n.project_name || ''}','${n.productcode || ''}','${n.productname || ''}','${n.cash_flow_code || ''}','${n.cash_flow_name || ''}','${n.sup_acc_code || ''}','${n.sup_acc_name || ''}','${n.sup_acc_type || ''}','${item.uuid}',0`)
        })
      }
      return `'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debit ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},0,'${item.local_currency || ''}','${count ? 'Y' : ''}','${curr ? 'Y' : ''}'`
    })
 
    if (type === 'createVoucher') {
      extract = Array.from(new Set(extract))
      if (extract.length > 20) {
        extract.length = 20
      }
      localStorage.setItem(window.GLOB.host + '_voucher_extract', JSON.stringify(extract))
    }
 
    voucherMap.forEach(item => {
      let count = item.count_type === 'Y'
      let curr = item.foreign_currency_type === 'Y'
      let direct = item.debit ? 'debit' : 'credit'
 
      subject_data.push(`'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debit ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},1,'${item.local_currency || ''}','${count ? 'Y' : ''}','${curr ? 'Y' : ''}'`)
    })
 
    supMap.forEach(n => {
      sup_data.push(`'${n.uuid}','${n.sup_voucher_code}','${n.sup_voucher_lp}','${n.voucher_sup_lp || ''}','${n.sup_subject_code}','${n.sup_subject_name}','${n.sup_voucher_text || ''}','${n.sup_direct}',${n.sup_net_amount},'${n.customercode || ''}','${n.customername || ''}','${n.suppliercode || ''}','${n.suppliername || ''}','${n.co_pro_code || ''}','${n.co_pro_name || ''}','${n.workercode || ''}','${n.workername || ''}','${n.project_code || ''}','${n.project_name || ''}','${n.productcode || ''}','${n.productname || ''}','${n.cash_flow_code || ''}','${n.cash_flow_name || ''}','${n.sup_acc_code || ''}','${n.sup_acc_name || ''}','${n.sup_acc_type || ''}','${n.sup_bid}',1`)
    })
 
    param.subject_data = window.btoa(window.encodeURIComponent(subject_data.join(';un')))
    param.sup_data = window.btoa(window.encodeURIComponent(sup_data.join(';un')))
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
 
      notification.success({
        top: 92,
        message: '保存成功!' + (res.voucher_char_int !== charInt ? charInt + '号凭证号已经存在,已为您更新为' + res.voucher_char_int + '号凭证。'  : ''),
        duration: 5
      })
 
      if (t === 'add') {
        this.setState({
          status: 'empty',
          remark: '',
          tbdata: [],
          charInt: res.voucher_char_int + 1,
          BID: Utils.getguid(),
          saved: false
        })
        MKEmitter.emit('cleartable', config.uuid)
      } else {
        this.setState({
          status: 'saved',
          charInt: res.voucher_char_int || charInt,
          data: fromJS(list).toJS(),
          saved: true
        })
      }
    })
  }
 
  triggerprint = () => {
    this.setState({remarkVisible: true})
  }
 
  remarkSubmit = () => {
    const { config } = this.state
    let node = document.getElementById(config.uuid + 'remark')
    let val = node.value
 
    if (val && val.length > 512) {
      notification.warning({
        top: 92,
        message: '当前内容超长,备注最多512个字符。',
        duration: 5
      })
      return
    }
    this.setState({remark: val, remarkVisible: false})
  }
 
  dataChange = (data) => {
    this.setState({
      status: 'change',
      tbdata: data
    })
  }
 
  changeAttach = (val) => {
    let _val = val
 
    if (isNaN(val) || val < 0) {
      _val = 0
    } else {
      _val = parseInt(val)
    }
    
    this.setState({attachments: _val})
  }
 
  changeVouDate = (val) => {
    const { type, status, saved } = this.state
    this.setState({vouDate: val})
 
    if (type === 'createVoucher' && val && !saved && (status === 'empty' || status === 'change')) {
      this.updateVoucherChar(val)
    }
  }
 
  updateVoucherChar = (val) => {
    const {book} = this.state
 
    if (!book) return
 
    let param = {
      func: 's_get_fcc_account_data',
      search_type: 'Y',
      fcc_date: book.months ? book.months + '-01' : moment().format('YYYY-MM-DD'),
      account_year_code: book.account_year_code || '',
      months: moment(val).format('YYYY-MM'),
      BID: book.id
    }
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
 
      // let typeOptions = res.char || []
      // let charInt = typeOptions[0] ? typeOptions[0].voucher_char_int + 1 : 1
 
      // this.setState({
      //   typeOptions: typeOptions,
      //   charType: typeOptions[0] ? typeOptions[0].voucher_class : '',
      //   charName: typeOptions[0] ? typeOptions[0].voucher_char : '',
      //   charInt: charInt,
      //   orgcode: res.orgcode,
      //   orgname: res.orgname,
      // })
    })
  }
 
  triggermore = () => {
 
  }
 
  triggerclose = () => {
 
  }
 
  triggerAttach = () => {
 
  }
 
  render() {
    const { type, status, loading, config, typeOptions, charType, charInt, data, vouDate, username, remark, remarkVisible, attachments, title } = this.state
 
    return (
      <div className="menu-voucher-wrap" style={config.style}>
        {type === 'createVoucher' ? <div className="voucher-header">
          <Button className="add-background header-btn" disabled={status === 'empty'} onClick={() => this.triggersave('add')}>保存并新增</Button>
          <Button className="add-background header-btn" disabled={status === 'empty' || status === 'saved'} onClick={() => this.triggersave()}>保存</Button>
          <Button className="print-background header-btn" disabled={status !== 'saved'} onClick={this.triggerprint}>打印</Button>
          <Button className="out-background header-btn" onClick={this.triggermore}>更多</Button>
        </div> : null}
        {type === 'checkVoucher' ? <div className="voucher-header">
          <Button className="add-background header-btn" disabled={status === 'empty' || status === 'saved'} onClick={() => this.triggersave()}>保存</Button>
          <Button className="print-background header-btn" disabled={status !== 'saved'} onClick={this.triggerprint}>打印</Button>
          <Button className="out-background header-btn" onClick={this.triggerclose}>关闭</Button>
        </div> : null}
        <div className="voucher-body">
          {type === 'createVoucher' || type === 'checkVoucher' ? <div className="pre-wrap">
            <div className="voucher-code">
              <Select value={charType} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({charType: val, charName: option.props.charName, charInt: option.props.charint})}>
                {typeOptions.map(option =>
                  <Select.Option key={option.voucher_char_int} value={option.voucher_class} charName={option.voucher_char} charint={option.voucher_char_int}>{option.voucher_char}</Select.Option>
                )}
              </Select>
              <InputNumber precision={0} min={1} value={charInt} autoComplete="off" onChange={(val) => this.setState({charInt: val})}/> 号
            </div>
            <div className="voucher-date">
              日期:<DatePicker value={vouDate} onChange={this.changeVouDate}/>
            </div>
            <div className="voucher-text">
              <Input value={title} placeholder="凭证文本" autoComplete="off" onChange={(e) => this.setState({title: e.target.value})}/>
            </div>
            <div className="voucher-affix">
              附单据 <InputNumber precision={0} value={attachments || 0} autoComplete="off" onChange={this.changeAttach}/> 张
              <Button type="link" className="" onClick={this.triggerAttach}>附件</Button>
              <Button type="link" className="" onClick={this.triggerprint}>备注</Button>
            </div>
          </div> : null}
          <VoucherTable config={config} loading={loading} data={data} onChange={this.dataChange}/>
        </div>
        <div className="user">制单人:{username}</div>
        <Modal
          title="备注"
          visible={remarkVisible}
          width={700}
          maskClosable={false}
          onOk={this.remarkSubmit}
          onCancel={() => { this.setState({ remarkVisible: false })}}
          destroyOnClose
        >
          <TextArea id={config.uuid + 'remark'} defaultValue={remark} rows={6}/>
        </Modal>
      </div>
    )
  }
}
 
export default VoucherModule