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

fix: 表格增加自动计算

parent 6b445141
{
"name": "panda-xform",
"version": "5.0.8",
"description": "5.0.8 关联表单可编辑增加数值与日期形态",
"version": "5.0.9",
"description": "5.0.9 表格增加自动计算",
"keywords": [
"panda-xform"
],
......
import React from 'react'
import React, { useEffect, useCallback } from 'react'
import { Input, InputNumber, DatePicker } from 'antd'
import locale from 'antd/lib/date-picker/locale/zh_CN'
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 preview = sessionStorage.getItem('FormRender')
const userInfo = preview === 'preview' ? { fullName: '【本人姓名】', depart: { name: '【本人部门】' } } : window?.globalConfig?.userInfo || { fullName: '【本人姓名】', depart: { name: '【本人部门】' } }
const {
onChange,
value,
fieldName,
record,
autoArray,
otherChange,
presetValue,
disabled,
placeholder,
widget,
......@@ -15,8 +39,34 @@ const ValueEdit = (props) => {
min,
max,
formatter,
isStoreID,
} = 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') {
const isValid = value ? moment(value)._isValid : false
const timeOtions = format === 'dateTime' ?
......@@ -43,9 +93,9 @@ const ValueEdit = (props) => {
locale={locale}
onChange={(date) => {
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 {
onChange('')
onChange({ fieldName, fieldValue: '' })
}
}}
/>
......@@ -62,10 +112,19 @@ const ValueEdit = (props) => {
disabled={disabled}
value={value === '' ? null : Number(value)}
onChange={(value) => {
if (value !== null) {
onChange(`${value}`)
} else {
onChange('')
onChange({ fieldName, fieldValue: value !== null ? `${value}` : '' })
if (autoArray.length) {
autoArray.forEach(v => {
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%' }}
......@@ -76,7 +135,7 @@ const ValueEdit = (props) => {
return (
<Input
disabled={disabled}
onChange={(e) => onChange(e.target.value)}
onChange={(e) => onChange({ fieldName, fieldValue: e.target.value })}
value={value}
/>
)
......
......@@ -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 { widget } = json?.[fieldName] || {}
let searchProps = {}
......@@ -229,12 +229,17 @@ const TablePack = (props, ref) => {
},
}),
render: (value, record) => {
let props = { ...json[fieldName], value }
let props = { ...json[fieldName], fieldName, value, autoArray, record: { ...record } }
if (isEdit && !notUse?.includes('edit')) {
return (
<ValueEdit
{...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}
/>
)
......@@ -299,10 +304,30 @@ const TablePack = (props, ref) => {
const fileColumns = useMemo(() => {
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 = []
showField.forEach((v, i) => {
if (parent === '关联表单') {
array.push(getRelevanceColumnProps(json, v, isEdit))
// array.push(getRelevanceColumnProps(json, v, isEdit))
array.push(getRelevanceColumnProps({ json, field: v, isEdit, autoArray }))
} else {
array.push(getColumnProps(json, v))
}
......@@ -447,8 +472,6 @@ const TablePack = (props, ref) => {
tableChange?.({}, filtered, sortedInfo)
}
console.log('props', props, btns, columns)
return (
<div className={styles.tablePack} style={{ paddingTop: filtered.length ? '30px' : '10px' }}>
{
......
......@@ -305,6 +305,7 @@ const RelationForm = (props) => {
let field = config?.accountFieids?.filter(v => v.webDisplay).map(v => v.fieldName)
let obj = {}
field.forEach(v => {
obj[v] = ''
if (Array.isArray(mappedField)) {
mappedField.forEach(s => {
if (s.toField === v) {
......
import RelationForm from './RelationForm'
import Signature from './Signature'
import AutoCalculate from './AutoCalculate'
const advanced = {
RelationForm,
Signature,
AutoCalculate,
}
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