ttk-app-core
Version:
enterprise develop framework
692 lines (663 loc) • 25.9 kB
JavaScript
import React from 'react'
import { action as MetaAction } from 'edf-meta-engine'
import config from './config'
import isEquall from 'lodash.isequal'
import { fromJS } from 'immutable'
import { Select, LoadingMask } from 'edf-component'
import { CryptoJS } from 'edf-utils'
const Option = Select.Option
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
injections.reduce('init')
this.initEnumData()
this.load()
this.selectOption = []
this.timer = null
let addEventListener = this.component.props.addEventListener
if (addEventListener) {
addEventListener('onTabFocus', this.load)
}
let addTabsListen = this.component.props.addTabsListen
if( addTabsListen ) {
addTabsListen('edfx-app-org', this.hasModify)
}
}
renderSelectOption = (data) => {
const arr = data.map(item => {
return (
<Option key={item.id} value={item.code}>
{item.name}
</Option>
)
})
this.selectOption = arr
this.metaAction.sf('data.other.key', Math.floor(Math.random()*10000))
}
getSelectOption = () => {
return this.selectOption
}
load = async () => {
//验证是否能修改性质和准则
let canModify = await this.webapi.org.modify()
this.metaAction.sfs({
'data.other.canModify': canModify
})
//初始化数据
const initData = await this.webapi.org.query()
this.injections.reduce('load', initData[0])
this.metaAction.sf('data.copyBasic',this.metaAction.gf('data.basic'))
this.metaAction.sf('data.copyNsxxDto',this.metaAction.gf('data.nsxxDto'))
}
//判断界面是否有修改
hasModify = () => {
let activeTabIndex = this.metaAction.gf('data.other.activeTabKey'),
basic = this.metaAction.gf('data.basic'),
nsxxDto = this.metaAction.gf('data.nsxxDto'),
copyBasic = this.metaAction.gf('data.copyBasic'),
copyNsxxDto = this.metaAction.gf('data.copyNsxxDto')
if(isEquall(basic, copyBasic) && isEquall(nsxxDto, copyNsxxDto)) {
return false
}else {
return true
}
}
//判断界面是否有修改
hasModifyInside = () => {
let activeTabIndex = this.metaAction.gf('data.other.activeTabKey'),
basic = this.metaAction.gf('data.basic'),
nsxxDto = this.metaAction.gf('data.nsxxDto'),
copyBasic = this.metaAction.gf('data.copyBasic'),
copyNsxxDto = this.metaAction.gf('data.copyNsxxDto')
if(activeTabIndex == 3 || activeTabIndex == 4) {
return false
}
if(activeTabIndex == 1) {
return isEquall(basic, copyBasic) ? false : true
}else if(activeTabIndex == 2) {
return isEquall(nsxxDto, copyNsxxDto) ? false : true
}
}
initEnumData = async () => {
const enumIdList = {
enumIdList: ['200001', '200002']
}
let res = await this.webapi.getEnumData.basicEnum(enumIdList)
let basicEnum = {
vatTaxpayer: res['200001'],
accountingStandards: res['200002'],
'SS': [{id: 2000080001, name: "北京市", code: "11"},{id: 2000080019, name: "广东省", code: "44"}],
'DLFS': [{id:'1', name: 'CA证书'},{id:'2', name:'用户名密码登录'},{id:'3', name:'实名制登录'}]
}
this.metaAction.sfs({
'data.enumData.basic': fromJS(basicEnum)
})
this.initTaxEnumData()
}
initTaxEnumData = async () => {
let taxEnum = await this.webapi.getEnumData.taxEnum()
this.metaAction.sfs({
'data.enumData.tax': fromJS(taxEnum)
})
this.renderSelectOption(taxEnum.SSHY.enumDetails)
}
handleTabChange = async (activeKey) => {
let isModify = this.hasModifyInside()
if(isModify) {
const ret = await this.metaAction.modal('confirm', {
title: '提示',
content: `当前数据尚未保存,还要切换页签吗?`,
})
if (!ret) {
return
}
}
this.metaAction.sf('data.other.activeTabKey', activeKey)
}
//保存基本信息
saveBasicInfo = async () => {
let basic = this.metaAction.gf('data.basic').toJS()
let initState = this.metaAction.gf('data.initState').toJS()
let isShowOtherMsg = this.metaAction.gf('data.other.isShowOtherMsg')
if(isShowOtherMsg && initState.vatTaxpayerNum != basic.vatTaxpayerNum) {
const res = await this.metaAction.modal('confirm', {
title: '提示',
content: '修改纳税人识别号,纳税信息页签需要重新读取企业信息,是否确认修改?',
})
if (!res) {
//还原值
this.metaAction.sfs({
'data.basic.name': initState.name,
'data.basic.accountingStandards': initState.accountingStandards,
'data.basic.enableDate': initState.enableDate,
'data.basic.vatTaxpayer': initState.vatTaxpayer,
'data.basic.vatTaxpayerNum': initState.vatTaxpayerNum,
'data.basic.isSignAndRetreat': initState.isSignAndRetreat,
'data.basic.ss': initState.ss
})
return
}
}
const info = await this.check([{
path: 'data.basic.name', value: basic.name
}, {
path: 'data.basic.enableDate', value: basic.enableDate
}, {
path: 'data.basic.vatTaxpayerNum', value: basic.vatTaxpayerNum
}, {
path: 'data.basic.ss', value: basic.ss
}], 'save')
if (!info) return
this.saveInfo(basic, 'reload')
}
saveInfo = async (basic, str) => {
let params = {}
params.name = basic.name.trim()
params.accountingStandards = basic.accountingStandards
params.enabledYear = basic.enableDate.split('-')[0]
params.enabledMonth = basic.enableDate.split('-')[1]
params.vatTaxpayerNum = basic.vatTaxpayerNum.trim()
params.vatTaxpayer = basic.vatTaxpayer
// params.isSignAndRetreat = basic.isSignAndRetreat
let areas = this.metaAction.gf('data.enumData.basic.SS').toJS(),
areasCode = areas.find(o => basic.ss == o.id)
params.SS = areasCode.code
if(params.vatTaxpayer == '2000010002') {
params.isSignAndRetreat = false
}else if(params.vatTaxpayer == '2000010001'){
params.isSignAndRetreat = true
}
params.ts = basic.ts
const response = await this.webapi.org.saveBasicInfo(params)
if (response) {
if(str == 'reload') {
this.metaAction.toast('success', '保存成功')
}
this.load()
this.component.props.onPortalReload && this.component.props.onPortalReload()
}else {
this.metaAction.toast('error', '保存失败')
}
}
//保存企业信息
saveOrgInfo = async () => {
let orgInfo = this.metaAction.gf('data.nsxxDto').toJS(),
error = this.metaAction.gf('data.error.orgInfo').toJS()
for(let i in error) {
if(error[i] != undefined) return
}
const response = await this.webapi.org.saveOrgInfo(orgInfo)
if (response) {
this.metaAction.toast('success', '保存成功')
}else {
this.metaAction.toast('error', '保存失败')
}
}
fieldChange = (fieldPath, value, operate) => {
this.check([{ path: fieldPath, value }], operate)
}
check = async (fieldPathAndValues, operate) => {
if (!fieldPathAndValues)
return
let checkResults = []
for (let o of fieldPathAndValues) {
let r = { ...o }
switch(o.path) {
case 'data.basic.name':
Object.assign(r, await this.name(o.value, operate))
break
case 'data.basic.enableDate':
Object.assign(r, await this.enableDate(o.value))
break
case 'data.basic.vatTaxpayerNum':
Object.assign(r, this.vatTaxpayerNum(o.value, operate))
break
case 'data.basic.ss':
Object.assign(r, this.ss(o.value))
break
default:
break
}
checkResults.push(r)
}
var json = {}
var hasError = true
checkResults.forEach(o => {
json[o.path] = o.value
json[o.errorPath] = o.message
if (o.message)
hasError = false
})
this.metaAction.sfs(json)
return hasError
}
name = async (name, operate) => {
var message
let currentName = this.metaAction.gf('data.initState.name')
if((name && name.trim()) == currentName)
return { errorPath: 'data.error.name', message }
if(operate && (operate == 'save' || operate == 'blur')) {
if(!name) {
message = '请输入企业名称'
}else if(await this.webapi.org.existsSysOrg(name)){
return { errorPath: 'data.error.name', message:"该企业名称已注册"}
}
}
if (name.length <= 200 && name != '')
return { errorPath: 'data.error.name', message }
else if(!name)
message = '请输入企业名称'
else if(name.length > 200)
message = "企业名称不能超过200个字"
return { errorPath: 'data.error.name', message }
}
enableDate = async (enableDate) => {
var message
let currentEnableDate = this.metaAction.gf('data.initState.enableDate')
if (enableDate == currentEnableDate) {
return { errorPath: 'data.error.enableDate', message }
}
if(!enableDate) {
return { errorPath: 'data.error.enableDate', message: '请选择启用时间' }
}
const obj ={}
obj.toYear = enableDate.split('-')[0]
obj.toMonth = Number(enableDate.split('-')[1])
const res = await this.webapi.org.updatePeriod(obj)
if(res.result){
message
}else if(!res.result){
message = res.error.message
}
return { errorPath: 'data.error.enableDate', message }
}
vatTaxpayerNum = (vatTaxpayerNum, operate) => {
vatTaxpayerNum = vatTaxpayerNum && vatTaxpayerNum.trim()
var message
if (!vatTaxpayerNum)
message = '请输入纳税人识别号'
else if (vatTaxpayerNum.length <=14) {
if(operate && (operate == 'save')) {
message = "纳税人识别号位数错误"
}else {
message = undefined
}
}else if(vatTaxpayerNum.length > 14 && vatTaxpayerNum.length !== 15 && vatTaxpayerNum.length !== 18 && vatTaxpayerNum.length !== 20)
message = "纳税人识别号位数错误"
else if(vatTaxpayerNum.length > 20)
message = "纳税人识别号不能超过20个字"
return { errorPath: 'data.error.vatTaxpayerNum', message }
}
ss = (name) => {
let message
if(!name)
message = '请选择省市'
return { errorPath: 'data.error.ss', message }
}
//校验非必填字段
checkNotRequire = (length, str, value, field) => {
let path = str.replace('error.orgInfo', 'nsxxDto')
var message
if(value.length > length)
message = field + "不能超过" + length + "个字"
this.metaAction.sfs({
[path]: value,
[str]: message
});
}
zczb = (value) => {
value = this.addThousandsPosition(value, true)
this.metaAction.sf('data.nsxxDto.ZCZB', value)
}
//判断读取按钮状态
readOrgInfoBtnState = () => {
let dlfs = this.metaAction.gf('data.basic.dlfs'),
ss = this.metaAction.gf('data.basic.ss')
if(!ss || !dlfs) {
this.metaAction.sf('data.other.readOrgInfoBtn', true)
return
}
if(dlfs != 1) {
let wbzh = this.metaAction.gf('data.basic.wbzh'),
wbmm = this.metaAction.gf('data.basic.wbmm')
if(!wbzh || !wbmm) {
this.metaAction.sf('data.other.readOrgInfoBtn', true)
}else {
this.metaAction.sf('data.other.readOrgInfoBtn', false)
}
}else {
let hasReadCA = this.metaAction.gf('data.other.hasReadCA')
if(hasReadCA) {
this.metaAction.sf('data.other.readOrgInfoBtn', false)
}else {
this.metaAction.sf('data.other.readOrgInfoBtn', true)
}
}
}
//改变纳税人识别号
handleNsrsbhChange = (value) => {
//同步改变网报账号
// this.metaAction.sfs({
// 'data.basic.wbzh': value
// })
this.check([{path: 'data.basic.vatTaxpayerNum', value}])
}
//失去焦点,改变ss
handleNsrsbhBlur = (value) => {
if(!value) return
let wbzh = this.metaAction.gf('data.basic.wbzh')
if(!wbzh) {
this.metaAction.sf('data.basic.wbzh', value)
}
let code = null
if(value.length == 15) {
code = value.substr(0,2)
}else if(value.length == 18) {
code = value.substr(2,2)
}
if(!!code) {
let ss = this.metaAction.gf('data.enumData.basic.SS').toJS()
let area = ss.find(o => o.code.substr(0,2) == code)
if(!!area) {
this.metaAction.sf('data.basic.ss', area.id)
this.changeDlfs(area.id)
}
}
}
//Select改变事件
handleSelectChange = (path, value) => {
switch(path) {
case 'data.basic.dlfs':
this.checkReadCAState(value)
break
case 'data.basic.ss':
this.metaAction.sfs({
[path]: value,
'data.error.ss': undefined
})
this.changeDlfs(value)
break
default:
break
}
}
//获取省市code
getSSCode = (value) => {
let ss = this.metaAction.gf('data.enumData.basic.SS').toJS()
let code = null
for(let i = 0 ;i < ss.length; i++){
if(ss[i].id == value) {
code = ss[i].code
break
}
}
return code
}
//根据省市改变登录方式
changeDlfs = (value) => {
clearTimeout(this.timer)
let code = this.getSSCode(value)
let loginModeList = null
if(code == '11') {
loginModeList = [{id:'1', name: 'CA证书'},{id:'2', name:'用户名密码登录'}]
}else if(code == '44') {
loginModeList = [{id:'3', name:'实名制登录'}]
}
let id = this.metaAction.gf('data.basic.dlfs')
let flag = {}
if(!!id) {
flag = loginModeList.find(o => o.id == id) || {}
}
this.metaAction.sfs({
'data.enumData.basic.DLFS': fromJS(loginModeList),
'data.basic.dlfs': flag.id || (code == '44' && '3')
})
this.readOrgInfoBtnState()
}
//隐藏打开CA登录步骤
changeCAStep = () => {
this.metaAction.sf('data.other.CAStep', !this.metaAction.gf('data.other.CAStep'))
}
//检查是否读取过CA
checkReadCAState = async (value) => {
clearTimeout(this.timer)
if(value != 1) {
this.metaAction.sf('data.basic.dlfs', String(value))
this.readOrgInfoBtnState()
return
}
let platform = window.navigator.platform
if(platform != 'Win32') {
await this.metaAction.modal('warning', {
content: 'CA登录只支持windows系统',
title: '提示',
okText: '确定'
})
return
}
let res = await this.webapi.CAState.queryCAState()
this.metaAction.sfs({
'data.basic.dlfs': '1',
'data.other.CAStep': !res,
'data.other.hasReadCA': res
})
this.readOrgInfoBtnState()
}
//下载CA证书
downloadCACertifacate = () => {
window.open("https://ttk-dev.oss-cn-beijing.aliyuncs.com/DOWNLOAD/CATool.exe")
}
//打开dlfs判断省市
onDlfsSelectChange = () => {
let ss = this.metaAction.gf('data.basic.ss')
let code = this.getSSCode(ss)
let loginModeList = null
if(code == '11') {
loginModeList = [{id:'1', name: 'CA证书'},{id:'2', name:'用户名密码登录'}]
}else if(code == '44') {
loginModeList = [{id:'3', name:'实名制登录'}]
}
this.metaAction.sf('data.enumData.basic.DLFS', fromJS(loginModeList))
}
//唤起CA工具
openCATool = async () => {
let basic = this.metaAction.gf('data.basic').toJS()
const info = await this.check([{
path: 'data.basic.name', value: basic.name
}, {
path: 'data.basic.vatTaxpayerNum', value: basic.vatTaxpayerNum
}, {
path: 'data.basic.ss', value: basic.ss
}], 'save')
if (!info) return
let vatTaxpayerNum = this.metaAction.gf('data.basic.vatTaxpayerNum'),
ss = this.metaAction.gf('data.basic.ss'),
areaCode = this.metaAction.gf('data.enumData.basic.SS').toJS(),
name = this.metaAction.gf('data.basic.name'),
area = null
for(let i = 0 ; i < areaCode.length; i++){
if(ss == areaCode[i].id) {
area = areaCode[i].name
break
}
}
let a = document.createElement('a')
a.setAttribute('href', `ttk://nsrsbh:${vatTaxpayerNum}&qymc:${name}&token:${sessionStorage.getItem('_accessToken')}&shengshi:${area}`)
a.click()
this.queryCAState()
}
queryCAState = async () => {
//如果当前的登录方式为CA登录时轮询
let result = await this.webapi.CAState.queryCAState()
if(!result) {
this.timer = setTimeout(this.queryCAState, 2000)
}else {
this.metaAction.sfs({
'data.other.CAStep': false,
'data.other.hasReadCA': true
})
this.readOrgInfoBtnState()
}
}
//读取企业信息
readOrgInfo = async (canChange) => {
let isShowOtherMsg = this.metaAction.gf('data.other.isShowOtherMsg')
if (isShowOtherMsg) {
const result = await this.metaAction.modal('confirm', {
title: '提示',
content: '重新读取企业信息后,采集发票或申报将以新读取的企业信息为准,是否确认修改?',
})
if (!result) {
return
}
}
let basic = this.metaAction.gf('data.basic').toJS()
const info = await this.check([{
path: 'data.basic.name', value: basic.name
}, {
path: 'data.basic.enableDate', value: basic.enableDate
}, {
path: 'data.basic.vatTaxpayerNum', value: basic.vatTaxpayerNum
}, {
path: 'data.basic.ss', value: basic.ss
}], 'save')
if (!info) return
let areas = this.metaAction.gf('data.enumData.basic.SS').toJS(),
areasCode = areas.find(o => basic.ss == o.id),
params = {
DLFS: basic.dlfs,
NSRSBH: basic.vatTaxpayerNum.trim(),
QYMC: basic.name,
SS: areasCode.code,
}
params.canChange =typeof canChange != 'object' ? canChange : false
if(basic.isAuthorization != null) {
params.isAuthorization = basic.isAuthorization
}
if(basic.dlfs != 1) {
params.DLZH = basic.wbzh.trim()
let pwd = this.metaAction.gf('data.initState.pwd')
if(pwd != basic.wbmm) {
params.DLMM = this.encryptByDES(basic.wbmm, '3kingdom')
}else {
params.DLMM = basic.wbmm
}
}
LoadingMask.show()
//判断基本信息是否保存
let isSave = this.isSaveBasicInfo(basic)
if(!isSave) {
await this.saveInfo(basic, 'notReload')
}
const res = await this.webapi.org.readOrgMessage({dlxxDto: params, isReturnValue: true})
if(res && !res.error) {
this.metaAction.toast('success', '读取成功')
LoadingMask.hide()
this.load()
}else if(!res.result) {
LoadingMask.hide()
if(res.error && res.error.code == "502021") {
const result = await this.metaAction.modal('confirm', {
title: '提示',
content: '税局登记的纳税人性质与产品录入的纳税人性质必须一致才可读取企业信息,是否修改产品的纳税人性质使其一致?',
})
if (result) {
this.readOrgInfo(true)
}else {
const result = await this.metaAction.modal('warning', {
title: '提示',
content: '税局登记的纳税人性质与产品录入的纳税人性质不一致,无法读取企业信息',
okText: '确定'
})
}
}else if(res.error && res.error.code == "502022"){
await this.metaAction.modal('error', {
content: '税局登记的纳税人性质与产品录入的纳税人性质不一致,请检查并修改登录账号或产品的纳税人性质',
title: '提示',
okText: '确定'
})
return
}else {
this.metaAction.toast('error', res.error.message)
this.metaAction.sfs({
'data.other.isShowOtherMsg': false,
'data.nsxxDto': fromJS({})
})
}
}
}
//判断基本信息是否保存
isSaveBasicInfo = (basic) => {
let initState = this.metaAction.gf('data.initState').toJS()
const state = (basic.name == initState.name) &&
(basic.accountingStandards == initState.accountingStandards) &&
(basic.enableDate == initState.enableDate) &&
(basic.vatTaxpayer == initState.vatTaxpayer)
return state
}
//加密
encryptByDES = (message, key) => {
let keyHex = CryptoJS.enc.Utf8.parse(key);
let encrypted = CryptoJS.DES.encrypt(message, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
hideInfo = () => {
this.metaAction.sf('data.other.detailInfo', !this.metaAction.gf('data.other.detailInfo'))
}
//资格认定,税费种信息
//添加千分位
addThousandsPosition = (input, isFixed) => {
if(!input) return null
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,")
}
//时间格式化
renderDate = (value) => {
if (value) {
let newDate=/\d{4}-\d{1,2}-\d{1,2}/g.exec(value)
return newDate
}
}
//列表中列字典项
renderColValue = (value, list) => {
const currentObj = list.find(o => o.code == value)
return currentObj && currentObj.name
}
//重新初始化
reinit = async () => {
const ret = await this.metaAction.modal('show', {
title: '重新初始化',
width:652,
height:311,
children: this.metaAction.loadApp('edfx-app-org-reinit', {
store: this.component.props.store,
})
})
//更新content部分
ret &&
this.load()
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
o = new action({ ...option, metaAction }),
ret = { ...metaAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}