UNPKG

ttk-app-core

Version:
254 lines (235 loc) 9.88 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { Icon } from 'edf-component' import config from './config' import { Tree } from 'edf-component' import { FormDecorator } from 'edf-component' import extend from './extend' 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.component = component this.injections = injections if (this.component.props.setOkListener) { this.component.props.setOkListener(this.onOk) } injections.reduce('init') this.load() } load = async () => { let inventoryType = this.component.props.inventoryType // delivery 销项 this.metaAction.sf('data.other.loading', true) let res = await this.webapi.handleRule.getMatchingRule(); // res.invoiceInventoryList = [ // { // } // ] let inventory, response if (inventoryType == 'delivery') { //进项 inventory = await this.webapi.handleRule.inventory() if (inventory) inventory = inventory.list.filter(item => item.isEnable == true) response = { inventoryType, res, inventory } } else { // 进项 inventory = await this.webapi.handleRule.queryInventory() if (inventory) { inventory.forEach(el => { el.name = el.code + ' ' + el.name; }); } response = { inventoryType, res, inventory } } if (res) { this.metaAction.sf('data.other.loading', false) this.injections.reduce('load', response) } } isDelivery = (id) => { let inventoryType = this.component.props.inventoryType if (inventoryType == id) { return true } else { return false } } renderCustomer = () => { let inventoryType = this.component.props.inventoryType if (inventoryType == 'delivery') { return '生成客户档案' } else { return '生成供应商档案' } } renderChild = () => { let inventoryType = this.component.props.inventoryType if (inventoryType == 'delivery') { return '发票采集/导入后,按"购方名称"作为"客户名称"新增客户档案' } else { return '发票采集/导入后,按"销方名称"作为"供应商名称"新增供应商档案' } } setInventory = (path, value) => { this.injections.reduce('upDate', { path, value }) } onFieldChange = (value, index) => { // console.log(value, index) if (!value) { this.injections.reduce('upDate', { path: `data.form.details.${index}.inventoryId`, value: null }) this.injections.reduce('upDate', { path: `data.form.details.${index}.name`, value: null }) } else { let detail = this.metaAction.gf('data.other.inventory').toJS() let inventory = detail.find(item => item.id == value) this.injections.reduce('upDate', { path: `data.form.details.${index}.inventoryId`, value: inventory.id }) this.injections.reduce('upDate', { path: `data.form.details.${index}.name`, value: inventory.name }) this.injections.reduce('upDate', { path: `data.form.details.${index}.propertyId`, value: inventory.propertyId }) // this.injections.reduce('upDate', { path: `data.form.details.${index}.propertyName`, value: inventory.propertyName }) } } //新增档案 addRecordClick = async (index) => { const ret = await this.metaAction.modal('show', { title: '新增存货', width: 750, children: this.metaAction.loadApp( 'app-card-inventory', { store: this.component.props.store } ) }) // console.log(ret) if (ret) { if (!ret.isEnable) { return } this.injections.reduce('upDate', { path: `data.form.details.${index}.inventoryId`, value: ret.id }) this.injections.reduce('upDate', { path: `data.form.details.${index}.name`, value: ret.name }) this.injections.reduce('upDate', { path: `data.form.details.${index}.propertyId`, value: ret.propertyId }) // this.injections.reduce('upDate', { path: `data.form.details.${index}.propertyName`, value: ret.propertyName }) //this.load() let inventoryType = this.component.props.inventoryType // delivery 销项 let inventory if (inventoryType == 'delivery') { inventory = await this.webapi.handleRule.inventory() } else { // 进项 inventory = await this.webapi.handleRule.queryInventory() } this.injections.reduce('upDate', { path: 'data.other.inventory', value: inventory.list }) } } //支持搜索 filterOption = (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 || paramsValue.get('helpCodeFull').search(regExp) != -1 // TODO 只支持助记码搜索,简拼 } onOk = async () => { this.metaAction.sf('data.other.loading', true) let inventoryType = this.component.props.inventoryType // delivery 销项 let inventorySet = this.metaAction.gf('data.form.inventorySet'), customerSet = this.metaAction.gf('data.form.customerSet'), detail = this.metaAction.gf('data.form.details').toJS(), otherCustomerSet = this.metaAction.gf('data.form.otherCustomerSet'), id = this.metaAction.gf('data.form.id'), ts = this.metaAction.gf('data.form.ts') detail.forEach((el) => { if (el.propertyId == 4001001) { el.businessTypeId = el.inventoryId; el.inventoryId = null } else { el.businessTypeId = null } delete el.propertyId }) if (inventorySet) { inventorySet = 1 } else { inventorySet = 0 } if (customerSet) { customerSet = 1 } else { customerSet = 0 } let filter = { achivalRuleDto: {}, invoiceInventoryList: detail } if (otherCustomerSet) { otherCustomerSet = 1 } else { otherCustomerSet = 0 } if (inventoryType == 'delivery') { filter.vatOrEntry = 0 filter.achivalRuleDto = { inventorySet, customerSet, supplierSet: otherCustomerSet, id, ts } } else { filter.vatOrEntry = 1 filter.achivalRuleDto = { inventorySet, supplierSet: customerSet, customerSet: otherCustomerSet, id, ts } } let res = await this.webapi.handleRule.updateMatchingRule(filter) if (res.result) { this.metaAction.toast('success', '更新成功') } else { this.metaAction.toast('error', '更新失败') } } } 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 }