UNPKG

ttk-app-core

Version:
1,274 lines (1,140 loc) 55.1 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, ColumnsSetting} from 'edf-component' const Option = Select.Option const FormItem = Form.Item class action { constructor(option) { this.metaAction = option.metaAction this.extendAction = option.extendAction this.voucherAction = option.voucherAction this.config = config.current this.webapi = this.config.webapi } onInit = ({ component, injections }) => { this.extendAction.gridAction.onInit({ component, injections }) this.voucherAction.onInit({ component, injections }) this.component = component this.injections = injections let addEventListener = this.component.props.addEventListener if (addEventListener) { addEventListener('onTabFocus', :: this.onTabFocus) } injections.reduce('init') this.initLoad(this.component.props.id || null) 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 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"} ] const result = await this.webapi.arrival.init(params.id) if (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] if (other[item.label] && form[`${item.label}Id`]) { //找出点击并选择了的档案这样就可以减少没有必要的更新 await this.voucherAction[`get${item.name}`]({}, `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 (!selected) { other[item.label] = voucherList delete form[`${item.label}Id`] delete form[`${item.label}Name`] data.other = other data.form = form isChange = true } } } // if (other[item.label] == 'inventory') { // let details = form.details // details = details.filter(o => o.inventoryId) // console.log(details, 'details') // if (details.length != 0) { // await this.voucherAction.getInventory({}, `data.other.inventory`) // const inventoryList = this.metaAction.gf('data.other.inventory') // } // } } isChange && this.metaAction.sf('data', fromJS(data)) } } initLoad = async (id) => { const response = await this.webapi.arrival.init({ id: id }) this.injections.reduce('initLoad', response) } load = (voucher) => { this.injections.reduce('load', voucher) } renderStyle = () => { const detailHeight = this.metaAction.gf('data.other.detailHeight') return {height: detailHeight} } getDom = () => { let content = document.getElementsByClassName("edfx-app-portal-content-main"), detailsDom = document.getElementsByClassName("app-pu-arrival-card-form-details")[0], cardFormHead = document.getElementsByClassName("app-pu-arrival-card-form-header")[0], card = content[0], cardHeight = card.clientHeight, value=[], data = this.metaAction.gf('data').toJS(), details = data.form.details, length = details.length // const cardFormHeadHeight = cardFormHead&&cardFormHead.clientHeight ? cardFormHead&&cardFormHead.clientHeight : 106 const cardFormHeadHeight = cardFormHead&&cardFormHead.clientHeight let height = cardHeight-10 -245- cardFormHeadHeight let columnSetting = this.metaAction.gf('data.other.columnSetting') columnSetting = columnSetting && columnSetting.toJS() // 因为需要前端自己从数组里面过滤哪些显示和不显示会有个时间 // 如果这个数组还没拿过来就已经渲染了表格高度,这个高度就会计算错误 if (!detailsDom || !cardFormHeadHeight || !columnSetting) { setTimeout(() => { this.renderNum = this.renderNum + 1 return this.getDom() },100) } else { const detailHeight = this.metaAction.gf('data.other.detailHeight') this.metaAction.sf('data.other.detailHeight', height + 'px') if (card.length != 0) { length = Math.ceil(height / 35) > 5 ? Math.ceil(height / 35) : 5 const blankDetail = { warehouseId: null, inventoryId: null, unitId: null, quantity: null, price: null, taxInclusivePrice: null, taxRateId: null, tax: null, amount: null, taxInclusiveAmount: null } value = Array(length - 5).fill(blankDetail) } details = details.concat(value) this.injections.reduce('setrowsCount', details, details.length) } } componentDidMount = () => { this.getDom() const win = window if (win.addEventListener) { document.body.addEventListener('keydown', this.bodyKeydownEvent, false) } else if (win.attachEvent) { document.body.attachEvent('onkeydown', this.bodyKeydownEvent) } } componetWillUnmount = () => { const win = window if (win.removeEventListener) { document.body.removeEventListener('keydown', this.bodyKeydownEvent, false) } else if (win.detachEvent) { document.body.detachEvent('onkeydown', this.bodyKeydownEvent) } } bodyKeydownEvent = (e) => { const dom = document.getElementById('app-pu-arrival-card') const modalBody = document.getElementsByClassName('ant-modal-body') if (dom && modalBody && modalBody.length<1){ this.keyDownCickEvent({event:e}) } } //监听键盘事件 keyDownCickEvent = (keydown) => { if (keydown && keydown.event) { let e = keydown.event if (e.ctrlKey && e.altKey && (e.key == 'n' || e.keyCode == 78)) { //新增 // this.add() if (e.preventDefault) { e.preventDefault() } if (e.stopPropagation) { e.stopPropagation() } } else if (e.ctrlKey && !e.altKey && (e.key == 's' || e.keyCode == 83)) { //保存 this.save(false) if (e.preventDefault) { e.preventDefault() } if (e.stopPropagation) { e.stopPropagation() } } else if (e.ctrlKey && !e.altKey && (e.key == '/' || e.keyCode == 191)) {//保存并新增 this.save(true) if (e.preventDefault) { e.preventDefault() } if (e.stopPropagation) { e.stopPropagation() } } else if (e.ctrlKey && !e.altKey && (e.key == 'y' || e.keyCode == 89)) { //审核 this.audit() if (e.preventDefault) { e.preventDefault() } if (e.stopPropagation) { e.stopPropagation() } } //判断设备是否为mac else if (navigator.userAgent.indexOf('Mac OS X') !== -1) { if (e.ctrlKey && !e.altKey && (e.key == "[" || e.keyCode == 219)) { //上一张 this.prev() } else if (e.ctrlKey && !e.altKey && (e.key == "]" || e.keyCode == 221)) { //下一张 this.next() } } else { if (e.ctrlKey && !e.altKey && (e.key == "[" || e.keyCode == 37 || e.keyCode == 219)) { //219 win7 IE11下的keyCode //上一张 this.prev() } else if (e.ctrlKey && !e.altKey && (e.key == "]" || e.keyCode == 39 || e.keyCode == 221)) { //221 win7 IE11下的keyCode //下一张 this.next() } } } } prev = async () => { const code = this.metaAction.gf('data.form.code') const response = await this.webapi.arrival.previous({ code,isReturnValue: true }) if (response) { if (response.result == false && response.error) { this.metaAction.sfs({ 'data.other.prevDisalbed':true, 'data.other.nextDisalbed': false }) this.metaAction.toast('error', response.error.message) } else { this.metaAction.sf('data.other.nextDisalbed', false) this.load(response) } } } next = async () => { const code = this.metaAction.gf('data.form.code') const response = await this.webapi.arrival.next({ code,isReturnValue: true }) if (response) { if (response.result == false && response.error) { this.metaAction.sfs({ 'data.other.prevDisalbed':false, 'data.other.nextDisalbed': true }) this.metaAction.toast('error', response.error.message) } else { this.metaAction.sf('data.other.prevDisalbed', false) this.load(response) } } } setting = async () => { // this.metaAction.toast('error', '请实现设置功能') let setting = this.metaAction.gf('data.other.columnSetting') let initOption = [] setting = setting && setting.toJS() // console.log(setting, 'setting') 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, children: <ColumnsSetting option={initOption} singleKey='id' sort={true} editName={true} checkedKey='isVisible' labelKey="caption" /> }) if (res && res.type == 'confirm') { this.handleConfirmSet(res.option) } else if (res && res.type == 'reset') { this.handleResetSet(setting.code) } } //设置 恢复默认设置 handleResetSet = async (code) => { if (code) { const result = await this.webapi.arrival.reInitByUser({code: code}) this.metaAction.sf('data.other.columnSetting', fromJS(result)) } } //设置 确定 handleConfirmSet = async (params) => { if (params) { const setting = this.metaAction.gf('data.other.columnSetting').toJS() const cards = params[0] && params[0].option const tables = params[1] && params[1].option if (setting) { setting.header.cards = cards setting.body.tables[0].details = tables } const result = await this.webapi.arrival.updateWithDetail(setting) this.metaAction.sf('data.other.columnSetting', fromJS(result)) } } add = async() => { const res = await this.metaAction.modal('confirm',{ title: '放弃', content: '点击放弃会重置你所有的操作,确定要放弃吗?', }) if (res) { this.initLoad() } } audit = async () => { const id = this.metaAction.gf('data.form.id'), ts = this.metaAction.gf('data.form.ts'), status = this.metaAction.gf('data.form.status') if (!id && !ts) { this.metaAction.toast('error', '请保存单据') return } if (status == consts.consts.VOUCHERSTATUS_NotApprove || status == consts.consts.VOUCHERSTATUS_Rejected) { const response = await this.webapi.arrival.audit({ id, ts }) this.metaAction.toast('success', '单据审核成功') this.load(response) } else { const response = await this.webapi.arrival.unaudit({ id, ts }) this.metaAction.toast('success', '单据反审核成功') this.load(response) } } getAuditBtnText = () => { const status = this.metaAction.gf('data.form.status') return status == consts.consts.VOUCHERSTATUS_Approved ? '反审核' : '审核' } history = async () => { this.component.props.setPortalContent('采购', 'app-pu-arrival-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) { const response = await this.webapi.arrival.del({ id, ts }) this.metaAction.toast('success', '删除单据成功') this.initLoad() } } generateReturn = async () => { let id = this.metaAction.gf(`data.form.id`), ts = this.metaAction.gf(`data.form.ts`) if (!id && !ts) { this.metaAction.toast('error', '请保存单据!') return } } 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} ) } // 认证状态 手工录入 采集 导入 isShowAuthenticated = () => { const form = this.metaAction.gf('data.form') && this.metaAction.gf('data.form').toJS() if (form && (form.id || form.id == 0)) { if (form.voucherSource && form.voucherSource != "4000090001") { return true } } else { return false } } save = async (isNew) => { if (!this.checkForSave()) return let form = this.metaAction.gf('data.form').toJS() if (form.details) { form.details = form.details.filter(detail => { return (detail.inventoryId || detail.quantity || detail.price || 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 } const isDisableBank = this.metaAction.gf('data.other.isDisableBank') if (isDisableBank) { //退货业务不支持现结 params.settles = [] // params.settles = params.settles.filter(o => o.amount&&o.bankAccountId) } //不管是否为退货过滤掉没有金额和账户的,这样就不会出现只有账户也能生生付款单的清况 //但是当过滤掉这些时 现结账户就不会有默认值了 // params.settles = params.settles.filter(o => o.amount&&o.bankAccountId) 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() } } } else { const response = await this.webapi.arrival.create(params) if (response) { this.metaAction.toast('success', '保存单据成功') if (!isNew) { this.load(response) } else { this.initLoad() } } } } checkForSave = () => { const form = this.metaAction.gf('data.form').toJS(), chargeAmount = this.metaAction.gf('data.other.chargeAmount'), isDisableBank = this.metaAction.gf('data.other.isDisableBank') let msg = this.voucherAction.checkSaveInvoice(form, 'pu') 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 (chargeAmount < 0 && !isDisableBank) { //当不是退货 剩余金额小于0时 this.metaAction.toast('error', '现结金额不能大于价税合计金额') return false } return true } getDisplayErrorMSg = (msg) => { return <div style={{ display: 'inline-table' }}>{msg.map(item => <div>{item}<br /></div>)}</div> } // cancel = async () => { // // await this.voucherAction.cancel() // } cancel = () => { this.injections.reduce('init') } onFieldChange = (field, storeField,rowIndex,rowData,index) => (id) => { if (!field || !storeField) return let value = this.metaAction.gf(storeField).find(o => o.get('id') == id) if (value) { Object.keys(field).forEach(key => { this.metaAction.sf(field[key], value.get(key)) }) } if (storeField == 'data.other.inventory') { //当改变存货名称或编码时以下数据也要发生更改 const amount = utils.number.round(rowData.amount, 2), tax = utils.number.round(amount * value.get('taxRate'), 2), taxInclusiveAmount = utils.number.round(amount + tax, 2) this.metaAction.sfs({ [`data.form.details.${rowIndex}.taxRateId`]: value.get('rate'), [`data.form.details.${rowIndex}.taxRateName`]: value.get('rateName'), [`data.form.details.${rowIndex}.taxRate`]: value.get('taxRate'), [`data.form.details.${rowIndex}.tax`]: tax, [`data.form.details.${rowIndex}.taxInclusiveAmount`]: taxInclusiveAmount, }) } if (storeField == 'data.other.bankAccount') { if (value) { let settles = this.metaAction.gf('data.form.settles') settles = settles ? settles.toJS() : [] const id = value.toJS().id, name = value.toJS().name,amount = this.metaAction.gf('data.form.paymentAmount') if (settles.length == 0) { const obj ={ bankAccountId: id, amount: '', bankAccountName: name, } settles.push(obj) } else { settles[index].bankAccountId = id settles[index].bankAccountName = name } this.metaAction.sf('data.form.settles', fromJS(settles)) } } this.metaAction.sf('data.other.auditVisible', false) // if (storeField == 'data.other.supplier') { //现结账户不再由供应商带出默认 // this.supplierChange(value) // } } renderPropertyName = (rowData) => { //存货及服务分类 const form = this.metaAction.gf('data.form').toJS() if (form.id || form.id == 0) { if (rowData) { return rowData.invPropFullName } } else { if (rowData) { const propertyName = rowData.propertyName const propertyDetailName = rowData.propertyDetailName if (rowData.propertyDetailName) { return propertyName + '-'+ propertyDetailName } return propertyName } } } //支持搜索 filterOption = (inputValue, option, name) => { // console.log(inputValue, option, name) if (!option || !option.props || !option.props.value) { 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) 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('helpCode').search(regExp) != -1 // TODO 只支持助记码搜索,简拼 } //根据选择的供应商来得到对应的现结账户 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)) } } //计算 calc = (col, rowIndex, rowData, params) => (v) => { params = Object.assign(params, { value: v }) //以下两个if 是为了区分 是否修改了价税合计 // 修改了价税合计之后在修改税率 算法是不一样的 if (col === 'taxInclusiveAmount') { this.opertionTaxAmount = true this.oldIndex = rowIndex } if (col === 'taxRateName' && rowIndex == this.oldIndex && this.opertionTaxAmount) { params = Object.assign(params, { hasChangeTaxAmount: true }) } // const vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer'), // invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId') // let ncpfpType = false // if (vatTaxpayer == consts.consts.VATTAXPAYER_generalTaxPayer && invoiceTypeId == consts.consts.INVOICETYPE_ncpfp) { // ncpfpType = true // } this.voucherAction.calc(col, rowIndex, rowData, params) 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) { this.metaAction.sf('data.other.isDisableBank', true) return true } else { this.metaAction.sf('data.other.isDisableBank', false) return false } }) this.metaAction.sf('data.other.auditVisible', false) } delRowAfter = () => { console.log('1111') // this.extendAction.gridAction.delRow(params) } //计算剩余金额 calcBalance = (data) => { const taxInclusiveAmount = this.voucherAction.sum(data.form.details, (a, b) => a + b.taxInclusiveAmount) let paymentAmount = this.metaAction.gf('data.form.paymentAmount') paymentAmount = utils.number.round(paymentAmount,2) || 0 let payAmount = 0, settles = this.metaAction.gf('data.form.settles') settles = settles ? settles.toJS() : [] settles.forEach((item, index) => { payAmount = payAmount + item.amount }) const chargeAmount = this.voucherAction.numberFormat(taxInclusiveAmount - payAmount, 2) this.metaAction.sf('data.other.chargeAmount', chargeAmount) return chargeAmount } quantityFormat = (quantity, decimals, isFocus) => { if (quantity) { return this.voucherAction.numberFormat(quantity, decimals, isFocus) } } isRowOperation = () => { return this.metaAction.gf('data.form.certificateStatus') == data.STATUS_VOUCHER_NOT_AUDITED } // 控制 税率 税额 价税合计 认证 认证月份 是否显示 getControlVisible = (num, params) => { //INVOICETYPE_generalVATInvoice 增值税普通发票 //INVOICETYPE_otherInvoice 其他票据 //INVOICETYPE_uninvoiced 未开具发票 //VATTAXPAYER_smallScaleTaxPayer: '2000010002', //纳税人身份: 2000010002 小规模纳税人 let visible = false, invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId'), vatTaxpayer = this.metaAction.gf('data.other.vatTaxpayer') if (invoiceTypeId && vatTaxpayer != '2000010002') { switch(num) { case 0 : const generalVATInvoice = consts.consts.INVOICETYPE_generalVATInvoice const otherInvoice = consts.consts.INVOICETYPE_otherInvoice const uninvoiced = consts.consts.INVOICETYPE_uninvoiced // visible = (invoiceTypeId != generalVATInvoice || invoiceTypeId != otherInvoice || invoiceTypeId != uninvoiced) visible = !(invoiceTypeId == generalVATInvoice || invoiceTypeId == otherInvoice || invoiceTypeId == uninvoiced) break; case 1: const specialVATInvoice = consts.consts.INVOICETYPE_specialVATInvoice const hgjkzzszyjks = consts.consts.INVOICETYPE_hgjkzzszyjks visible = invoiceTypeId == specialVATInvoice || invoiceTypeId == hgjkzzszyjks break; default: visible = false } } return visible } 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 } authMonthValue = () => { const form = this.metaAction.gf('data.form').toJS() const authMonth = this.metaAction.gf('data.other.authMonth') if (form.id) { // let authenticatedMonth = form.authenticatedMonth // authenticatedMonth = authenticatedMonth.split('-')[1] // if (authenticatedMonth < 10) { // return authenticatedMonth%10 + '月' // } else { // return authenticatedMonth + '月' // } return form.authenticatedMonth && moment(form.authenticatedMonth) } else { // return moment().endOf('month') return authMonth&&moment(authMonth) } } // 勾选认证 authenticationChange = () => { const authenticated = this.metaAction.gf('data.form.authenticated') // date = new Date(), // authMonth = date.getMonth()+1 + '月', // authMonthList = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'], // year = date.getFullYear(), // authenticatedMonth = `${year}-${month}` // let month = date.getMonth() + 1 // month = month < 10 ? '0'+ month : month if (!authenticated) { // this.metaAction.sfs({ // 'data.other.authMonth': authMonth, // 'data.form.authenticatedMonth': authenticatedMonth, // 'data.other.authMonthList': fromJS(authMonthList) // }) const authenticatedMonth = moment().endOf('month').format('YYYY-MM') this.metaAction.sfs({ 'data.form.authenticatedMonth': moment().endOf('month').format('YYYY-MM'), 'data.other.authMonth': moment(authenticatedMonth) }) } else { this.metaAction.sfs({ // 'data.other.authMonth': '', 'data.form.authenticatedMonth': '', 'data.form.deductible': false }) } this.metaAction.sf('data.form.authenticated', !authenticated) } //认证 rendeRauthentication = () => { let authenticated = '认证', invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId') if (invoiceTypeId) { if (invoiceTypeId == consts.consts.INVOICETYPE_specialVATInvoice) { authenticated = '认证' } else if (invoiceTypeId == consts.consts.INVOICETYPE_hgjkzzszyjks) { authenticated = '比对' } } return authenticated } //抵扣 renderDeduction = () => { const invoiceTypeId = this.metaAction.gf('data.form.invoiceTypeId'), //票据类型id deductible = this.metaAction.gf('data.form.deductible'), authenticated = this.metaAction.gf('data.form.authenticated') //农产品发票,默认为勾选 if (invoiceTypeId == consts.consts.INVOICETYPE_ncpfp) { return <Checkbox checked={!deductible} className='app-pu-arrival-card-form-footer-settlement-leftFooter-deduction1' onChange={this.handleDeduction}>抵扣</Checkbox> } if (invoiceTypeId == consts.consts.INVOICETYPE_specialVATInvoice || invoiceTypeId == consts.consts.INVOICETYPE_hgjkzzszyjks) { return <Checkbox onChange={this.handleDeduction} checked={deductible} className='app-pu-arrival-card-form-footer-settlement-leftFooter-deduction' disabled={!authenticated}>抵扣</Checkbox> } return null } // 勾选抵扣 handleDeduction = () => { const deductible = this.metaAction.gf('data.form.deductible') this.metaAction.sf('data.form.deductible', !deductible) } //点击增加 现结账户 addPaymentAmount = () => { let settles = this.metaAction.gf('data.form.settles') settles = settles ? settles.toJS() : [] const obj = { bankAccountId: '', amount: '', bankAccountName: '', } if (settles.length == 0) settles.push(obj) settles.push(obj) this.metaAction.sf('data.form.settles', fromJS(settles)) } //现结金额失去焦点 才改变剩余金额 handlePayBlur = (v, index) => { let settles = this.metaAction.gf('data.form.settles') settles = settles ? settles.toJS() : [] if (settles.length == 0) { const obj ={ bankAccountId: '', amount: v, bankAccountName: '', } settles.push(obj) } else { settles[index].amount = v } this.metaAction.sf("data.form.paymentAmount", v) this.metaAction.sf("data.form.settles", fromJS(settles)) } //点击删除 现结账户金额 delPaymentAmount = (index) => { if (index) { let settles = this.metaAction.gf('data.form.settles') settles = settles ? settles.toJS() : [] settles.splice(index, 1) this.metaAction.sf('data.form.settles', fromJS(settles)) } } 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') return settles.map((item, index) => { return <div key={index}> <Form className='app-pu-arrival-card-form-footer-settlement'> <FormItem label='现结账户'> <Select showSearch={false} disabled={this.getDisable() || isDisableBank} placeholder='请选择账户' value={item.bankAccountName ? item.bankAccountName : undefined} onFocus={() => this.voucherAction.getBankAccount({}, `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='现结金额' > <Input.Number disabled={this.getDisable() || isDisableBank} value={item.amount} onBlur={(v) => this.handlePayBlur(v, index)} ></Input.Number> </FormItem> <div className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv'> <Icon type='plus' title='新增' className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv-iconAdd' disabled={this.getDisable() || isDisableBank} onClick={this.addPaymentAmount}></Icon> <Icon type='minus' title='删除' disabled={(index == 0 || isDisableBank) ? true : false} className='app-pu-arrival-card-form-footer-paymentAmount-iconDiv-iconDel' onClick={this.delPaymentAmount.bind(null, index)}></Icon> </div> </Form> </div> }) } //附件的下载操作 download = (ps) => { const form = this.metaAction.gf('data.form').toJS() if (form.id) { ps = ps.file } 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) } updateEnclosure = async (res) => { const result = await this.webapi.arrival.updateEnclosure(res) return result } beforeUpload = (info,infoList) => { this.voucherAction.beforeUpload(info,infoList) } attachmentChange = (info) => { this.voucherAction.attachmentChange(info, 'vouchers', this.updateEnclosure) } //即征即退 signChange = (id) => { const signAndRetreat = this.metaAction.gf('data.other.signAndRetreat').toJS() signAndRetreat.map((obj) => { if (obj.id == id) { obj.visible = true } else { obj.visible = false } }) // this.metaAction.sf('data.other.signAndRetreat', fromJS(signAndRetreat)) this.metaAction.sfs({ 'data.other.signAndRetreat': fromJS(signAndRetreat), 'data.other.auditVisible': false }) } getDisable = () => { let pageStatus = this.metaAction.gf('data.other.pageStatus') let disabled = pageStatus == common.commonConst.PAGE_STATUS.READ_ONLY return disabled } renderSign = () => { let signAndRetreat = this.metaAction.gf('data.other.signAndRetreat') signAndRetreat = signAndRetreat && signAndRetreat.toJS() return signAndRetreat ? signAndRetreat.map((item) => { if (item.visible == undefined) { if (item.name == '一般项目') { item.visible = true } else { item.visible = false } } return <Checkbox checked={item.visible} disabled={this.getDisable()} onChange={() => this.signChange(item.id)}>{item.name}</Checkbox> }) : null } //下拉选 票据类型 供应商 handleSelect = (params) => { params = params && params.toJS() if (params) { return params.map((item,index) => { return <Option value={item && item.id}>{item && item.name}</Option> }) } } //新增档案 addRecordClick = async (add, params, index, rowData) => { if (params == 'inventory') { await this.voucherAction[add]('data.other.inventoryItem') let inventory = this.metaAction.gf('data.other.inventory').toJS() const inventoryItem = this.metaAction.gf('data.other.inventoryItem').toJS() inventory.push(inventoryItem) this.metaAction.sf('data.other.inventory', fromJS(inventory)) let filed = { id: `data.form.details.${index}.inventoryId`, name: `data.form.details.${index}.inventoryName`, code: `data.form.details.${index}.inventoryCode`, unitId: `data.form.details.${index}.unitId`, unitName: `data.form.details.${index}.unitName`, propertyName: `data.form.details.${index}.propertyName`, taxRateName: `data.form.details.${index}.taxRateName`, specification: `data.form.details.${index}.specification` } this.onFieldChange(filed,'data.other.inventory',index,rowData)(inventoryItem.id) } else { await this.voucherAction[add]({ id: `data.form.${params}Id`, name: `data.form.${params}Name`}) } } //新增档案 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 let beginDate = this.metaAction.gf('data.other.beginDate'), currentDate = current.format('YYYY-MM-DD') beginDate = beginDate.replace(/-/g, '') currentDate = currentDate.replace(/-/g, '') return currentDate && currentDate < beginDate } filterOptionArchives = (name,inputValue, option) => { const namePrmas = { currentPath: name } return this.filterOption(inputValue, option, namePrmas) } renderArchives = () => { let columnSetting = this.metaAction.gf('data.other.columnSetting'), departmentName = this.metaAction.gf('data.form.departmentName')?this.metaAction.gf('data.form.departmentName'): undefined, purchasePersonName = this.metaAction.gf('data.form.purchasePersonName')?this.metaAction.gf('data.form.purchasePersonName'): undefined, projectName = this.metaAction.gf('data.form.projectName') ? this.metaAction.gf('data.form.projectName') : 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') columnSetting = columnSetting && columnSetting.toJS() const archivesArr = [ {label:'部门', name: 'department', upName: 'Department', value: departmentName, optionArr: department}, {label:'业务员', name: 'purchasePerson', upName: 'Person', value: purchasePersonName, optionArr: purchasePerson}, {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 if (isVisible) { return ( <FormItem label={item.label}> <Select showSearch={true} filterOption={this.filterOptionArchives.bind(null, item.name)} placeholder='按名称/拼音搜索' disabled={this.getDisable()} value={item.value} onFocus={() => this.voucherAction[`get${item.upName}`]({}, `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)} </Select> </FormItem> ) } else { return null } }) return domArr } } handleChange = (name,value) => { let obj = { 'data.other.auditVisible': false } obj[name] = value this.metaAction.sfs(obj) } //渲染表头 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') let defaultContentArr = [ <FormItem label='记账日期' required={true}> <DatePicker value={this.metaAction.stringToMoment(businessDate)} // onChange={(d) => this.metaAction.sf('data.form.businessDate', this.metaAction.momentToString(d, 'YYYY-MM-DD'))} 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}> <Select // showSearch={true} // filterOption={this.filterOption} disabled={this.getDisable()} value={invoiceTypeName} 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> </FormItem>, <FormItem label='供应商' required={true}> <Select showSearch={true} filterOption={this.filterOptionArchives.bind(null, 'supplier')} placeholder='按名称/拼音搜索' disabled={this.getDisable()}