import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, Table, Select, Pagination, Space, Menu, Dropdown, Modal, Breadcrumb, message, Row, Col } from 'antd';
import { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import AddDict from './addDict'
import '@common/common.less';
import { useSelector } from 'react-redux'
import apiObj from '@api/index';
import DictContext from './Dict-context';
const { post, api, xPost } = apiObj;
const { Option } = Select;
//获取列表
function DictManager() {
useEffect(() => {
getDictPage();
}, []);
const [DictList, setDictList] = useState([]);//当前页列表数据
const [Dictid, setDictid] = useState([]);//当前列表id
const [title, setTitle] = useState("");//数据总量
const [visible, setVisible] = useState(false);//弹窗
const [msvisible, setMsvisible] = useState(false);//删除的弹窗
const [modalType, setModalType] = useState("");
const [groupTypeList, setgroupTypeList] = useState([]);//代码类别模糊查找
const [type, setType] = useState("");
const [formData, setFormData] = useState(null);//当前行数据
const [size, setSize] = useState(15);//每页显示条数
const [total, setTotal] = useState(0);
const [current, setCurrent] = useState(1);//当前页
const [params, setParams] = useState({
pages: 1,
current: 1,
size: 15
});
const [form] = Form.useForm();
let list = []
let data = {
pages: 1,
current: 1,
size: size
}
//新增弹窗
const showModal = (name, type, flag, Dictrow) => {
setVisible(type);
setTitle(name);
setType(flag)
if (flag == 1) {
setFormData({
status: '1'
})
}
if (flag == 3) {
setFormData(Dictrow)
getDictPage()
}
}
//表格数据
function getDictPage(param) {
post(api.getDictTree, param || params).then((res) => {
if (res.data.code === 200) {
const data = res.data.data;
console.log(data.records)
setDictList(data.records);
setTotal(data.total)
}
})
}
//模糊查询
function getCodeCategory(val){
xPost(api.getCodeCategory,{groupType:val}).then((res) => {
if (res.data.code === 200) {
const data = res.data.data;
setgroupTypeList(data)
}
})
}
function onSearch(value) {
getCodeCategory(value)
}
function onFocus() {
getCodeCategory("")
}
//删除
function deleteDict() {
xPost(api.deleteDict,{id:Dictid}).then((res) => {
if (res.data.code === 200) {
getDictPage();
setMsvisible(false);
setDictid(null)
message.success("删除成功");
} else {
message.warning(res.data.msg || '操作失败');
}
}).catch(() => {
message.error("接口出错");
});
}
//每页显示条数切换
function onSizeChange(current, pageSize) {
params.current = current
params.size = pageSize
setSize(pageSize)
setCurrent(current)
setParams(params)
getDictPage()
}
//翻页
function changePage(page, pageSize) {
params.current = page
params.size = pageSize
setCurrent(page)
setParams(params)
getDictPage()
}
const onFinish = (value) => {
const param = {
...data,
...value
}
setCurrent(1)
setParams(param)
getDictPage(param);
};
const onReset = () => {
setCurrent(1)
setParams(data)
form.resetFields();
getDictPage(data);
};
const messageBox = (id) => {
setDictid(id)
setMsvisible(true)
}
//提示框取消
function handleCancel() {
setMsvisible(false);
}
function cancel() {
setVisible(false)
setFormData(null)
}
function DictChange() {
setVisible(false)
getDictPage();
}
const columns = [
{ title: '代码类别', dataIndex: 'groupType', key: 'index' },
{ title: '字典编码', dataIndex: 'val', key: 'index' },
{ title: '代码名称', dataIndex: 'name', key: 'index' },
{ title: '字典说明', dataIndex: 'remark', key: 'index' },
{ title: '状态', dataIndex: 'status', key: 'status'},
{
title: '操作', dataIndex: 'key', render: (text, record) => (