/* * @Author: your name * @Date: 2021-07-26 10:13:13 * @LastEditTime: 2021-08-30 15:57:46 * @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} from 'antd'; import React, { useState, useRef} from 'react'; import { useModel } from 'umi'; import { PageContainer } from '@ant-design/pro-layout'; import ProTable from '@ant-design/pro-table'; import { ModalForm, ProFormText} from '@ant-design/pro-form'; import UpdateForm from './updateForm'; import CAUpload from '@/components/CAUpload'; import { getCostProjecttList, editCostProject, delCostProject, addCostProject,importExcel } from './service'; const CostProjectMana = () => { const columns = [ { title: 'Id', dataIndex: 'id', key: 'id', hideInTable: true, hideInSearch: true, }, { title: '成本编号', dataIndex: 'productCode', key: 'productCode', hideInSearch: true, }, { title: '成本项目名', dataIndex: 'productName', key: 'productName', hideInSearch: false, }, { title:'操作', dataIndex: 'option', valueType: 'option', render: (_, record) => [ { handleUpdateModalVisible(true); setCurrentRow(record); }} > 编辑 , { setCurrentRow(record); delListHandler(record); }} > 删除 , ], }, ]; const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); const actionRef = useRef(); //表格 const ref = useRef(); //新增表单 const [currentRow, setCurrentRow] = useState({}); const { initialState, setInitialState } = useModel('@@initialState'); const {currentUser:{token}} = initialState; /** * * @param {Boolean} bool 弹窗展示状态 */ const updateModalVisibleChange = (bool) => { handleUpdateModalVisible(bool); if (!bool) setCurrentRow(undefined); }; //获取科室列表 const getList = async (params = {}, sort, filter) => { const res = await getCostProjecttList(params); return { data: res.data.list, total: res.data.totalCount, success: res.success, }; }; /** * * @param {Object} value 删除项数据 */ const delListHandler = async (value) => { const resp = await delCostProject(value); if (resp.status == 200) { if (actionRef.current) { actionRef.current.reload(); } } }; //自定义上传回调 /** * * @param {FormData} formData */ const customRequestCallback = async (formData)=>{ const resp = await importExcel({formData},{ 'content-type':'multipart/form-data', }) const {status} = resp; if(status==200){ if (actionRef.current) { actionRef.current.reload(); } } } return ( [ , { }} token={token} customRequestCallback={customRequestCallback} /> ]} pagination={{ pageSize: 10, }} search={{ defaultCollapsed: false, labelWidth: 'auto', }} /> { if (ref.current) { ref.current.resetFields(); } handleModalVisible(bool); }} onFinish={async (value) => { const success = await addCostProject(value); // console.log({ success }); if (success) { handleModalVisible(false); if (actionRef.current) { actionRef.current.reload(); } } }} > {/* 更新 */} { // console.log({ '编辑': value }); const success = await editCostProject(value); if (success) { handleUpdateModalVisible(false); setCurrentRow(undefined); if (actionRef.current) { actionRef.current.reload(); } } }} onCancel={() => { handleUpdateModalVisible(false); setCurrentRow(undefined); }} updateModalVisible={updateModalVisible} updateModalVisibleChange={updateModalVisibleChange} values={currentRow || {}} /> ); }; export default CostProjectMana;