king
2023-01-30 e469a34f26637e177854b960bbd35c900ce0daff
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, Select, Input, DatePicker, notification } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const VoucherTable = asyncComponent(() => import('./voucherTable'))
 
class VoucherModule extends Component {
  static propTpyes = {
    config: PropTypes.object,        // 组件配置信息
  }
 
  state = {
    BID: '',
    config: null,
    loading: false,
    data: [],
    disableAdd: false,
    disableSave: false,
    typeOptions: [],
    charType: '',
    charInt: '',
    vouDate: null,
    book: null,
    username: sessionStorage.getItem('User_Name'),
    change: 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 || ''
    }
 
    window.GLOB.CacheVoucher.delete(config.uuid)
 
    this.setState({
      config: fromJS(config).toJS(),
      BID: BID || '',
      book: window.GLOB.CacheData.get(config.wrap.supBook) || null
    }, () => {
      this.loadData()
    })
  }
 
  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 } = 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()
      })
      return
    }
 
    if (!config.wrap.supModule || config.wrap.supModule !== MenuID) return
    if (id !== this.state.BID || id !== '') {
      this.setState({ BID: id, BData: data }, () => {
        this.loadData()
      })
    }
  }
 
  loadData = () => {
    const { book, config } = 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')
    }
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
 
      let typeOptions = res.char || []
 
      this.setState({
        typeOptions: typeOptions,
        charType: typeOptions[0] ? typeOptions[0].voucher_class : '',
        charInt: typeOptions[0] ? typeOptions[0].voucher_char_int : '',
      })
 
      let names = {}
      let supplier = []
      let customer = []
      let department = []
      let project = []
      let inventory = []
      let employee = []
      let cash_flow = []
 
      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})
      })
 
      let message = {
        subjects: res.subjects || [],
        names: names,
        supplier: supplier,
        customer: customer,
        department: department,
        project: project,
        inventory: inventory,
        employee: employee,
        cash_flow: cash_flow,
      }
 
      window.GLOB.CacheVoucher.set(config.uuid, message)
 
      setTimeout(() => {
        this.getVoucher()
      }, 200)
    })
  }
 
 
  getVoucher = () => {
    let data = [
      {remark: '提现', subjectscode: '1001', subjectsname: '库存现金', debtor: 124, creditor: ''},
      {remark: '购入固定资产', subjectscode: '1001', subjectsname: '库存现金', debtor: '', creditor: 124},
      {remark: '转结销售成本', subjectscode: '1001', subjectsname: '库存现金', debtor: -524, creditor: ''},
      {remark: '提现', subjectscode: '1001', subjectsname: '库存现金', debtor: 34, creditor: '', i: Math.random()},
    ]
 
    this.setState({
      data: data
    })
  }
 
  triggeradd = () => {
    
  }
 
  triggersave = () => {
 
  }
 
  triggerprint = () => {
 
  }
 
  render() {
    const { config, disableSave, disableAdd, typeOptions, charType, charInt, data, vouDate, username } = this.state
 
    return (
      <div className="menu-voucher-wrap" style={config.style}>
        <div className="voucher-header">
          <Button className="add-background header-btn" disabled={disableAdd} onClick={this.triggeradd}>新增</Button>
          <Button className="add-background header-btn" disabled={disableSave} onClick={this.triggersave}>保存</Button>
          <Button className="print-background header-btn" disabled={disableSave} onClick={this.triggerprint}>打印</Button>
          <Button className="system-background header-btn" disabled={disableSave} onClick={this.triggerprint}>导入</Button>
          <Button className="out-background header-btn" disabled={disableSave} onClick={this.triggerprint}>导出</Button>
        </div>
        {config.wrap.type === 'edit' ? <div className="voucher-body">
          <div className="pre-wrap">
            <div className="voucher-code">
              <Select value={charType} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({charType: val, charInt: option.props.charint})}>
                {typeOptions.map(option =>
                  <Select.Option key={option.voucher_char_int} value={option.voucher_class} charint={option.voucher_char_int}>{option.voucher_char}</Select.Option>
                )}
              </Select>
              <Input value={charInt} autoComplete="off" onChange={(e) => this.setState({charInt: e.target.value})}/> 号
            </div>
            <div className="voucher-date">
              日期:<DatePicker value={vouDate} onChange={(val) => this.setState({vouDate: val})}/>
            </div>
            <div className="voucher-affix">
              附单据 <Input autoComplete="off" /> 张
              <Button type="link" className="" onClick={this.triggerprint}>附件</Button>
              <Button type="link" className="" onClick={this.triggerprint}>备注</Button>
            </div>
          </div>
          <VoucherTable config={config} data={data}/>
        </div> : null}
        {config.wrap.type === 'check' ? <div className="voucher-body">
          <div className="pre-wrap">
            <div className="voucher-code">
              记 1 号
            </div>
            <div className="voucher-date">
              日期:2022-02-24
            </div>
            <div className="voucher-affix">
              附单据 2 张
              <Button type="link" className="" onClick={this.triggerprint}>附件</Button>
              <Button type="link" className="" onClick={this.triggerprint}>备注</Button>
            </div>
          </div>
          <VoucherTable config={config} data={data}/>
        </div> : null}
        <div className="user">制单人:{username}</div>
      </div>
    )
  }
}
 
export default VoucherModule