Commit 740047df authored by 涂伟's avatar 涂伟

fix: '台账选择器形态优化'

parent 93ebbe4d
{
"name": "panda-xform",
"version": "3.10.7",
"description": "3.10.7: 选项编辑优化",
"version": "3.10.8",
"description": "3.10.8: 台账选择器形态交互优化",
"keywords": [
"panda-xform"
],
......
import React, { useState, useMemo, useEffect } from 'react'
import { Modal, Input, Table, Tooltip, message } from 'antd'
import { SnippetsOutlined } from '@ant-design/icons'
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID } from '../../../../apis/process'
import styles from './index.less'
import { isJson } from '../../../../utils'
import Drag from '../../../components/Drag'
import React, { useState, useMemo, useEffect } from 'react';
import { Modal, Input, Table, Tooltip, message } from 'antd';
import { SnippetsOutlined } from '@ant-design/icons';
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID } from '../../../../apis/process';
import styles from './index.less';
import { isJson } from '../../../../utils';
import Drag from '../../../components/Drag';
const AccountSelector = (props) => {
const userID = window?.globalConfig?.userInfo?.OID || 1
const { value, onChange, schema, addons } = props
const { disabled, accountName, fieldshine, siteFilter, sql, isMultiple, presetValue, placeholder } = schema
const userID = window?.globalConfig?.userInfo?.OID || 1;
const { value, onChange, schema, addons } = props;
const { disabled, accountName, fieldshine, siteFilter, sql, isMultiple, presetValue, placeholder } = schema;
const [params, setParams] = useState({ info: '', total: 0, pageIndex: 1, pageSize: 20 })
const [loading, setLoading] = useState(false)
const [dataSource, setDataSource] = useState([])
const [pageConfig, setPageConfig] = useState({ webShowFieldGroup: '' })
const [visible, setVisible] = useState(false)
const [keys, setKeys] = useState([])
const [params, setParams] = useState({ info: '', total: 0, pageIndex: 1, pageSize: 20 });
const [loading, setLoading] = useState(false);
const [dataSource, setDataSource] = useState([]);
const [pageConfig, setPageConfig] = useState({ webShowFieldGroup: '' });
const [visible, setVisible] = useState(false);
const [keys, setKeys] = useState([]);
const columns = useMemo(() => {
const { webShowFieldGroup } = pageConfig
let fields = webShowFieldGroup.split(',')
let array = []
const { webShowFieldGroup } = pageConfig;
let fields = webShowFieldGroup.split(',');
let array = [];
if (fields.length) {
fields.forEach(v => {
if (v) {
......@@ -33,44 +33,44 @@ const AccountSelector = (props) => {
width: 120,
ellipsis: true,
render: (value, r) => <Tooltip placement="top" title={value}>{value}</Tooltip>
})
});
}
})
});
}
return array
}, [pageConfig])
return array;
}, [pageConfig]);
const onSearch = (value) => {
getPageList({ info: value })
}
getPageList({ info: value });
};
const iconClick = () => {
if (addons) {
if (!accountName) {
return message.info('请配置台账名称!')
return message.info('请配置台账名称!');
}
if (!fieldshine.length) {
return message.info('请配置映射字段!')
return message.info('请配置映射字段!');
}
setVisible(true)
setVisible(true);
if (!pageConfig.webShowFieldGroup) {
getPageConfig()
getPageConfig();
}
getPageList()
getPageList();
}
}
};
const getPageConfig = async () => {
const { code, data } = await GetAccountConfigInfo(accountName)
const { code, data } = await GetAccountConfigInfo(accountName);
if (code == 0) {
setPageConfig(data)
setPageConfig(data);
}
}
};
const getPageList = async (outParams = {}) => {
let queryWheres = []
let queryWheres = [];
if (siteFilter) {
const { code, data } = await getStationListByUserID(...[userID, false])
const { code, data } = await getStationListByUserID(...[userID, false]);
if (code === 0) {
queryWheres = [
{
......@@ -78,10 +78,10 @@ const AccountSelector = (props) => {
type: '包括',
value: data.join(',')
}
]
];
}
}
setLoading(true)
setLoading(true);
let param = {
accountName: accountName,
condition: sql ? window.btoa(encodeURIComponent(sql)) : '',
......@@ -89,67 +89,70 @@ const AccountSelector = (props) => {
queryWheres: queryWheres,
...params,
...outParams,
}
const { data, code, msg } = await GetAccountPageList(param)
};
const { data, code, msg } = await GetAccountPageList(param);
if (code === 0) {
if (data.jsonData) {
let dataSource = JSON.parse(data.jsonData)
setDataSource(dataSource)
let valueArr = value ? value.split(',') : []
let rows = dataSource.filter(v => valueArr.includes(v[fieldshine[0].fromField]))
setKeys(rows.map(v => v.ID))
setParams({ ...params, ...outParams, total: data.totalCount })
let dataSource = JSON.parse(data.jsonData);
setDataSource(dataSource);
let valueArr = value ? value.split(',') : [];
let rows = dataSource.filter(v => valueArr.includes(v[fieldshine[0].fromField]));
setKeys(rows.map(v => v.ID));
setParams({ ...params, ...outParams, total: data.totalCount });
}
} else {
message.error(msg)
message.error(msg);
}
setLoading(false)
}
setLoading(false);
};
const tableChange = ({ current, pageSize }) => {
getPageList({ pageIndex: current, pageSize })
}
getPageList({ pageIndex: current, pageSize });
};
const rowChange = (keys, rows) => {
setKeys(keys)
}
setKeys(keys);
};
const rowClick = (row) => {
setKeys([row.ID]);
};
const onOk = () => {
if (fieldshine.length > 1) {
let row = dataSource.find(v => v.ID === keys[0]) || {}
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}`)
const schema = addons.getSchemaByPath(`${child}.${sun}`);
if (schema.widget === 'fileUpload') {
addons.setSchemaByPath(`${child}.${sun}`, { ...schema, otherFile: row[v.fromField] })
addons.setSchemaByPath(`${child}.${sun}`, { ...schema, otherFile: row[v.fromField] });
} else {
addons.setValue(`${child}.${sun}`, row[v.fromField] || '')
addons.setValue(`${child}.${sun}`, row[v.fromField] || '');
}
}
})
})
})
});
});
});
} else {
let array = dataSource.filter(v => keys.includes(v.ID))
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)
let rowValues = array.map(v => v[fieldshine[0].fromField]).filter(v => v).join(',');
onChange(rowValues);
}
}
setVisible(false)
}
setVisible(false);
};
useEffect(() => {
if (addons) {
addons.setValue(addons.dataPath, presetValue)
addons.setValue(addons.dataPath, presetValue);
} else {
onChange(presetValue)
onChange(presetValue);
}
}, [presetValue])
}, [presetValue]);
const addonAfter = <SnippetsOutlined onClick={() => iconClick()} style={{ color: 'rgba(0, 0, 0, 0.25)' }} />
const addonAfter = <SnippetsOutlined onClick={() => iconClick()} style={{ color: 'rgba(0, 0, 0, 0.25)' }} />;
return (
<div className={styles.AccountSelector}>
......@@ -187,13 +190,19 @@ const AccountSelector = (props) => {
loading={loading}
bordered
size="small"
scroll={{ x: 1500, y: 400 }}
scroll={{ x: '100%', y: 400 }}
rowSelection={{
type: isMultiple && fieldshine.length === 1 ? 'checkbox' : 'radio',
selectedRowKeys: keys,
fixed: 'left',
onChange: rowChange
}}
onRow={record => ({
onClick: event => {
event.stopPropagation();
rowClick(record);
}, // 点击行
})}
pagination={{
total: params.total,
current: params.pageIndex,
......@@ -206,8 +215,8 @@ const AccountSelector = (props) => {
/>
</Drag>
</div>
)
);
}
};
export default AccountSelector
\ No newline at end of file
export default AccountSelector;
\ 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