Commit 3ff0cd3a authored by 田翔's avatar 田翔

fix: 台账选择器支持存储ID

parent 94376944
{
"name": "panda-xform",
"version": "6.9.17",
"description": "6.9.17 支持多区域绘制",
"version": "6.9.18",
"description": "6.9.18 台账选择器支持存储ID",
"keywords": [
"panda-xform"
],
......
......@@ -328,7 +328,7 @@ export function GetTableDataInfo({ accountName, id, timeLimit }) {
// headers: {
// 'Civ-Site': window?.globalConfig?.userInfo?.site
// },
url: `${BASEURL}/GetTableDataInfo?accountName=${accountName}&id=${id}&timeLimit=${timeLimit}`,
url: `${BASEURL}/GetTableDataInfo?accountName=${accountName}&id=${id}${timeLimit ? `&timeLimit=${timeLimit}` : ''}`,
method: 'GET',
});
}
......
......@@ -1682,25 +1682,35 @@ const businessWidgets = [
dependencies: ['accountName', '$id'],
description: '默认获取前端台账字段',
},
isStoreID: {
title: '存储ID',
name: '存储ID',
type: 'boolean',
default: false,
displayType: 'row',
labelWidth: 110,
widget: 'BooleanSwitch',
description: '开启后将会存储台账的ID',
},
siteFilter: {
title: '站点过滤',
name: '站点过滤',
type: 'boolean',
default: false,
displayType: 'row',
labelWidth: 160,
labelWidth: 110,
widget: 'BooleanSwitch',
description: '开启后只显示自己所属站点数据',
},
autofill: {
title: '自动映射值(移动端)',
title: '自动映射值',
name: '站点过滤',
type: 'boolean',
default: false,
displayType: 'row',
labelWidth: 160,
labelWidth: 110,
widget: 'BooleanSwitch',
description: '开启后会将台账中的值自动映射在表单中',
description: '开启后会将台账中的值自动映射在表单中(移动端)',
},
isMultiple: {
title: '多选',
......
import React, { useState, useEffect, useRef } from 'react'
import React, { useState, useEffect, useRef, useMemo } from 'react'
import { Input, message, Pagination } from 'antd'
import { SnippetsOutlined } from '@ant-design/icons'
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID } from '../../../../apis/process'
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID, GetTableDataInfo } from '../../../../apis/process'
import styles from './index.less';
import { isJson } from '../../../../utils'
import { isJson, isObject } from '../../../../utils'
import TablePack from '../../../../core/Account/components/TablePack'
import SearchGroup from '../../../../core/Account/components/SearchGroup'
import Drag from '../../../components/Drag'
......@@ -29,7 +29,18 @@ const AccountSelector = (props) => {
const userID = window?.globalConfig?.userInfo?.OID || 1
const codes = window?.pandaXform?.codes || { 工单编号: '', 事件编号: '', }
const { value, onChange, schema, addons } = props
const { disabled, accountName, fieldshine, siteFilter, sql, isMultiple, presetValue, placeholder, fieldList } = schema
const {
disabled,
accountName,
fieldshine,
siteFilter,
sql,
isMultiple,
presetValue,
placeholder,
fieldList,
isStoreID,
} = schema
const initParams = {
user: userID,
accountName,
......@@ -42,6 +53,7 @@ const AccountSelector = (props) => {
siteFilter,
...defaultParams,
}
const [showValue, setShowValue] = useState('')
const [params, setParams] = useState(initParams)
const [loading, setLoading] = useState(false)
const [dataSource, setDataSource] = useState([])
......@@ -160,31 +172,66 @@ const AccountSelector = (props) => {
return value
}
const getShowValue = (keys) => {
let array = []
if (keys.length) {
keys.forEach(v => {
array.push(GetTableDataInfo({ accountName: accountName, id: v, timeLimit: null }))
})
Promise.all(array).then(res => {
let showArray = []
res?.forEach(v => {
if (v.code === 0) {
v.data?.forEach(v => {
if (v.fieldName === fieldshine[0].fromField) {
showArray.push(v.fieldValue)
}
})
}
})
setShowValue(showArray.join(','))
})
}
}
const onOk = () => {
if (fieldshine.length > 1) {
let row = dataSource.find(v => v.ID === keys[0]) || {};
Object.keys(addons.formData).forEach(child => {
Object.keys(addons.formData[child]).forEach(sun => {
fieldshine.forEach(v => {
if (sun === v.toField) {
const schema = addons.getSchemaByPath(`${child}.${sun}`);
if (['TextInput', 'fileUpload'].includes(schema.widget)) {
addons.setSchemaByPath(`${child}.${sun}`, { ...schema, otherValue: row[v.fromField] });
} else if (schema.widget === 'NumberInput') {
let numberValue = formatterFn({ value: row[v.fromField] || '', formatter: schema.formatter, decimalDigits: schema.decimalDigits })
addons.setValue(`${child}.${sun}`, numberValue);
} else {
addons.setValue(`${child}.${sun}`, row[v.fromField] || '');
let childObj = addons.formData[child]
if (isObject(childObj)) {
Object.keys(childObj).forEach(sun => {
fieldshine.forEach((v, index) => {
if (sun === v.toField) {
const schema = addons.getSchemaByPath(`${child}.${sun}`);
if (['TextInput', 'fileUpload'].includes(schema.widget)) {
addons.setSchemaByPath(`${child}.${sun}`, { ...schema, otherValue: row[v.fromField] });
} else if (schema.widget === 'NumberInput') {
let numberValue = formatterFn({ value: row[v.fromField] || '', formatter: schema.formatter, decimalDigits: schema.decimalDigits })
addons.setValue(`${child}.${sun}`, numberValue);
} else {
addons.setValue(`${child}.${sun}`, row[v.fromField] || '');
}
//存储ID特殊处理
if (isStoreID && index === 0) {
addons.setValue(`${child}.${sun}`, keys[0] || '')
getShowValue(keys)
}
}
}
});
});
});
}
});
} else {
let array = dataSource.filter(v => keys.includes(v.ID));
if (array.length) {
let rowValues = array.map(v => v[fieldshine[0].fromField]).filter(v => v).join(',');
onChange(rowValues);
if (isStoreID) {
onChange(`${keys.join(',')}` || '')
getShowValue(keys)
} else {
let rowValues = array.map(v => v[fieldshine[0].fromField]).filter(v => v).join(',');
onChange(rowValues);
}
}
}
setVisible(false);
......@@ -210,6 +257,9 @@ const AccountSelector = (props) => {
useEffect(() => {
if (addons) {
addons.setValue(addons.dataPath, presetValue)
if (presetValue && isStoreID) {
getShowValue(presetValue?.split(','))
}
} else {
onChange(presetValue)
}
......@@ -221,12 +271,17 @@ const AccountSelector = (props) => {
<div className={styles.AccountSelector}>
<Input
placeholder={disabled ? (placeholder || '') : (placeholder || '点击选择台账')}
value={value}
value={isStoreID ? showValue : value}
// value={value}
onClick={() => iconClick()}
addonAfter={!disabled ? addonAfter : null}
disabled={disabled}
allowClear
onChange={e => onChange('')}
className=''
onChange={e => {
onChange('')
setShowValue('')
}}
/>
<Drag
onCancel={() => setVisible(false)}
......
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