UNPKG

ttk-app-core

Version:
237 lines (213 loc) 8.24 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { fromJS } from 'immutable' import config from './config' import extend from './extend' import { parse } from 'querystring'; import { number } from 'edf-utils' import { normalize } from 'path'; class action { constructor(option) { this.metaAction = option.metaAction this.config = config.current this.extendAction = option.extendAction this.webapi = this.config.webapi } onInit = ({ component, injections }) => { this.extendAction.gridAction.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.load() } load = async() => { const res = await this.webapi.list.getBussinessType({inventoryPropertyId: ''}) const date = await this.webapi.list.getEnableDate() console.log(res, date) this.injections.reduce('initOption', { inventoryPropertyOption: res, enableDate: date }) this.loadList() } onTabFocus = async (props) => { this.load() } dateChange = (value) => { console.log(value) this.metaAction.sf('data.form.accountingPeriod', fromJS(value)) this.loadList() } handleDisabledDate = (current) => { if (current) { let enableTime = this.metaAction.gf('data.other.enableDate'), currentDate = current.format('YYYY-MM') if (enableTime) enableTime = enableTime.replace(/-/g, '') if (currentDate) currentDate = currentDate.replace(/-/g, '') return currentDate && currentDate < enableTime } } autoCreate = async() => { let selectedArrInfo = this.extendAction.gridAction.getSelectedInfo('dataGrid') console.log(selectedArrInfo) if(!selectedArrInfo.length){ this.metaAction.toast('warn', '请选择要自动生成暂估单的数据') return false } const list = this.metaAction.gf('data.list').toJS() let noAmountArr = [] selectedArrInfo.forEach(item => { if( !item.amount ) { let itemIndex = list.findIndex(o => o.id == item.id) noAmountArr.push(itemIndex+1) } }) if( noAmountArr.length > 0 ) { return this.metaAction.toast('warn', `第${noAmountArr.join('、')}行的金额为空!`) } let date = this.metaAction.gf('data.form.accountingPeriod') const prefix = await this.webapi.list.getCode({ businessDate: date.format('YYYY-MM-DD'), codePrefix: 'ZR' }) let obj = { attachments: [], businessTypeId: 5001001004, businessDate: date.format('YYYY-MM-DD'), codePrefix: 'ZR', sourceVoucherCode: prefix, isEnable: true, manufacturCost: [], laborCost: null, materialCost: null, details: selectedArrInfo.map(item =>{ const amount = number.clearThousPos(item.amount) return { ...item, quantity: item.temporaryEstimationQty, amount: amount, price: Math.abs(amount/item.temporaryEstimationQty) } }) } const res = await this.webapi.list.create(obj) console.log(res) } selectChange = (value) => { console.log(value) this.metaAction.sf('data.form.inventoryPropertyId', value) this.loadList() } loadList = async() => { const params = this.metaAction.gf('data.form').toJS() let obj = { inventoryPropertyId: params.inventoryPropertyId ? params.inventoryPropertyId : '', accountingYear: params.accountingPeriod.format('YYYY'), accountingPeriod: params.accountingPeriod.format('M') } const res = await this.webapi.list.getList(obj) this.metaAction.sf('data.list', fromJS(res)) } btnTipsClick = () => { this.metaAction.sf('data.stepsEnabled',true) } onExit = () => { this.injections.reduce('modifyContent') } isSelectAll = (gridName) => { return this.extendAction.gridAction.isSelectAll(gridName) } selectRow = (rowIndex) => (e) => { this.injections.reduce('selectRow', rowIndex, e.target.checked) } renderQuantity = (a, b, c) => { if(a && b && c){ let value = parseFloat(a) + parseFloat(b) - parseFloat(c) return number.format(value,6) } } formatAmount = (value) => { if (value) { return number.format(value, 2) } return null } amountChange = (value, index) => { console.log(value, index) const list = this.metaAction.gf('data.list').toJS() list[index].amount = value this.metaAction.sf('data.list', fromJS(list)) console.log(list) } amountBlur = (value, index) => { console.log(value, index) const list = this.metaAction.gf('data.list').toJS() list[index].amount = number.format(value, 2) this.metaAction.sf('data.list', fromJS(list)) } // 导出 export = async() => { let list = this.metaAction.gf('data.list').toJS(), partInventoryDtos = [] const params = this.metaAction.gf('data.form').toJS() list.map(item=> { partInventoryDtos.push({ inventoryId: item.inventoryId, temporaryEstimationQty: item.temporaryEstimationQty, temporaryEstimationAmount: item.amount }) }) let filter = { inventoryPropertyId: params.inventoryPropertyId ? params.inventoryPropertyId : '', accountingYear: params.accountingPeriod.format('YYYY'), accountingPeriod: params.accountingPeriod.format('M'), partInventoryDtos } if(!list.length){ this.metaAction.toast('warning', '当前没有可导出数据') return false }else{ let res = await this.webapi.list.export(filter) if(res) this.metaAction.toast('success', '导出成功') } } // 打印 print = async() => { let list = this.metaAction.gf('data.list').toJS(), partInventoryDtos = [] const params = this.metaAction.gf('data.form').toJS() list.map(item=> { partInventoryDtos.push({ inventoryId: item.inventoryId, temporaryEstimationQty: item.temporaryEstimationQty, temporaryEstimationAmount: item.amount }) }) let filter = { inventoryPropertyId: params.inventoryPropertyId ? params.inventoryPropertyId : '', accountingYear: params.accountingPeriod.format('YYYY'), accountingPeriod: params.accountingPeriod.format('M'), partInventoryDtos } if(!list.length){ this.metaAction.toast('warning', '当前没有可打印数据') return false }else{ let res = await this.webapi.list.print(filter) if(res) this.metaAction.toast('success', '打印成功') } } changeNumber = (value, name) => { if(name == 'quantity'){ return number.format(value,6) }else{ return number.format(value,2) } } } export default function creator(option) { const metaAction = new MetaAction(option), extendAction = extend.actionCreator({...option, metaAction}), o = new action({...option, metaAction, extendAction}), ret = {...metaAction, ...extendAction.gridAction, ...o} metaAction.config({metaHandlers: ret}) return ret }