ttk-app-core
Version:
enterprise develop framework
112 lines (100 loc) • 3.79 kB
JavaScript
import React from 'react'
import { fromJS } from 'immutable'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import config from './config'
import { FormDecorator } from 'edf-component'
import { getInitState } from './data'
class action {
constructor(option) {
this.metaAction = option.metaAction
this.voucherAction = option.voucherAction
this.config = config.current
}
onInit = ({ component, injections }) => {
this.voucherAction.onInit({ component, injections })
this.component = component
this.injections = injections
injections.reduce('init')
}
btnClick = () => {
this.injections.reduce('modifyContent')
}
valueChange = (key, value) => {
console.log(key, value)
this.metaAction.sf(`data.form.${key}`, value)
}
nextClick = (current) => {
console.log(current)
if (current == 2) {
this.metaAction.sf('data.current', 0)
this.metaAction.sf('data.form', fromJS(getInitState().data.form))
return
}
const falg = this.check(current)
if( !falg ) {
this.metaAction.sf('data.current', current + 1)
}
}
check = (current) => {
const form = this.metaAction.gf('data.form').toJS()
let error = {}
let flag = false
switch (current) {
case 0:
const requireKey = ['name', 'age', 'sex', 'deparment']
for( const [key, value] of Object.entries(form)){
if( !value && requireKey.includes(key)){
console.log(key, value)
if( !error ){
error = {}
}
flag = true
error[key] = '该项是必填项,请正确填写。'
}else{
console.log(key, value, 'ssssssss')
error[key] = null
}
}
break;
case 1:
const requireKey2 = ['address', 'level', 'time']
for( const [key, value] of Object.entries(form)){
if( !value && requireKey2.includes(key)){
console.log(key, value)
if( !error ){
error = {}
}
flag = true
error[key] = '该项是必填项,请正确填写。'
}else if( key == 'checkbox' && value != true){
flag = true
error[key] = '你没有勾选该项。'
}else{
console.log(key, value, 'ssssssss')
error[key] = null
}
}
default:
break;
}
this.metaAction.sf('data.error', fromJS(error))
return flag
}
preClick = (current) => {
console.log(current)
let num = current - 1
this.metaAction.sf('data.current',num)
}
cancelClick = () => {
this.metaAction.sf('data.current', 0)
this.metaAction.sf('data.form', fromJS(getInitState().data.form))
}
}
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
}