ttk-app-core
Version:
enterprise develop framework
1,251 lines (1,136 loc) • 49.8 kB
JavaScript
import React from 'react'
import ReactDOM from 'react-dom'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import config from './config'
import { Map, fromJS } from 'immutable'
import moment from 'moment'
import utils, { fetch } from 'edf-utils'
import extend from './extend'
import { consts, common } from 'edf-constant'
import changeToOption from './utils/changeToOption'
import changeToOptionTwo from './utils/changeToOptionTwo'
import {
Repeter, FormDecorator, Select, Checkbox,
Form, DatePicker, Button, Input, Icon,
ColumnsSetting, Layout,Cascader
} from 'edf-component'
const Option = Select.Option
const FormItem = Form.Item
class action {
constructor(option) {
this.metaAction = option.metaAction
this.extendAction = option.extendAction
this.voucherAction = option.voucherAction
this.config = config.current
this.webapi = this.config.webapi
}
onInit = ({ component, injections }) => {
this.extendAction.gridAction.onInit({ component, injections })
this.voucherAction.onInit({ component, injections })
this.component = component
this.injections = injections
let addEventListener = this.component.props.addEventListener
if (addEventListener) {
addEventListener('onTabFocus', :: this.onTabFocus)
}
injections.reduce('init')
this.initLoad(this.component.props.id || null) //4445862265978880
}
onTabFocus = async (params) => {
params = params.toJS()
if (params.accessType != 0) {
if (params.id) {
this.initLoad(params.id)
} else {
this.initLoad(null)
}
}
}
initLoad = async (id) => {
const response = await this.webapi.expense.init({ id: id })
let getCalcObject = await this.webapi.expense.getCalcObject()
if (getCalcObject) {
getCalcObject = changeToOption(getCalcObject, 'name', 'id')
}
let getCalcObjects = []
if(getCalcObject) {
for(var i=0; i<getCalcObject[0].children.length;i++) {
getCalcObjects.push(getCalcObject[0].children[i])
}
for(var i=0; i<getCalcObject[1].children.length;i++) {
getCalcObjects.push(getCalcObject[1].children[i])
}
for(var i=0; i<getCalcObject[2].children.length;i++) {
getCalcObjects.push(getCalcObject[2].children[i])
}
}
response.getCalcObject = getCalcObject
response.getCalcObjects = getCalcObjects
if(response.businessTypes){
response.businessTypes = changeToOptionTwo(response.businessTypes, 'name', 'id')
}
this.injections.reduce('initLoad', response)
}
load = (voucher) => {
this.injections.reduce('load', voucher)
}
renderStyle = () => {
const detailHeight = this.metaAction.gf('data.other.detailHeight')
return {height: detailHeight}
}
getInvoiceType = () => {
const other = this.metaAction.gf('data.other').toJS()
this.metaAction.sf('data.other', fromJS(other))
}
componetWillUnmount = () => {
const win = window
if (win.removeEventListener) {
document.body.removeEventListener('keydown', this.bodyKeydownEvent, false)
} else if (win.detachEvent) {
document.body.detachEvent('onkeydown', this.bodyKeydownEvent)
}
}
bodyKeydownEvent = (e) => {
const dom = document.getElementById('app-pu-arrival-card')
const modalBody = document.getElementsByClassName('ant-modal-body')
if (dom && modalBody && modalBody.length<1){
this.keyDownCickEvent({event:e})
}
}
//监听键盘事件
keyDownCickEvent = (keydown) => {
if (keydown && keydown.event) {
let e = keydown.event
if (e.ctrlKey && e.altKey && (e.key == 'n' || e.keyCode == 78)) { //新增
// this.add()
if (e.preventDefault) {
e.preventDefault()
}
if (e.stopPropagation) {
e.stopPropagation()
}
}
else if (e.ctrlKey && !e.altKey && (e.key == 's' || e.keyCode == 83)) { //保存
this.save(false)
if (e.preventDefault) {
e.preventDefault()
}
if (e.stopPropagation) {
e.stopPropagation()
}
}
else if (e.ctrlKey && !e.altKey && (e.key == '/' || e.keyCode == 191)) {//保存并新增
this.save(true)
if (e.preventDefault) {
e.preventDefault()
}
if (e.stopPropagation) {
e.stopPropagation()
}
}
else if (e.ctrlKey && !e.altKey && (e.key == 'y' || e.keyCode == 89)) {
//审核
this.audit()
if (e.preventDefault) {
e.preventDefault()
}
if (e.stopPropagation) {
e.stopPropagation()
}
}
//判断设备是否为mac
else if (navigator.userAgent.indexOf('Mac OS X') !== -1) {
if (e.ctrlKey && !e.altKey && (e.key == "[" || e.keyCode == 219)) {
//上一张
this.prev()
}
else if (e.ctrlKey && !e.altKey && (e.key == "]" || e.keyCode == 221)) {
//下一张
this.next()
}
} else {
if (e.ctrlKey && !e.altKey && (e.key == "[" || e.keyCode == 37 || e.keyCode == 219)) {
//219 win7 IE11下的keyCode
//上一张
this.prev()
}
else if (e.ctrlKey && !e.altKey && (e.key == "]" || e.keyCode == 39 || e.keyCode == 221)) {
//221 win7 IE11下的keyCode
//下一张
this.next()
}
}
}
}
getAccessToken = () => {
let token = fetch.getAccessToken()
return { token: token }
}
prev = async () => {
const code = this.metaAction.gf('data.form.code')
const response = await this.webapi.expense.previous({ code,isReturnValue: true })
if (response) {
if (response.result == false && response.error) {
this.metaAction.sfs({
'data.other.prevDisalbed':true,
'data.other.nextDisalbed': false
})
this.metaAction.toast('error', response.error.message)
} else {
this.metaAction.sf('data.other.nextDisalbed', false)
this.load(response)
}
}
}
next = async () => {
const code = this.metaAction.gf('data.form.code')
const response = await this.webapi.expense.next({ code,isReturnValue: true })
if (response) {
if (response.result == false && response.error) {
this.metaAction.sfs({
'data.other.prevDisalbed':false,
'data.other.nextDisalbed': true
})
this.metaAction.toast('error', response.error.message)
} else {
this.metaAction.sf('data.other.prevDisalbed', false)
this.load(response)
}
}
}
setting = async () => {
// this.metaAction.toast('error', '请实现设置功能')
let setting = this.metaAction.gf('data.other.columnSetting')
let initOption = []
setting = setting && setting.toJS()
if (setting && setting.body) {
let obj = {
key: setting.code,
name: setting.name
}
obj.option = setting.header && setting.header.cards
let detailObj = {}
setting.body.tables.forEach((objItem) => {
detailObj.key = objItem.name
detailObj.name = objItem.caption
detailObj.option = objItem.details
})
initOption.push(obj)
initOption.push(detailObj)
}
const res = await this.metaAction.modal('show',{
title: '显示设置',
width: 500,
iconType: null,
children: <ColumnsSetting
option={initOption}
singleKey='id'
sort={true}
editName={true}
checkedKey='isVisible'
labelKey="caption"
/>
})
if (res && res.type == 'confirm') {
this.handleConfirmSet(res.option)
} else if (res && res.type == 'reset') {
this.handleResetSet(setting.code)
}
}
//设置 恢复默认设置
handleResetSet = async (code) => {
if (code) {
const result = await this.webapi.expense.reInitByUser({code: code})
this.metaAction.sf('data.other.columnSetting', fromJS(result))
}
}
//设置 确定
handleConfirmSet = async (params) => {
if (params) {
const setting = this.metaAction.gf('data.other.columnSetting').toJS()
const cards = params[0] && params[0].option
const tables = params[1] && params[1].option
if (setting) {
setting.header.cards = cards
setting.body.tables[0].details = tables
}
const result = await this.webapi.expense.updateWithDetail(setting)
this.metaAction.sf('data.other.columnSetting', fromJS(result))
}
}
add = () => {
this.initLoad()
}
giveUp = async () => {
const res = await this.metaAction.modal('confirm',{
title: '放弃',
content: '点击放弃会重置你所有的操作,确定要放弃吗?',
})
if (res) {
this.initLoad()
}
}
audit = async () => {
const id = this.metaAction.gf('data.form.id'),
ts = this.metaAction.gf('data.form.ts'),
status = this.metaAction.gf('data.form.status')
if (!id && !ts) {
this.metaAction.toast('error', '请保存单据')
return
}
if (status == consts.consts.VOUCHERSTATUS_NotApprove || status == consts.consts.VOUCHERSTATUS_Rejected) {
const response = await this.webapi.expense.audit({ id, ts })
this.metaAction.toast('success', '单据审核成功')
this.load(response)
} else {
const response = await this.webapi.expense.unaudit({ id, ts })
this.metaAction.toast('success', '单据反审核成功')
this.load(response)
}
}
//附件的下载操作
download = (ps) => {
this.voucherAction.download(ps)
}
delFile = (index) => {
this.voucherAction.delFile(index, 'vouchers', this.updateEnclosure)
}
updateEnclosure = async (res) => {
const result = await this.webapi.expense.updateEnclosure(res)
return result
}
attachmentChange = (info) => {
this.voucherAction.attachmentChange(info, 'vouchersSa')
}
beforeUpload = (info,infoList) => {
this.voucherAction.beforeUpload(info,infoList)
}
getAuditBtnText = () => {
const status = this.metaAction.gf('data.form.status')
return status == consts.consts.VOUCHERSTATUS_Approved ? '反审核' : '审核'
}
history = async () => {
this.component.props.setPortalContent('费用', 'ttk-scm-app-expense-list')
}
moreMenuClick = (e) => {
switch (e.key) {
case 'del':
this.del()
break
case 'pay':
this.pay()
break
case 'antiAudit':
this.audit()
break
}
}
del = async () => {
const id = this.metaAction.gf('data.form.id'),
ts = this.metaAction.gf('data.form.ts')
const ret = await this.metaAction.modal('confirm', {
title: '删除',
content: '确认删除?'
})
if (ret) {
const response = await this.webapi.expense.del({ id, ts })
this.metaAction.toast('success', '删除单据成功')
this.initLoad()
}
}
generateReturn = async () => {
let id = this.metaAction.gf(`data.form.id`),
ts = this.metaAction.gf(`data.form.ts`)
if (!id && !ts) {
this.metaAction.toast('error', '请保存单据!')
return
}
this.metaAction.toast('error', 'TODO')
}
pay = () => {
this.metaAction.toast('error', 'TODO')
}
save = async (isNew) => {
if (!this.checkForSave()) return
let form = this.metaAction.gf('data.form').toJS()
let other = this.metaAction.gf('data.other').toJS()
if (form.settles.length != 0) {
form.settles = form.settles.filter((item) => {
return item.bankAccountId
})
form.settles = form.settles.map((item) => { //去除多余的字段
if (item.bankAccountName) {
delete item.bankAccountName
}
return item
})
}
let params = {}
//往来单位或个人情况处理
let sss
other.getCalcObject.map(item => {
return {
children: item.children.map(items => {
if(items.value == form.supplierId) {
sss = item.value
}
})
}
})
if(sss == '1'){
params.supplierId = form.supplierId
}else if(sss == '2'){
params.customerId = form.supplierId
}else if(sss == '3'){
params.personId = form.supplierId
}
//费用类型id处理
for(var i=0;i<other.details.length;i++){
other.details[i].businessTypeId = other.details[i].businessTypeId[1]
}
params.attachmentFiles = form.attachmentFiles
params.settles = form.settles
params.businessDate = form.businessDate
// params.supplierId = form.supplierId
params.departmentId = form.departmentId
params.projectId = form.projectId
params.remark = form.remark
params.details = other.details
if (form.id || form.id == 0) {
params.id = form.id
params.ts = form.ts
const response = await this.webapi.expense.update(params)
if (response) {
this.metaAction.toast('success', '保存更新成功')
if (!isNew) {
this.load(response)
} else {
this.initLoad()
}
}
} else {
const response = await this.webapi.expense.create(params)
if (response) {
this.metaAction.toast('success', '保存单据成功')
if (!isNew) {
this.load(response)
} else {
this.initLoad()
}
}
}
}
getProject = () => {
this.voucherAction.getProject({}, `data.other.getProject`)
}
getDepartment = () => {
this.voucherAction.getDepartment({}, `data.other.getDepartment`)
}
getBankAccount = () => {
this.voucherAction.getBankAccount({}, `data.other.bankAccount`)
}
onFieldDataChanges = (field, storeField) => (value) => {
if (!field || !storeField) return
let values = this.metaAction.gf(storeField).find(o => o.get('value') == value)
if (values) {
Object.keys(field).forEach(key => {
this.metaAction.sf(field[key], values.get(key))
})
}
}
onFieldDataChange = (field, storeField,rowIndex,rowData, index) => (id) => {
if (!field || !storeField) return
let value = this.metaAction.gf(storeField).find(o => o.get('id') == id)
if (value) {
Object.keys(field).forEach(key => {
this.metaAction.sf(field[key], value.get(key))
})
}
if (storeField == 'data.other.bankAccount') {
if (value) {
let settles = this.metaAction.gf('data.form.settles')
settles = settles ? settles.toJS() : []
const id = value.toJS().id, name = value.toJS().name,amount = this.metaAction.gf('data.form.paymentAmount')
if (settles.length == 0) {
const obj ={
bankAccountId: id,
amount: '',
bankAccountName: name,
}
settles.push(obj)
} else {
settles[index].bankAccountId = id
settles[index].bankAccountName = name
}
this.metaAction.sf('data.form.settles', fromJS(settles))
}
}
}
checkForSave = () => {
const form = this.metaAction.gf('data.form').toJS()
const other = this.metaAction.gf('data.other').toJS()
let msg = []
let newAmount = 0
for(var i=0;i<form.settles.length;i++){
newAmount += Number(form.settles[i].amount)
}
// accumulativeMoney
if(newAmount != 0) {
if(Number(form.accumulativeMoney) == newAmount) {
msg = []
}else {
msg.push('费用累计金额和现结金额不相等!')
}
}
if (!form.businessDate) {
msg.push('记账日期不能为空!')
}
const details = other.details.map((item,index) => {
if(item.invoiceTypeId==4000010020){
if(!item.taxInclusiveAmount){
msg.push('价税合计不能为空!')
}
if(!item.tax){
msg.push('税额不能为空!')
}
}
if(!item.invoiceTypeId){
msg.push('票据类型不能为空!')
}
if(!item.amount){
msg.push('金额不能为空!')
}
if(!item.businessTypeId){
msg.push('费用类型不能为空!')
}
if(item.invoiceNumber && (item.invoiceNumber.length != 8)){
msg.push('发票号码长度必须为8位!')
}
if(item.invoiceCode && item.invoiceCode.length != 10 && item.invoiceCode.length != 12){
msg.push('发票代码长度必须为10位或者12位!')
}
return []
})
if (msg.length > 0) {
this.metaAction.toast('error', this.getDisplayErrorMSg(msg))
return false
}
return true
}
getDisplayErrorMSg = (msg) => {
return <div style={{ display: 'inline-table' }}>{msg.map(item => <div>{item}<br /></div>)}</div>
}
cancel = () => {
this.injections.reduce('init')
}
fieldChange = (path, value) => {
this.voucherAction.fieldChange(path, value)
}
getRemarks = (path, value) => {
this.metaAction.sf('data.form.remark', value)
}
onFieldChange = (value, index, key) => {
const details = this.metaAction.gf('data.other.details').toJS()
if (key == 'invoiceTypeId' && value != 4000010020) {
details[index].isInvoice = false
}
if(key == 'invoiceTypeId' && value == 4000010020) {
details[index].isInvoice = true
}
if(key == 'amount') {
details[index].amount = (details[index].amount)
}
if(key=='taxRateId'){
details[index].taxRate = value/100
}
//选择费用类型给税率值
if(key=='businessTypeId'){
let businessTypes = this.metaAction.gf('data.other.businessTypes').toJS()
let NewTaxRateId
businessTypes.map(item => {
return {
children: item.children.map(items => {
if(items.value == value[1]) {
NewTaxRateId = items.taxRateId
}
})
}
})
if(NewTaxRateId) {
details[index].taxRateId = NewTaxRateId
details[index].taxRate = NewTaxRateId/100
}
}
details[index][key] = value
this.metaAction.sf('data.other.details', fromJS(details))
}
//支持搜索
filterOption = (inputValue, option, name) => {
if (!option || !option.props || !option.props.value) {
return false
}
//需要确定部门项目这些是否也需要支持助记码这些的搜索
let parmasName = null
if (name.currentPath) {
parmasName= name.currentPath
}
if (parmasName.indexOf('supplier') != -1) {
parmasName = 'supplier'
} else if (parmasName.indexOf('inventory') != -1) {
parmasName = 'inventory'
} else if (parmasName.indexOf('department') != -1) {
parmasName = 'department'
} else if (parmasName.indexOf('project') != -1) {
parmasName = 'project'
} else if (parmasName.indexOf('purchasePerson') != -1) {
parmasName = 'purchasePerson'
}
const paramsValues = this.metaAction.gf(`data.other.${parmasName}`),
value = option.props.value
let paramsValue = paramsValues.find(item => item.get('id') == option.props.value)
if (!paramsValue) {
return false
}
let regExp = new RegExp(inputValue, 'i')
return paramsValue.get('name').search(regExp) != -1
|| paramsValue.get('helpCode').search(regExp) != -1 // TODO 只支持助记码搜索,简拼
}
//存货编码
filterOptionCode = (inputValue, option) => {
if (!option || !option.props || !option.props.value) {
return false
}
const paramsValues = this.metaAction.gf(`data.other.inventory`),
value = option.props.value
let paramsValue = paramsValues.find(item => item.get('id') == option.props.value)
if (!paramsValue) {
return false
}
let regExp = new RegExp(inputValue, 'i')
return paramsValue.get('code').search(regExp) != -1
}
// customerChange = async (v) => {
// let customerId = v
// const response = await this.webapi.arrival.queryByCustomer({ customerId })
// if (response) {
// this.metaAction.sf('data.form.bankAccount', fromJS({
// id: response.lastBankAccountId,
// name: response.lastBankAccountName
// }))
// this.metaAction.sf('data.form.advanceAmount', this.voucherAction.numberFormat(response.preReceiveAmount, 2))
// }
// }
//计算
calc = (col, rowIndex, rowData, params) => (v) => {
params = Object.assign(params, {
value: v
})
//以下两个if 是为了区分 是否修改了价税合计
// 修改了价税合计之后在修改税率 算法是不一样的
if (col === 'taxInclusiveAmount') {
this.opertionTaxAmount = true
this.oldIndex = rowIndex
}
if (col === 'taxRateName' && rowIndex == this.oldIndex && this.opertionTaxAmount) {
params = Object.assign(params, {
hasChangeTaxAmount: true
})
}
this.voucherAction.calc(col, rowIndex, rowData, params)
}
//计算剩余金额
calcBalance = (data) => {
const taxInclusiveAmount = this.voucherAction.sum(data.form.details, (a, b) => a + b.taxInclusiveAmount)
let paymentAmount = this.metaAction.gf('data.form.paymentAmount')
paymentAmount = utils.number.round(paymentAmount,2) || 0
let payAmount = 0,
settles = this.metaAction.gf('data.form.settles')
settles = settles ? settles.toJS() : []
settles.forEach((item, index) => {
payAmount = payAmount + item.amount
})
// console.log(payAmount, taxInclusiveAmount, 'paymentAmount taxInclusiveAmount')
const chargeAmount = this.voucherAction.numberFormat(taxInclusiveAmount - payAmount, 2)
this.metaAction.sf('data.other.chargeAmount', chargeAmount)
return chargeAmount
}
quantityFormat = (quantity, decimals, isFocus) => {
if (quantity) {
return this.voucherAction.numberFormat(quantity, decimals, isFocus)
}
}
isRowOperation = () => {
return this.metaAction.gf('data.form.certificateStatus') == data.STATUS_VOUCHER_NOT_AUDITED
}
// 控制 税率 税额 价税合计 认证 认证月份 是否显示
getControlVisible = (num) => {
//INVOICETYPE_generalVATInvoice 增值税普通发票
//INVOICETYPE_otherInvoice 其他票据
//INVOICETYPE_uninvoiced 未开具发票
//VATTAXPAYER_smallScaleTaxPayer: '2000010002', //纳税人身份: 2000010002 小规模纳税人
// let visible = true,
let visible = false,
invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId'),
vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
if (invoiceTypeId && vatTaxpayer != '2000010002') {
switch(num) {
case 0 :
const generalVATInvoice = consts.consts.INVOICETYPE_generalVATInvoice
const otherInvoice = consts.consts.INVOICETYPE_otherInvoice
const uninvoiced = consts.consts.INVOICETYPE_uninvoiced
visible = (invoiceTypeId != generalVATInvoice || invoiceTypeId != otherInvoice || invoiceTypeId != uninvoiced)
break;
case 1:
const specialVATInvoice = consts.consts.INVOICETYPE_specialVATInvoice
const hgjkzzszyjks = consts.consts.INVOICETYPE_hgjkzzszyjks
visible = invoiceTypeId == specialVATInvoice || invoiceTypeId == hgjkzzszyjks
break;
default: visible = false
}
}
return visible
}
// 勾选认证
authenticationChange = () => {
const authenticated = this.metaAction.gf('data.form.authenticated')
const date = new Date()
const authMonth = date.getMonth()+1 + '月'
const authMonthList = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
const year = date.getFullYear()
let month = date.getMonth() + 1
month = month < 10 ? '0'+ month : month
const authenticatedMonth = `${year}-${month}`
// console.log(authenticatedMonth, 'authenticatedMonth')
if (!authenticated) {
this.metaAction.sf('data.other.authMonth', authMonth)
this.metaAction.sf('data.form.authenticatedMonth', authenticatedMonth)
this.metaAction.sf('data.other.authMonthList', fromJS(authMonthList))
} else {
this.metaAction.sf('data.other.authMonth', '')
this.metaAction.sf('data.form.deductible', false)
}
this.metaAction.sf('data.form.authenticated', !authenticated)
}
renderPayDiv = () => {
let settles = this.metaAction.gf('data.form.settles')
settles = settles ? settles.toJS() : []
let bankAccount = this.metaAction.gf('data.other.bankAccount'),
bankAccountName = this.metaAction.gf('data.form.bankAccountName'),
isDisableBank = this.metaAction.gf('data.other.isDisableBank')
return settles.map((item, index) => {
return <div key={index}>
<Form className='app-pu-arrival-card-form-footer-settlement'>
<FormItem label='现结账户'
>
<Select
showSearch={false}
disabled={this.getDisable() || isDisableBank}
value={item.bankAccountName}
onFocus={() => this.voucherAction.getBankAccount({}, `data.other.bankAccount`)}
onChange={this.onFieldDataChange({ id: `data.form.bankAccountId`, name: `data.form.bankAccountName` }, `data.other.bankAccount`, null, null, index)}
>
{this.handleSelect(bankAccount)}
</Select>
</FormItem>
<FormItem
label='现结金额'
>
<Input.Number
disabled={this.getDisable() || isDisableBank}
value={item.amount}
onBlur={(v) => this.handlePayBlur(v, index)}
></Input.Number>
</FormItem>
<div className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv'>
<Icon
type='plus'
// fontFamily='edficon'
title='新增'
disabled={isDisableBank}
className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv-iconAdd'
onClick={this.addPaymentAmount}></Icon>
<Icon
type='minus'
// fontFamily='edficon'
title='删除'
disabled={(index == 0 || isDisableBank) ? true : false}
className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv-iconDel'
onClick={this.delPaymentAmount.bind(null, index)}></Icon>
</div>
</Form>
</div>
})
}
//认证
rendeRauthentication = () => {
let authenticated = '认证',
invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')
if (invoiceTypeId) {
if (invoiceTypeId == consts.consts.INVOICETYPE_specialVATInvoice) {
authenticated = '认证'
} else if (invoiceTypeId == consts.consts.INVOICETYPE_hgjkzzszyjks) {
authenticated = '比对'
}
}
return authenticated
}
//抵扣
renderDeduction = () => {
const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId'), //票据类型id
deductible = this.metaAction.gf('data.form.deductible'),
authenticated = this.metaAction.gf('data.form.authenticated')
//农产品发票,默认为勾选
if (invoiceTypeId == consts.consts.INVOICETYPE_ncpfp) {
return <Checkbox checked={!deductible} onChange={this.handleDeduction}>抵扣</Checkbox>
}
if (invoiceTypeId == consts.consts.INVOICETYPE_specialVATInvoice || invoiceTypeId == consts.consts.INVOICETYPE_hgjkzzszyjks) {
return <Checkbox onChange={this.handleDeduction} checked={deductible} disabled={!authenticated}>抵扣</Checkbox>
}
return null
}
// 勾选抵扣
handleDeduction = () => {
const deductible = this.metaAction.gf('data.form.deductible')
this.metaAction.sf('data.form.deductible', !deductible)
}
//点击增加 现结账户
addPaymentAmount = () => {
let settles = this.metaAction.gf('data.form.settles')
settles = settles ? settles.toJS() : []
// console.log(settles, 'settles 增加')
const obj = {
bankAccountId: '',
amount: '',
bankAccountName: '',
}
if (settles.length == 0) settles.push(obj)
settles.push(obj)
this.metaAction.sf('data.form.settles', fromJS(settles))
}
//现结金额失去焦点 才改变剩余金额
handlePayBlur = (v, index) => {
let settles = this.metaAction.gf('data.form.settles')
settles = settles ? settles.toJS() : []
if (settles.length == 0) {
const obj ={
bankAccountId: '',
amount: v,
bankAccountName: '',
}
settles.push(obj)
} else {
settles[index].amount = v
}
this.metaAction.sf("data.form.paymentAmount", v)
this.metaAction.sf("data.form.settles", fromJS(settles))
}
//点击删除 现结账户金额
delPaymentAmount = (index) => {
// console.log(index, 'index')
if (index) {
let settles = this.metaAction.gf('data.form.settles')
settles = settles ? settles.toJS() : []
settles.splice(index, 1)
// console.log(settles, 'settles 删除')
this.metaAction.sf('data.form.settles', fromJS(settles))
}
}
//即征即退
signChange = (name) => {
const signAndRetreat = this.metaAction.gf('data.other.signAndRetreat').toJS()
signAndRetreat.map((obj) => {
if (obj.id == name) {
obj.visible = true
} else {
obj.visible = false
}
})
this.metaAction.sf('data.other.signAndRetreat', fromJS(signAndRetreat))
}
getDisable = () => {
let pageStatus = this.metaAction.gf('data.other.pageStatus')
let disabled = pageStatus == common.commonConst.PAGE_STATUS.READ_ONLY
return disabled
}
//下拉选 票据类型 供应商
handleSelect = (params) => {
params = params && params.toJS()
if (params) {
return params.map((item,index) => {
return <Option value={item && item.id}>{item && item.name}</Option>
})
}
}
//新增档案
handleAddRecord = (paramsU,params) => {
const add = `add${paramsU}`
return <Button type='primary'
style={{ width: '100%', borderRadius: '0' }}
onClick={this.addRecordClick.bind(null,add,params)}
>新增</Button>
}
//新增档案
addRecordClick = async (add, params) => {
await this.voucherAction[add]({ id: `data.form.${params}Id`, name: `data.form.${params}Name`})
}
//控制显示
handleVisible = (params) => {
const columnSetting = this.metaAction.gf('data.other.columnSetting')
return columnSetting && columnSetting.filter(o=> o.propertyName === params )[0].visible
}
//记账日期控制
handleDisabledDate = (current) => {
// Can not select days before today and today
let beginDate = this.metaAction.gf('data.other.beginDate'), currentDate = current.format('YYYY-MM-DD')
beginDate = beginDate.replace(/-/g, '')
currentDate = currentDate.replace(/-/g, '')
return currentDate && currentDate < beginDate
}
addCallBack = () => {
const details = this.metaAction.gf('data.other.details').toJS()
const other = this.metaAction.gf('data.other').toJS()
details.push({
invoiceTypeId : (other.vatTaxpayer == 2000010001) ? 4000010020 : 4000010010,
isInvoice: true,
deductible : (details[0].invoiceTypeId == 4000010020) ? true : false,
authenticated : (details[0].invoiceTypeId == 4000010020) ? true : false,
authenticatedMonth : other.details[0].authenticatedMonth,
invoiceDate : other.details[0].invoiceDate,
signAndRetreat : 4000100001
})
this.metaAction.sf('data.other.details', fromJS(details))
}
delClick = (index) => {
let details = this.metaAction.gf('data.other.details').toJS()
details.splice(index,1)
this.metaAction.sf('data.other.details', fromJS(details))
}
renderRepeter = () => {
let data = this.metaAction.gf('data.other.details').toJS()
return data.map((item, index) => {
return (
<Repeter
key={index}
// buttonName="+增加费用"
// inputLife={true}
// inputLifeName = '费用合计金额'
addCallBack={this.addCallBack}
btnVisible={ index == data.length - 1 }
>
{this.renderChildren(item, index)}
</Repeter>
)
})
}
renderSelect = (details, index) => {
if(details){
return details.map(item => {
return <Select.Option value={item.id}>{item.name}</Select.Option>
})
}
}
onBlurChange = (value, index, key) => {
let details = this.metaAction.gf('data.other.details').toJS()
if(key == 'taxInclusiveAmount') {
if(details[index].taxRateId) {
let newValue = value/(1+details[index].taxRateId/100)
details[index].amount = newValue.toFixed(2)
this.metaAction.sf('data.other.details', fromJS(details))
}
if(details[index].amount) {
let newValue = value-details[index].amount
details[index].tax = newValue.toFixed(2)
this.metaAction.sf('data.other.details', fromJS(details))
}
}
if(key == 'amount') {
if(details[index].taxRateId) {
let newValue = value*(details[index].taxRateId/100)
details[index].tax = newValue.toFixed(2)
this.metaAction.sf('data.other.details', fromJS(details))
}
if(details[index].tax) {
let newValue = Number(value)+Number(details[index].tax)
details[index].taxInclusiveAmount = newValue.toFixed(2)
this.metaAction.sf('data.other.details', fromJS(details))
}
}
if(key == 'taxRateId' && value !== 1000 && value !==9999) {
if(details[index].taxInclusiveAmount) {
let newValue = details[index].taxInclusiveAmount/(1+value/100)
details[index].amount = newValue.toFixed(2)
this.metaAction.sf('data.other.details', fromJS(details))
}
if(details[index].amount && details[index].taxInclusiveAmount) {
let newValue = details[index].taxInclusiveAmount - details[index].amount
details[index].tax = newValue.toFixed(2)
this.metaAction.sf('data.other.details', fromJS(details))
}
}
if(key == 'taxRateId' && value === 1000 || value === 9999) {
if(details[index].taxInclusiveAmount) {
details[index].amount = details[index].taxInclusiveAmount
this.metaAction.sf('data.other.details', fromJS(details))
}
if(details[index].amount && details[index].taxInclusiveAmount) {
let newValue = details[index].taxInclusiveAmount - details[index].amount
details[index].tax = newValue
this.metaAction.sf('data.other.details', fromJS(details))
}
}
let accumulativeMoney = 0
for(var i=0;i<details.length;i++){
if(details[i].taxInclusiveAmount&&details[i].invoiceTypeId==4000010020){
accumulativeMoney += Number(details[i].taxInclusiveAmount)
}else if(details[i].amount){
accumulativeMoney += Number(details[i].amount)
}
}
this.metaAction.sf('data.form.accumulativeMoney', fromJS(accumulativeMoney))
}
renderChildren = (item, index) => {
const data = this.metaAction.gf('data').toJS()
let invoiceNumber,invoiceCode,invoiceDate
if(data.other.columnSetting){
invoiceNumber = data.other.columnSetting.body.tables[0].details[0].isVisible
invoiceCode = data.other.columnSetting.body.tables[0].details[1].isVisible
invoiceDate = data.other.columnSetting.body.tables[0].details[2].isVisible
}
return (
<Layout className="ttk-scm-app-expense-card-form-footer">
<Form className="ttk-scm-app-expense-card-form-footer-top">
<Form.Item label='票据类型' required={true}>
<Select
value={item.invoiceTypeId}
disabled={this.getDisable()}
onChange={(value) => this.onFieldChange(value, index, 'invoiceTypeId')}
>
{this.renderSelect(data.other.invoiceTypes)}
</Select>
</Form.Item>
{(data.other.isVisible && item.isInvoice) ? <Checkbox
children='认证'
disabled={this.getDisable()}
checked = {item.authenticated}
>
</Checkbox> : null}
{(data.other.isVisible && item.isInvoice) ? <Form.Item label='认证月份'>
<DatePicker.MonthPicker
disabled= {true}
value = {this.metaAction.stringToMoment(item.authenticatedMonth)}
>
</DatePicker.MonthPicker>
</Form.Item> : null}
{(data.other.isVisible && item.isInvoice) ? <Checkbox
children='抵扣'
checked = {item.deductible}
disabled={this.getDisable()}
onChange={() => this.onFieldChange(!item.deductible, index, 'deductible')}
>
</Checkbox> : null}
<div className='topDiv'>征收方式</div>
<Checkbox
children='一般项目'
disabled={this.getDisable()}
checked = {item.signAndRetreat == 4000100001 ? true : false}
onChange={(value) => this.onFieldChange(4000100001, index, 'signAndRetreat')}
>
</Checkbox>
<Checkbox
children='即征即退'
disabled={this.getDisable()}
checked = {item.signAndRetreat == 4000100002 ? true : false}
onChange={(value) => this.onFieldChange(4000100002, index, 'signAndRetreat')}
>
</Checkbox>
<Button
className = 'ttk-scm-app-expense-card-form-footer-top-button'
onClick = {() => this.delClick(index)}
disabled= {(index == 0) ? true : false}
children = '×'>
</Button>
</Form>
<Form className="ttk-scm-app-expense-card-form-footer-center">
<Form.Item label='费用类型' required={true}>
<Cascader
value={item.businessTypeId}
placeholder=""
options = {data.other.businessTypes}
disabled={this.getDisable()}
onChange={(value) => this.onFieldChange(value, index, 'businessTypeId')}
>
</Cascader>
</Form.Item>
{invoiceNumber ? <Form.Item label='发票号码'>
<Input
value={item.invoiceNumber}
maxLength={8}
disabled={this.getDisable()}
onChange={(e) => this.onFieldChange(e.target.value, index, 'invoiceNumber')}>
</Input>
</Form.Item> : null}
{invoiceCode ? <Form.Item label='发票代码'>
<Input
value={item.invoiceCode}
maxLength={12}
disabled={this.getDisable()}
onChange={(e) => this.onFieldChange(e.target.value, index, 'invoiceCode')}>
</Input>
</Form.Item> : null}
{invoiceDate ? <Form.Item label='开票日期'>
<DatePicker
value = {this.metaAction.stringToMoment(item.invoiceDate)}
disabled={this.getDisable()}
onChange={(d) => this.onFieldChange(this.metaAction.momentToString(d, 'YYYY-MM-DD'),index,'invoiceDate')}
>
</DatePicker>
</Form.Item> : null}
</Form>
<Form className="ttk-scm-app-expense-card-form-footer-bottom">
{(data.other.isVisible && item.isInvoice) ? <Form.Item label='价税合计' required={true}>
<Input
value={item.taxInclusiveAmount}
disabled={this.getDisable()}
onBlur={(e) => this.onBlurChange(e.target.value, index, 'taxInclusiveAmount')}
onChange={(e) => this.onFieldChange(e.target.value, index, 'taxInclusiveAmount')}>
</Input>
</Form.Item> : null }
{(data.other.isVisible && item.isInvoice) ? <Form.Item label='税率' required={true}>
<Select
value={item.taxRateId}
disabled={this.getDisable()}
onBlur={(e) => this.onBlurChange(item.taxRateId, index, 'taxRateId')}
onChange={(value) => this.onFieldChange(value, index, 'taxRateId')}
>
{this.renderSelect(data.other.taxRates)}
</Select>
</Form.Item> : null }
<Form.Item label='金额' required={true}>
<Input
value={item.amount}
disabled={this.getDisable()}
onBlur={(e) => this.onBlurChange(e.target.value, index, 'amount')}
onChange={(e) => this.onFieldChange(e.target.value, index, 'amount')}>
</Input>
</Form.Item>
{(data.other.isVisible && item.isInvoice) ? <Form.Item label='税额' required={true}>
<Input
value={item.tax}
disabled={this.getDisable()}
onChange={(e) => this.onFieldChange(e.target.value, index, 'tax')}>
</Input>
</Form.Item> : null }
</Form>
</Layout>
)
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
extendAction = extend.actionCreator({ ...option, metaAction }),
voucherAction = FormDecorator.actionCreator({ ...option, metaAction }),
o = new action({ ...option, metaAction, extendAction, voucherAction }),
ret = { ...metaAction, ...extendAction.gridAction, ...voucherAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}