UNPKG

ttk-app-core

Version:
285 lines (260 loc) 11.1 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { List, fromJS } from 'immutable' import moment from 'moment' import config from './config' import { consts } from 'edf-consts' import { LoadingMask ,Icon, FormDecorator} from 'edf-component' import { fetch } from 'edf-utils' import noFile from './images/noFile.png' class action { constructor(option) { this.metaAction = option.metaAction this.voucherAction = option.voucherAction this.config = config.current this.webapi = this.config.webapi this.beforeLoad = option.voucherAction.excelbeforeUpload } onInit = ({ component, injections }) => { this.voucherAction.onInit({ component, injections }) this.component = component this.injections = injections injections.reduce('init', { isPop: this.component.props.isPop }) this.load() } load = async (option) => { LoadingMask.show() let queryData = await this.webapi.financeinit.query() const enumIdList = { enumIdList: ['200001', '200002'] } let res = await this.webapi.financeinit.enum(enumIdList), getModifyStatus = await this.webapi.financeinit.getModifyStatus() let queryExcelCheckedInfo = await this.webapi.financeinit.queryExcelCheckedInfo() queryData.vatTaxpayerEnum = res['200001'] queryData.accountingStandardsEnum = res['200002'] queryData.modifyStatus = getModifyStatus queryData.queryExcelCheckedInfo = queryExcelCheckedInfo this.injections.reduce('load', queryData) LoadingMask.hide() } //月份渲染 monthCellCustom = (date) => { let currentOrg = this.metaAction.context.get("currentOrg"), enableTime = currentOrg.enabledYear + '-' + currentOrg.enabledMonth, maxClosingPeriod = currentOrg.maxClosingPeriod return <DateCellCustom enableTime={enableTime} maxClosingPeriod={maxClosingPeriod} nowTime={date.format('YYYY-MM')}></DateCellCustom> } setField = async (path, value) => { if (path == 'data.form.templateType') { this.metaAction.sf('data.other.disabled', false) } this.metaAction.sf(path, value) } fiSoftChange = (path, value) => { this.injections.reduce('fiSoftChange', path, value) } edit = async () => { let getModifyStatus = await this.webapi.financeinit.getModifyStatus() // this.metaAction.sf('data.other.modifyStatus', getModifyStatus.modifyStatus) // this.metaAction.sf('data.other.isEdit', true) this.metaAction.sfs({ 'data.other.isEdit': true, 'data.other.modifyStatus': getModifyStatus }) } editSave = async () => { let enabledYear = this.metaAction.gf('data.form.periodDate').split('-')[0], enabledMonth = this.metaAction.gf('data.form.periodDate').split('-')[1], accountingStandards = this.metaAction.gf('data.form.accountingStandards'), vatTaxpayer = this.metaAction.gf('data.form.vatTaxpayer'), ts = this.metaAction.gf('data.form.ts'), params = { enabledYear,enabledMonth,accountingStandards,vatTaxpayer,ts } let res = await this.webapi.financeinit.updatePeriodAndProperty(params) if(!res.error){ this.metaAction.toast('success', '修改成功') this.metaAction.sf('data.other.isEdit', false) this.injections.reduce('load', res) } else if(res.error){ this.metaAction.sf('data.other.isEdit', false) this.metaAction.toast('error', res.error.message) // return false } } getAccessToken = () => { let token = fetch.getAccessToken() return { token } } handwork = async () => { //手工录入 this.nextStep('manualEentry') } getNoDataPic = () => { return noFile } getCheckedResultContent = (checkType, checkedValue) => { if (this.metaAction.gf('data.other.checkedResult') == undefined) return '' let content switch (checkType) { case 'checkTaxpayer': if (checkedValue == 0) { content = '纳税人身份:未识别' } else if (checkedValue == 1) { content = '纳税人身份:一般纳税人' } else if (checkedValue == 2) { content = '纳税人身份:小规模纳税人' } break; case 'excelType': content = '模板类型:' + checkedValue break; case 'accountStandard': if (checkedValue == -1) { content = '会计准则:未识别' } else if (checkedValue == '2000020002') { content = '会计准则:小企业会计准则' } else if (checkedValue == '2000020001') { content = '会计准则:企业会计准则' } break; case 'checkExistDataInExcel': content = '有无数据:' + checkedValue break; case 'checkSameCodeOrName': if (checkedValue && checkedValue.length > 0) { content = '科目是否重复:重复' } else { content = '科目是否重复:正常' } break; case 'checkDataFormat': if (checkedValue && checkedValue.length > 0) { content = '数据格式检查:不匹配' } else { content = '数据格式检查:正常' } break; default: } return content } // 导入模板 leadInTemplate = async () => { const data = await this.webapi.financeinit.downloadTemplate() this.metaAction.toast('success', '下载成功') } // 上传文件 handleOnChange = async (info) => { if (!info.file.status) { this.metaAction.toast('error', '仅支持上传Excel格式的文件') return } LoadingMask.show() if (info.file.status == 'done') { LoadingMask.hide() if (info.file.response.result && info.file.response.value) { let templateType = this.metaAction.gf('data.form.templateType') const checkedResult = await this.webapi.financeinit.importAccountBalance({ type: templateType, fileId: info.file.response.value.id }) let tipContent = this.getImportTip(checkedResult) if (tipContent.result == true) { this.metaAction.toast('success', '文件导入成功') } else { let checkStyle = { textAlign: 'left', fontSize: '14px', display: 'inline-block', verticalAlign: 'top' } this.metaAction.toast('error', <div style={checkStyle}> { tipContent.message.map((o, index) => <p style={{ marginBottom: '0' }}>{index==0 ? o : (index) + '.' + o}</p>) } </div> ) } this.injections.reduce('uploadFile', info.file.response.value, checkedResult) } } else if (info.file.status === 'error') { LoadingMask.hide() this.metaAction.toast('warning', '文件上传失败') } } getImportTip = (response) => { let message = [], tip = {} if (!!response.flag) { tip = { result: true } } else { message.push('导入失败') if (response.checkExistDataInExcel == '导入余额表内无数据') { message.push(response.checkExistDataInExcel) } if (response.checkSameCodeOrName && response.checkSameCodeOrName.length > 0) { for (var i = 0; i < response.checkSameCodeOrName.length; i++) { message.push(response.checkSameCodeOrName[i]) } } if (response.checkDataFormat && response.checkDataFormat.length > 0) { for (var i = 0; i < response.checkDataFormat.length; i++) { message.push(response.checkDataFormat[i]) } } tip = { result: false, message: message } } return tip } //下一步 nextStep = (key) => { //根据当前页面的参数跳转不同的app key:uploadExcel(上传excel)、manualEentry(手工录入) //上传跳转科目初始化对照页面、下载模板和手工录入跳转科目页面 if (key == 'manualEentry') { this.component.props && this.component.props.setPortalContent('科目', 'app-account-subjects', { key }) } else { this.component.props && this.component.props.setPortalContent('科目映射', 'ttk-gl-app-financeinit-accountrelation', { key: 'uploadExcel', isUploaded: this.metaAction.gf('data.other.isUploaded') }) } } } class DateCellCustom extends React.Component { constructor(props) { super(props) } render() { if (this.props.maxClosingPeriod == '') { return ( <div > {Number(moment(this.props.nowTime).format('MM'))}月 </div> ) } else { if ((moment(this.props.nowTime) <= moment(this.props.maxClosingPeriod)) && (moment(this.props.nowTime) >= moment(this.props.enableTime))) { return ( <div style={{ position: 'relative' }}> {Number(moment(this.props.nowTime).format('MM'))}月 <Icon type="duigou" fontFamily='edficon' className='iconCustom' style={{ fontSize: '17px', float: 'right', position: 'absolute', top: '-4px', right: '-12px' }} /> </div> ) } else { return ( <div > {Number(moment(this.props.nowTime).format('MM'))}月 </div> ) } } } } export default function creator(option) { const metaAction = new MetaAction(option), voucherAction = FormDecorator.actionCreator({ ...option, metaAction }), o = new action({ ...option, metaAction, voucherAction }), ret = { ...metaAction, ...voucherAction, ...o } metaAction.config({ metaHandlers: ret }) return ret }