UNPKG

ttk-app-core

Version:
478 lines (441 loc) 19.8 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' import { Radio, Select } from 'edf-component' const RadioGroup = Radio.Group; 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.tabarr = ["1"]; this.load1() this.load2() this.load3() } load1 = async () => { let vatOrEntry = this.component.props.vatOrEntry if (vatOrEntry == 0) { this.metaAction.sf('data.other.visible', false) } else { this.metaAction.sf('data.other.visible', true) } const res = await this.webapi.bookkeeping.initKeepAccount({ vatOrEntry }); this.injections.reduce('load1', { ...res, vatOrEntry }); } onBookWayChange = (e) => { const bankAccount = this.metaAction.gf('data.bankAccount').toJS(); const bank = bankAccount.filter((x) => { return x.bankAccountTypeName == '银行' }); const alipay = bankAccount.filter((x) => { return x.bankAccountTypeName == '支付宝' }); const wechat = bankAccount.filter((x) => { return x.bankAccountTypeName == '微信' }); this.metaAction.sf('data.form1.settlement', e.target.value) if (e.target.value == '3000050002') { this.metaAction.sf('data.form1.bankAccountId', bank[0].id) } else if (e.target.value == '3000050003') { this.metaAction.sf('data.form1.bankAccountId', wechat[0].id) } else if (e.target.value == '3000050004') { this.metaAction.sf('data.form1.bankAccountId', alipay[0].id) } else { this.metaAction.sf('data.form1.bankAccountId', null) } } onBookDateChange = (e) => { this.metaAction.sf('data.form1.accountDateSet', e.target.value) } onAccountChange = (value) => { this.metaAction.sf('data.form1.bankAccountId', value) } renderBookWay = () => { const data = this.metaAction.gf('data').toJS(); const bankAccount = data.bankAccount; const settlement = data.form1.settlement; const bankAccountId = data.form1.bankAccountId const radioStyle = { display: 'block', height: '30px', lineHeight: '30px', fontSize: '12px' }; const bank = bankAccount.filter((x) => { return x.bankAccountTypeName == '银行' }); const alipay = bankAccount.filter((x) => { return x.bankAccountTypeName == '支付宝' }); const wechat = bankAccount.filter((x) => { return x.bankAccountTypeName == '微信' }); return <RadioGroup onChange={this.onBookWayChange} value={`${settlement}`}> <Radio style={radioStyle} value='3000050006'>暂未收款</Radio> <Radio style={radioStyle} value='3000050001'>现金</Radio> {bank.length > 0 && <Radio style={radioStyle} value='3000050002'> 银行 {settlement == '3000050002' ? <Select showSearch={false} style={{ width: '100%', marginLeft: 10, fontSize: '12px' }} onChange={this.onAccountChange.bind(this)} value={bankAccountId}> {bank.map((item, index) => { return <Option value={item.id} key={index}>{item.name}</Option> })} </Select> : null} </Radio> } {wechat.length > 0 && <Radio style={radioStyle} value='3000050003'> 微信 {settlement == '3000050003' ? <Select showSearch={false} style={{ width: 105, marginLeft: 10, fontSize: '12px' }} onChange={this.onAccountChange.bind(this)} value={bankAccountId}> {wechat.map((item, index) => { return <Option value={item.id} key={index}>{item.name}</Option> })} </Select> : null} </Radio>} { alipay.length > 0 && <Radio style={radioStyle} value='3000050004'> 支付宝 {settlement == '3000050004' ? <Select showSearch={false} style={{ width: 105, marginLeft: 10, fontSize: '12px' }} onChange={this.onAccountChange.bind(this)} value={bankAccountId}> {alipay.map((item, index) => { return <Option value={item.id} key={index}>{item.name}</Option> })} </Select> : null} </Radio> } </RadioGroup> } renderBookDate = () => { const bookDate = this.metaAction.gf('data.form1.accountDateSet'); const radioStyle = { display: 'block', height: '30px', lineHeight: '30px', fontSize: '12px' }; if (!this.component.props.vatOrEntry) { return <RadioGroup onChange={this.onBookDateChange} value={bookDate}> <Radio style={radioStyle} value={1}>发票日期</Radio> <Radio style={radioStyle} value={0}>发票日期所在月最后一天</Radio> </RadioGroup > } else { return <RadioGroup onChange={this.onBookDateChange} value={bookDate}> <Radio style={radioStyle} value={0}>采集发票所在月最后一天</Radio> </RadioGroup > } } onOk1 = async () => { const params = this.metaAction.gf('data.form1').toJS(); const res = await this.webapi.bookkeeping.update({ ...params }); if (!res) { this.metaAction.toast('error', `${res.msg}`) } return res; // if (res) { // this.component.props.closeModal(res); // } else { // this.component.props.closeModal(res); // } } load2 = async () => { let inventoryType = this.component.props.inventoryType // delivery 销项 this.metaAction.sf('data.other.loading2', true) let res = await this.webapi.handleRule.getMatchingRule(); // res.invoiceInventoryList = [ // { // } // ] let inventory, response if (inventoryType == 'delivery') { inventory = await this.webapi.handleRule.inventory() response = { inventoryType, res, inventory: inventory.list } } else { // 进项 inventory = await this.webapi.handleRule.queryInventory() if (inventory) { inventory.forEach(el => { el.name = el.code + ' ' + el.name; }); } response = { inventoryType, res, inventory } } if (res) { res.invoiceInventoryList.forEach((el) => { if (el.businessTypeName && !el.name) { el.name = el.businessTypeName } } ) this.metaAction.sf('data.other.loading2', false) this.injections.reduce('load2', 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 }) } isNormal = () => { if (this.metaAction.context.get("currentOrg").vatTaxpayer != 2000010002) { return true } else { return false } } //进项 onFieldChange = (value, index) => { if (!value) { this.injections.reduce('upDate', { path: `data.form2.details.${index}.inventoryId`, value: null }) this.injections.reduce('upDate', { path: `data.form2.details.${index}.name`, value: null }) this.injections.reduce('upDate', { path: `data.form2.details.${index}.businessTypeId`, value: null }) this.injections.reduce('upDate', { path: `data.form2.details.${index}.businessTypeName`, value: null }) } else { let detail = this.metaAction.gf('data.other.inventory').toJS() let inventory = detail.find(item => item.id == value) if (inventory.propertyId == 4001001) { // this.injections.reduce('upDate', { path: `data.form2.details.${index}.businessTypeId`, value: inventory.id }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.businessTypeName`, value: inventory.name }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.inventoryId`, value: null }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.name`, value: inventory.name }) let arr = {} arr[`data.form2.details.${index}.businessTypeId`] = inventory.id; arr[`data.form2.details.${index}.businessTypeName`] = inventory.name; arr[`data.form2.details.${index}.inventoryId`] = null; arr[`data.form2.details.${index}.name`] = inventory.name; this.injections.reduce('upDateSfs', arr); } else { // this.injections.reduce('upDate', { path: `data.form2.details.${index}.businessTypeId`, value: null }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.businessTypeName`, value: null }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.inventoryId`, value: inventory.id }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.name`, value: inventory.name }) let arr = {} arr[`data.form2.details.${index}.businessTypeId`] = null; arr[`data.form2.details.${index}.businessTypeName`] = null; arr[`data.form2.details.${index}.inventoryId`] = inventory.id; arr[`data.form2.details.${index}.name`] = inventory.name; this.injections.reduce('upDateSfs', arr); } // this.injections.reduce('upDate', { path: `data.form2.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.form2.details.${index}.inventoryId`, value: ret.id }) this.injections.reduce('upDate', { path: `data.form2.details.${index}.name`, value: ret.name }) // this.injections.reduce('upDate', { path: `data.form2.details.${index}.propertyId`, value: ret.propertyId }) // this.injections.reduce('upDate', { path: `data.form2.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() this.injections.reduce('upDate', { path: 'data.other.inventory', value: inventory.list }) } else { // 进项 inventory = await this.webapi.handleRule.queryInventory() if (inventory) { inventory.forEach(el => { el.name = el.code + ' ' + el.name; }); } this.injections.reduce('upDate', { path: 'data.other.inventory', value: inventory }) } } } //支持搜索 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 只支持助记码搜索,简拼 } onOk2 = async () => { this.metaAction.sf('data.other.loading2', true) let inventoryType = this.component.props.inventoryType // delivery 销项 let inventorySet = this.metaAction.gf('data.form2.inventorySet'), customerSet = this.metaAction.gf('data.form2.customerSet'), detail = this.metaAction.gf('data.form2.details').toJS(), otherCustomerSet = this.metaAction.gf('data.form2.otherCustomerSet'), id = this.metaAction.gf('data.form2.id'), ts = this.metaAction.gf('data.form2.ts') //接口返回数据没有propertyId所以出现bug detail.forEach((el) => { // if (el.propertyId == 4001001) { // el.businessTypeId = el.inventoryId; // //el.bussnessTypeName = el.name; // el.inventoryId = null // // delete el.name // } else { // el.businessTypeId = null // } if (el.businessTypeId) { el.name = null el.inventoryId = null } if (el.inventoryId) { el.businessTypeName = null el.businessTypeId = null } if (!el.businessTypeId && !el.inventoryId) { el.name = null el.inventoryId = null el.businessTypeName = null el.businessTypeId = null } }) 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) return res.result; // if (res.result) { // this.metaAction.toast('success', '更新成功') // } else { // this.metaAction.toast('error', '更新失败') // } } load3 = async () => { const res = await this.webapi.handleType.queryCollectParam(); this.injections.reduce('load3', res); } handleCheckboxChange = (path, value) => { this.injections.reduce('upDate', { path, value: value ? 1 : 0 }) } onOk3 = async () => { const params = this.metaAction.gf('data.form3').toJS(); const res = await this.webapi.handleType.saveCollectParam(params); return res; } onOk = async () => { let res1 = true, res2 = true, res3 = true if (this.tabarr.includes('1')) { res1 = await this.onOk1(); } if (this.tabarr.includes('2')) { res2 = await this.onOk2(); } if (this.tabarr.includes('3')) { res3 = await this.onOk3(); } if (res1 && res2 && res3) { this.metaAction.toast('success', '保存成功') } else { this.metaAction.toast('error', '保存失败'); return false } } changeTabs = (activeKey) => { if (!this.tabarr.includes(activeKey)) this.tabarr.push(activeKey) } } 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 }