123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821 |
- /*
- * @Author: your name
- * @Date: 2021-07-26 10:13:13
- * @LastEditTime: 2021-09-10 09:20:09
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
- */
- import { PlusOutlined } from '@ant-design/icons';
- import { Button, Popconfirm,Tag } from 'antd';
- import React, { useState, useRef, useEffect } from 'react';
- import { PageContainer } from '@ant-design/pro-layout';
- import ProTable from '@ant-design/pro-table';
- import ProForm, { ModalForm, DrawerForm, ProFormSelect, ProFormTextArea, ProFormDigit, ProFormText } from '@ant-design/pro-form';
- import UpdateForm from './updateForm';
- import UpdateFormDrawer from './updateForm_drawer';
- // import CAUpload from '@/components/CAUpload';
- import DrawerContent from './selectCopyDrawer';
- import { getAccountingSubjectList } from '../accountingSubject/service';
- import {
- getCostshareparamConnectList, editCostshareparamConnectList, delCostshareparamConnect,
- addCostshareparamConnect, getResponsibilityCenterSelecterList, getAccountingSubjectForSelecter,
- getHasSetParamsList, getParamsSelectableList, saveParamsList, copyParamsList,getCopyableToList
- } from './service';
- import {deepGetAllParents} from '@/utils';
- const CostAllocationParamsConnect = () => {
- const columns = [
- {
- title: '分摊级别',
- dataIndex: 'shareLevel',
- key: 'shareLevel',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: '责任中心编码',
- dataIndex: 'responsibilityCode',
- key: 'responsibilityCode',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: '责任中心名',
- dataIndex: 'responsibilityName',
- key: 'responsibilityName',
- ellipsis: true,
- hideInSearch: false,
- render:(_,record) => {
- const {isShareCost,responsibilityName} = record;
- return isShareCost==1?<Tag color="default">{`${responsibilityName}(含)`}</Tag>:`${responsibilityName}`
- }
- },
- {
- title: '会计科目名称',
- dataIndex: 'accountingNames',
- key: 'accountingName',
- hideInSearch: true,
- ellipsis: true,
-
- },
- {
- title: '会计科目编码',
- dataIndex: 'accountingCodes',
- key: 'accountingCode',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: '别名',
- dataIndex: 'alias',
- key: 'alias',
- ellipsis: true,
- hideInSearch: true,
- },
- {
- title: '备注',
- dataIndex: 'costNode',
- key: 'costNode',
- ellipsis: true,
- hideInSearch: true,
- },
- {
- title: '操作',
- dataIndex: 'option',
- valueType: 'option',
- width:'18%',
- render: (_, record) => [
- <a
- key="config1"
- onClick={() => {
- setDrawerVisible(true);
- setCurrentRow(record);
- setCurrentResponsibilityRow(record);
- }}
- >
- 分摊参数设置
- </a>,
- <a
- key="config1"
- onClick={() => {
- setCurrentRow(record);
- setDrawerType(1);
- setCopySelectDrawerVisible(true);
- }}
- >
- 复制
- </a>,
- <a
- key="config2"
- onClick={() => {
- setEdit(true);
- handleUpdateModalVisible(true);
- setCurrentRow(record);
- }}
- >
- 编辑
- </a>,
- <Popconfirm
- key="subscribeAlert"
- title="是否确定删除?"
- onConfirm={() => {
- setCurrentRow(record);
- delListHandler(record);
- }}
- >
- <a>删除</a>
- </Popconfirm>,
- ],
- },
- ];
- const drawerTableColumns = [
- {
- title: '分摊参数编码',
- dataIndex: 'shareParamCode',
- key: 'shareParamCode',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: '分摊参数名称',
- dataIndex: 'shareParamName',
- key: 'shareParamName',
- hideInSearch: false,
- ellipsis: true,
- },
- {
- title: '分摊比例',
- dataIndex: 'shareParamPopout',
- key: 'shareParamPopout',
- hideInSearch: false,
- ellipsis: true,
- },
- {
- title: '操作',
- dataIndex: 'option',
- valueType: 'option',
- render: (_, record) => [
- <a
- key="config2"
- onClick={() => {
- setDrawerUpdateModalVisible(true);
- setCurrentRow(record);
- }}
- >
- 编辑
- </a>,
- <Popconfirm
- key="subscribeAlert"
- title="是否确定删除?"
- onConfirm={() => {
- setCurrentRow(record);
- delParamsListHandler(record);
- }}
- >
- <a>删除</a>
- </Popconfirm>,
- ],
- },
- ];
- const responsibilityColumns = [
- {
- title: '责任中心Id',
- dataIndex: 'id',
- key: 'id',
- hideInSearch: false,
- ellipsis: true,
- },
- {
- title: '责任中心名',
- dataIndex: 'responsibilityName',
- key: 'responsibilityName',
- hideInSearch: false,
- ellipsis: true,
- }
- ]
- const accountSubjectColumns = [
- {
- title: '会计科目Id',
- dataIndex: 'id',
- key: 'id',
- hideInSearch: false,
- ellipsis: true,
- },
- {
- title: '会计科目名名',
- dataIndex: 'accountingName',
- key: 'accountingName',
- hideInSearch: false,
- ellipsis: true,
- }
- ]
- const [createModalVisible, handleModalVisible] = useState(false);
- const [updateModalVisible, handleUpdateModalVisible] = useState(false);
- const [cascaderOptions, setCascaderOptions] = useState([]);
- const actionRef = useRef(); //表格
- const ref = useRef(); //新增表单
- const [currentResponsibilityRow, setCurrentResponsibilityRow] = useState({});
- const [currentRow, setCurrentRow] = useState(undefined);
- const [ifDisable, setIfDisable] = useState(false);
- const [selectedResponsibilityId, setSelectedResponsibilityId] = useState(null);
- const [selectedResponsibility, setSelectedResponsibility] = useState(null);
- const [copySelectDrawerVisible, setCopySelectDrawerVisible] = useState(false);
- const [drawerType, setDrawerType] = useState(0); //1 复制数据 2 新增选择会计科目
- const [accountType, setAccountType] = useState(2); // 1 收入 2 支出
- const [edit,setEdit] = useState(false);
- const drawerFormRef = useRef(); //DrawerForm
- const actionDrawertableRef = useRef(); //Drawertable
- const drawerModalRef = useRef(); //DrawerModal
- const [drawerVisible, setDrawerVisible] = useState(false);
- const [drawerMadalVisible, setDrawerMadalVisible] = useState(false);
- const [hasSetParamsList, setHasSetParamsList] = useState([]);
- const [selectedParam, setSelectedParam] = useState(null);
- const [newAddParamList, setNewAddParamList] = useState([]);
- const [drawerUpdateModalVisible, setDrawerUpdateModalVisible] = useState(false);
- const [expandedRowKeys,setexpandedRowKeys] = useState([]);
- const [selectedAccountSubjects,setSelectedAccountSubjects] = useState([]);
- const updateFormRef = useRef();
- /**
- *
- * @param {Boolean} bool 弹窗展示状态
- */
- const updateModalVisibleChange = (bool) => {
- handleUpdateModalVisible(bool);
- if (!bool) setCurrentRow(undefined);
- };
- const drawerUpdateModalVisibleChange = (bool) => {
- setDrawerUpdateModalVisible(bool);
- if (!bool) setCurrentRow(undefined);
- }
- //获取科室列表
- const getList = async (params = {}, sort, filter) => {
- const res = await getCostshareparamConnectList(params);
- return {
- data: res.data.list,
- total: res.data.totalCount,
- success: res.success,
- };
- };
- /**
- *
- * @param {Object} value 删除项数据
- */
- const delListHandler = async (value) => {
- const resp = await delCostshareparamConnect(value);
- if (resp.status == 200) {
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- };
- /**
- *
- * @param {Object} record 表格行数据
- */
- const delParamsListHandler = (record) => {
- const { id } = record;
- const arr = hasSetParamsList;
- arr.splice(arr.findIndex(item => item.id === id), 1);
- setHasSetParamsList([].concat(arr));
- if (actionDrawertableRef.current) {
- actionDrawertableRef.current.reload();
- }
- }
- //分摊参数回调
- /**
- *
- * @param {Boolean} bool
- */
- const drawerVisibleChange = async (bool) => {
- // console.log({currentRow});
- if (bool) {
- //展示
- const { id } = currentRow;
- const resp = await getHasSetParamsList({ id });
- const { data, msg, status } = resp;
- // console.log({data, msg, status});
- if (status == 200) {
- setHasSetParamsList(data ? data : []);
- if (actionDrawertableRef.current) {
- actionDrawertableRef.current.reload();
- }
- }
- }
- setDrawerVisible(bool);
- }
- /**
- *
- * @param {Boolean} bool
- */
- const handleDrawerModalVisible = (bool) => {
- setDrawerMadalVisible(bool);
- }
- const getCopyableTableList = async () => {
- const {id:accountShareId} = currentRow;
- const resp = await getCopyableToList({accountShareId});
- const { status, data} = resp;
- if (status == 200) {
- return {
- data: data,
- total:data.length ,
- success: true
- }
- }
- }
- const getAccountingSubjects = async (params = {}, sort, filter) => {
- const resp = await getAccountingSubjectList({...params,accountType });
- const { status, data: { list, totalCount } } = resp;
- let accountingIdList=undefined;
-
- currentRow&&(accountingIdList = currentRow.accountingIdList)
- const defaultSelected = accountingIdList?accountingIdList.map(item=>Number(item)):[];
- // console.log({defaultSelected});
- setSelectedAccountSubjects(defaultSelected);
- const allParents = deepGetAllParents(list,'children');
- const ids = allParents?allParents.map(item=>item.id):[];
- setexpandedRowKeys(ids);
- if (status == 200) {
- return {
- data: list,
- total: totalCount,
- success: true
- }
- }
- }
- const selectAccountSubjecthandle = () => {
- setDrawerType(2);
- setCopySelectDrawerVisible(true);
- }
- useEffect(async () => {
- const respForSelecter = await getAccountingSubjectForSelecter();
- if (respForSelecter.status == 200) {
- setCascaderOptions(respForSelecter.data);
- }
- }, [])
- return (
- <PageContainer>
- <ProTable
- columns={columns}
- request={getList}
- actionRef={actionRef}
- rowKey="id"
- toolBarRender={() => [
- <Button
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- onClick={() => {
- setEdit(false);
- handleModalVisible(true);
- }}
- >
- 新增
- </Button>
- ]}
- pagination={{
- pageSize: 10,
- }}
- search={{
- defaultCollapsed: false,
- labelWidth: 'auto',
- }}
- />
- <ModalForm
- title="新增成本分摊参数对应"
- width="800px"
- labelCol={{ span: 5, offset: 3 }}
- layout={'horizontal'}
- visible={createModalVisible}
- formRef={ref}
- onVisibleChange={(bool) => {
- if (ref.current) {
- setIfDisable(false);
- ref.current.resetFields();
- }
- handleModalVisible(bool);
- }}
- onFinish={async (value) => {
- // console.log({value});
- // console.log(ref.current.getFieldsValue(true));
- const { costNode,isShareCost=1,alias} = value;
- const { accountingIds } = ref.current.getFieldsValue(true);
- const { responsibilityCode, responsibilityId, responsibilityName, shareLevel } = selectedResponsibility;
- const success = await addCostshareparamConnect({
- responsibilityId: selectedResponsibilityId,
- accountingIds: accountingIds,isShareCost,alias,
- costNode, responsibilityName, shareLevel, responsibilityCode
- });
- // console.log({ success });
- if (success) {
- handleModalVisible(false);
-
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }}
- >
- <ProFormSelect
- rules={[
- {
- required: true,
- message: '请选择责任中心',
- },
- ]}
- fieldProps={{//这里使用了select的onChange方法,必须使用这样的写法来进行调用onChange方法
- onChange: async (val) => {
- setSelectedResponsibilityId(val);
- const resp = await getResponsibilityCenterSelecterList();
- const { data, msg, status } = resp;
- if (status == 200) {
- const selected = data.filter(item => item.id == val);
- setSelectedResponsibility(selected[0]);
- if (selected && selected[0].calcType == 1) {
- setIfDisable(false);
- } else {
- setIfDisable(true);
- }
- }
- },
- }}
- request={async () => {
- const resp = await getResponsibilityCenterSelecterList();
- const { data=[], msg, status } = resp;
- if (status == 200) {
- return data.map(item => ({
- label: item.responsibilityName,
- value: item.id
- }))
- }
- }}
- width="sm"
- name="responsibilityId"
- label="请选择责任中心"
- />
- <ProFormText
- disabled={ifDisable}
- rules={[
- {
- required: ifDisable?false:true,
- message: '请选择会计科目',
- },
- ]}
- fieldProps={{
- onClick: () => selectAccountSubjecthandle()
- }}
- width="sm"
- name="accountingName"
- label="选择会计科目"
- />
- <ProFormSelect
- disabled={ifDisable}
- rules={[
- {
- required: ifDisable?false:true,
- message: '请选择',
- },
- ]}
- width="sm"
- request={async () => [
- { label: '不包含分摊成本', value: 0 },
- { label: '包含分摊成本', value: 1 }
- ]}
- name="isShareCost"
- label="是否包含分摊成本"
- />
- <ProFormText
- width="sm"
- name="alias"
- label="别名"
- />
- <ProFormTextArea
- name="costNode"
- label="备注"
- width={300}
- placeholder="请输入备注"
- />
- </ModalForm>
- {/* 成本分摊参数设置 */}
- <DrawerForm
- title="分摊参数设置"
- formRef={drawerFormRef}
- visible={drawerVisible}
- onVisibleChange={(visible) => drawerVisibleChange(visible)}
- // onFinish={(value) => onSubmit({ ...values, ...value })}
- onFinish={async () => {
- if (true) {
- const { id } = currentResponsibilityRow;
- const resp = await saveParamsList({
- id,
- shareParamProportionVOList: hasSetParamsList
- });
- const { status } = resp;
- if (status == 200) {
- setDrawerVisible(false);
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }
- }}
- >
- <ProTable
- columns={drawerTableColumns}
- rowKey="id"
- actionRef={actionDrawertableRef}
- toolBarRender={() => [
- <Button
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- onClick={() => {
- setDrawerMadalVisible(true);
- setCurrentRow(undefined);
- }}
- >
- 新增
- </Button>
- ]}
- request={async (params = {}, sort, filter) => {
- // console.log({ hasSetParamsList });
- return {
- data: hasSetParamsList,
- success: true
- };
- }}
- pagination={false}
- search={false}
- />
- <ModalForm
- title="新增分摊参数"
- width="800px"
- labelCol={{ span: 5, offset: 3 }}
- layout={'horizontal'}
- visible={drawerMadalVisible}
- formRef={drawerModalRef}
- onVisibleChange={(bool) => {
- if (drawerModalRef.current) {
- drawerModalRef.current.resetFields();
- }
- handleDrawerModalVisible(bool);
- }}
- onFinish={async (value) => {
- // console.log({ '新增分摊参数': value, selectedParam,hasSetParamsList});
- const { shareParamPopout } = value;
- const { id, shareParamCode, shareParamName } = selectedParam;
- setHasSetParamsList(hasSetParamsList.concat([{
- id, shareParamCode, shareParamName, shareParamPopout
- }]));
- setNewAddParamList(newAddParamList.concat([{
- id, shareParamCode, shareParamName, shareParamPopout
- }]));
- setDrawerMadalVisible(false);
- if (actionDrawertableRef.current) {
- actionDrawertableRef.current.reload();
- }
- }}
- >
- <ProFormSelect
- rules={[
- {
- required: true,
- message: '请选择责任中心',
- },
- ]}
- fieldProps={{//这里使用了select的onChange方法,必须使用这样的写法来进行调用onChange方法
- onChange: async (val) => {
- // setSelectedParam(val);
- const { id } = currentResponsibilityRow;
- // console.log({currentResponsibilityRow});
- const resp = await getParamsSelectableList({ id });
- const { data:{list=[]}, status } = resp;
- // console.log({resp});
- if (status == 200) {
- const selected = list.filter(item => item.id == val);
- console.log({ selected });
- setSelectedParam(selected[0]);
- }
- },
- }}
- request={async () => {
- const { id } = currentResponsibilityRow;
- const resp = await getParamsSelectableList({ id });
- const { data:{list=[]}, status } = resp;
- // console.log({ resp });
- if (status == 200) {
- const temp = list.map(item => ({
- label: item.shareParamName,
- value: item.id
- }));
- return temp;
- }
- }}
- width="sm"
- name="id"
- label="请选择分摊参数"
- />
- <ProFormDigit width={100} label="分摊比例" name="shareParamPopout" min={0} max={100} />
- </ModalForm>
- {/* 分摊更新 */}
- <UpdateFormDrawer
- onSubmit={async (value) => {
-
- const {id,selectedParam} = value;
- const index = hasSetParamsList.findIndex(item=>item.id == id);
- let temp = hasSetParamsList;
- temp[index] = value;
- if(selectedParam){
- //修改了分摊参数名
- const {shareParamCode,shareParamName} = selectedParam;
- temp[index] = {...temp[index],shareParamCode,shareParamName}
- // console.log({shareParamCode,shareParamName,'temp[index]':temp[index]});
- }
- setHasSetParamsList([].concat(temp));
- setDrawerUpdateModalVisible(false);
- if (actionDrawertableRef.current) {
- actionDrawertableRef.current.reload();
- }
-
- }}
- onCancel={() => {
- drawerUpdateModalVisible(false);
- setCurrentRow(undefined);
- }}
- currentResponsibilityRow={currentResponsibilityRow}
- drawerUpdateModalVisible={drawerUpdateModalVisible}
- drawerUpdateModalVisibleChange={drawerUpdateModalVisibleChange}
- values={currentRow || {}}
- />
- </DrawerForm>
- {/* 选择复制抽屉 */}
- {
- drawerType != 0 && (
- <DrawerContent
- columns={drawerType == 1 ? responsibilityColumns : accountSubjectColumns}
- visible={copySelectDrawerVisible}
- currentRow={currentRow}
- title={drawerType == 1 ? '选择复制目标' : '选择会计科目'}
- defaultSelected={drawerType == 1?[]:selectedAccountSubjects}
- pageContainerConfig={(tableRef) => {
- return {
- header: {
- title: ''
- }
- }
- }}
- onVisibleChange={(bool) => setCopySelectDrawerVisible(bool)}
- renderListFunc={drawerType == 1 ? getCopyableTableList : getAccountingSubjects}
- config={{ rowKeys: 'id', tableSearch: false }}
- tableSearch={false}
- expandable={{
- expandedRowKeys:expandedRowKeys
- }}
- onFinishFunc={async (value, selectedRowKeys, selectedRows) => {
- // console.log({ value, selectedRowKeys, selectedRows,drawerType });
- if (drawerType == 1) {
- const { id } = currentRow;
- const resp = await copyParamsList({ id, responsibilityIds: selectedRowKeys });
- const { status } = resp;
- if (status == 200) {
- setCurrentRow(undefined);
- setCopySelectDrawerVisible(false);
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }
- if (drawerType == 2) {
-
- //selectedRows为空标识没有编辑
- let selectedItemNames = selectedRows.map(item => item.accountingName);
- if(edit){
- if(selectedRows.length>0){
- if (updateFormRef.current) {
- updateFormRef.current.setFieldsValue({ accountingNames: selectedItemNames.join(','), accountingIds: selectedRowKeys.join(',') })
- }
- }
- }
- if(!edit){
-
- if (ref.current) {
- ref.current.setFieldsValue({ accountingName:selectedItemNames.join(','), accountingIds: selectedRowKeys.join(',') })
- }
-
- }
- setCopySelectDrawerVisible(false);
- }
- setDrawerType(0);
- }}
- />
- )
- }
- {/* 更新 */}
- <UpdateForm
- onSubmit={async (value) => {
- // console.log({ '编辑': value });
- // // return;
- // console.log(updateFormRef.current.getFieldsValue(true));
- const { accountingIds } = updateFormRef.current.getFieldsValue(true);
- const { responsibilityId,responsibilityName,responsibilityCode,shareLevel,ifDisable, costNode,alias, id,isShareCost=1 } = value;
- console.log({alias});
- const success = await editCostshareparamConnectList(ifDisable ? {
- responsibilityId, costNode, id,responsibilityName,responsibilityCode,shareLevel,isShareCost,alias
- } : { responsibilityId,accountingIds, costNode,alias,id,responsibilityName,responsibilityCode,shareLevel,isShareCost });
- if (success) {
- handleUpdateModalVisible(false);
- setCurrentRow(undefined);
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
-
- }}
- onCancel={() => {
- handleUpdateModalVisible(false);
- setCurrentRow(undefined);
- }}
- updateModalVisible={updateModalVisible}
- updateModalVisibleChange={updateModalVisibleChange}
- values={currentRow || {}}
- updateFormRef={updateFormRef}
- selectAccountSubjecthandle={selectAccountSubjecthandle}
- />
- </PageContainer>
- );
- };
- export default CostAllocationParamsConnect;
|