UNPKG

ttk-app-core

Version:
118 lines (103 loc) 3.96 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import config from './config' import { FormDecorator, LoadingMask } from 'edf-component' import { fetch } from 'edf-utils' import utils from 'edf-utils' import { trimExt } from 'upath'; import moment from 'moment' import { Map, fromJS, toJS } from 'immutable' class action { constructor(option) { this.metaAction = option.metaAction this.config = config.current this.webapi = this.config.webapi // this.beforeLoad = option.voucherAction.excelbeforeUpload } onInit = ({ component, injections }) => { this.component = component this.injections = injections if (this.component.props.setOkListener) { this.component.props.setOkListener(this.onOk) } // let defaultdate = this.component.props.defaultdate // if (!defaultdate) { // defaultdate = moment().subtract(1, "months").startOf('month') // } injections.reduce('init'); //this.load(this.component.props.vatOrEntry) this.load(); } load = async () => { let enableddate = this.component.props.enableddate;//启用日期 let defaultdate = this.component.props.defaultdate;//默认日期 let settledate = await this.webapi.getSettleDate();//结账日期 //let defaultdate = moment().subtract(1, "months").startOf('month');//默认日期为上月 if (settledate && settledate.year && settledate.month) { settledate = utils.date.transformMomentDate(`${settledate.year}-${settledate.month}`); if (settledate.format('YYYYMM') > defaultdate.format('YYYYMM')) { defaultdate = settledate.startOf('month');//记账日期的下月 } enableddate = settledate //setTimeout(() => { this.injections.reduce('load', { defaultdate, enableddate }); //}, 3000); } } //load = async () => { //获取银行账户 //const res = await this.webapi.bankAccount({ status: true }); //this.injections.reduce('load', { res: res.list }); //} // onCancel = async () => { // this.component.props.closeModal({ cancel: true }); // } //改变账户 // bankAccountChange = async (value) => { // this.injections.reduce('updateArr', 'data.form.bankAccountId', value); // } dateChange = async (date, dateString) => { this.injections.reduce('dateChange', date); } // accountDateChange = async (date) => { // this.injections.reduce('accountDateChange', date); // } onOk = async () => { const data = this.metaAction.gf('data').toJS(); if (!data.date) { this.metaAction.toast('error', '请选择采集月份') return false } this.injections.reduce('updateTip', '发票采集中...'); this.injections.reduce('loading', true); let date = data.date.format('YYYY-MM');//当前月份 let begin = moment(date).startOf('month')//起始日期 let end = moment(date).endOf('month')//结束日期 begin = `${begin.format('YYYY-MM-DD')} 00:00:00`; end = `${end.format('YYYY-MM-DD')} 23:59:59`; const res = await this.component.props.collectOnOk({ begin, end }); this.injections.reduce('loading', false); //console.log(res, '1'); if (res) { res.collectDate = [moment(begin), moment(end)]; return res // return this.component.props.closeModal(res); } else { //this.metaAction.toast('error', res.message) return false } } disabledRangePicker = (currentDate) => { let enableddate = this.metaAction.gf('data.enableddate'); return currentDate.format('YYYYMM') < enableddate.format('YYYYMM') //|| currentDate.format('YYYYMM') > moment().format('YYYYMM') } } export default function creator(option) { const metaAction = new MetaAction(option), voucherAction = FormDecorator.actionCreator({ ...option, metaAction }), o = new action({ ...option, metaAction, voucherAction }), ret = { ...metaAction, ...voucherAction, ...o } metaAction.config({ metaHandlers: ret }) return ret }