Commit 1b68a7f5 authored by 田翔's avatar 田翔

fix: 表格增加自动计算

parent 6b445141
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "5.0.8", "version": "5.0.9",
"description": "5.0.8 关联表单可编辑增加数值与日期形态", "description": "5.0.9 表格增加自动计算",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
import React from 'react' import React, { useEffect, useCallback } from 'react'
import { Input, InputNumber, DatePicker } from 'antd' import { Input, InputNumber, DatePicker } from 'antd'
import locale from 'antd/lib/date-picker/locale/zh_CN' import locale from 'antd/lib/date-picker/locale/zh_CN'
import moment from 'moment' import moment from 'moment'
import { debounce } from '../../../../../../utils'
import { formAutomaticComputation } from '../../../../../../apis/process'
const formAutomatic = async (parmas, callback) => {
const { code, data } = await formAutomaticComputation(parmas)
if (code === 0) {
let otherRow = {}
let datas = [...parmas.values, ...data]
datas.forEach(v => {
otherRow[v.fieldName] = v.fieldValue + ''
})
callback(otherRow)
}
}
const formAuto = debounce(formAutomatic)
const ValueEdit = (props) => { const ValueEdit = (props) => {
const preview = sessionStorage.getItem('FormRender')
const userInfo = preview === 'preview' ? { fullName: '【本人姓名】', depart: { name: '【本人部门】' } } : window?.globalConfig?.userInfo || { fullName: '【本人姓名】', depart: { name: '【本人部门】' } }
const { const {
onChange, onChange,
value, value,
fieldName,
record,
autoArray,
otherChange,
presetValue,
disabled, disabled,
placeholder, placeholder,
widget, widget,
...@@ -15,8 +39,34 @@ const ValueEdit = (props) => { ...@@ -15,8 +39,34 @@ const ValueEdit = (props) => {
min, min,
max, max,
formatter, formatter,
isStoreID,
} = props } = props
useEffect(() => {
if (widget === 'TextInput') {
let paths = ['【本人姓名】', '【本人部门】']
let value = presetValue
if (preview === 'preview') {
if (paths.includes(value)) {
if (value === '【本人姓名】') {
if (isStoreID) {
value = userInfo.OID + ''
} else {
value = userInfo.fullName
}
} else if (value === '【本人部门】') {
if (isStoreID) {
value = userInfo.depart.OID + ''
} else {
value = userInfo.depart.name
}
}
onChange({ fieldName, fieldValue: value })
}
}
}
}, [])
if (widget === 'DateTime') { if (widget === 'DateTime') {
const isValid = value ? moment(value)._isValid : false const isValid = value ? moment(value)._isValid : false
const timeOtions = format === 'dateTime' ? const timeOtions = format === 'dateTime' ?
...@@ -43,9 +93,9 @@ const ValueEdit = (props) => { ...@@ -43,9 +93,9 @@ const ValueEdit = (props) => {
locale={locale} locale={locale}
onChange={(date) => { onChange={(date) => {
if (date && date._d) { if (date && date._d) {
onChange(moment(date._d).format('YYYY-MM-DD HH:mm:ss')) onChange({ fieldName, fieldValue: moment(date._d).format('YYYY-MM-DD HH:mm:ss') })
} else { } else {
onChange('') onChange({ fieldName, fieldValue: '' })
} }
}} }}
/> />
...@@ -62,10 +112,19 @@ const ValueEdit = (props) => { ...@@ -62,10 +112,19 @@ const ValueEdit = (props) => {
disabled={disabled} disabled={disabled}
value={value === '' ? null : Number(value)} value={value === '' ? null : Number(value)}
onChange={(value) => { onChange={(value) => {
if (value !== null) { onChange({ fieldName, fieldValue: value !== null ? `${value}` : '' })
onChange(`${value}`) if (autoArray.length) {
} else { autoArray.forEach(v => {
onChange('') if (v.fields.includes(fieldName)) {
let values = v.fields.map(s => {
if (s === fieldName) {
return { fieldName, fieldValue: value !== null ? `${value}` : '' }
}
return { fieldName: s, fieldValue: record?.[s] || '' }
})
formAuto({ ...v, values }, otherChange)
}
})
} }
}} }}
style={{ width: '100%' }} style={{ width: '100%' }}
...@@ -76,7 +135,7 @@ const ValueEdit = (props) => { ...@@ -76,7 +135,7 @@ const ValueEdit = (props) => {
return ( return (
<Input <Input
disabled={disabled} disabled={disabled}
onChange={(e) => onChange(e.target.value)} onChange={(e) => onChange({ fieldName, fieldValue: e.target.value })}
value={value} value={value}
/> />
) )
......
...@@ -145,7 +145,7 @@ const TablePack = (props, ref) => { ...@@ -145,7 +145,7 @@ const TablePack = (props, ref) => {
} }
//关联表单表头 //关联表单表头
const getRelevanceColumnProps = (json, field, isEdit = false) => { const getRelevanceColumnProps = ({ json, field, isEdit, autoArray }) => {
const { fieldName, columnWidth, isSort, accurateSearch } = field const { fieldName, columnWidth, isSort, accurateSearch } = field
const { widget } = json?.[fieldName] || {} const { widget } = json?.[fieldName] || {}
let searchProps = {} let searchProps = {}
...@@ -229,12 +229,17 @@ const TablePack = (props, ref) => { ...@@ -229,12 +229,17 @@ const TablePack = (props, ref) => {
}, },
}), }),
render: (value, record) => { render: (value, record) => {
let props = { ...json[fieldName], value } let props = { ...json[fieldName], fieldName, value, autoArray, record: { ...record } }
if (isEdit && !notUse?.includes('edit')) { if (isEdit && !notUse?.includes('edit')) {
return ( return (
<ValueEdit <ValueEdit
{...props} {...props}
onChange={(value) => btnsClick({ type: '变化', row: { ...record, [fieldName]: value } })} onChange={({ fieldName, fieldValue }) => {
btnsClick({ type: '变化', row: { ...record, [fieldName]: fieldValue } })
}}
otherChange={(otherRow) => {
btnsClick({ type: '变化', row: { ...record, ...otherRow } })
}}
value={value} value={value}
/> />
) )
...@@ -299,10 +304,30 @@ const TablePack = (props, ref) => { ...@@ -299,10 +304,30 @@ const TablePack = (props, ref) => {
const fileColumns = useMemo(() => { const fileColumns = useMemo(() => {
let json = getFieldInfo(formJson) let json = getFieldInfo(formJson)
let autoArray = []
Object.keys(json).forEach(key => {
let item = json[key]
if (item.widget === 'NumberInput') {
if (item.calculateRule) {
let parmas = {
fields: item?.rules[0]?.fields,
tableName: item.tableNameParent,
filedFormulas: [
{
fieldName: key,
formula: item.calculateRule
}
]
}
autoArray.push(parmas)
}
}
})
let array = [] let array = []
showField.forEach((v, i) => { showField.forEach((v, i) => {
if (parent === '关联表单') { if (parent === '关联表单') {
array.push(getRelevanceColumnProps(json, v, isEdit)) // array.push(getRelevanceColumnProps(json, v, isEdit))
array.push(getRelevanceColumnProps({ json, field: v, isEdit, autoArray }))
} else { } else {
array.push(getColumnProps(json, v)) array.push(getColumnProps(json, v))
} }
...@@ -447,8 +472,6 @@ const TablePack = (props, ref) => { ...@@ -447,8 +472,6 @@ const TablePack = (props, ref) => {
tableChange?.({}, filtered, sortedInfo) tableChange?.({}, filtered, sortedInfo)
} }
console.log('props', props, btns, columns)
return ( return (
<div className={styles.tablePack} style={{ paddingTop: filtered.length ? '30px' : '10px' }}> <div className={styles.tablePack} style={{ paddingTop: filtered.length ? '30px' : '10px' }}>
{ {
......
...@@ -305,6 +305,7 @@ const RelationForm = (props) => { ...@@ -305,6 +305,7 @@ const RelationForm = (props) => {
let field = config?.accountFieids?.filter(v => v.webDisplay).map(v => v.fieldName) let field = config?.accountFieids?.filter(v => v.webDisplay).map(v => v.fieldName)
let obj = {} let obj = {}
field.forEach(v => { field.forEach(v => {
obj[v] = ''
if (Array.isArray(mappedField)) { if (Array.isArray(mappedField)) {
mappedField.forEach(s => { mappedField.forEach(s => {
if (s.toField === v) { if (s.toField === v) {
......
import RelationForm from './RelationForm' import RelationForm from './RelationForm'
import Signature from './Signature' import Signature from './Signature'
import AutoCalculate from './AutoCalculate'
const advanced = { const advanced = {
RelationForm, RelationForm,
Signature, Signature,
AutoCalculate,
} }
export default advanced export default advanced
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment