UNPKG

ttk-app-core

Version:
732 lines (671 loc) 28.6 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import config from './config' import { Select, Modal, Icon, Form, Button} from 'edf-component' import { fromJS } from 'immutable' import { consts } from 'edf-consts' const FormItem = Form.Item class action { constructor(option) { this.metaAction = option.metaAction this.config = config.current this.webapi = this.config.webapi } onInit = ({ component, injections }) => { this.component = component this.injections = injections let addEventListener = this.component.props.addEventListener if (addEventListener) { addEventListener('onTabFocus', :: this.onTabFocus) addEventListener('enlargeClick', :: this.enlargeClick) } injections.reduce('init') this.initLoad() } componentDidMount = () => { if (window.addEventListener) { window.addEventListener('resize', this.getTableScroll) } else if (window.attachEvent) { window.attachEvent('onresize', this.getTableScroll) } } componetWillUnmount = () => { if (window.removeEventListener) { window.removeEventListener('resize', this.getTableScroll) } else if (window.detachEvent) { win.detachEvent('onresize', this.getTableScroll) } } enlargeClick = () => { setTimeout(()=>{ this.getTableScroll() }, 100) } onTabFocus = async () => { const entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() this.load({entity, page}) } initLoad = async() => { const entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() this.load({entity, page}) } load = async (parmas) => { this.injections.reduce('loading', 'data.loading', true) const res = await this.webapi.unauthorized.uncertifiedList(parmas) if (res) { res.loading = false this.injections.reduce('initLoad', res) } else { this.injections.reduce('loading', 'data.loading', false) } setTimeout(()=>{ this.getTableScroll() }, 100) } getTableScroll = () => { try { let tableOption = this.metaAction.gf('data.tableOption').toJS() let dom = document.getElementsByClassName('ttk-scm-app-unauthorized-list-table')[0] let tableDom if (!dom) { return } tableDom = dom.getElementsByClassName('ant-table-tbody')[0]; tableDom.scrollTop = 0; tableDom.scrollLeft = 0; if (tableDom && dom) { let num = dom.offsetHeight - tableDom.offsetHeight if (num < 74) { const width = dom.offsetWidth const height = dom.offsetHeight tableOption = { ...tableOption, y: height - 74 } this.injections.reduce('update', {path: 'data.tableOption', value: tableOption}) } else { // 当数量太少 不用出现滚动条 delete tableOption.y this.injections.reduce('update', {path: 'data.tableOption', value: tableOption}) } } } catch (err) { // console.log(err) } } rowSelection = (text, row, index) => { return undefined } // 金额 税额 renderTextRight = (name, rowData, path, index) => { return <div style={{ textAlign: 'right' }} key={index}>{this.addThousandsPosition(rowData[name], true)}</div> } // 千分位格式化 addThousandsPosition = (input, isFixed) => { if (isNaN(input)) return null let num if (isFixed) { num = parseFloat(input).toFixed(2) } else { num = input.toString() } let regex = /(\d{1,3})(?=(\d{3})+(?:\.))/g return num.replace(regex, "$1,") } // 操作 renderOption = (record, index) => { return( <div className='option'> <Icon fontFamily='edficon' type='dikou' className='dikou' title='抵扣' onClick={this.handleIsDeductible.bind(null, true, record, 'oneRow')}></Icon> <Icon fontFamily='edficon' type='buyudikoutubiao' title='不予抵扣' className='buyudikoutubiao' onClick={this.handleIsDeductible.bind(null, false, record, 'oneRow')}></Icon> <Icon fontFamily='edficon' type='chexiaorenzheng' className='chexiaorenzheng' title='撤销认证' onClick={this.reauthentication.bind(null, record, 'oneRow')}></Icon> </div> ) } // 凭证字号 renderCode = (record, index) => { if (record.uncertDocId) { return <a href="javascript:;" onClick={() => this.openDocContent(record.uncertDocId)}>{`${record.docType}-${record.docCode}`}</a> } else { return '' } } openDocContent = (id) => { this.component.props.setPortalContent && this.component.props.setPortalContent( '填制凭证', 'app-proof-of-charge', { accessType: 1, initData: { id } } ) } // 系统认证期间 renderMoreStatus = (name, value, index) => { if (value[name]) { return value[name] } else { return '未认证' } } //税局认证状态 renderAuthenticated = (name, value, index) => { if (value[name]) { switch(name) { case 'authenticated': return '已认证' case 'sysDeductible': return '已抵扣' } } else { if (value[name] == false) { switch(name) { case 'authenticated': return '未认证' case 'sysDeductible': return '不予抵扣' } } else { switch(name) { case 'authenticated': return '' case 'sysDeductible': return '未抵扣' } } } } // 认证状态 handleChangeAuth = (key) => { let entity = {}, page = { currentPage: 1, pageSize: 20 } if (key) { this.load({entity, page}) } else { entity.uncertFlag = true this.load({entity, page}) } const auth = this.metaAction.gf('data.other.authentication') this.metaAction.sf('data.other.authentication', !auth) } // 抵扣 不予抵扣 handleIsDeductible = async (isDeductible, rowData, type) => { const tableCheckbox = this.metaAction.gf('data.tableCheckbox').toJS() let selectedOption = tableCheckbox.selectedOption const currentOrg = this.metaAction.context.get("currentOrg") let periodDate = currentOrg.periodDate if (type == 'oneRow') { const parmas = {} parmas.sysDeductible = isDeductible ? true : false parmas.id = rowData.id parmas.ts = rowData.ts parmas.sysAuthenticate = periodDate ? periodDate : null if (rowData.uncertDocId) { if (isDeductible && rowData.sysDeductible) { this.metaAction.toast('error', '当前没有可抵扣的数据') return } else if(isDeductible === false && rowData.sysDeductible === false){ this.metaAction.toast('error', '当前没有不予抵扣的数据') return } } const res = await this.webapi.unauthorized.certified([parmas]) if (res) { if (res.success.length != 0) { const entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() this.injections.reduce('loading', 'data.loading', true) const result = await this.webapi.unauthorized.uncertifiedList({entity, page}) if (result) { result.loading = false this.injections.reduce('initLoad', result) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) this.metaAction.toast('success', isDeductible ? '抵扣成功' : '不予抵扣成功') } } // else { if (res.fail.length != 0) { this.metaAction.toast('error', res.fail[0].message) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } // } } } else { if (tableCheckbox.checkboxValue.length == 0 || tableCheckbox.selectedOption.length == 0) { if(isDeductible) { this.metaAction.toast('error', '请选择要抵扣的数据') } else { this.metaAction.toast('error', '请选择要不予抵扣的数据') } } else { let list = [] let deductible = isDeductible ? true : false let flag = null selectedOption.forEach((item) => { if (item.sysDeductible != deductible) { flag = true } let obj = {sysDeductible: deductible} obj.id = item.id obj.ts = item.ts obj.sysAuthenticate = periodDate ? periodDate : null list.push(obj) }) if (!flag) { if (deductible) { this.metaAction.toast('error', '当前没有可抵扣的数据') return } else if(isDeductible === false && rowData.sysDeductible === false){ this.metaAction.toast('error', '当前没有不予抵扣的数据') return } } const res = await this.webapi.unauthorized.certified(list) if (res) { if (res.success.length != 0) { const entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() this.injections.reduce('loading', 'data.loading', true) const result = await this.webapi.unauthorized.uncertifiedList({entity, page}) if (result) { result.loading = false this.injections.reduce('initLoad', result) this.metaAction.toast('success', isDeductible ? '抵扣成功' : '不予抵扣成功') this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } } // else { if(res.fail.length != 0) { this.showError(isDeductible? '抵扣结果' : '不予抵扣结果', res.success, res.fail) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } // } } } } } // 撤销认证 reauthentication = async (rowData, type) => { if (type == 'oneRow') { const parmas = { id: rowData.id, ts: rowData.ts } const res = await this.webapi.unauthorized.removeCertified([parmas]) if (res) { if (res.success.length != 0) { const entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() this.injections.reduce('loading', 'data.loading', true) const result = await this.webapi.unauthorized.uncertifiedList({entity, page}) if (result) { result.loading = false this.injections.reduce('initLoad', result) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) this.metaAction.toast('success', '撤销认证成功') } } // else { if (res.fail.length != 0) { this.metaAction.toast('error', res.fail[0].message) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } // } } } else { const tableCheckbox = this.metaAction.gf('data.tableCheckbox').toJS() const selectedOption = tableCheckbox.selectedOption if (tableCheckbox.checkboxValue.length == 0 || tableCheckbox.selectedOption.length == 0) { this.metaAction.toast('error', '请选择要撤销认证的数据') } else { let list = [] selectedOption.forEach((item) => { list.push({ id: item.id, ts: item.ts }) }) const res = await this.webapi.unauthorized.removeCertified(list) if (res) { if (res.success.length != 0) { const entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() this.injections.reduce('loading', 'data.loading', true) const result = await this.webapi.unauthorized.uncertifiedList({entity, page}) if (result) { result.loading = false this.injections.reduce('initLoad', result) this.metaAction.toast('success', '撤销认证成功') this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } } // else { if(res.fail.length != 0) { this.showError('撤销认证结果', res.success, res.fail) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } // } } } } } showError = (title, successArr, failArr) => { const ret = this.metaAction.modal('show', { title, width: 585, // footer: null, bodyStyle: { padding: '2px 0 10px 24px' }, children: this.metaAction.loadApp('ttk-scm-app-error-list', { store: this.component.props.store, successArr, failArr }), }) } // 发票号码搜索 handleInputSearch = (value) => { // const page = this.metaAction.gf('data.page').toJS() const page = {pageSize: 20, currentPage: 1} const entity = value ? {invoiceNumber : value} : {} this.load({entity, page}) } // 高级搜索 entityChange = (value) => { // const page = this.metaAction.gf('data.page').toJS() const page = {pageSize: 20, currentPage: 1} let entity = { ...value, sysAuthenticate: this.metaAction.momentToString(value.sysAuthenticate, 'YYYY-MM-DD'), } for (let key in entity) { if (entity[key] === '') { delete entity[key] } } this.load({entity, page}) this.metaAction.sf('data.searchValue', fromJS(value)) } // 刷新 refreshBtnClick = () => { // this.initLoad() let entity = this.metaAction.gf('data.searchValue').toJS() const page = this.metaAction.gf('data.page').toJS() for (let key in entity) { if (entity[key] === '') { delete entity[key] } } this.load({entity, page}) } // 更多 moreActionOpeate = (e) => { // console.log(e.key, 'e.key') if (e.key == 'reauthentication') { this.reauthentication && this.reauthentication() } else if (e.key == 'subjectSet') { this.subjectSet && this.subjectSet() } } //生成新的科目编码 generateNewSubCode = (parentId, parentCode, subjectList) => { let newCode, newSubjectList = subjectList.filter(subItem => { return parseInt(subItem.parentId) == parseInt(parentId) }) if (newSubjectList.length == 0) { newCode = '01' } else { let endGradeList = [] for (var i = 0; i < newSubjectList.length; i++) { let code = newSubjectList[i].code endGradeList.push(code.substring(code.length - 2)) } // endGradeList = endGradeList.sort(sortNumber) endGradeList = endGradeList.sort((a, b) => a-b) let maxCode = endGradeList[endGradeList.length - 1] if (maxCode == '99' && endGradeList.length < 98) { maxCode = endGradeList[endGradeList.length - 2] if (!isNaN(maxCode)) { newCode = '00' + (parseInt(maxCode) + 1).toString() newCode = newCode.substring(newCode.length - 2) } else { newCode = '00' } } else if (maxCode != '99' && !isNaN(maxCode)) { newCode = '00' + (parseInt(maxCode) + 1).toString() newCode = newCode.substring(newCode.length - 2) } else { newCode = '00' } } return newCode } // 新增科目 addSubjects = async (type) => { let data = this.metaAction.gf('data.nodeSubject').toJS() const list = this.metaAction.gf('data.queryList').toJS() const {id, code} = data const ret = await this.metaAction.modal('show', { title: '科目', width: 400, okText: '保存', style: { top: 40 }, bodyStyle: { padding: 24, fontSize: 12 }, children: this.metaAction.loadApp('app-proof-of-charge-subjects-add', { store: this.component.props.store, active: 'add', newCode: this.generateNewSubCode(id, code, list), // newCode: this.generateNewSubCode(99038, '2221', list), data: data, }) }) if (ret) { let certifiedList = this.metaAction.gf('data.certifiedList').toJS() if (type == 'taxs') { certifiedList[0].accountCode = ret.code } else if (type == 'taxTurnover') { certifiedList[1].accountCode = ret.code } this.injections.reduce('loading', 'data.certifiedList', fromJS(certifiedList)) return ret } } // 科目设置 subjectSet = async () => { const requestList = [ // this.webapi.unauthorized.query({"isEndNode": true,"isEnable": true }), this.webapi.unauthorized.query({}), this.webapi.unauthorized.queryCertified(), ] const resList = await Promise.all(requestList) let list = [] let nodeSubject = null if (resList) { const result = resList[0] && resList[0] let reg = new RegExp("^2221") if (result) { let glAccounts = result.glAccounts list = glAccounts.filter(obj => reg.test(obj.code)) nodeSubject = list[0] list = list.filter(item => item.isEndNode && item.isEnable) } this.metaAction.sfs({ 'data.certifiedList': fromJS(resList[1]), 'data.queryList': fromJS(list), 'data.nodeSubject': fromJS(nodeSubject) }) } const certifiedList = resList[1] const ret = await this.metaAction.modal('show', { title: '自定义科目', width: 450, bodyStyle: { padding: 6, fontSize: 12 }, wrapClassName:'subjectSetClass', children: <TipContnet defaultValueTaxs={certifiedList[0] && certifiedList[0].accountCode ? certifiedList[0].accountCode : ''} defaultValueTurnTax={certifiedList[1] && certifiedList[1].accountCode ? certifiedList[1].accountCode : ''} onChange={this.handleOnChange} addSubjects={this.addSubjects} list={list}></TipContnet> }) if (ret) { let certifiedList = this.metaAction.gf('data.certifiedList').toJS() certifiedList.forEach(item => { delete item.accountName }) const response = await this.webapi.unauthorized.saveCertified(certifiedList) if (response) { this.metaAction.toast('success', '设置成功') } } } handleOnChange = (value, type) => { let certifiedList = this.metaAction.gf('data.certifiedList').toJS() if (type == 'taxs') { certifiedList[0].accountCode = value } else if (type == 'taxTurnover') { certifiedList[1].accountCode = value } this.injections.reduce('loading', 'data.certifiedList', fromJS(certifiedList)) return certifiedList } // 触发高级搜索 searchValueChange = (value) => { // console.log(value, '触发高级搜索'); this.injections.reduce('update', {path: 'data.searchValue', value: value}) } // 分页 pageChanged = (current, size) => { let page = this.metaAction.gf('data.page').toJS() const length = this.metaAction.gf('data.list').toJS() const entity = this.metaAction.gf('data.searchValue').toJS() if (size) { page = { ...page, 'currentPage': length ? current : 1, 'pageSize' : size } } else { page = { ...page, 'currentPage': length ? current : 1 } } this.load({entity, page}) this.injections.reduce('update', {path: 'data.tableCheckbox', value: {checkboxValue: [],selectedOption: []}}) } // 勾选 checkboxChange = (arr, itemArr) => { this.injections.reduce('update', { path: 'data.tableCheckbox', value: { checkboxValue: arr, selectedOption: itemArr } }) } } class TipContnet extends React.Component { constructor(props) { super(props) this.state = { list: props.list, defaultValueTaxs: props.defaultValueTaxs, defaultValueTurnTax: props.defaultValueTurnTax, } } handleClick = async (type) => { const {addSubjects} = this.props const res = await addSubjects(type) if (res) { let {list, defaultValueTaxs, defaultValueTurnTax} = this.state list.push(res) if (type == 'taxs') { defaultValueTaxs = res.code } else if (type == 'taxTurnover') { defaultValueTurnTax = res.code } this.setState({ list: list, defaultValueTaxs: defaultValueTaxs, defaultValueTurnTax: defaultValueTurnTax }) } } handleChange = (value, type) => { const result = this.props.onChange(value, type) let {defaultValueTaxs, defaultValueTurnTax} = this.state if (type == 'taxs') { defaultValueTaxs = result[0].accountCode this.setState({ defaultValueTaxs: defaultValueTaxs }) } else if (type == 'taxTurnover') { defaultValueTurnTax = result[1].accountCode this.setState({ defaultValueTurnTax: defaultValueTurnTax }) } } render(){ const {onChange, addSubjects} = this.props const {defaultValueTaxs, defaultValueTurnTax, list} = this.state return <div style={{ textAlign: 'center' }}> <Form> <FormItem label='未认证进项税额'> <Select value={defaultValueTaxs} // onChange={(e) => onChange(e, 'taxs')} onChange={(e) => this.handleChange(e, 'taxs')} dropdownFooter={ <Button type='primary' onClick={() => this.handleClick('taxs')} // onClick={() => addSubjects('taxs')} style={{ width: '100%', borderRadius: '0' }}>新增 </Button>}> { list.map((item, index) => { return <Option key={item.code} title={item.codeAndName}>{item.codeAndName}</Option> }) } </Select> </FormItem> <span className='decritionSpan'>注:系统预制 应交税费-待认证进项税额</span> <FormItem label='进项税额转出'> <Select value={defaultValueTurnTax} // onChange={(e) => onChange(e, 'taxTurnover')} onChange={(e) => this.handleChange(e, 'taxTurnover')} dropdownFooter={ <Button type='primary' // onClick={() => addSubjects('taxTurnover')} onClick={() => this.handleClick('taxTurnover')} style={{ width: '100%', borderRadius: '0' }}>新增 </Button>}> { list.map((item, index) => { return <Option key={item.code} title={item.codeAndName}>{item.codeAndName}</Option> }) } </Select> </FormItem> <span className='decritionSpan'>注:系统预制 应交税费-应交增值税-进项税额转出</span> </Form> </div> } } export default function creator(option) { const metaAction = new MetaAction(option), o = new action({ ...option, metaAction }), ret = { ...metaAction, ...o } metaAction.config({ metaHandlers: ret }) return ret }