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: [],
|
subjects: [],
|
charType: '',
|
charInt: '',
|
vouDate: null,
|
book: null
|
}
|
|
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 || ''
|
}
|
|
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 } = 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 : '',
|
subjects: res.subjects || [],
|
})
|
|
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: ''},
|
]
|
|
this.setState({
|
data: data
|
})
|
}
|
|
triggeradd = () => {
|
|
}
|
|
triggersave = () => {
|
|
}
|
|
triggerprint = () => {
|
|
}
|
|
render() {
|
const { config, disableSave, disableAdd, typeOptions, charType, charInt, data, vouDate, subjects } = 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} subjects={subjects} 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>
|
)
|
}
|
}
|
|
export default VoucherModule
|