|
@@ -2,7 +2,7 @@
|
|
|
* @Author: code4eat awesomedema@gmail.com
|
|
|
* @Date: 2023-03-03 11:30:33
|
|
|
* @LastEditors: code4eat awesomedema@gmail.com
|
|
|
- * @LastEditTime: 2023-03-30 17:17:44
|
|
|
+ * @LastEditTime: 2023-03-31 10:42:53
|
|
|
* @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
|
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
*/
|
|
@@ -14,10 +14,10 @@ import BMSPagecontainer from '@/components/BMSPageContainer';
|
|
|
import { BMSTable } from '@/components/BMSTable';
|
|
|
import { createFromIconfontCN } from '@ant-design/icons';
|
|
|
|
|
|
-import { ActionType, ProFormDigit, ProFormSelect } from '@ant-design/pro-components';
|
|
|
+import { ActionType, ProFormDigit, ProFormInstance, ProFormSelect } from '@ant-design/pro-components';
|
|
|
import { ModalForm, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
|
|
|
import { ProColumns } from '@ant-design/pro-table';
|
|
|
-import { Input, message, Modal, Popconfirm, Table, Transfer } from 'antd';
|
|
|
+import { Form, Input, InputNumber, message, Modal, Popconfirm, Table, Transfer } from 'antd';
|
|
|
import { DefaultOptionType } from 'antd/es/select';
|
|
|
import { ColumnsType, TableRowSelection } from 'antd/es/table/interface';
|
|
|
import { TransferItem, TransferProps } from 'antd/es/transfer';
|
|
@@ -30,6 +30,7 @@ import difference from 'lodash/difference';
|
|
|
import { addData, addIndicGroup, addUnitForGroup, delData, editData, getAllUnit, getData } from './service';
|
|
|
|
|
|
import './style.less';
|
|
|
+import { omit } from 'lodash';
|
|
|
|
|
|
|
|
|
const IconFont = createFromIconfontCN({
|
|
@@ -304,7 +305,7 @@ export default function IndicGroupWeightSet() {
|
|
|
targetKeys={targetKeys}
|
|
|
selectedKeys={selectedKeys}
|
|
|
filterOption={(inputValue, item) => {
|
|
|
- return item.name!.indexOf(inputValue) !== -1
|
|
|
+ return item.unitName!.indexOf(inputValue) !== -1
|
|
|
|
|
|
}}
|
|
|
>
|
|
@@ -361,6 +362,10 @@ export default function IndicGroupWeightSet() {
|
|
|
|
|
|
const [indicatorData, set_indicatorData] = useState<any[]>([]);
|
|
|
|
|
|
+ const [indicatorIniData,set_indicatorIniData] = useState({});
|
|
|
+
|
|
|
+ const formRef = useRef<ProFormInstance>();
|
|
|
+
|
|
|
const triggerNode = () => {
|
|
|
if (type == 'ADD') {
|
|
|
return <span className='add'>新增</span>
|
|
@@ -393,19 +398,55 @@ export default function IndicGroupWeightSet() {
|
|
|
|
|
|
|
|
|
const addIndicator = () => {
|
|
|
- set_indicatorData([...indicatorData, {}]);
|
|
|
+
|
|
|
+ const key = Math.random()
|
|
|
+ const temp = [...indicatorData, {tempId:key,id:key,[`indicatorCode${key}`]:'',[`weight${key}`]:''}];
|
|
|
+
|
|
|
+ set_indicatorIniData({...indicatorIniData,[`indicatorCode${key}`]:'',[`weight${key}`]:''});
|
|
|
+
|
|
|
+ set_indicatorData([...temp]);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ const delGroupIndic = (data:any,index:number)=>{
|
|
|
+ let temp = [...indicatorData];
|
|
|
+ let defaultFormData:{[key:string]:any} = {};
|
|
|
+ const result = temp.filter((a:any)=>a.id != data.id);
|
|
|
+ result.forEach((a:any)=>{
|
|
|
+ defaultFormData[`indicatorCode${a.id}`] = a.indicatorCode;
|
|
|
+ defaultFormData[`weight${a.id}`] = a.weight;
|
|
|
+ });
|
|
|
+ console.log({defaultFormData});
|
|
|
+ set_indicatorIniData({...defaultFormData});
|
|
|
+ set_indicatorData([...result]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (type == 'INDICATOR') {
|
|
|
- set_indicatorData([{}]);
|
|
|
+ let defaultFormData:{[key:string]:any} = {};
|
|
|
+ if(record.indicatorWeights&&record.indicatorWeights.length>0){
|
|
|
+ const defaultVal = record.indicatorWeights.map((a:any)=>{
|
|
|
+ defaultFormData[`indicatorCode${a.id}`] = a.indicatorCode;
|
|
|
+ defaultFormData[`weight${a.id}`] = a.weight;
|
|
|
+ return {...a,tempId:Math.random()}
|
|
|
+ });
|
|
|
+
|
|
|
+ set_indicatorIniData({...defaultFormData});
|
|
|
+
|
|
|
+ set_indicatorData([...defaultVal]);
|
|
|
+ }else{
|
|
|
+ set_indicatorData([{}]);
|
|
|
+ }
|
|
|
}
|
|
|
}, [type]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- // console.log({ indicatorData });
|
|
|
- }, [indicatorData]);
|
|
|
+ // useEffect(() => {
|
|
|
+ // console.log({'change':indicatorData });
|
|
|
+ // }, [indicatorData]);
|
|
|
|
|
|
return (
|
|
|
|
|
@@ -413,7 +454,8 @@ export default function IndicGroupWeightSet() {
|
|
|
title={title()}
|
|
|
width={352}
|
|
|
className='IndicGroupWeightSet-ModalForm'
|
|
|
- initialValues={type == 'EDIT' ? { ...record } : {}}
|
|
|
+ initialValues={type == 'EDIT'? { ...record } :type == 'INDICATOR'?{...indicatorIniData}:{}}
|
|
|
+ formRef={formRef}
|
|
|
trigger={
|
|
|
triggerNode()
|
|
|
}
|
|
@@ -425,7 +467,17 @@ export default function IndicGroupWeightSet() {
|
|
|
return updateTable({ ...record, ...val }, type)
|
|
|
}
|
|
|
if (type == 'INDICATOR') {
|
|
|
- return updateTable({ id: record.id, indicatorWeights: indicatorData }, type)
|
|
|
+
|
|
|
+ const total = indicatorData.reduce((prev:any,cur:any)=>prev + cur.weight,0);
|
|
|
+
|
|
|
+ if(total != 1){
|
|
|
+ Modal.confirm({
|
|
|
+ title:'占比加总必须是1!'
|
|
|
+ });
|
|
|
+ return Promise.resolve(false);
|
|
|
+ }else{
|
|
|
+ return updateTable({ id: record.id, indicatorWeights: indicatorData }, type)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return Promise.resolve(true);
|
|
@@ -454,12 +506,14 @@ export default function IndicGroupWeightSet() {
|
|
|
indicatorData.map((item: any, index: number) => {
|
|
|
return (
|
|
|
<div className='item' key={index}>
|
|
|
- <ProFormSelect label="管理指标:" width={160} request={async () => {
|
|
|
+ <ProFormSelect label="管理指标:" width={160}
|
|
|
+ name={`indicatorCode${item.id}`}
|
|
|
+ request={async () => {
|
|
|
const resp = await getManaIndicListData();
|
|
|
if (resp) {
|
|
|
return resp.list.map((a: any) => ({
|
|
|
label: a.name,
|
|
|
- value: a.id
|
|
|
+ value: `${a.code}`
|
|
|
}))
|
|
|
}
|
|
|
return []
|
|
@@ -468,20 +522,55 @@ export default function IndicGroupWeightSet() {
|
|
|
fieldProps={{
|
|
|
// labelInValue:true,
|
|
|
onChange(value, option:any) {
|
|
|
- let temp = indicatorData;
|
|
|
- temp[index] = { ...temp[index], indicatorCode: value, indicatorName: option.label }
|
|
|
- set_indicatorData([...temp]);
|
|
|
+ // console.log({value,option});
|
|
|
+ const temp = [...indicatorData];
|
|
|
+ const newArr = temp.map((a:any)=>{
|
|
|
+ if(a.id == item.id){
|
|
|
+ return {...a, indicatorCode: value, indicatorName: option.label }
|
|
|
+ }
|
|
|
+ return a
|
|
|
+ });
|
|
|
+
|
|
|
+ set_indicatorData([...newArr]);
|
|
|
},
|
|
|
}}
|
|
|
/>
|
|
|
- <ProFormDigit label='占比:' width={120} fieldProps={{
|
|
|
+ <Form.Item name={`weight${item.id}`} label='占比(请输入小数):'>
|
|
|
+ <InputNumber
|
|
|
+ style={{width:120,height:24,position:'relative',top:0}}
|
|
|
+ onChange={(value)=>{
|
|
|
+ //console.log({value,index,indicatorData});
|
|
|
+ const temp = [...indicatorData];
|
|
|
+ const newArr = temp.map((a:any)=>{
|
|
|
+ if(a.id == item.id){
|
|
|
+ return {...a,weight:value}
|
|
|
+ }
|
|
|
+ return a
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log({newArr});
|
|
|
+
|
|
|
+ set_indicatorData([...newArr]);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ {/* <ProFormText label='占比(请输入小数):' name={`weight${item.id}`} width={120} fieldProps={{
|
|
|
onChange(value) {
|
|
|
- let temp = indicatorData;
|
|
|
- temp[index] = { ...temp[index], weight: value };
|
|
|
- set_indicatorData([...temp]);
|
|
|
+ //console.log({value,index,indicatorData});
|
|
|
+ const temp = [...indicatorData];
|
|
|
+ const newArr = temp.map((a:any)=>{
|
|
|
+ if(a.id == item.id){
|
|
|
+ return {...a,weight:value}
|
|
|
+ }
|
|
|
+ return a
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log({newArr});
|
|
|
+
|
|
|
+ set_indicatorData([...newArr]);
|
|
|
},
|
|
|
- }} />
|
|
|
- <span className='delIcon'><IconFont type="iconshanchu" /></span>
|
|
|
+ }} /> */}
|
|
|
+ <span className='delIcon' onClick={()=>delGroupIndic(item,index)}><IconFont type="iconshanchu" /></span>
|
|
|
</div>
|
|
|
)
|
|
|
})
|