ttk-app-core
Version:
enterprise develop framework
136 lines (123 loc) • 4.72 kB
JavaScript
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 md5 from 'md5'
import { userInfo } from 'os';
import Item from 'antd/lib/list/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
if (this.component.props.setOkListener)
this.component.props.setOkListener(this.onOk)
injections.reduce('init')
this.load()
}
onOk = async () => {
this.component.props.closeModal();
}
load = async () => {
// const config = await this.webapi.tplus.configQuery();//查询配置信息
// this.injections.reduce('load', config)
const vatOrEntry = this.component.props.vatOrEntry;
this.metaAction.sf('data.other.vatOrEntry', vatOrEntry);
}
getCurrentOrg = () => this.metaAction.context.get('currentOrg') || {}
getOrgId = () => {
const org = this.getCurrentOrg()
if (org) {
return org.id;
}
return ""
}
nextStep = async () => {
const other = this.metaAction.gf('data.other').toJS();
const form = this.metaAction.gf('data.form').toJS();
let loading = this.metaAction.gf('data.loading');
//let baseUrl = other.baseUrl;
const baseUrl = this.component.props.baseUrl;
if (loading) {
return
}
if (other.step === 1) {
this.metaAction.sf('data.other.step', 2)
}
else if (other.step === 2) {
this.metaAction.sf('data.loading', true);
let res1;
if (this.component.props.vatOrEntry == 0) {
res1 = await this.webapi.tplus.auditBatchForTPlusSa(this.component.props.selectedData);
} else {
res1 = await this.webapi.tplus.auditBatchForTPlusPu(this.component.props.selectedData);
}
let params = []
if (res1 && res1.success) {
if (res1.success.length == 0) {
this.metaAction.toast('生成凭证失败')
return false
}
this.metaAction.sf('data.other.successCount', res1.success.length)
res1.success.forEach(item => {
params.push(JSON.parse(item.message))
});
}
//let url = 'http://124.193.174.170:20001/common/doc/CreateBatch'
let options = {
headers: {
token: this.getOrgId()
}
}
let url = `${baseUrl}/common/doc/CreateBatch`;
//生成t+凭证
const res = await this.webapi.tplus.create(url, params, options);
if (res.result) {
// let value = JSON.parse(res.value);
// if (value.message) {
// this.metaAction.toast('error',value.message);
// return false
// } else {
if (this.component.props.vatOrEntry == 0) {
await this.webapi.tplus.updateBatchForTPlusSa(this.component.props.selectedData)
} else {
await this.webapi.tplus.updateBatchForTPluPu(this.component.props.selectedData)
}
this.metaAction.toast('success', '生成凭证成功')
this.metaAction.sf('data.other.step', 3);
this.metaAction.sf('data.loading', false);
// }
} else {
this.metaAction.sf('data.loading', false);
}
}
else if (other.step === 3) {
this.onOk()
}
}
//返回上一步
backLastStep = () => {
let loading = this.metaAction.gf('data.loading');
if (loading) {
return
}
let step = this.metaAction.gf('data.other.step')
this.metaAction.sf('data.other.step', step - 1)
}
//检查是否要置灰下一步按钮
checkNext = () => {
return false
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
o = new action({ ...option, metaAction }),
ret = { ...metaAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}