UNPKG

ttk-app-core

Version:
2,940 lines 131 kB
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 { FormDecorator, Select, Checkbox, Form, DatePicker, Button, Input, Icon, Popover, ColumnsSetting } from 'edf-component'
import { blankDetail } from './data'
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)
            addEventListener('enlargeClick', :: this.enlargeClick)
        }
        injections.reduce('init')
        this.initLoad(this.component.props.id || null)
        this.renderNum = 1
    }

    onTabFocus = async (params) => {

        params = params.toJS()
        if (params.accessType != 0) {
            if (params.id) {
                this.initLoad(params.id)
            } else {
                this.initLoad(null)
            }
        } else {
            let data = this.metaAction.gf('data').toJS(),
                other = data.other,
                form = data.form,
                isChange = false,
                details = form.details

            let list = [
                this.webapi.arrival.init({ id: form.id }),
                this.webapi.arrival.queryInventory()
            ]
            const res = await Promise.all(list)
            if (res) {
                let result = res[0]
                if (!result.voucher) {
                    this.initLoad(null)
                    return
                }

                if (result.vatTaxpayer != other.vatTaxpayer) {
                    result = this.handleDefalutDate(result)
                    this.injections.reduce('initLoad', result)
                    return
                }
                if (!result.voucher || result.voucher.accountStatus != 4000140002) {
                    const inventorys = res[1]
                    await this.handleCheckisEnable(result,form, other, data, isChange, details, inventorys, "onTabFocus")

                    this.metaAction.sfs({
                        'data.other.isSignAndRetreat': result.isSignAndRetreat,
                        'data.other.inventorys': fromJS(res[1]),
                        'data.form.status': result.voucher.status,
                        'data.other.accountStatus': result.voucher.accountStatus,
                        'data.other.vatTaxpayer': result.vatTaxpayer,
                        'data.form.ts': result.voucher.ts,
                    })

                } else {
                    this.injections.reduce('load', result.voucher)
                    this.injections.reduce('updateState', 'data.other.allMessage', fromJS(result))
                }
            }
        }
    }

    
    initLoad = async (id, type) => {
        let list = [
            this.webapi.arrival.init({ id: id }),
            this.webapi.arrival.queryInventory()
        ]

        if (id) {
            list.push(this.voucherAction.getSupplier({ entity: { isEnable: true } }, 'data.other.supplier'))
            list.push(this.voucherAction.getDepartment({ entity: { isEnable: true } }, `data.other.department`))
            list.push(this.voucherAction.getProject({ entity: { isEnable: true } }, `data.other.project`))
            list.push(this.voucherAction.getBankAccount({entity: { isEnable: true }}, `data.other.bankAccount`))
        }

        const res = await Promise.all(list)
        if (res) {
            let response = res[0]
            response.inventorys = res[1] && res[1]
            let sfObj = {}

            if (id) {
                let data = this.metaAction.gf('data').toJS(),
                other = data.other,
                form = response.voucher,
                isChange = false,
                details = response.voucher.details,
                result = response

                if (!result.voucher ||  result.voucher.accountStatus != 4000140002) {
                    const inventorys = res[1]
                    this.handleCheckisEnable(result, form, other, data, isChange, details, inventorys, "initLoad")
                    this.handleRequireCheck(form, details, inventorys)
                   
                    sfObj['data.other.inventorys'] = fromJS(res[1])
                } else {
                    sfObj['data.error'] = fromJS({})
                }
            }else {
                response = this.handleDefalutDate(response)
                sfObj['data.error'] = fromJS({})
            }
            sfObj['data.other.auditVisible'] = false
            this.metaAction.sfs(sfObj)
            this.injections.reduce('initLoad', response)
        }
    }

    handleRequireCheck = (form, details, inventorys) => {
        const param = form.supplierId
        const sfObj = {}
        sfObj[`data.error`] = fromJS({})

        if (form.accountStatus != 4000140002) {
            if (!param) {
                sfObj[`data.error.supplier`] = '请选择销方名称'
            } else {
                let voucherList = this.metaAction.gf(`data.other.supplier`)
                if (voucherList) {
                    voucherList = voucherList.toJS()
                    let selected = voucherList.find(o => {
                        if (o.id == param) {
                            return true
                        } else {
                            return false
                        }
                    })
    
                    if (!selected) {
                        sfObj[`data.error.supplier`] = '请选择销方名称'
                    } else {
                        sfObj[`data.error.supplier`] = undefined
                    }
                }
            }
            if (details && details.length != 0) {
                let selecteds = null
                let currentIndex = null
                details = details.filter(o => o.amount || o.taxRateId || o.inventoryId || o.businessTypeId)
                details.forEach((obj, index) => {

                    if (!obj.propertyName) {
                        sfObj[`data.error.${index}.propertyName`] = '请选择业务类型'
                    } else {
                        sfObj[`data.error.${index}.propertyName`] = undefined
                    }

                    if (!obj.inventoryId && !obj.businessTypeId) {
                        sfObj[`data.error.${index}.inventory`] = '请选择存货名称'
                    } else {
                        if (obj.inventoryId || obj.businessTypeId) {
                            if (inventorys && inventorys.length != 0) {
                                inventorys.find((item, key) => {
                                    if (item.id == obj.inventoryId || item.id == obj.businessTypeId) {
                                        selecteds = true
                                        return true
                                    } else {
                                        currentIndex = index
                                        selecteds = false
                                        return false
                                    }
                                })
                            }
                        }
                        if (!selecteds) {
                            if (currentIndex != null) {
                                sfObj[`data.error.${currentIndex}.inventory`] = '请选择存货名称'
                            } else {
                                sfObj[`data.error.${currentIndex}.inventory`] = undefined
                            }
                        }
                    }
                })
            }
        } 
        
        this.metaAction.sfs(sfObj)
    }

    handleDefalutDate = (params) => {
        const currentOrg = this.metaAction.context.get("currentOrg")
        let periodDate = currentOrg.periodDate
        if (periodDate) {
            let monthDate = utils.date.monthStartEndDay(periodDate)
            params.voucher.businessDate = monthDate.endDay ? monthDate.endDay : moment().format('YYYY-MM-DD')
            params.voucher.invoiceDate = monthDate.endDay ? monthDate.endDay : moment().format('YYYY-MM-DD')
            params.voucher.authenticatedMonth = monthDate.endDay ? monthDate.endDay : moment().format('YYYY-MM')
        } else {
            params.voucher.businessDate = moment().format('YYYY-MM-DD')
            params.voucher.invoiceDate = moment().format('YYYY-MM-DD')
            params.voucher.authenticatedMonth = moment().format('YYYY-MM')
        }

        return params
    }

    handleCheckisEnable = async (result, form, other, data, isChange, details, inventorys, type) => {
        const fileArr = [
            { label: 'supplier', name: 'Supplier' },
            { label: 'department', name: 'Department' },
            // { label: 'purchasePerson', name: 'Person' },
            { label: 'project', name: 'Project' },
            { label: 'bankAccount', name: 'BankAccount' },
            // {label: 'inventory', name: "Inventory"}
        ]

        if (result.beginDate && other.beginDate && result.beginDate.replace(/-/g, '') != other.beginDate.replace(/-/g, '')) {
            isChange = true
            other.beginDate = result.beginDate
        }
        for (let i = 0; i < fileArr.length; i++) {
            const item = fileArr[i]
            const param = item.label == 'bankAccount' ? other[item.label] : other[item.label] && form[`${item.label}Id`]
            if (param) { //找出点击并选择了的档案这样就可以减少没有必要的更新
                if (type != 'initLoad') {
                    await this.voucherAction[`get${item.name}`]({ entity: { isEnable: true } }, `data.other.${item.label}`)
                }

                let voucherList = this.metaAction.gf(`data.other.${item.label}`)

                if (voucherList) {
                    voucherList = voucherList.toJS()
                    let selected = voucherList.find(o => {
                        if (o.id == form[`${item.label}Id`]) {
                            return true
                        } else {
                            return false
                        }
                    })

                    if (item.label == 'bankAccount') {
                        form.settles.forEach(obj => {
                            voucherList.find(item => {
                                if (obj.bankAccountId == item.id) {
                                    selected = true
                                    return true
                                } else {
                                    selected = false
                                    return false
                                }
                            })

                            if (!selected) {
                                obj.bankAccountId = ''
                            }
                        })
                    }
                    if (!selected) {
                        other[item.label] = voucherList
                        delete form[`${item.label}Id`]
                        delete form[`${item.label}Name`]
                        data.other = other
                        if (result.voucher.ts) form.ts = result.voucher.ts
                        if (result.voucher.accountStatus) form.accountStatus = result.voucher.accountStatus
                        data.form = form
                        // result.voucher = form
                        isChange = true
                    }
                }
            }

            if (details && details.length != 0) {
                let selecteds = null
                let currentIndex = null
                details.forEach((obj, index) => {
                    if (obj.inventoryId || obj.businessTypeId) {
                        if (inventorys && inventorys.length != 0) {
                            inventorys.find((item, key) => {
                                // if (item.id == (obj.inventoryId || obj.id) || item.id == (obj.businessTypeId || obj.id)) {
                               
                                if (item.id == obj.inventoryId || item.id == obj.businessTypeId) {
                                    selecteds = true
                                    if (!form.id) {
                                        if (item.specification != obj.specification) {
                                            obj.specification = item.specification
                                            isChange = true
                                        } 
                                        // else {
                                        //     isChange = false
                                        // }
                                        if (item.unitId != obj.unitId) {
                                            obj.unitId = item.unitId
                                            obj.unitName = item.unitName
                                            isChange = true
                                        } 
                                        // else {
                                        //     isChange = false
                                        // }
                                    }
                                    
                                    return true
                                } else {
                                    currentIndex = index
                                    selecteds = false
                                    return false
                                }
                                
                            })
                        }
                    }
                    if (!selecteds) {
                        if (currentIndex != null) {
                            if (details[currentIndex].inventoryId) {
                                delete details[currentIndex].inventoryId
                            } else if (details[currentIndex].businessTypeId) {
                                delete details[currentIndex].businessTypeId
                            }

                            if (details[currentIndex].inventoryName) {
                                delete details[currentIndex].inventoryName
                            } else if (details[currentIndex].businessTypeName) {
                                delete details[currentIndex].businessTypeName
                            }
                            data.form.details = details
                            isChange = true
                        }
                    }
                })
            }
        }
        // if (data.form.ts != result.voucher.ts) { // 切换页签时 type == 'onTabFocus'
        //     data.form.ts = result.voucher.ts
        // }

        // isChange && this.metaAction.sf('data', fromJS(data))
        isChange && this.injections.reduce('updateState', 'data', fromJS(data))
        
    }

    enlargeClick = async (params) => {
        // this.getDom(true)
        this.getDom()
    }

    load = (voucher, vatTaxpayer) => {
        this.injections.reduce('load', voucher, vatTaxpayer)
    }

    getDom = (isNotInit) => {
        let content = document.getElementsByClassName("edfx-app-portal-content-main"),
            detailsDom = document.getElementsByClassName("ttk-scm-app-pu-invoice-card-form-details")[0],
            cardFormHead = document.getElementsByClassName("ttk-scm-app-pu-invoice-card-form-header")[0],
            card = content[0],
            cardHeight = card.clientHeight,
            value = [],
            data = this.metaAction.gf('data') && this.metaAction.gf('data').toJS(),
            details = data.form.details,
            length = details.length

        // const cardFormHeadHeight = cardFormHead&&cardFormHead.clientHeight ? cardFormHead&&cardFormHead.clientHeight : 106

        let cardFormHeadHeight = cardFormHead && cardFormHead.clientHeight
        let columnSetting = this.metaAction.gf('data.other.columnSetting')
        columnSetting = columnSetting && columnSetting.toJS()
        // let height = cardHeight - 220 - cardFormHeadHeight
        let height = cardHeight - 223 - cardFormHeadHeight
        
        // 因为需要前端自己从数组里面过滤哪些显示和不显示会有个时间
        // 如果这个数组还没拿过来就已经渲染了表格高度,这个高度就会计算错误
        if (!detailsDom || !cardFormHeadHeight || !columnSetting) {
            setTimeout(() => {
                this.renderNum = this.renderNum + 1
                return this.getDom()
            }, 100)
        } else {
            if (height < 110) { // 打开控制台的时候防止明细行数太少
                height = 109
            }
            const detailHeight = this.metaAction.gf('data.other.detailHeight')
            this.injections.reduce('updateState', 'data.other.detailHeight', height + 'px')

            if (!isNotInit) {
                if (card.length != 0) {
                    length = Math.ceil(height / 35) > 5 ? Math.ceil(height / 35) : 5
                    let details = this.metaAction.gf('data.form.details').toJS()

                    while (details.length < length-2) {
                        details.push(blankDetail)
                    }
                    this.injections.reduce('setrowsCount', details, details.length)
                }
            }
        }
    }

    componentDidMount = () => {
        this.getDom()
        const win = window
        if (win.addEventListener) {
            document.body.addEventListener('keydown', this.bodyKeydownEvent, false)
            win.addEventListener('resize', this.getDom, false)
        } else if (win.attachEvent) {
            document.body.attachEvent('onkeydown', this.bodyKeydownEvent)
            win.attachEvent('onresize', this.getDom)
        }

        setTimeout(() => {
            let header = document.getElementsByClassName('ttk-scm-app-pu-invoice-card-form-header')[0] //ReactDOM.findDOMNode(thisStub.refs.auxItem)
            let footer = document.getElementsByClassName('app-pu-arrival-card-form-footer-settlement')[0]
            if (header && footer) {
                if (header.addEventListener) {
                    header.addEventListener('keydown', (e)=>this.handleKeyDown(e, null, 'ttk-scm-app-pu-invoice-card-form-header'), false)
                    footer.addEventListener('keydown', (e)=>this.handleKeyDown(e, null, 'app-pu-arrival-card-form-footer-settlement'), false)
                } else if (header.attachEvent) {
                    header.attachEvent('onkeydown', (e)=>this.handleKeyDown(e, null, 'ttk-scm-app-pu-invoice-card-form-header'))
                    footer.attachEvent('onkeydown', (e)=>this.handleKeyDown(e, null, 'app-pu-arrival-card-form-footer-settlement'))
                } else {
                    header.onKeyDown = (e)=>this.handleKeyDown(e, null, 'ttk-scm-app-pu-invoice-card-form-header')
                    footer.onKeyDown = (e)=>this.handleKeyDown(e, null, 'app-pu-arrival-card-form-footer-settlement')
                }
            }
        }, 0)
    }

    componetWillUnmount = () => {
        const win = window
        if (win.removeEventListener) {
            document.body.removeEventListener('keydown', this.bodyKeydownEvent, false)
            win.removeEventListener('resize', this.getDom, false)
        } else if (win.detachEvent) {
            document.body.detachEvent('onkeydown', this.bodyKeydownEvent)
            win.detachEvent('onresize', this.getDom)
        }
    }
   
    bodyKeydownEvent = (e) => {
        const dom = document.getElementById('ttk-scm-app-pu-invoice-card')
        const modalBody = document.getElementsByClassName('ant-modal-body')
        if (dom && modalBody && modalBody.length < 1) {
            this.keyDownCickEvent({ event: e })
        }
    }

    keyDownAdd = async() => {
        const editing = this.metaAction.gf('data.other.auditVisible')
        if( !editing ) {
            const ret = await this.metaAction.modal('confirm', {
                content: '当前界面存在未保存数据,是否保存?'
            })
            if( ret ) {
                this.save(true)
            }else{
                this.initLoad()
                this.editCloseTips(false)
            }
        }else{
            this.initLoad()
            this.editCloseTips(false)
        }
        
    }

    //监听键盘事件
    keyDownCickEvent = (keydown) => {
        if (keydown && keydown.event) {
            let e = keydown.event
            if (e.ctrlKey && e.altKey && (e.key == 'n' || e.keyCode == 78)) { //新增
                // this.add()
                this.keyDownAdd()
                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()
                }
            }
        }
    }

    prev = async () => {
        const code = this.metaAction.gf('data.form.code')
        let list = [
            this.webapi.arrival.previous({ code, isReturnValue: true }),
            this.voucherAction.getSupplier({ entity: { isEnable: true } }, 'data.other.supplier'),
            this.voucherAction.getDepartment({ entity: { isEnable: true } }, `data.other.department`),
            this.voucherAction.getProject({ entity: { isEnable: true } }, `data.other.project`),
            this.voucherAction.getBankAccount({entity: { isEnable: true }}, `data.other.bankAccount`)
        ]
        const other = this.metaAction.gf('data.other').toJS()

        const res = await Promise.all(list)
        let response = res[0]
         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 {
                const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
                let details = response.details,
                settles = response.settles,
                data = this.metaAction.gf('data').toJS(),
                other = data.other,
                inventorys = this.metaAction.gf('data.other.inventorys').toJS()

                if (response.accountStatus != 4000140002) {
                    response = await this.handleCheckisEnableEasy(response, details, settles, other, inventorys, 'prev')
                }
                
                this.injections.reduce('updateState', 'data.other.nextDisalbed', false)
                this.load(response, vatTaxpayer)
                this.handleRequireCheck(response, details, inventorys)
            }
        }
       
    }

    next = async () => {
        const code = this.metaAction.gf('data.form.code')

        let list = [
            this.webapi.arrival.next({ code, isReturnValue: true }),
            this.voucherAction.getSupplier({ entity: { isEnable: true } }, 'data.other.supplier'),
            this.voucherAction.getDepartment({ entity: { isEnable: true } }, `data.other.department`),
            this.voucherAction.getProject({ entity: { isEnable: true } }, `data.other.project`),
            this.voucherAction.getBankAccount({entity: { isEnable: true }}, `data.other.bankAccount`)
        ]
        const other = this.metaAction.gf('data.other').toJS()

        const res = await Promise.all(list)
        let response = res[0]
         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 {
                const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
                let details = response.details,
                settles = response.settles,
                data = this.metaAction.gf('data').toJS(),
                other = data.other,
                inventorys = this.metaAction.gf('data.other.inventorys').toJS()

                // response = await this.handleCheckisEnableEasy(response, details, settles, other, inventorys, 'next')
                if (response.accountStatus != 4000140002) {
                    response = await this.handleCheckisEnableEasy(response, details, settles, other, inventorys, 'prev')
                }
                this.injections.reduce('updateState', 'data.other.prevDisalbed', false)
                this.load(response, vatTaxpayer)
                this.handleRequireCheck(response, details, inventorys)
            }
        }
    }

    setting = async () => {
        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
            }

            if (setting.header) {
                obj.option = setting.header.cards
            }

            let detailObj = {}
            const objItem = setting.body.tables[0]
            if (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,
            footer: null,
            children: <ColumnsSetting
                option={initOption}
                singleKey='id'
                sort={false}
                editName={false}
                checkedKey='isVisible'
                labelKey="caption"
            />
        })

        if (res && res.type == 'confirm') {
            await this.handleConfirmSet(res.option)
            this.getDom(true)
        } else if (res && res.type == 'reset') {
            await this.handleResetSet(setting.code)
            this.getDom(true)
        }

    }
    //设置 恢复默认设置
    handleResetSet = async (code) => {
        if (code) {
            const result = await this.webapi.arrival.reInitByUser({ code: code })
            this.injections.reduce('updateState', 'data.other.columnSetting', fromJS(result))
            this.getDom(true)
        }
    }
    //设置 确定
    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.arrival.updateWithDetail(setting)
            this.injections.reduce('updateState', 'data.other.columnSetting', fromJS(result))
        }
    }


    add = async () => {
        const res = await this.metaAction.modal('confirm', {
            title: '放弃',
            content: '点击放弃会重置你所有的操作,确定要放弃吗?',
        })
        if (res) {
            this.initLoad()
        }
    }

    handleCheckisEnableEasy = async (response, details, settles, other, inventorys, type) => {
        const fileArr = [
            { label: 'supplier', name: 'Supplier' },
            { label: 'department', name: 'Department' },
            { label: 'project', name: 'Project' },
            { label: 'bankAccount', name: 'BankAccount' },
        ]

        for (let i = 0; i < fileArr.length; i++) {
            const item = fileArr[i]
            const param = item.label == 'bankAccount' ? other[item.label] : other[item.label] && response[`${item.label}Id`]
            if (param) {
                if (type == 'audit') {
                    await this.voucherAction[`get${item.name}`]({ entity: { isEnable: true } }, `data.other.${item.label}`)
                }

                let voucherList = this.metaAction.gf(`data.other.${item.label}`)

                if (voucherList) {
                    voucherList = voucherList.toJS()
                    let selected = voucherList.find(o => {
                        if (o.id == response[`${item.label}Id`]) {
                            return true
                        } else {
                            return false
                        }
                    })

                    if (item.label == 'bankAccount') {
                        settles.forEach(obj => {
                            voucherList.find(item => {
                                if (obj.bankAccountId == item.id) {
                                    selected = true
                                    return true
                                } else {
                                    selected = false
                                    return false
                                }
                            })

                            if (!selected) {
                                obj.bankAccountId = ''
                            }
                        })
                    }
                    if (!selected) {
                        other[item.label] = voucherList
                        delete response[`${item.label}Id`]
                        delete response[`${item.label}Name`]
                    }
                }
            }
        }

        if (details && details.length != 0) {
            let selecteds = null
            let currentIndex = null
            details.forEach((obj, index) => {
                if (obj.inventoryId || obj.businessTypeId) {
                    if (inventorys && inventorys.length != 0) {
                        inventorys.find((item, key) => {
                            if (item.id == obj.inventoryId || item.id == obj.businessTypeId) {
                                selecteds = true
                                return true
                            } else {
                                currentIndex = index
                                selecteds = false
                                return false
                            }
                        })
                    }
                }
                console.log(selecteds, currentIndex)
                if (!selecteds) {
                    if (currentIndex != null) {
                        if (details[currentIndex].inventoryId) {
                            delete details[currentIndex].inventoryId
                        } else if (details[currentIndex].businessTypeId) {
                            delete details[currentIndex].businessTypeId
                        }

                        if (details[currentIndex].inventoryName) {
                            delete details[currentIndex].inventoryName
                        } else if (details[currentIndex].businessTypeName) {
                            delete details[currentIndex].businessTypeName
                        }
                        response.details = details
                    }

                }
            })
        }

        return response
    }

    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) {
            if (! await this.checkForSave()) return
            const response = await this.webapi.arrival.audit({ id, ts })
            if (response) {
                this.metaAction.toast('success', '单据生成凭证成功')
                this.load(response)
            }
        } else {

            const list =[
                // this.webapi.arrival.unaudit({ id, ts, isReturnValue: true }),
                this.webapi.arrival.unaudit({ id, ts}),
                this.webapi.arrival.queryInventory()
            ]
            const res = await Promise.all(list)
            let response = res[0]
            const inventorys = res[1]
            if (response) {
                // if (response.result == false && response.error) {
                //     this.metaAction.toast('error', response.error.message)
                // } else {
                    // this.metaAction.toast('success', '单据删除凭证成功')

                    let form = response,
                    details = response.details,
                    settles = response.settles,
                    data = this.metaAction.gf('data').toJS(),
                    other = data.other,
                    sfObj= {}

                    response = await this.handleCheckisEnableEasy(response, details, settles, other, inventorys, 'audit')
                    this.metaAction.toast('success', '单据删除凭证成功')

                    this.load(response)
                    this.handleRequireCheck(response, details, inventorys)
                    sfObj['data.other.inventorys'] = fromJS(inventorys)
                    const allMessage = this.metaAction.gf('data.other.allMessage') && this.metaAction.gf('data.other.allMessage').toJS()

                    if (allMessage) {
                        sfObj['data.other.isSignAndRetreat'] = allMessage.isSignAndRetreat
                    }

                    this.metaAction.sfs(sfObj)
                // }
            }
        }
    }

    getAuditBtnText = () => {
       
        const accountStatus = this.metaAction.gf('data.other.accountStatus')
        return accountStatus == 4000140002 ? '删除凭证' : '生成凭证'
    }

    history = async () => {
        this.component.props.setPortalContent('进项', 'ttk-scm-app-pu-invoice-list')
    }

    moreMenuClick = (e) => {
        switch (e.key) {
            case 'del':
                this.del()
                break
            // case 'generateReturn':
            //     this.generateReturn()
            //     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) {
            if (id) {
                const response = await this.webapi.arrival.del({ id, ts })
                if (response) {
                    this.metaAction.toast('success', '删除单据成功')
                    this.initLoad()
                }
            } else {
                this.initLoad()
                this.metaAction.toast('success', '删除单据成功')
            }
        }
    }

    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
        }
    }

    pay = () => {
        const data = this.metaAction.gf('data').toJS()
        data.form.details = data.form.details.filter(o => o.amount)
        let details = data.form.details.map((item) => {
            return {
                businessTypeId: 3001002001001,
                supplierId: data.form.supplierId,
                departmentId: data.form.departmentId,
                personId: data.form.personId,
                projectId: data.form.projectId,
                amount: item.amount,
                fees: null,
                remark: null
            }
        })
        const obj = {
            businessDate: data.form.businessDate,
            // bankAccountId: data.form.bankAccountId,
            summary: null,
            remark: data.form.remark,
            details: details,
            attachments: data.form.attachments
        }
        this.component.props.setPortalContent &&
            this.component.props.setPortalContent(
                '付款单',
                'ttk-scm-app-payment-card',
                { accessType: 1, obj }
            )
    }

    save = async (isNew) => {
        if (! await this.checkForSave()) return
        let form = this.metaAction.gf('data.form').toJS()
        if (form.details) {
            form.details = form.details.filter(detail => {
                return (detail.inventoryId || detail.taxRate || detail.amount)
            })
        }

        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 { attachmentFiles, ...otherParmas } = form
        let params = {
            ...otherParmas,
            attachments: attachmentFiles
        }

        //控制单价 数量 为零时为null
        for (var i = 0; i < params.details.length; i++) {
            if (params.details[i].price == 0 || !params.details[i].price) {
                params.details[i].price = null
            }
            if (params.details[i].quantity == 0 || !params.details[i].quantity) {
                params.details[i].quantity = null
            }
            if (params.details[i].taxInclusiveAmount == 0 || !params.details[i].taxInclusiveAmount) {
                params.details[i].taxInclusiveAmount = null
            }

            if (params.details[i].businessTypeId) {
                params.details[i].inventoryId = null

                params.details[i].inventoryName = null
                params.details[i].inventoryCode = null
            } else {
                params.details[i].businessTypeId = null

                params.details[i].businessTypeName = null
                params.details[i].businessTypeCode = null
                
            }

            if (!params.details[i].unitId) {
                params.details[i].unitId = null
            }

            if (!params.details[i].specification) {
                params.details[i].specification = null
            }
        }
        const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
        if (vatTaxpayer == 2000010001 && !params.signAndRetreat) {
            params.signAndRetreat = 4000100002
        }

        // let isChangeProperties = null
        // console.log(params, 'params')

        // params.details.find(obj => { //只能判断由费用变为其他的 存货之间的改变判断不出来
        //     if (obj.propertyId != 4001001 && (obj.businessTypeId && !obj.inventoryId)) {
        //         isChangeProperties = true
        //         return true
        //     } else {
        //         return false
        //     }
        // })
        delete params.inventorys
        if (params.id || params.id == 0) {
            // const response = await this.webapi.arrival.update(params)
            // if (response) {
            //     this.metaAction.toast('success', '保存更新成功')
            //     if (!isNew) {
            //         this.load(response)
            //     } else {
            //         this.initLoad()
            //     }
            // }
            
            // const response = await this.webapi.arrival.update(params)
            // if (response) {
            //     let result = null
            //     if (isChangeProperties) {
            //         result = await this.webapi.arrival.queryInventory()
            //         if (result) {
            //             response.inventorys = result
            //         }
            //     }
            //     this.metaAction.toast('success', '保存更新成功')
            //     if (!isNew) {
            //         this.load(response)
            //     } else {
            //         this.initLoad()
            //     }
            // }
            const response = await this.webapi.arrival.update(params)
            if (response) {
                // if (isChangeProperties) {
                let result = await this.webapi.arrival.queryInventory()
                if (result) {
                    response.inventorys = result
                }
                // }
                this.metaAction.toast('success', '保存更新成功')
                if (!isNew) {
                    this.load(response)
                } else {
                    this.initLoad()
                }
            }
        } else {
            // const response = await this.webapi.arrival.create(params)
            // if (response) {
            //     this.metaAction.toast('success', '保存单据成功')
            //     if (!isNew) {
            //         this.load(response)
            //     } else {
            //         this.initLoad()
            //     }
            // }

            // const response = await this.webapi.arrival.create(params)
            // if (response) {
            //     let result = null
            //     if (isChangeProperties) {
            //         result = await this.webapi.arrival.queryInventory()
            //         if (result) {
            //             response.inventorys = result
            //         }
            //     }
            //     this.metaAction.toast('success', '保存单据成功')
            //     if (!isNew) {
            //         this.load(response)
            //     } else {
            //         this.initLoad()
            //     }
            // }
            const response = await this.webapi.arrival.create(params)
            if (response) {
                // if (isChangeProperties) {
                let result = await this.webapi.arrival.queryInventory()
                if (result) {
                    response.inventorys = result
                }
                // }
                this.metaAction.toast('success', '保存单据成功')
                if (!isNew) {
                    this.load(response)
                } else {
                    this.initLoad()
                }
            }
        }
        this.editCloseTips(false)
    }

    // 存货名称
    renderSelectOption = (index, data) => {
        const inventorys = this.metaAction.gf('data.other.inventorys') && this.metaAction.gf('data.other.inventorys').toJS() || []
        const propertyId = data.propertyId
        const propertyName = data.propertyName
        let list = []
        if (propertyId || propertyName) {
            list =inventorys.filter(o => (o.propertyId == propertyId || o.propertyName == propertyName))
            return(
                list.map((item) => {
                    const name = item.fullName ? item.fullName : `${item.code} ${item.name}`
                    return <Option key={item.id} value={item.id} title={item.name}>{name}</Option>
                })
            )
        } else {
            return(
                inventorys.map((item) => {
                    const name = item.fullName ? item.fullName : `${item.code} ${item.name}`
                    return <Option key={item.id} value={item.id} title={item.name}>{name}</Option>
                })
            )
        }

        const resList = list.length != 0 ? list : inventorys
        this.metaAction.sf('data.other.inventory', fromJS(resList))
    }

    getList = ({ vatTaxpayer, taxRate , taxRateName, taxRateTypeList}) => {
        let list = vatTaxpayer == '2000010001' ? taxRateTypeList :  [{id: 3000070002, name: "简易征收", code: "simple"}]
        if (vatTaxpayer == '2000010001' && (taxRate || taxRate == 0)) {
            if (taxRate == 0) {
                list = [{id: 3000070005, name: "免税", code: "mianshui"},
                {id: 3000070004, name: "免抵退", code: "mdt"}]

            } else if (taxRate > 0.06){
                list = [{id: 3000070001, name: "一般计税", code: "general"}]
            } else if (taxRate > 0 && taxRate <= 0.06) {
                if (taxRate == 0.06 || (taxRate == 0.03 && taxRateName == '3%')) {
                    list = [{id: 3000070002, name: "简易征收", code: "simple"},{id: 3000070001, name: "一般计税", code: "general"}]
                } else {
                    list = [{id: 3000070002, name: "简易征收", code: "simple"}]
                }
            }
        } else if (vatTaxpayer == '2000010002' && (taxRate || taxRate == 0)) {
            if (taxRate == 0) {
                list = [{id: 3000070002, name: "简易征收", code: "simple"},{id: 3000070005, name: "免税", code: "mianshui"}]
            } else {
                list = [{id: 3000070002, name: "简易征收", code: "simple"}]
            }
        }
        return list
    }
       // 计税方式
       renderTaxRateTypesSelect = (index, data, isChange) => {
        const taxRate = this.metaAction.gf(`data.form.details.${index}.taxRate`)
        const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
        const taxRateTypeList = this.metaAction.gf('data.other.taxRateType') && this.metaAction.gf('data.other.taxRateType').toJS()
        const taxRateName = this.metaAction.gf(`data.form.details.${index}.taxRateName`)
        let list = []
        if (taxRate || taxRate == 0) {
            if (isChange) {
                if (vatTaxpayer == '2000010001' && (taxRate || taxRate == 0)) {
                    if (taxRate == 0) {
                        this.metaAction.sfs({
                            [`data.form.details.${index}.taxRateType`]: 3000070005,
                            [`data.form.details.${index}.taxRateTypeName`]: '免税'
                        })
                    } else if (taxRate > 0.06){
                        this.metaAction.sfs({
                            [`data.form.details.${index}.taxRateType`]: 3000070001,
                            [`data.form.details.${index}.taxRateTypeName`]: '一般计税'
                        })
                    } else if (taxRate > 0 && taxRate <= 0.06) {
                        this.metaAction.sfs({
                            [`data.form.details.${index}.taxRateType`]: 3000070002,
                            [`data.form.details.${index}.taxRateTypeName`]: '简易征收'
                        })
                    }
                } else if(vatTaxpayer == '2000010002' && (taxRate || taxRate == 0)){
                    this.metaAction.sfs({
                        [`data.form.details.${index}.taxRateType`]: 3000070002,
                        [`data.form.details.${index}.taxRateTypeName`]: '简易征收'
                    })
                }
            } else {
                list = this.getList({ vatTaxpayer, taxRate , taxRateName, taxRateTypeList})
            }
        } else {
            // list = taxRateTypeList
            list= vatTaxpayer == '2000010001' ? taxRateTypeList : [{id: 3000070002, name: "简易征收", code: "simple"}]
        }
        return list.map((item) => {
            return <Option key={item.id} value={item.id}>{item.name}</Option>
        })
    }

    //根据选择的供应商来得到对应的现结账户
    // supplierChange = async (value) => {
    //     const supplierId = value && value.toJS().id
    //     const response = await this.webapi.arrival.queryBySupplier({ supplierId })

    //     let settles = this.metaAction.gf('data.form.settles')
    //     settles = settles && settles.toJS()
    //     // 若在选择供应商之前添加了现结账户,将改动第一个
    //     settles.splice(0,1,{
    //         bankAccountId: response.bankAccountId,
    //         bankAccountName: response.bankAccountName,
    //         amount: ''
    //     })

    //     if (response) {
    //         this.metaAction.sf('data.form.settles', fromJS(settles))
    //     }
    // }

    getFocusInventory = async (index, data) => {
        const propertyId = data.propertyId
        const propertyName = data.propertyName
        const id = this.component.props.id || null

        if (!propertyId && !propertyName) {
            const res = await this.webapi.arrival.queryInventory({ id: id })
            if (res) {
                this.metaAction.sfs({
                    'data.other.inventorys': fromJS(res),
                    'data.other.inventory': fromJS(res)
                })
            }
        } else {
            const inventoryId = data.inventoryId || data.businessTypeId
            let inventoryList = this.metaAction.gf('data.other.inventorys') && this.metaAction.gf('data.other.inventorys').toJS() || []
            inventoryList = inventoryList.filter(o => (o.propertyId == propertyId || o.propertyName == propertyName))

            let sfObj = {}
            if (inventoryId) {
                const isHave = inventoryList.find(obj => {
                    if (obj.id == inventoryId) {
                        return true
                    } else {
                        return false
                    }
                })

                if (!isHave) {
                    const obj = fromJS(blankDetail).toJS()
                    obj.propertyId = propertyId ? propertyId : null
                    obj.propertyName = data.propertyName ? data.propertyName : null
                    sfObj[`data.form.details.${index}`] = fromJS(obj)
                }
            }
            sfObj['data.other.inventory'] = fromJS(inventoryList)

            this.metaAction.sfs(sfObj)
        }
    }

    renderPayDiv = () => {
        let settles = this.metaAction.gf('data.form.settles')
        settles = settles ? settles.toJS() : []

        const bankAccount = this.metaAction.gf('data.other.bankAccount'),
            bankAccountName = this.metaAction.gf('data.form.bankAccountName'),
            paymentAmount = this.metaAction.gf('data.form.paymentAmount'),
            isDisableBank = this.metaAction.gf('data.other.isDisableBank'),
            error = this.metaAction.gf('data.error') && this.metaAction.gf('data.error').toJS(),
            form = this.metaAction.gf('data.form').toJS()

        return settles.map((item, index) => {
            const errorObj = error[index] ? error[index] : {}
            const customAttribute = this.metaAction.gf('data.other.customAttribute')
            return <div key={index}>
                <Form className='app-pu-arrival-card-form-footer-settlement'>
                    <FormItem label='现结账户' validateStatus={errorObj.bankAccount ? 'error' : 'success'}>
                        <Select
                            className="autoFocus_item"
                            showSearch={false}
                            allowClear={item.bankAccountId && String(item.bankAccountId) ? true : false}
                            disabled={this.getDisable()}
                            placeholder='请选择账户'
                            getPopupContainer={()=> document.querySelector('.edfx-app-portal-content-main')}
                            // value={item.bankAccountId ? String(item.bankAccountId) : undefined}
                            value={this.renderInventoryName(String(item.bankAccountId), `data.other.bankAccount`, item.bankAccountName)}
                            onFocus={() => this.voucherAction.getBankAccount({entity: { isEnable: true }}, `data.other.bankAccount`)}
                            onChange={this.onFieldChange({ id: `data.form.bankAccountId`, name: `data.form.bankAccountName` }, `data.other.bankAccount`, null, null, index)}
                        >
                            {this.handleSelect(bankAccount)}
                        </Select>
                    </FormItem>
                    <FormItem label='现结金额' validateStatus={errorObj.amount ? 'error' : 'success'} style={{marginLeft: '15px'}}>
                        <Input.Number
                            className="autoFocus_item"
                            disabled={this.getDisable()}
                            // value={item.amount}
                            value={item.amount && Number(item.amount).toFixed(2)}
                            precision={2}
                            executeBlur={true}
                            customAttribute={customAttribute}
                            onBlur={(v) => this.handlePayBlur(v, index)}
                        ></Input.Number>
                    </FormItem>
                    <div className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv'>
                        <Icon
                            type='plus'
                            title='新增'
                            className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv-iconAdd'
                            disabled={this.getDisable()}
                            style={{cursor: 'pointer'}}
                            onClick={this.addPaymentAmount}></Icon>
                        <Icon
                            type='minus'
                            title='删除'
                            // disabled={(index == 0) ? true : false} 
                            disabled={(settles.length == 1 ? true : false) || this.getDisable()}
                            style={{cursor: 'pointer'}}
                            className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv-iconDel'
                            onClick={this.delPaymentAmount.bind(null, index)}></Icon>
                    </div>
                </Form>
            </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,")
    }

    //现结金额失去焦点 才改变剩余金额
    handlePayBlur = (v, index) => {
        let settles = this.metaAction.gf('data.form.settles')
        settles = settles ? settles.toJS() : []
        let sfObj = {}
        if (v !== '') {
            v = v.toFixed(2)
        }
        if (settles.length == 0) {
            const obj = {
                bankAccountId: '',
                amount: v,
                bankAccountName: '',
            }
            settles.push(obj)
        } else {
            settles[index].amount = v
            sfObj[`data.error.${index}.amount`] = undefined
        }

        sfObj["data.form.paymentAmount"] = v
        sfObj["data.form.settles"] = fromJS(settles)
        sfObj["data.other.auditVisible"] = false
        sfObj["data.other.customAttribute"] = Math.random()

        this.metaAction.sfs(sfObj)
    }

    handleComCheck = (checkArr, errorList, ishasError) => {
        const authenticated = this.metaAction.gf('data.form.authenticated')
        const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
        const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')

        for (let obj of checkArr) {
            if (obj.path == 'data.form.supplierId') {
                if (!obj.value) {
                    errorList.push({
                        errorPath: 'data.error.supplier', message: '请选择销方名称'
                    })
                    ishasError = true
                } else {
                    errorList.push({
                        errorPath: 'data.error.supplier', message: undefined
                    })
                }
            } else if (obj.path == 'data.form.businessDate') {
                if (!obj.value) {
                    errorList.push({
                        errorPath: 'data.error.businessDate', message: '请选择记账日期'
                    })
                    ishasError = true
                } else {
                    errorList.push({
                        errorPath: 'data.error.businessDate', message: undefined
                    })
                }
            } else if (obj.path == 'data.form.invoiceTypeId') {
                if (!obj.value) {
                    errorList.push({
                        errorPath: 'data.error.invoiceType', message: '请选择发票类型'
                    })
                    ishasError = true
                } else {
                    errorList.push({
                        errorPath: 'data.error.invoiceType', message: undefined
                    })
                }
            } else if (obj.path == 'data.form.authenticatedMonth') {
                // 4000010900 其他发票
                // 4000010010 增值税普通发票
                //4000010030 农产品发票
                if (authenticated && vatTaxpayer== '2000010001' && (invoiceTypeId != 4000010030 && invoiceTypeId != 4000010010 && invoiceTypeId != 4000010900)) {
                    if (!obj.value) {
                        errorList.push({
                            errorPath: 'data.error.authenticatedMonth', message: '请选择认证月份'
                        })
                        ishasError = true
                    } else {
                        errorList.push({
                            errorPath: 'data.error.authenticatedMonth', message: undefined
                        })
                    }
                }
            } else if (obj.path == 'data.form.invoiceNumber') {
                if (!authenticated && vatTaxpayer== '2000010001' && (invoiceTypeId != 4000010030 && invoiceTypeId != 4000010010 && invoiceTypeId != 4000010900)) {
                    if (!obj.value) {
                        errorList.push({
                            errorPath: 'data.error.invoiceNumber', message: '请填写发票号码'
                        })
                        ishasError = true
                    } else {
                        errorList.push({
                            errorPath: 'data.error.invoiceNumber', message: undefined
                        })
                    }
                }
            } else if (obj.path == 'data.form.invoiceCode') {
                if (!authenticated && vatTaxpayer== '2000010001' && (invoiceTypeId != 4000010030 && invoiceTypeId != 4000010010 && invoiceTypeId != 4000010900)) {
                    if (!obj.value) {
                        errorList.push({
                            errorPath: 'data.error.invoiceCode', message: '请填写发票代码'
                        })
                        ishasError = true
                    } else {
                        errorList.push({
                            errorPath: 'data.error.invoiceCode', message: undefined
                        })
                    }
                }
            }
        }

        return { errorList, ishasError }
    }

    handleCheck = async (checkArr, form, operate) => {
        if (checkArr && checkArr.length == 0) {
            return
        }
        let ishasError = false
        let errorList = []
        const forms = this.metaAction.gf('data.form').toJS()
        form = form ? form : forms
        if (operate == 'save') {
            const objRet = await this.handleComCheck(checkArr, errorList, ishasError)
            errorList = objRet.errorList ? objRet.errorList : errorList
            ishasError = objRet.ishasError != undefined ? objRet.ishasError : ishasError

            if (form.invoiceNumber && (form.invoiceNumber.length != 8)) {
                errorList.push({
                    errorPath: 'data.error.invoiceNumber', message: '发票号码位数错误'
                })
                ishasError = true
            }

            if (form.invoiceCode && form.invoiceCode.length != 10 && form.invoiceCode.length != 12) {
                errorList.push({
                    errorPath: 'data.error.invoiceCode', message: '发票代码位数错误'
                })
                ishasError = true
            }

            if (form.settles && form.settles.length != 0) {
                form.settles = form.settles.filter((item) => {
                    return item.bankAccountId || item.amount
                })
                for (let i = 0; i < form.settles.length; i++) {
                    if (!form.settles[i].bankAccountId && Number(form.settles[i].amount)) {
                        errorList.push({
                            errorPath: `data.error.${i}.bankAccount`, message: '请选择现结账户'
                        })
                        ishasError = true
                    }

                    if (form.settles[i].bankAccountId && !Number(form.settles[i].amount)) {
                        errorList.push({
                            errorPath: `data.error.${i}.amount`, message: '请输入现结金额'
                        })
                        ishasError = true
                    }

                    if (!form.settles[i].bankAccountId && form.settles[i].amount == 0) {
                        errorList.push({
                            errorPath: `data.error.${i}.amount`, message: '现结金额不能为零'
                        })
                        ishasError = true
                    }
                }
            }
        } else {

            const objRet = await this.handleComCheck(checkArr, errorList, ishasError)
            errorList = objRet.errorList ? objRet.errorList : errorList
            ishasError = objRet.ishasError != undefined ? objRet.ishasError : ishasError
        }
        if (errorList.length != 0) {
            let json = {}
            errorList.forEach(item => {
                json[item.errorPath] = item.message
            })
            this.metaAction.sfs(json)
        }
        return ishasError
    }

    checkForSave = async () => {
        const form = this.metaAction.gf('data.form').toJS(),
            chargeAmount = this.metaAction.gf('data.other.chargeAmount'),
            isDisableBank = this.metaAction.gf('data.other.isDisableBank'),
            taxInclusiveAmount = this.metaAction.gf('data.other.taxInclusiveAmount'),
            payAmount = this.metaAction.gf('data.other.payAmount'),
            other = this.metaAction.gf('data.other').toJS()

        let isPassCheck = await this.handleCheck([{
            path: 'data.form.supplierId', value: form.supplierId
        }, {
            path: 'data.form.businessDate', value: form.businessDate
        }, {
            path: 'data.form.invoiceTypeId', value: form.invoiceTypeId
        }, {
            path: 'data.form.authenticatedMonth', value: form.authenticatedMonth
        }, {
            path: 'data.form.invoiceNumber', value: form.invoiceNumber
        }, {
            path: 'data.form.invoiceCode', value: form.invoiceCode
        }], form, 'save')

        // if (isPassCheck) {
        //     return false
        // }

        let msg = this.voucherAction.checkSaveInvoice(form, 'pu', other)
        if (msg.length > 0) {
            // this.voucherAction.showMsg(msg)
            this.metaAction.toast('error', this.getDisplayErrorMSg(msg))
            return false
        }

        let otherErrorMsg = this.voucherAction.checkSaveOtherInvoice(form)
        if (otherErrorMsg.length > 0) {

            this.metaAction.toast('error', this.getDisplayErrorMSg(otherErrorMsg))
            return false
        }
        if (taxInclusiveAmount * payAmount < 0) {
            this.metaAction.toast('error', '现结金额和明细金额正负不一致')
            return false
        }

        // if (Number(chargeAmount) < 0 && !isDisableBank) { //当不是退货 剩余金额小于0时
        //     this.metaAction.toast('error', '现结金额不能大于价税合计金额')
        //     return false
        // }

        if (payAmount > taxInclusiveAmount && taxInclusiveAmount > 0 && payAmount > 0) {
            this.metaAction.toast('error', '现结金额不能大于价税合计金额')
            return false
        }

        if (payAmount < taxInclusiveAmount && taxInclusiveAmount < 0 && payAmount < 0) {
            this.metaAction.toast('error', '现结金额不能小于价税合计金额')
            return false
        }

        return true
    }

    getDisplayErrorMSg = (msg) => {
        return <div style={{ display: 'inline-table' }}>{msg.map(item => <div style={{ textAlign: 'left' }}>{`· ${item}`}<br /></div>)}</div>
    }

    cancel = () => {
        this.injections.reduce('init')
    }

    onFieldChangePro = (field, storeField, rowIndex, rowData, label) => (id) => {
        if (storeField == 'data.other.properties') {
            field={
                propertyId:`data.form.details.${rowIndex}.propertyId`,
                propertyName:`data.form.details.${rowIndex}.propertyName`,
            }
        }
        if (!field || !storeField) return
        label = label || 'id'
        let value = this.metaAction.gf(storeField).find(o => o.get(label) == id)
        let sfObj = {}
        
        if (value) {
            Object.keys(field).forEach(key => {
                // this.injections.reduce('updateState', field[key], value.get(key))
                sfObj[field[key]] = value.get(key)
            })

            if (value.get('propertyId') == 4001001 && rowData.inventoryId) {
                sfObj[`data.form.details.${rowIndex}.inventoryId`] = null
                sfObj[`data.form.details.${rowIndex}.inventoryName`] = null
                sfObj[`data.form.details.${rowIndex}.inventoryCode`] = null
                sfObj[`data.form.details.${rowIndex}.taxRate`] = null
                sfObj[`data.form.details.${rowIndex}.taxRateId`] = null
                sfObj[`data.form.details.${rowIndex}.taxRateName`] = null
                // sfObj[`data.form.details.${rowIndex}.unitId`] = null 
                // sfObj[`data.form.details.${rowIndex}.unitName`] = null
                // sfObj[`data.form.details.${rowIndex}.specification`] = null
            }

            if (storeField == 'data.other.properties') {
                const inventorys = this.metaAction.gf('data.other.inventorys').toJS()
                const filterInventory = inventorys.filter(o => o.propertyId == value.get('propertyId'))

                sfObj['data.other.inventory'] = fromJS(filterInventory)
                sfObj[`data.error.${rowIndex}.propertyName`] = undefined
            }
        } else {
            Object.keys(field).forEach(key => {
                // this.injections.reduce('updateState', field[key], null)
                sfObj[field[key]] = null
            })
        }
       
        let details = this.metaAction.gf('data.form.details').toJS()
        if (details.length - 1 == rowIndex) {
            details.push(blankDetail)
            sfObj['data.form.details'] = fromJS(details)
        }

        sfObj['data.other.auditVisible'] = false
        this.editCloseTips(true)
        this.metaAction.sfs(sfObj)
    }

    renderInventoryName = (value, name, nameValue) => {
        const inventory = this.metaAction.gf(name) && this.metaAction.gf(name).toJS()
        const accountStatus = this.metaAction.gf('data.other.accountStatus')
        if (accountStatus == 4000140002 && value) {
            return nameValue
        } else {
            let isHave = false
            if (inventory && inventory.length !=0) {
                inventory.find(obj => {
                    if ( obj.id == value) {
                        isHave = true
                        return true
                    } else {
                        isHave = false
                        return false
                    }
                })
            }
    
            if (isHave) {
                return value
            } else {
                return undefined
            }
        }
    }

    onFieldChange = (field, storeField, rowIndex, rowData, index, type, paramsObj) => (id) => {
        if (storeField == 'data.other.inventory') {
            if (!field) {
                field = {
                    id: `data.form.details.${rowIndex}.inventoryId`,
                    name: `data.form.details.${rowIndex}.inventoryName`,
                    code: `data.form.details.${rowIndex}.inventoryCode`,
                    unitId: `data.form.details.${rowIndex}.unitId`,
                    unitName: `data.form.details.${rowIndex}.unitName`,
                    revenueType: `data.form.details.${rowIndex}.revenueType`,
                    revenueTypeName: `data.form.details.${rowIndex}.revenueTypeName`,
                    inventoryType: `data.form.details.${rowIndex}.inventoryType`,
                    inventoryTypeName: `data.form.details.${rowIndex}.inventoryTypeName`,
                    taxRateType: `data.form.details.${rowIndex}.taxRateType`,
                    taxRateTypeName: `data.form.details.${rowIndex}.taxRateTypeName`,
                    propertyId: `data.form.details.${rowIndex}.propertyId`,
                    propertyName: `data.form.details.${rowIndex}.propertyName`,
                    propertyDetailName: `data.form.details.${rowIndex}.propertyDetailName`,
                    specification: `data.form.details.${rowIndex}.specification`,
                }
            }
        }
        if(storeField == "data.other.inventoryTypes"){
            field = {
                id: `data.form.details.${rowIndex}.inventoryType`,
                name: `data.form.details.${rowIndex}.inventoryTypeName`,
            }
        }
        if(storeField == 'data.other.taxRateTypes'){
            field = {
                id: `data.form.details.${rowIndex}.taxRateType`,
                name: `data.form.details.${rowIndex}.taxRateTypeName`,
            }
        }
        if (!field || !storeField) return
        if (storeField == "data.other.taxRateTypes") {
            if (rowData.taxRate || rowData.taxRate == 0) {
                storeField = "data.other.taxRateTypes"
            }
            else {
                storeField = "data.other.taxRateType"
            }
        } 
        
        let sfObj = {}
        let value = this.metaAction.gf(storeField).find(o => o.get('id') == id)
        let invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')
        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
                }
                
                sfObj['data.form.settles'] = fromJS(settles)
                sfObj[`data.error.${index}.bankAccount`] = undefined
            } else {
                let settles = this.metaAction.gf('data.form.settles')
                settles = settles ? settles.toJS() : []

                settles[index].bankAccountId = null
                settles[index].bankAccountName = null
          
                sfObj['data.form.settles'] = fromJS(settles)
            }
        }
        if (value) {
            if (storeField == 'data.other.inventory') { //当改变存货名称或编码时以下数据也要发生更改
                field.id = value.get('isInventory') ? `data.form.details.${rowIndex}.inventoryId` : `data.form.details.${rowIndex}.businessTypeId`
                field.name = value.get('isInventory') ? `data.form.details.${rowIndex}.inventoryName` : `data.form.details.${rowIndex}.businessTypeName`
                field.code = value.get('isInventory') ? `data.form.details.${rowIndex}.inventoryCode` : `data.form.details.${rowIndex}.businessTypeCode`
                if (!value.get('isInventory')) {
                    this.metaAction.sfs({
                        [`data.form.details.${rowIndex}.inventoryId`] : null,
                        [`data.form.details.${rowIndex}.inventoryName`] : null,
                        [`data.form.details.${rowIndex}.inventoryCode`] : null,
                    })
                }
                // Object.keys(field).forEach(key => {
                //     // this.injections.reduce('updateState', field[key], value.get(key))
                //     sfObj[field[key]] = value.get(key)
                // })

                this.handleChangeInventory(field,sfObj,value,rowData,rowIndex)
                // const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')
                // const isNCPFP = invoiceTypeId == '4000010030' ? true : false
                // let amount = utils.number.round(rowData.amount, 2),
                //     tax = utils.number.round(amount * value.get('taxRate'), 2),
                //     taxInclusiveAmount = utils.number.round(amount + tax, 2)

                //     if (isNCPFP) {
                //         taxInclusiveAmount = utils.number.round(amount / (1 - value.get('taxRate')), 2)
                //         tax = utils.number.round(taxInclusiveAmount - amount, 2)
                //     }

                // const taxRateIds = value.get('taxRateId') || value.get('taxRateId') == 0 ? value.get('taxRateId') : value.get('rate')

                // sfObj[`data.form.details.${rowIndex}.taxRateId`] = taxRateIds
                // sfObj[`data.form.details.${rowIndex}.taxRateName`] = value.get('taxRateName') || value.get('rateName')
                // sfObj[`data.form.details.${rowIndex}.taxRate`] = value.get('taxRate')
                // sfObj[`data.form.details.${rowIndex}.tax`] = tax
                // sfObj[`data.form.details.${rowIndex}.taxInclusiveAmount`] = taxInclusiveAmount
                // sfObj[`data.error.${rowIndex}.inventory`] = undefined
                // sfObj[`data.error.${rowIndex}.propertyName`] = undefined
           
                // this.renderTaxRateTypesSelect(rowIndex, rowData, true)
            } else {
                Object.keys(field).forEach(key => {
                    // this.injections.reduce('updateState', field[key], value.get(key))
                    sfObj[field[key]] = value.get(key)
                    this.handleCheck([{ path: field[key], value: value.get(key) }])
                })
            }
        } else {
            Object.keys(field).forEach(key => {
                if (storeField == 'data.other.inventory') {
                    sfObj[`data.form.details.${rowIndex}.inventoryId`] = null
                    sfObj[`data.form.details.${rowIndex}.inventoryName`] = null
                    sfObj[`data.form.details.${rowIndex}.businessTypeId`] = null
                    sfObj[`data.form.details.${rowIndex}.businessTypeName`] = null

                } else {
                    // this.injections.reduce('updateState', field[key], null)
                    sfObj[field[key]] = null
                    this.handleCheck([{ path: field[key], value: null }])
                }
            })
        }

        //征收方式,认证抵扣判断
        const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
        // if (storeField == 'data.other.invoiceType' && vatTaxpayer == '2000010001') {
        if (storeField == 'data.other.invoiceType') {

            if (id == 4000010030) { //农产品
                const details = this.metaAction.gf('data.form.details').toJS() || []
                details.forEach((item, index) => {
                    if (item.taxInclusiveAmount) {
                        this.voucherAction.calc('taxInclusiveAmount', index, item, {value: null}, true)
                    }
                })

                if (vatTaxpayer == '2000010001') {
                    // sfObj['data.form.deductible'] = true
                    // sfObj['data.other.isShowAuth'] = false
                    // sfObj['data.other.deductabled'] = false
                    // sfObj['data.other.isShowDedu'] = true
                    // sfObj['data.error.invoiceNumber'] = undefined
                    // sfObj['data.error.invoiceCode'] = undefined
                    // sfObj['data.form.authenticated'] = false
                    // sfObj['data.form.authenticatedMonth'] = null
                    this.metaAction.sfs({
                        'data.form.deductible': true,
                        'data.other.isShowAuth': false,
                        'data.other.deductabled': false,
                        'data.other.isShowDedu': true,
                        'data.error.invoiceNumber': undefined,
                        'data.error.invoiceCode': undefined,
                        'data.form.authenticated': false,
                        'data.form.authenticatedMonth': null
                    })
                } else {
                    sfObj['data.error.invoiceNumber'] = undefined
                    sfObj['data.error.invoiceCode'] = undefined
                }
            } else {

                if (invoiceTypeId == '4000010030') {
                    const details = this.metaAction.gf('data.form.details').toJS() || []
                    details.forEach((item, index) => {
                        if (item.amount) {
                            this.voucherAction.calc('amount', index, item, {value: null}, false)
                        }
                    })
                }
                if (id == 4000010020 || id == 4000010040 || id == 4000010045) {//专用,海关,通行费
                    if (vatTaxpayer == '2000010001') {
                        // sfObj['data.form.deductible'] = true
                        // sfObj['data.other.isShowAuth'] = true
                        // sfObj['data.other.isShowDedu'] = true
                        // sfObj['data.form.authenticated'] = true
                        // sfObj['data.other.authMonthabled'] = false
                        // sfObj['data.other.deductabled'] = false
                        // sfObj['data.error.invoiceNumber'] = undefined
                        // sfObj['data.error.invoiceCode'] = undefined
                        this.metaAction.sfs({
                            'data.form.deductible': true,
                            'data.other.isShowAuth': true,
                            'data.other.isShowDedu': true,
                            'data.form.authenticated': true,
                            'data.other.authMonthabled': false,
                            'data.other.deductabled': false,
                            'data.error.invoiceNumber': undefined,
                            'data.error.invoiceCode': undefined
                        })
                    }
                } else {
                    
                    if (vatTaxpayer == '2000010001') {
                        // sfObj['data.other.isShowDedu'] = false
                        // sfObj['data.other.isShowAuth'] = false
                        // sfObj['data.form.authenticated'] = false
                        // sfObj['data.form.deductible'] = true
                        // sfObj['data.other.authMonthabled'] = false
                        // sfObj['data.other.deductabled'] = false
                        // sfObj['data.error.invoiceNumber'] = undefined
                        // sfObj['data.error.invoiceCode'] = undefined
                        // sfObj['data.form.authenticatedMonth'] = null
                        this.metaAction.sfs({
                            'data.other.isShowDedu': false,
                            'data.other.isShowAuth': false,
                            'data.form.authenticated': false,
                            'data.form.deductible': true,
                            'data.other.authMonthabled': false,
                            'data.other.deductabled': false,
                            'data.error.invoiceNumber': undefined,
                            'data.error.invoiceCode': undefined,
                            'data.form.authenticatedMonth': null
                        })
                    } else {
                        sfObj['data.error.invoiceNumber'] = undefined
                        sfObj['data.error.invoiceCode'] = undefined
                    }
                }

                const businessDate = this.metaAction.gf("data.form.businessDate")
                const authenticated = this.metaAction.gf('data.form.authenticated')
                if (businessDate && authenticated) {
                    const value = businessDate && businessDate.slice(0, 7)
                    let authenticatedMonth = this.metaAction.gf('data.form.authenticatedMonth')
                    if (authenticatedMonth == undefined) {
                        sfObj['data.form.authenticatedMonth'] = value
                    }
                }
            }
        }

        this.editCloseTips(true)
        sfObj['data.other.auditVisible'] = false
        this.metaAction.sfs(sfObj)
    }

    //认证月份
    renderauthMonth = () => {
        const authenticatedMonth = this.metaAction.gf('data.form.authenticatedMonth')

        if (!authenticatedMonth) {
            const businessDate = this.metaAction.gf("data.form.businessDate")
            const authenticated = this.metaAction.gf('data.form.authenticated')
            if (businessDate && authenticated) {
                const value = businessDate && businessDate.slice(0, 7)
                // return value
                // return this.metaAction.stringToMoment(value && value.replace(/-/g, "/"))
                return this.metaAction.stringToMoment(value && value)
            }
        } else {
            // // return this.metaAction.stringToMoment(authenticatedMonth&&authenticatedMonth.replace(/-/g, "/"))
            return this.metaAction.stringToMoment(authenticatedMonth&&authenticatedMonth)
        }
    }

    openDocContent = async () => {
        let data = this.metaAction.gf('data.form').toJS()
        let id = data.docId
        this.component.props.setPortalContent &&
            this.component.props.setPortalContent(
                '填制凭证',
                'app-proof-of-charge',
                { accessType: 1, initData: { id } }
            )
    }

    editCloseTips = (istip) => {
        if (this.component.props.editing) {
            //设置当前单据状态,供单据页签关闭用 false:关闭不提醒 true 关闭提醒
            this.component.props.editing(this.component.props.appName, istip)
        }
    }

    //支持搜索
    filterOption = (inputValue, option, name) => {
        inputValue = inputValue.replace(/\\/g, "\\\\")
        if (!option || !option.props || !option.props.children) {
            return false
        }
        //需要确定部门项目这些是否也需要支持助记码这些的搜索
        let parmasName = null, parmasNameCode = null
        if (name.currentPath) {
            parmasName = name.currentPath
        }
        if (parmasName.indexOf('supplier') != -1) {
            parmasName = 'supplier'
        } else if (parmasName.indexOf('inventoryCode') != -1) {
            parmasName = 'inventory'
            parmasNameCode = 'inventoryCode'
        } 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)

        let paramsValue = paramsValues.find(item => item.get('id') == (option.key))

        if (!paramsValue) {
            return false
        }

        if (parmasNameCode && parmasNameCode.indexOf('inventoryCode') != -1) {
            let regExp = new RegExp(inputValue, 'i')
            return paramsValue.get('code').search(regExp) != -1
        }

        let regExp = new RegExp(inputValue, 'i')
        return paramsValue.get('name').search(regExp) != -1
            || (paramsValue.get('code') && paramsValue.get('code').search(regExp) != -1)
            || (paramsValue.get('helpCode') && paramsValue.get('helpCode').search(regExp) != -1) // TODO 只支持助记码搜索,简拼
            || (paramsValue.get('helpCodeFull') && paramsValue.get('helpCodeFull').search(regExp) != -1) 
    }

    //计算
    calc = (col, rowIndex, rowData, params) => (v) => {

        if (col == 'quantity' || col == 'price' || col == 'amount' || col == 'tax' || col == 'taxInclusiveAmount') {
            if (v && Number(v) > 9999999999.99) {
                v = 9999999999.99
            }
        }
        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
        //     })
        // }
        let sfObj = {}
        if ((v == null || v == undefined) && col == 'taxRateName') {
            sfObj[`data.form.details.${rowIndex}.taxRateName`]= null
            sfObj[`data.form.details.${rowIndex}.taxRateId`] = null
            sfObj[`data.form.details.${rowIndex}.taxRate`] = null
        } else {
            const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')
            const isNCPFP = invoiceTypeId == '4000010030' ? true : false

            this.voucherAction.calc(col, rowIndex, rowData, params, isNCPFP)

            // const details = this.metaAction.gf('data.form.details').toJS()
            // details.find((item) => { //为了判断是否为退货
            //     if (item.amount < 0 || item.quantity < 0 || item.quantity < 0 || item.taxInclusiveAmount < 0) {
            //         sfObj['data.other.isDisableBank'] = true 
            //         return true
            //     } else {
            //         sfObj['data.other.isDisableBank'] = false 
            //         return false
            //     }
            // })
            
            if (col == 'taxRateName') {
                this.renderTaxRateTypesSelect(rowIndex, rowData, true)
            }
        }

        sfObj['data.other.auditVisible'] = false
        this.metaAction.sfs(sfObj)
    }


    //计算剩余金额
    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 = Number(payAmount) + Number(item.amount)
        })

        const chargeAmount = this.voucherAction.numberFormat(taxInclusiveAmount - payAmount, 2)
        this.metaAction.sfs({
            'data.other.chargeAmount': chargeAmount,
            'data.other.taxInclusiveAmount': taxInclusiveAmount,
            'data.other.payAmount': payAmount,
        })
        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
    }

    getColumnVisible = (params) => {
        let columnSetting = this.metaAction.gf('data.other.columnSetting'), visible = false
        columnSetting = columnSetting && columnSetting.toJS()

        if (columnSetting && !!columnSetting.body && columnSetting.body.tables) {
            columnSetting.body.tables.forEach((item) => {
                if (item.details.length != 0) {
                    visible = item.details.filter(o => o.fieldName == params)[0].isVisible
                }
            })
        }
        return visible
    }

    getColumnCaption = (params) => {
        let columnSetting = this.metaAction.gf('data.other.columnSetting'), caption = ''
        columnSetting = columnSetting && columnSetting.toJS()

        if (columnSetting && !!columnSetting.body && columnSetting.body.tables) {
            columnSetting.body.tables.forEach((item) => {
                if (item.details.length != 0) {
                    caption = item.details.filter(o => o.fieldName == params)[0].caption
                }
            })
        }
        return caption
    }

    // 切换征收方式
    settlementChange = (value) => {
        let signAndRetreatCheck = this.metaAction.gf('data.other.signAndRetreatCheck')
        this.metaAction.sfs({
            'data.other.signAndRetreatCheck': !signAndRetreatCheck,
            'data.form.signAndRetreat': value,
            'data.other.auditVisible': false
        })
        this.editCloseTips(true)
    }

    //抵扣 不给予抵扣
    deductibleChange = () => {
        let deductible = this.metaAction.gf('data.form.deductible')
        this.metaAction.sfs({
            'data.form.deductible': !deductible,
            'data.other.auditVisible': false
        })
        this.editCloseTips(true)
    }

    // 勾选认证
    authenticationChange = () => {
        const authenticated = this.metaAction.gf('data.form.authenticated')

        let sfObj = {}
        if (!authenticated) {
            const businessDate = this.metaAction.gf('data.form.businessDate')
            if (businessDate) {
                sfObj['data.form.authenticatedMonth'] = businessDate.slice(0, 7)
            }
            sfObj['data.other.authMonthabled'] = false
            sfObj['data.other.deductabled'] = false
            sfObj['data.form.deductible'] = true
            sfObj['data.error.invoiceCode'] = undefined
            sfObj['data.error.invoiceNumber'] = undefined
        } else {
            sfObj['data.other.authMonthabled'] = true
            sfObj['data.other.deductabled'] = true
            sfObj['data.form.deductible'] = undefined
            sfObj['data.form.authenticatedMonth'] = null
        }

        sfObj['data.form.authenticated'] = !authenticated
        sfObj['data.other.auditVisible'] = false

        this.metaAction.sfs(sfObj)
        this.editCloseTips(true)
    }

    //认证还是比对
    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
    }

    //点击增加 现结账户
    addPaymentAmount = () => {
        let settles = this.metaAction.gf('data.form.settles')
        settles = settles ? settles.toJS() : []
        const obj = {
            bankAccountId: '',
            amount: '',
            bankAccountName: '',
        }
        if (settles.length == 0) settles.push(obj)
        settles.push(obj)
        this.metaAction.sfs({
            'data.form.settles': fromJS(settles),
            'data.other.auditVisible': false
        })
        this.editCloseTips(true)
    }

    //点击删除 现结账户金额
    delPaymentAmount = (index) => {
        let settles = this.metaAction.gf('data.form.settles')
        settles = settles ? settles.toJS() : []
        let error = this.metaAction.gf('data.error').toJS()
        if (settles.length != 1) {
            settles.splice(index, 1)
            // this.metaAction.sfs({
            //     'data.form.settles': fromJS(settles),
            //     'data.other.auditVisible': false,
            //     // [`data.error.${index}.amount`]: undefined,
            //     // [`data.error.${index}.bankAccount`]: undefined 
            // })

            for (let item in error) {
                if ( typeof error[item] == 'object') {
                    if (item >= index) {
                        if (error[item].amount) error[item].amount = undefined
                        if (error[item].bankAccount) error[item].bankAccount = undefined
                    }
                }
            }

            // this.metaAction.sf('data.error', fromJS(error))

            this.metaAction.sfs({
                'data.form.settles': fromJS(settles),
                'data.other.auditVisible': false,
                'data.error': fromJS(error)
            })

        }

        this.editCloseTips(true)
    }

    //附件的下载操作
    download = (ps) => {
        const form = this.metaAction.gf('data.form').toJS()
        if (form.id) {
            ps = ps.file ? ps.file : ps
        }
        this.voucherAction.download(ps)
    }

    getAccessToken = () => {
        let token = fetch.getAccessToken()
        return { token: token }
    }

    delFile = (index) => {
        // let form = this.metaAction.gf('data.form').toJS()
        // this.voucherAction.delFile(index, 'vouchers', this.updateEnclosure)
        const data = this.metaAction.gf('data').toJS()
        const status = data.consts.VOUCHERSTATUS_Approved
        if (status == data.form.status) {
            return false
        } else {
            this.voucherAction.delFile(index, 'vouchers', this.updateEnclosure)
        }
    }

    updateEnclosure = async (res) => {
        // const result = await this.webapi.arrival.updateEnclosure(res)
        // return result
        res.ts = ''
        const result = await this.webapi.arrival.updateEnclosure(res)
        return result
    }

    attachmentChange = (info) => {
        const isLt10M = this.metaAction.gf('data.other.isLt10M')
        if (isLt10M) {
            return
        }
        this.voucherAction.attachmentChange(info, 'vouchers', this.updateEnclosure)
    }

    beforeUpload = async (info, infoList) => {
        const isLt10M = info.size / 1024 / 1024 < 10;
        
        if (!isLt10M) {
            //LoadingMask.hide()            
            this.metaAction.toast('warning', '文件过大,请上传小于10兆的附件')
            this.injections.reduce('attachmentLoading', false)
            this.injections.reduce('updateState', 'data.other.isLt10M', true)
            return
        }

        let attachmentFiles = this.metaAction.gf('data.form.attachmentFiles').toJS() || []
        return new Promise((resolve, reject) => {
            if (attachmentFiles.length + infoList.length > 20) {
                this.metaAction.toast('warning', `当前凭证的附件数为${attachmentFiles.length},只能继续上传${20 - attachmentFiles.length}个附件`)
                reject(info);
            } else {
                resolve(info);
            }
        });

    }

    getDisable = () => {
        let pageStatus = this.metaAction.gf('data.other.pageStatus')
        let disabled = pageStatus == common.commonConst.PAGE_STATUS.READ_ONLY
        // let discarded = this.metaAction.gf('data.form.discarded')
        // if (discarded) {
        //     return true
        // }

        const accountStatus = this.metaAction.gf('data.other.accountStatus')
        let status = this.metaAction.gf('data.form.status')

        if (accountStatus == 4000140002) {
            return true
        } 
        
        if (status == 1000020003) {
            return false
        }
        if (status == 1000020001) {
            return false
        }
        if (status == 1000020002) {
            return true
        }
       
        return disabled
    }

    getDiscarded = () => {
        const discarded = this.metaAction.gf('data.form.discarded')
        const status = this.metaAction.gf('data.form.status')

        if (discarded) {
            if (status == consts.consts.VOUCHERSTATUS_Approved) {
                return false
            } else {
                return true
            }
        } else {
            return false
        }
    }

    //下拉选 票据类型 供应商
    handleSelect = (params, isCodeSeach) => {
        params = params && params.toJS()
        if (params) {
            return params.map((item, index) => {
                return isCodeSeach ? <Option key={item && item.id} title={item && item.name} >{item && `${item.code} ${item.name}`}</Option> :
                    <Option key={item && item.id} title={item && item.name}>{item && item.name}</Option>
            })
        }
    }

    //新增档案
    addRecordClick = async (add, params, index, rowData) => {
        let sfObj = {}, vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')
        if (params == 'inventory') {
            const isInventory = rowData.propertyId == '4001001' || rowData.propertyName == '费用'
            let inventory = [], inventorys = [], inventoryItem = null

            if (isInventory) {
                let result = await this.metaAction.modal('show', {
                    title: <div style={{ fontSize: '16px', fontWeight: '500' }}>新增费用类型</div>,
                    width: 400,
                    height: 500,
                    footer: '',
                    children: this.metaAction.loadApp('scm-incomeexpenses-setting-card', {
                        store: this.component.props.store,
                        columnCode: "common",
                        incomeexpensesTabId: '4001001'
                    }),
                })
                if (typeof result == 'object') {
                    result.propertyId = 4001001
                    result.propertyName = '费用'
                    inventoryItem = result
                }
            } else {
                const inventoryItemOld = this.metaAction.gf('data.other.inventoryItem') && this.metaAction.gf('data.other.inventoryItem').toJS()
                inventoryItem = await this.voucherAction[add]('data.other.inventoryItem', 'get')
                // inventoryItem = this.metaAction.gf('data.other.inventoryItem') && this.metaAction.gf('data.other.inventoryItem').toJS()
                
                if (inventoryItemOld && inventoryItemOld.id == inventoryItem.id) { // 若是取消状态
                    inventoryItem = null
                }
            }

            inventory = this.metaAction.gf('data.other.inventory') && this.metaAction.gf('data.other.inventory').toJS() || []
            inventorys = this.metaAction.gf('data.other.inventorys') && this.metaAction.gf('data.other.inventorys').toJS() || []
            if (inventoryItem) {

                inventoryItem.isInventory = isInventory ? false : true
                let list = inventorys.filter(o => (o.propertyId == inventoryItem.propertyId || o.propertyName == inventoryItem.propertyName))
                list.push(inventoryItem)
                inventorys.push(inventoryItem)
                // this.metaAction.sfs({
                //     'data.other.inventory': fromJS(list),
                //     'data.other.inventorys': fromJS(inventorys),
                //     [`data.error.${index}.inventory`]: undefined
                // })

                let field = {
                    id: `data.form.details.${index}.inventoryId`,
                    name: `data.form.details.${index}.inventoryName`,
                    code: `data.form.details.${index}.inventoryCode`,
                    specification: `data.form.details.${index}.specification`,
                    unitId: `data.form.details.${index}.unitId`,
                    unitName: `data.form.details.${index}.unitName`,
                    taxRateId: `data.form.details.${index}.rate`,
                    rateName: `data.form.details.${index}.taxRateName`,
                    inventoryType: `data.form.details.${index}.inventoryType`,
                    inventoryTypeName: `data.form.details.${index}.inventoryTypeName`,
                    taxRateType: `data.form.details.${index}.taxRateType`,
                    taxRateTypeName: `data.form.details.${index}.taxRateTypeName`,
                    propertyId: `data.form.details.${index}.propertyId`,
                    propertyName: `data.form.details.${index}.propertyName`
                }
                // this.onFieldChange(field, 'data.other.inventory', index, rowData, null, 'add', obj)(inventoryItem.id)
                const value = fromJS(inventoryItem)
                this.handleChangeInventory(field,sfObj,value,rowData,index,vatTaxpayer)
                sfObj['data.other.inventory'] = fromJS(list)
                sfObj[`data.other.inventorys`] = fromJS(inventorys)
                // const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')
                // const isNCPFP = invoiceTypeId == '4000010030' ? true : false

                // Object.keys(field).forEach(key => {
                //     sfObj[field[key]] = value.get(key)
                // })
                // let amount = utils.number.round(rowData.amount, 2),
                //     tax = utils.number.round(amount * value.get('taxRate'), 2),
                //     taxInclusiveAmount = utils.number.round(amount + tax, 2)

                // if (isNCPFP) {
                //     taxInclusiveAmount = utils.number.round(amount / (1 - value.get('taxRate')), 2)
                //     tax = utils.number.round(taxInclusiveAmount - amount, 2)
                // }

                // const taxRateIds = value.get('taxRateId') || value.get('taxRateId') == 0 ? value.get('taxRateId') : value.get('rate')
                // sfObj[`data.form.details.${index}.taxRateId`] = taxRateIds
                // sfObj[`data.form.details.${index}.taxRateName`] = value.get('taxRateName') || value.get('rateName')
                // sfObj[`data.form.details.${index}.taxRate`] = value.get('taxRate')
                // sfObj[`data.form.details.${index}.tax`] = tax
                // sfObj[`data.form.details.${index}.taxInclusiveAmount`] = taxInclusiveAmount
                // sfObj[`data.error.${index}.inventory`] = undefined
                // sfObj[`data.error.${index}.propertyName`] = undefined
                // sfObj['data.other.inventory'] = fromJS(list)
                // sfObj[`data.other.inventorys`] = fromJS(inventorys)
                // // this.renderTaxRateTypesSelect(index,rowData, true)
                // // this.metaAction.sfs(sfObj)
            }
        } else {
            await this.voucherAction[add](`data.other.${params}s`)
            const res = this.metaAction.gf(`data.other.${params}s`).toJS()
            const list = this.metaAction.gf(`data.other.${params}`).toJS()
            list.push(res)
            // this.metaAction.sfs({
            //     [`data.other.${params}`]: fromJS(list),
            //     [`data.form.${params}Id`]: res.id,
            //     [`data.form.${params}Name`]: res.name,
            //     [`data.error.${params}`]: undefined
            // })
            sfObj[`data.other.${params}`] = fromJS(list)
            sfObj[`data.form.${params}Id`] = res.id
            sfObj[`data.form.${params}Name`] = res.name
            sfObj[`data.error.${params}`] = undefined
        }

        this.editCloseTips(true)
        sfObj['data.other.auditVisible'] = false
        this.metaAction.sfs(sfObj)
    }

    handleChangeInventory = (field,sfObj,value,rowData,index, vatTaxpayer) => {
        const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId')
        const isNCPFP = invoiceTypeId == '4000010030' ? true : false

        Object.keys(field).forEach(key => {
            sfObj[field[key]] = value.get(key)
        })
        let amount = utils.number.round(rowData.amount, 2),
            tax = utils.number.round(amount * value.get('taxRate'), 2),
            taxInclusiveAmount = utils.number.round(amount + tax, 2)

        if (isNCPFP) {
            taxInclusiveAmount = utils.number.round(amount / (1 - value.get('taxRate')), 2)
            tax = utils.number.round(taxInclusiveAmount - amount, 2)
        }

        const taxRateIds = value.get('taxRateId') || value.get('taxRateId') == 0 ? value.get('taxRateId') : value.get('rate')
        sfObj[`data.form.details.${index}.taxRateId`] = taxRateIds
        sfObj[`data.form.details.${index}.taxRateName`] = value.get('taxRateName') || value.get('rateName')
        sfObj[`data.form.details.${index}.taxRate`] = value.get('taxRate')
        sfObj[`data.form.details.${index}.tax`] = tax
        sfObj[`data.form.details.${index}.taxInclusiveAmount`] = taxInclusiveAmount
        sfObj[`data.error.${index}.inventory`] = undefined
        sfObj[`data.error.${index}.propertyName`] = undefined

        // if (vatTaxpayer == '2000010001' && (taxRate || taxRate == 0)) {
        //     if (taxRate == 0) {
        //         sfObj[`data.form.details.${index}.taxRateType`] = 3000070005
        //         sfObj[`data.form.details.${index}.taxRateTypeName`] = '免税'
        //     } else if (taxRate > 0.06){
        //         sfObj[`data.form.details.${index}.taxRateType`] = 3000070001
        //         sfObj[`data.form.details.${index}.taxRateTypeName`] = '一般计税'
        //     } else if (taxRate > 0 && taxRate <= 0.06) {
        //         sfObj[`data.form.details.${index}.taxRateType`] = 3000070002
        //         sfObj[`data.form.details.${index}.taxRateTypeName`] = '简易征收'
        //     }
        // } else if(vatTaxpayer == '2000010002' && (taxRate || taxRate == 0)){
        //     sfObj[`data.form.details.${index}.taxRateType`] = 3000070002
        //     sfObj[`data.form.details.${index}.taxRateTypeName`] = '简易征收'
        // }
    }

    //新增档案
    handleAddRecord = (paramsU, params, index, rowData) => {
        const add = `add${paramsU}`
        return <Button type='primary'
            style={{ width: '100%', borderRadius: '0' }}
            // onClick={() => this.voucherAction[add]({ id: `data.form.${params}Id`, name: `data.form.${params}Name`})}
            onClick={this.addRecordClick.bind(null, add, params, index, rowData)}
        >新增</Button>
    }

    ///控制显示
    handleVisible = (params) => {
        let columnSetting = this.metaAction.gf('data.other.columnSetting')
        columnSetting = columnSetting && columnSetting.toJS()
        if (columnSetting) {
            return !!columnSetting.header && columnSetting.header.cards.filter(o => o.fieldName == params)[0].isVisible
        }
    }

    //记账日期控制
    handleDisabledDate = (current) => {
        // Can not select days before today and today
        if (current) {
            let beginDate = this.metaAction.gf('data.other.beginDate'), currentDate = current.format('YYYY-MM-DD')
            let invoiceDate = this.metaAction.gf('data.form.invoiceDate')

            beginDate = beginDate && beginDate.replace(/-/g, '')
            currentDate = currentDate && currentDate.replace(/-/g, '')

            // if (invoiceDate) {
            //     invoiceDate = invoiceDate.replace(/-/g, '')
            //     return (currentDate && currentDate < beginDate) || (currentDate && currentDate < invoiceDate)
            // } else {
                return currentDate && currentDate < beginDate
            // }
        }
    }

    //开票日期控制
    handleDisInvoiceDate = (current) => {
        if (current) {
            let beginDate = this.metaAction.gf('data.other.beginDate'), currentDate = current.format('YYYYMMDD')
            let businessDate = this.metaAction.gf('data.form.businessDate')

            beginDate = beginDate && beginDate.replace(/-/g, '')
            if (businessDate) {
                businessDate = businessDate.replace(/-/g, '')
                // return (currentDate && currentDate < beginDate) || (currentDate && currentDate > businessDate)
                return currentDate && currentDate > businessDate
            } 
            // else {
            //     return currentDate && currentDate < beginDate
            // }
        }
    }

    //认证月份控制
    handleDisAuthMonthDate = (current) => {
        if (current) {
            let invoiceDate = this.metaAction.gf('data.form.invoiceDate'),
                currentDate = current.format('YYYYMM'),
                businessDate = this.metaAction.gf('data.form.businessDate'),
                beginDate = this.metaAction.gf('data.other.beginDate')

            beginDate = beginDate && beginDate.slice(0, 7).replace(/-/g, "")
            businessDate = businessDate && businessDate.slice(0, 7).replace(/-/g, "")
            invoiceDate = invoiceDate && invoiceDate.slice(0, 7).replace(/-/g, "")

            if (businessDate && invoiceDate) {
                return currentDate && currentDate < invoiceDate
            } else {
                if (businessDate) {
                    return currentDate && currentDate < businessDate
                } else if (invoiceDate) {
                    return currentDate && currentDate < invoiceDate
                } else {
                    return currentDate && currentDate < beginDate
                }
            }
        }
    }

    //认证月份
    autMonthChange = (d) => {
        this.editCloseTips(true)

        let sfObj = {}
        if (d) {
            sfObj['data.error.authenticatedMonth'] = undefined
        }
        sfObj['data.form.authenticatedMonth'] = this.metaAction.momentToString(d, 'YYYY-MM')
        sfObj['data.other.auditVisible'] = false

        this.metaAction.sfs(sfObj)
    }

    filterOptionArchives = (name, inputValue, option) => {
        const namePrmas = {
            currentPath: name
        }
        // inputValue = inputValue.replace(/\\/g, "\\\\")
        return this.filterOption(inputValue, option, namePrmas)
    }

    renderArchives = () => {
        let columnSetting = this.metaAction.gf('data.other.columnSetting'),
            departmentName = this.metaAction.gf('data.form.departmentId') ? this.metaAction.gf('data.form.departmentId') : undefined,
            purchasePersonName = this.metaAction.gf('data.form.purchasePersonName') ? this.metaAction.gf('data.form.purchasePersonName') : undefined,
            projectName = this.metaAction.gf('data.form.projectId') ? this.metaAction.gf('data.form.projectId') : undefined,
            department = this.metaAction.gf('data.other.department') && this.metaAction.gf('data.other.department'),
            purchasePerson = this.metaAction.gf('data.other.purchasePerson') && this.metaAction.gf('data.other.purchasePerson'),
            project = this.metaAction.gf('data.other.project') && this.metaAction.gf('data.other.project'),
            form = this.metaAction.gf('data.form').toJS()

        columnSetting = columnSetting && columnSetting.toJS()
        // let aaa = !!columnSetting.header && columnSetting.header.cards.filter(o=> o.fieldName == item.name )[0].caption
        const archivesArr = [
            { label: '部门', name: 'department', upName: 'Department', value: departmentName, optionArr: department },
            { label: '项目', name: 'project', upName: 'Project', value: projectName, optionArr: project },
        ]
        if (columnSetting) {
            let domArr = archivesArr.map((item) => {
                let isVisible = !!columnSetting.header && columnSetting.header.cards.filter(o => o.fieldName == item.name)[0].isVisible
                let caption = !!columnSetting.header && columnSetting.header.cards.filter(o => o.fieldName == item.name)[0].caption

                if (isVisible) {
                    return (
                        <FormItem label={caption}>
                            <Select
                                className="autoFocus_item"
                                showSearch={true}
                                allowClear={ item.value && String(item.value) ? true : false}
                                filterOption={this.filterOptionArchives.bind(null, item.name)}
                                placeholder='按名称/拼音/编码搜索'
                                disabled={this.getDisable()}
                                // value={item.value && String(item.value)}
                                value={this.renderInventoryName(String(item.value), `data.other.${item.name}`, form[`${item.name}Name`])}
                                onFocus={() => this.voucherAction[`get${item.upName}`]({entity:{isEnable:true}}, `data.other.${item.name}`)}
                                dropdownFooter={this.handleAddRecord(`${item.upName}`, `${item.name}`)}
                                onChange={this.onFieldChange({ id: `data.form.${item.name}Id`, name: `data.form.${item.name}Name` }, `data.other.${item.name}`)}
                            >
                                {this.handleSelect(item.optionArr, true)}
                            </Select>
                        </FormItem>
                    )
                } else {
                    return null
                }
            })
            return domArr
        }
    }

    handleChange = (name, value) => {
        let obj = {
            'data.other.auditVisible': false
        }
        obj[name] = value

        if (name == "data.form.businessDate" && value) {
            obj['data.error.businessDate'] = undefined
        } else if (name == "data.form.invoiceCode") {
            obj['data.error.invoiceCode'] = undefined
        } else if (name == "data.form.invoiceNumber") {
            obj['data.error.invoiceNumber'] = undefined
        }

        if (name == "data.form.businessDate") {
            obj[`data.form.authenticatedMonth`] = value && value.slice(0, 7)

            let invoiceDate = this.metaAction.gf('data.form.invoiceDate')
            if (invoiceDate == undefined) {
                obj['data.form.invoiceDate'] = value
            } else {
                if (value) {
                    let values = value.replace(/-/g, '')
                    let newinvoiceDate = invoiceDate.replace(/-/g, '')
                    if (newinvoiceDate > values) {
                        obj['data.form.invoiceDate'] = value
                    }
                }
            }
        }
        this.metaAction.sfs(obj)
        this.editCloseTips(true)
    }

    handleInvioceRequire = (vatTaxpayer, authenticated, invoiceTypeId) => {
        if (vatTaxpayer == 2000010001 && (invoiceTypeId == 4000010020 || invoiceTypeId == 4000010040 || invoiceTypeId == 4000010045)) {
            if (!authenticated) {
                return true
            } 
            return false
        }
    }

    //渲染表头
    renderFormContent = () => {
        const businessDate = this.metaAction.gf('data.form.businessDate'),
            invoiceTypeName = this.metaAction.gf('data.form.invoiceTypeName'),
            invoiceType = this.metaAction.gf('data.other.invoiceType'),
            supplierName = this.metaAction.gf('data.form.supplierName'),
            supplier = this.metaAction.gf('data.other.supplier'),
            invoiceCode = this.metaAction.gf('data.form.invoiceCode'),
            invoiceNumber = this.metaAction.gf('data.form.invoiceNumber'),
            invoiceDate = this.metaAction.gf('data.form.invoiceDate'),
            remark = this.metaAction.gf('data.form.remark'),
            error = this.metaAction.gf('data.error') && this.metaAction.gf('data.error').toJS(),
            vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer')

        let form = this.metaAction.gf('data.form').toJS(), other = this.metaAction.gf('data.other').toJS()
        let columnSetting = this.metaAction.gf('data.other.columnSetting')
        columnSetting = columnSetting && columnSetting.toJS()
        let defaultContentArr = [
            <FormItem className="businessDate_container" label='记账日期' required={true} validateStatus={error.businessDate ? 'error' : 'success'}>
                <DatePicker
                    className="autoFocus_item"
                    allowClear={true}
                    autoFocus={true}
                    value={this.metaAction.stringToMoment(businessDate)}
                    getCalendarContainer={() => document.getElementsByClassName('businessDate_container')[0]}
                    onChange={(d) => this.handleChange("data.form.businessDate", this.metaAction.momentToString(d, 'YYYY-MM-DD'))}
                    disabled={this.getDisable()}
                    disabledDate={this.handleDisabledDate}
                >
                </DatePicker>
            </FormItem>,
            <FormItem label='发票类型' required={true} validateStatus={error.invoiceType ? 'error' : 'success'}>
                <Select
                    className="autoFocus_item"
                    // allowClear={true}
                    disabled={this.getDisable()}
                    // value={invoiceTypeName}
                    value={form.invoiceTypeId && String(form.invoiceTypeId)}
                    onFocus={() => this.voucherAction.getTaxRate({}, `data.other.invoiceType`)}
                    onChange={this.onFieldChange({ id: `data.form.invoiceTypeId`, name: `data.form.invoiceTypeName` }, `data.other.invoiceType`)}
                >
                    {this.handleSelect(invoiceType)}
                </Select>
                <Popover content='增值税专用发票,机动车销售发票,税局代开增值税发票归类到增值税专用发票中,农产品销售发票,统一收购发票归类到农产品销售发票中' placement='rightTop' overlayClassName='ttk-scm-app-sa-invoice-card-helpPopover'>
                    <Icon fontFamily='edficon' type='bangzhutishi' className='helpIcon'>
                    </Icon>
                </Popover>,
            </FormItem>,
            <FormItem label='销方名称' required={true} validateStatus={error.supplier ? 'error' : 'success'}>
                <Select
                    className="autoFocus_item"
                    showSearch={true}
                    // allowClear={true}
                    filterOption={this.filterOptionArchives.bind(null, 'supplier')}
                    placeholder='按名称/拼音/编码搜索'
                    disabled={this.getDisable()}
                    dropdownMatchSelectWidth={false}
                    dropdownStyle={{ width: '225px' }}
                    // value={form.supplierId && String(form.supplierId)}
                    value={this.renderInventoryName(String(form.supplierId), `data.other.supplier`, form.supplierName)}
                    onFocus={() => this.voucherAction.getSupplier({ entity: { isEnable: true } }, `data.other.supplier`)}
                    dropdownFooter={this.handleAddRecord('Supplier', 'supplier')}
                    onChange={this.onFieldChange({ id: `data.form.supplierId`, name: `data.form.supplierName` }, `data.other.supplier`)}
                >
                    {this.handleSelect(supplier, true)}
                </Select>
            </FormItem>,
            // this.handleVisible('invoiceCode') ?
            // <FormItem label='发票代码' required={this.handleInvioceRequire(vatTaxpayer, form.authenticated, form.invoiceTypeId)} validateStatus={error.invoiceCode ? 'error' : 'success'}>
            <FormItem label='发票代码' validateStatus={error.invoiceCode ? 'error' : 'success'}>
                <Input
                    className="autoFocus_item"
                    value={invoiceCode}
                    maxLength={12}
                    onChange={(e) => this.handleChange("data.form.invoiceCode", e.target.value)}
                    timeout={true}
                    disabled={this.getDisable()}>
                </Input>
            </FormItem>,
            // this.handleVisible('invoiceNumber') ? 
            <FormItem label='发票号码' validateStatus={error.invoiceNumber ? 'error' : 'success'}>
                <Input
                    className="autoFocus_item"
                    value={invoiceNumber}
                    maxLength={8}
                    timeout={true}
                    onChange={(e) => this.handleChange("data.form.invoiceNumber", e.target.value)}
                    disabled={this.getDisable()}>
                </Input>
            </FormItem>
            ,
            // this.handleVisible('invoiceDate') ?
            <FormItem className="invoiceDate_container" label='开票日期'>
                <DatePicker
                    className="autoFocus_item"
                    getCalendarContainer={() => document.getElementsByClassName('invoiceDate_container')[0]}
                    value={this.metaAction.stringToMoment(invoiceDate)}
                    onChange={(d) => this.handleChange("data.form.invoiceDate", this.metaAction.momentToString(d, 'YYYY-MM-DD'))}
                    disabledDate={this.handleDisInvoiceDate}
                    disabled={this.getDisable()}>
                </DatePicker>
            </FormItem>
        ]

        if (this.renderArchives()) { //档案类
            const archives = this.renderArchives().filter(o => o)
            archives.forEach((item) => {
                defaultContentArr.push(item)
            })
        }

        if (this.handleVisible('remark')) {
            let caption = !!columnSetting.header && columnSetting.header.cards.filter(o => o.fieldName == 'remark')[0].caption
            defaultContentArr.push(
                <FormItem label={caption}
                    className='app-pu-arrival-card-form-header-remark'
                >
                    <Input
                        className="autoFocus_item"
                        value={remark}
                        timeout={true}
                        onChange={(e) => this.handleChange("data.form.remark", e.target.value)}
                        disabled={this.getDisable()}>
                    </Input>
                </FormItem>
            )
        }

        return defaultContentArr
    }

    handleKeyDown(e, index, className) {
        if (e.key === 'Enter' || e.keyCode == 13 || e.keyCode == 108) {
            let dom = document.getElementsByClassName(className)[0]  //ReactDOM.findDOMNode(this.refs.auxItem)

            if (dom) {
                setTimeout(() => {
                    let nextFocusIndex = this.getNextFocusIndex(className)
                    if (index) {
                        nextFocusIndex = index
                    }
                    if (nextFocusIndex > -1) {
                        let c = dom.children[nextFocusIndex].children[1].getElementsByClassName('autoFocus_item')[0]
                        if(c){
                            if( c.className && c.className.includes('ant-calendar-picker') ) {
                                c = $(c).find('input')[0]
                            }
                            c.tabIndex = 0
                            c.focus()
                            c.click()
                        }
                    }
                }, 0)
            }
        }
    }

    getNextFocusIndex(className) {
        let nextFocusIndex
        nextFocusIndex = $(document.activeElement).parents('.ant-row').index()
        const length = $(document.activeElement).parents('.ant-row').siblings().length

        nextFocusIndex++
        if (nextFocusIndex == length + 1) {
            let dom = document.getElementsByClassName(className)[0]
            if (dom) {
                let c = dom.children[nextFocusIndex - 1].children[1].getElementsByClassName('autoFocus_item')[0]
                if (c) {
                    c.blur()
                }
            }
            if( className =  'ttk-scm-app-pu-invoice-card-form-header') {
                setTimeout(() => {
                    this.metaAction.sf('data.other.focusFieldPath', 'root.children.content.children.details.columns.propertyName.cell.cell,0')
                    setTimeout(() => {
                        let a = $('.ttk-scm-app-pu-invoice-card-form-details').find('.ant-select-selection')
                        a.focus()
                        a.click()
                    }, 0)
                }, 16)
            }
        }
        return nextFocusIndex > length ? -1 : nextFocusIndex
    }

}

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
}