123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- /*
- * @Author: your name
- * @Date: 2021-07-26 10:13:13
- * @LastEditTime: 2021-09-29 19:14:25
- * @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, Space,Table } from 'antd';
- import React, { useState, useRef } from 'react';
- import { PageContainer } from '@ant-design/pro-layout';
- import ProTable from '@ant-design/pro-table';
- import { ModalForm, ProFormText, ProFormSelect} from '@ant-design/pro-form';
- import UpdateForm from './updateForm';
- import DrawerContent from './selectCopyDrawer';
- import {deepGetAllParents} from '@/utils';
- import { getCostshareparamList, editCostshareparamList, delCostshareparam, addCostshareparam,updateCostShareParamByAccountId } from './service';
- import { getAccountingSubjectList} from '../accountingSubject/service';
- const CostAllocationParamsSetting = () => {
- const columns = [
- {
- title: '成本分摊参数名',
- dataIndex: 'shareParamName',
- key: 'shareParamName',
- hideInSearch: false,
- ellipsis: true,
- },
- {
- title: '成本分摊参数编号',
- dataIndex: 'shareParamCode',
- key: 'shareParamCode',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: '计算方式',
- dataIndex: 'calcType',
- key: 'calcType',
- hideInSearch: true,
- ellipsis: true,
- render: (_,text) =>{return <>{text.calcType == 1 ? '手动填写' : '按对应会计科目计算'}</> },
- },
- {
- title:'操作',
- dataIndex: 'option',
- valueType: 'option',
- render: (_, record) =>{
- const {calcType} = record;
- const groups = [
- <a
- key="config"
- onClick={() => {
- handleUpdateModalVisible(true);
- setCurrentRow(record);
- }}
- >
- 编辑
- </a>,
- <Popconfirm
- key="subscribeAlert"
- title="是否确定删除?"
- onConfirm={() => {
- setCurrentRow(record);
- delListHandler(record);
- }}
- >
- <a>删除</a>
- </Popconfirm>,
- ]
- return calcType==1?groups:[...groups,<a
- key="config"
- onClick={() => {
- setDrawerVisible(true);
- setCurrentRow(record);
- setCurrentResponsibilityRow(record);
- }}
- >
- 设置对应会计科目
- </a>,]
- }
- },
- ];
- const drawerTableColumns = [
- {
- title: '会计科目编码',
- dataIndex: 'accountingCode',
- key: 'accountingCode',
- hideInSearch: true,
- },
- {
- title: '会计科目名称',
- dataIndex: 'accountingName',
- key: 'accountingName',
- hideInSearch: false,
- ellipsis: true,
- }
- ];
- const [createModalVisible, handleModalVisible] = useState(false);
- const [updateModalVisible, handleUpdateModalVisible] = useState(false);
- const actionRef = useRef(); //表格
- const ref = useRef(); //新增表单
- const [currentRow, setCurrentRow] = useState({});
- const [currentResponsibilityRow, setCurrentResponsibilityRow] = useState({});
- const [expandedRowKeys,setExpandedRowKeys] = useState([]);
- const actionDrawertableRef = useRef(); //Drawertable
- const [drawerVisible, setDrawerVisible] = useState(false);
- const [accountType, setAccountType] = useState(1);
- const [selectedRowKeys,setSelectedRowKeys] = useState([]);
-
- /**
- *
- * @param {Boolean} bool 弹窗展示状态
- */
- const updateModalVisibleChange = (bool) => {
- handleUpdateModalVisible(bool);
- if (!bool) setCurrentRow(undefined);
- };
- //获取科室列表
- const getList = async (params = {}, sort, filter) => {
- const res = await getCostshareparamList(params);
- return {
- data: res.data.list,
- total: res.data.totalCount,
- success: res.success,
- };
- };
- /**
- *
- * @param {Object} value 删除项数据
- */
- const delListHandler = async (value) => {
- const resp = await delCostshareparam(value);
- if (resp.status == 200) {
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- };
- //分摊参数回调
- const drawerVisibleChange = async (bool) => {
- // console.log({currentRow});
- if (bool) {
- if(actionDrawertableRef.current){
- actionDrawertableRef.current.reload();
- }
- }
- setDrawerVisible(bool);
- }
- const getAccountingSubjects = async (params = {}, sort, filter)=>{
- const {id} = currentResponsibilityRow;
- const {accountingIds=[]} = currentRow;
- const result = await getAccountingSubjectList({accountType,shareParamId:id});
- const {status,data:{list}} = result;
- if(status==200){
- const allparents= deepGetAllParents(list,'children');
- const allparentsIds = allparents?allparents.map(item=>item.id):[];
-
- setExpandedRowKeys(allparentsIds);
- const temp = accountingIds&&accountingIds.length>0?accountingIds.map(item=>Number(item)):[];
-
- setSelectedRowKeys(temp);
- return {
- data: list,
- success: true
- };
- }
- }
-
-
- /**
- *
- * @param {*} key tab key
- * @param {*} tableRef dtawer table instance
- */
- const onTabChange = (key,tableRef)=>{
- setAccountType(Number(key));
- if (tableRef.current) {
- tableRef.current.reload();
- }
- }
- return (
- <PageContainer>
- <ProTable
- columns={columns}
- request={getList}
- actionRef={actionRef}
- rowKey="id"
- toolBarRender={() => [
- <Button
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- onClick={() => {
- 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) {
- ref.current.resetFields();
- }
- handleModalVisible(bool);
- }}
- onFinish={async (value) => {
- const success = await addCostshareparam(value);
- // console.log({ success });
- if (success) {
- handleModalVisible(false);
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }}
- >
- <ProFormText
- label="成本分摊参数名"
- rules={[
- {
- required: true,
- message:'成本分摊参数名是必填项',
- },
- ]}
- width="sm"
- name="shareParamName"
- />
- <ProFormText
- label="成本分摊参数编号"
- rules={[
- {
- required: true,
- message:'成本分摊参数编号是必填项',
- },
- ]}
- width="sm"
- name="shareParamCode"
- />
- <ProFormSelect
- rules={[
- {
- required: true,
- message:'请选择计算方式',
- },
- ]}
- options={[
- {
- value: 1,
- label: '手动填写',
- },
- {
- value: 2,
- label: '按对应会计科目计算',
- },
- ]}
- width="sm"
- name="calcType"
- label="计算方式"
- />
- </ModalForm>
- {/* 设置对应会计科目 */}
- <DrawerContent
- columns={drawerTableColumns}
- visible={drawerVisible}
- currentRow={currentRow}
- title={'选择会计科目'}
- defaultSelected={selectedRowKeys}
- pageContainerConfig={(tableRef) => {
- return {
- header: {
- title: ''
- },
- tabList:[
- {
- tab: '收入',
- key: 1,
- },
- {
- tab: '支出',
- key: 2,
- },
- ],
- onTabChange:(key)=>onTabChange(key,tableRef)
- }
- }}
- onVisibleChange={(bool) => drawerVisibleChange(bool)}
- renderListFunc={getAccountingSubjects}
- config={{ rowKeys: 'id', tableSearch: false }}
- tableSearch={false}
- expandable={{
- expandedRowKeys:expandedRowKeys
- }}
- onFinishFunc={async (value, selectedRowKeys, selectedRows) => {
- const {id} = currentResponsibilityRow;
- const resp = await updateCostShareParamByAccountId({costShareParamId:id,accountIds:selectedRowKeys});
- const {status} = resp;
- setDrawerVisible(false);
- if(status==200){
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }}
- />
- {/* <DrawerForm
- title="设置对应会计科目"
- formRef={drawerFormRef}
- visible={drawerVisible}
- onVisibleChange={(visible) => drawerVisibleChange(visible)}
- // onFinish={(value) => onSubmit({ ...values, ...value })}
- onFinish={async () => {
- const {id} = currentResponsibilityRow;
- const resp = await updateCostShareParamByAccountId({costShareParamId:id,accountIds:selectedRowKeys});
- const {status} = resp;
- setDrawerVisible(false);
- if(status==200){
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
-
- }}
- >
- <PageContainer
- header={{
- title:''
- }}
- tabList={[
- {
- tab: '收益',
- key: 1,
- },
- {
- tab: '支出',
- key: 2,
- },
- ]}
- onTabChange={onTabChange}
- >
- <ProTable
- columns={drawerTableColumns}
- rowKey="id"
- actionRef={actionDrawertableRef}
- rowSelection={{
- // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
- // 注释该行则默认不显示下拉选项
- checkStrictly:false,
- selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
- selectedRowKeys:selectedRowKeys,
- onChange:(selectedRowKeys, selectedRows)=>{
- setSelectedRowKeys(selectedRowKeys);
- }
- }}
- tableAlertRender={({ selectedRowKeys, selectedRows, onCleanSelected }) =>{
- setSelectedRowKeys(selectedRowKeys);
- return (
- <Space size={24}>
- <span>
- 已选 {selectedRowKeys.length} 项
- <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
- 取消选择
- </a>
- </span>
- </Space>
- )
- }}
- request={async (params = {}, sort, filter) => {
- const {id} = currentResponsibilityRow;
- const result = await getAccountingSubjectList({accountType,shareParamId:id});
- const {status,data} = result;
- if(status==200){
- const selectedList = data.list.filter(item=>item.isSelect);
- const temp = selectedList.map(item=>item.id);
- setSelectedRowKeys(temp);
- return {
- data: data.list,
- success: true
- };
- }
- }}
- pagination={{
- pageSize: 10,
- }}
- search={false}
- />
- </PageContainer>
-
- </DrawerForm> */}
- {/* 更新 */}
- <UpdateForm
- onSubmit={async (value) => {
- console.log({ '编辑': value });
- const success = await editCostshareparamList(value);
- if (success) {
- handleUpdateModalVisible(false);
- setCurrentRow(undefined);
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }}
- onCancel={() => {
- handleUpdateModalVisible(false);
- setCurrentRow(undefined);
- }}
- updateModalVisible={updateModalVisible}
- updateModalVisibleChange={updateModalVisibleChange}
- values={currentRow || {}}
- />
- </PageContainer>
- );
- };
- export default CostAllocationParamsSetting;
|